npm package: @switchio/st-rp-sdk
Description: The ST RP SDK provides high-level API for tokenization processing via ST. Provides functions to redirect to tokenization page, open tokenization as modal or embedded iframe and handle tokenization responses.
Latest version: 1.0.2

# Switchio ST RP SDK

The ST RP SDK provides high-level API for tokenization processing via ST. Provides functions to redirect to tokenization page, open tokenization as modal or embedded iframe and handle tokenization responses.

The SDK is built with ES2015 target in ESM format, which is supported in all modern browsers. It is recommended to use bundler and minification for production use.

The documentation of specific methods and parameters is directly in the code as javadoc which works well with TypeScript.

## Installation via npm

```sh
npm install @switchio/st-rp-sdk
```

## Usage

It's recommended to pull in all you need directly from `'@switchio/st-rp-sdk'` as shown below with `StRpClient`.

### Example

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>ST RP SDK demo</title>
  </head>
  <body style="background-color: lightgray">
    <script type="module">
      import { StRpClient } from './node_modules/@switchio/st-rp-sdk/index.js';

      if (window.location.href.search('state=tokenize') > -1) {
        StRpClient.handleTokenizeWithRedirectCallback().then((x) => {
          if (x.type === 'success') {
            console.log('Successfully tokenized.', x);
            return;
          }
          console.log('Tokenization failed.', x);
        });
      }

      function tokenizeWithRedirect(gtwUrl) {
        StRpClient.tokenizeWithRedirect({
          tokenizationParams: { uri: gtwUrl },
          state: 'tokenize',
        });
      }

      function tokenizeInIframeModal(gtwUrl) {
        StRpClient.tokenizeInIframe({
          tokenizationParams: { uri: gtwUrl },
          festparams: { mode: 'modal' },
        }).then((x) => {
          if (x.type === 'success') {
            console.log('Successfully tokenized.', x);
            return;
          }
          console.log('Tokenization failed.', x);
        });
      }

      function tokenizeInIframeEmbedded(gtwUrl) {
        StRpClient.tokenizeInIframe({
          tokenizationParams: { uri: gtwUrl },
          festparams: { mode: 'embedded' },
          parentElement: document.getElementById('container'),
          iframeOptions: {
            style: {
              width: '400px',
              margin: 'auto',
              display: 'block',
              height: '0',
              border: '0',
              overflow: 'hidden',
            },
          },
        }).then((x) => {
          if (x.type === 'success') {
            console.log('Successfully tokenized.', x);
            return;
          }
          console.log('Tokenization failed.', x);
        });
      }

      console.log("Type tokenizeWithRedirect('YOUR_GTW_URL'), tokenizeInIframeModal('YOUR_GTW_URL') or tokenizeInIframeEmbedded('YOUR_GTW_URL') to console for start processing tokenization.");

      window.tokenizeWithRedirect = tokenizeWithRedirect;
      window.tokenizeInIframeModal = tokenizeInIframeModal;
      window.tokenizeInIframeEmbedded = tokenizeInIframeEmbedded;
    </script>
    <div id="container"></div>
  </body>
</html>
```

## Changelog

### 1.0.2

(2025-04-15)

- Update documentation.

### 1.0.1

(2025-04-15)

- New build system.

### 1.0.0

(2023-02-17)

- Initial library version.