1.1.1 • Published 1 year ago
@guestyorg/tokenization-js v1.1.1
Guesty Tokenization JS SDK
There are two ways to integrate the SDK:
Manually include a script tag
Add a script tag to your application head or body.
This loads guestyTokenization object to the global window scope of the browser
<script src="https://pay.guesty.com/tokenization/v1/init.js"></script>Use it as an ES module
Advantages of loading the SDK as a module:
- loads script asynchronously to ensure page rendering isn't blocked
- returns a Promise to know when script loading is complete
- resolves to nullif called in a server environment
Note: To be PCI-compliant, you must load the SDK directly from https://pay.guesty.com (either by adding a script tag or using the ES module). You cannot include it in a bundle or host it yourself.
Installation
Use npm to install the Guesty Tokenization JS module:
npm install @guestyorg/tokenization-jsUsage
Import the loadScript function for asynchronously loading the Guesty Tokenization JS SDK
loadScript(options?)
- accepts an optionsobject to configure script URL and attributes
- returns a Promise that resolves with window.guestyTokenizationafter the SDK is finished loading
options
- sandbox- load the SDK in a sandbox mode
- version- SDK version to load (default:- v1)
loadScript({ sandbox: true });This is equivalent to the following script:
<script
  src="https://pay.guesty.com/tokenization/v1/init.js"
  data-env="sandbox"
></script>Async/Await
import { loadScript } from '@guestyorg/tokenization-js';
try {
  const guestyTokenization = await loadScript();
  // Guesty Tokenization JS SDK is loaded and ready to use
} catch (error) {
  console.error('Failed to load the Guesty Tokenization JS SDK script', error);
}Promises
import { loadScript } from '@guestyorg/tokenization-js';
loadScript()
  .then((guestyTokenization) => {
    // Guesty Tokenization JS SDK is loaded and ready to use
  })
  .catch((error) => {
    console.error(
      'Failed to load the Guesty Tokenization JS SDK script',
      error
    );
  });TypeScript Support
This package includes TypeScript type definitions for the Guesty Tokenization JS SDK. This includes types for the window.guestyTokenization namespace. We support projects using TypeScript versions >= 3.8.