3.1.0 • Published 16 days ago

@unlimint/client-js-sdk v3.1.0

Weekly downloads
-
License
-
Repository
-
Last release
16 days ago

JavaScript SDK

JavaScript SDK provides integration-ready widgets suit for embedding into your application.

Kit contains a pre-made customizable UI featuring bank cards binding and payments acceptance form.

Getting started

Widget is a component that is embedded in iframe; refer to examples below.

  1. Create an element with an iframe in.
<iframe id="js-sdk" src="https://<environment>/js-sdk-frame/#/<form>"></iframe>

Possible environment values: sandbox.cardpay.com, unlimint.com/js-sdk-frame. It is recommended to use the sandbox environment for testing the js sdk.

Possible form values: card-form, pay-form, pay-by-saved-card-form

  1. Setup props for a form.
  2. Include data in form.
  3. Pass the data to the iframe.
// Find iframe element
const iframe = document.getElementById('js-sdk');

// Pass config if iframe loaded
iframe.addEventListener('load', function () {
  iframe.contentWindow.postMessage({ props }, '*');
});

// Add listener for receive data from iframe
window.addEventListener('message', function (data) {
  console.log('data', data);
});
  • Alternatively, you can use the wrapper to work with the js-sdk:
npm i @unlimint/client-js-sdk
  • Import js-sdk main file:
import '@unlimint/client-js-sdk/main.js';
  • Find for an element to embed an iframe (for example, it can be an empty div):
const element = document.getElementById('js-sdk');
  • Call load js-sdk function:
loadJsSdk({
  // Select js-sdk form (available values: card, pay, pay-token)
  form: 'card',
  // Pass element
  element,
  // Select sandbox env for debugging the js sdk
  environment: 'sandbox',
  // Pass props
  props,
  // Pass callback for listen iframe messages
  callback: (data) => {
    console.log(data);
  },
});

The default styling in JS SDK is made via Inter font. If you do not plan applying customizations with another font, then you have to include Inter separately:

<link
  href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap"
  rel="stylesheet"
/>

If your application contains TypeScript you can include *.d.ts annotations file to enable types checking into widget creation process.

TypeScript compiler includes these annotations into widget's data.


Widgets require URL addresses to receive requests. URLs must be pointed in propsurls property.

The supported URLs:

  • generateMobileToken - endpoint for mobile token generation, used in widget for authorization

Mobile token endpoint addresses:

It is possible to specify which environment to use. isProdMode can be specified in propsurls property. By default, the sandbox is used.


Widgets allow to setup enableRedirect property having true/false value; false by default:

  • true - after widget's form submitting user is redirected on the next step of flow via URL provided by processing backend, but callbacksresolve property will be ignored

CardForm widget

CardForm widget contains a form for bank card binding feature.

The form allows customer to fill in card's data and save (bind) it for further payments in order to make the purchasing process quick and simple.

npm.io

npm.io

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <iframe id="js-sdk" src="https://<environment>/js-sdk-frame/#/card-form"></iframe>

    <script>
      const props = {
        urls: {
          generateMobileToken: 'https://sandbox.cardpay.com/demo-merchant/mobile/generate_token',
          cardBinding: 'https://sandbox.cardpay.com/api/mobile/cardbinding',
        },
        enableRedirect: false,
        data: {
          recurringCurrency: 'USD',
          customer: {
            id: 'DfVg56Gvx',
            email: 'test@test.test',
          },
          returnUrls: {
            successUrl: 'https://example.com/success',
            declineUrl: 'https://example.com/decline',
          },
        },
      };

      // Find iframe element
      const iframe = document.getElementById('js-sdk');

      // Pass config if iframe loaded
      iframe.addEventListener('load', function () {
        iframe.contentWindow.postMessage({ props }, '*');
      });

      // Add listener for receive data from iframe
      window.addEventListener('message', function (data) {
        console.log('data', data);
      });
    </script>
  </body>
</html>

PayForm widget

PayForm widget contains a form for bank card payment feature. Form allows customer to fill in card's data and confirm payment. The card binding option is included too.

npm.io

npm.io

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <iframe id="js-sdk" src="https://<environment>/js-sdk-frame/#/pay-form"></iframe>

    <script>
      const props = {
        urls: {
          generateMobileToken: 'https://sandbox.cardpay.com/demo-merchant/mobile/generate_token',
          payment: 'https://sandbox.cardpay.com/api/mobile/payment',
        },
        enableRedirect: false,
        data: {
          merchantName: 'Merchant Name',
          merchantOrder: {
            description: 'description',
            id: '21513-216',
          },
          paymentMethod: 'BANKCARD',
          paymentData: {
            amount: '9700.00',
            currency: 'USD',
          },
          customer: {
            email: 'test@test.test',
          },
          returnUrls: {
            successUrl: 'https://example.com/success',
            declineUrl: 'https://example.com/decline',
          },
        },
      };

      // Find iframe element
      const iframe = document.getElementById('js-sdk');

      // Pass config if iframe loaded
      iframe.addEventListener('load', function () {
        iframe.contentWindow.postMessage({ props }, '*');
      });

      // Add listener for receive data from iframe
      window.addEventListener('message', function (data) {
        console.log('data', data);
      });
    </script>
  </body>
</html>

PayBySavedCardForm widget

PayBySavedCardForm widget contains a form for payment by saved card. Form allows customer to fill in CVV2/CVC2 code only and confirm payment.

npm.io

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <iframe id="js-sdk" src="https://<environment>/js-sdk-frame/#/pay-by-saved-card-form"></iframe>

    <script>
      const props = {
        urls: {
          generateMobileToken: 'https://sandbox.cardpay.com/demo-merchant/mobile/generate_token',
          payment: 'https://sandbox.cardpay.com/api/mobile/payment',
        },
        enableRedirect: false,
        data: {
          token: 'e51745bb-1865-5ceb-f20c-ade2c7a4f70e',
          lastDigits: '0002',
          merchantName: 'Merchant Name',
          merchantOrder: {
            description: 'description',
            id: '21513-216',
          },
          paymentMethod: 'BANKCARD',
          paymentData: {
            amount: '9700.00',
            currency: 'USD',
          },
          customer: {
            email: 'test@test.test',
          },
          returnUrls: {
            successUrl: 'https://example.com/success',
            declineUrl: 'https://example.com/decline',
          },
        },
      };

      // Find iframe element
      const iframe = document.getElementById('js-sdk');

      // Pass config if iframe loaded
      iframe.addEventListener('load', function () {
        iframe.contentWindow.postMessage({ props }, '*');
      });

      // Add listener for receive data from iframe
      window.addEventListener('message', function (data) {
        console.log('data', data);
      });
    </script>
  </body>
</html>

Entry data

Widgets accept entry data required for successful card binding or payment operation.

The entry data must be included during widget creation in propsdata property.

CardForm data

CardForm widget accepts the following parameters:

FieldSubfield 1Subfield 2TypeMin. lengthMax. lengthIs mandatoryDescription
merchantOrderNoMerchant order data.
idString50NoOrder ID used by the merchant’s shopping cart.
descriptionString200NoDescription of product/service being sold.
recurringCurrencyString3YesISO 4217 currency code (optional if paymentData is declared)
paymentDataIs mandatory if recurringCurrency is not declared.
generateTokenBooleanNoIf set to "true", token will be generated and returned in the response. Token can be generated only for successful transactions (not for declined transactions).
currencyString3YesISO 4217 currency code.
billingAddressNoAddress for billing.
countryString23YesISO 3166-1 code of billing country: 2 or 3 latin letters or numeric code.
stateString40NoThe state or province of the billing address associated with the card being used for this purchase.It's recommended to sent in following format: The country subdivision code defined in ISO 3166-2.May include whitespaces, hyphens, apostrophes, commas and dots.
zipString12YesBilling postal code.
cityString50YesBilling city. May include whitespaces, hyphens, apostrophes, commas and dots.
addrLine1String50YesFirst line of the street address or equivalent local portion of the Cardholder billing address associated with the card used for this purchase.May include whitespaces, hyphens, apostrophes, commas, quotes, dots, slashes and semicolons.Required (if available) unless market or regional mandate restricts sending this information.
addrLine2String50NoSecond line of the street address or equivalent local portion of the Cardholder billing address associated with the card used for this purchase. Required (if available) unless market or regional mandate restricts sending this information.
customerYesCustomer data.
emailString256YesCustomer’s e-mail address.Optional for wallets where setting in PM "May omit customer email" is enabled.
idString15YesCustomer ID is a unique identifier of a cardholder at the Recurring payments service. Each card used by a cardholder within the service is linked to Customer ID and Filing ID.
deviceNoCustomer's device.
fingerprintString256NoThe fingerprint of device.
ipString15NoCustomer’s IPv4. Mandatory only for S2S mode.
localeString2NoPreferred locale for the payment page (ISO 639-1 language code).The default locale (en or other locale if it's set as default in Merchant account) will be applied if the selected locale (received in request) is not supported.Supported locales are: ar, az, bg, cs, de, el, en, es, fr, hu, hy, id, it, ja, ka, ko, ms, nl, pl, pt, ro, ru, sr, sv, th, tr, uk, vi, zh.
phoneString818NoCustomer’s phone number.Recommended to send phone number in following format "+1 111111111" with country code and subscriber sections (only digits are accepted) of the number, "+" as prefix and "space" as delimiter.Refer to ITU-E.164 for additional information on format and length.Mandatory for wallets where setting in PM "May omit customer email" is enabled and customer.email isn't presented in request.
homePhoneString818NoThe home phone number provided by the Cardholder. Required (if available) unless market or regional mandate restricts sending this information.Characters format: recommended to send phone number in following format "+1 111111111" with country code and subscriber sections (only digits are accepted) of the number, "+" as prefix and "space" as delimiter.Refer to ITU-E.164 for additional information on format and length.
workPhoneString818NoThe work phone number provided by the Cardholder. Required (if available) unless market or regional mandate restricts sending this information.Characters format: recommended to send phone number in following format "+1 111111111" with country code and subscriber sections (only digits are accepted) of the number, "+" as prefix and "space" as delimiter.Refer to ITU-E.164 for additional information on format and length.
returnUrlsNoReturn URLs are the URLs where customer returns by pressing “Back to the shop” or “Cancel” button in Payment Page mode and redirected automatically in Gateway mode.
returnUrlString512NoOverrides default success URL, decline URL, cancel URL (only in Payment page mode), inprocess URL.return URL can be used separately or together with other url parameters.
successUrlString512NoOverrides default success URL only.
declineUrlString512NoOverrides default decline URL only.
cancelUrlString512NoOverrides default cancel URL only.
inprocessUrlString512NoSpecial URL for In process status of transaction.
settingsNoSettings parameters.
cardholderNoDefines the cardholder name input field element on the form.
requiredBooleanNoSupported values:• true - customer must enter a valid cardholder name• false - cardholder name is an optional field

PayForm data

PayForm widget accepts the following parameters:

FieldSubfield 1Subfield 2TypeMin. lengthMax. lengthIs mandatoryDescription
merchantNameString150NoMerchant order data.
merchantOrderYesMerchant order data.
idString50YesOrder ID used by the merchant’s shopping cart.
descriptionString200YesDescription of product/service being sold.
itemsNoArray of items (in the shopping cart).
nameString50YesThe name of product / service, provided to the customer.
descriptionString200NoThe description of product / service, provided to the customer.
countIntegerNoThe count of product / service, provided to the customer.
priceDecimalNoPrice of product / service with dot as a decimal separator.
shippingAddressNoShipping Address
countryString23YesISO 3166-1 code of delivery country: 2 or 3 latin letters or numeric code
stateString40NoThe state or province of the shipping address associated with the card being used for this purchase.It's recommended to send in following format: The country subdivision code defined in ISO 3166-2.May include whitespaces, hyphens, apostrophes, commas and dots.
zipString12NoDelivery postal code.
cityString50NoDelivery city. May include whitespaces, hyphens, apostrophes, commas and dots
phoneString520NoValid customer phone number
addrLine1String50NoFirst line of the street address or equivalent local portion of the Cardholder shipping address associated with the card used for this purchase. May include street and house number.
addrLine2String50NoSecond line of the street address or equivalent local portion of the Cardholder shipping address associated with the card used for this purchase.
paymentMethodString50YesPayment method type name; insert BANKCARD value.
paymentDataYes
amountDecimalYesThe total transaction amount in selected currency with dot as a decimal separator, must be less than 100 millions.
currencyString3YesISO 4217 currency code.
preauthBooleanNoOption allows to hold on customer funds before providing a service; supported values:• true - enable holding• false - skip holding
noteString100NoNote about the transaction that will not be displayed to customer.
dynamicDescriptorString25NoShort description of the service or product, must be enabled by your manager to be used.For Visa cards: maximum length 25 symbols, for MasterCard cards - 22 symbols.
transTypeString22NoIdentifies the type of transaction being authenticated.Supported values:• 01 = Goods / Service Purchase• 03 = Check Acceptance• 10 = Account Funding • 11 = Quasi-Cash Transaction• 28 = Prepaid Activation and Load Note: Values derived from the 8583 ISO Standard.
billingAddressNoBilling Address.
countryString23YesISO 3166-1 code of billing country: 2 or 3 latin letters or numeric code.
stateString40NoThe state or province of the billing address associated with the card being used for this purchase.It's recommended to send in following format: The country subdivision code defined in ISO 3166-2.May include whitespaces, hyphens, apostrophes, commas and dots.
zipString12YesBilling postal code.
cityString50YesBilling city. May include whitespaces, hyphens, apostrophes, commas and dots.
addrLine1String50YesFirst line of the street address or equivalent local portion of the Cardholder billing address associated with the card used for this purchase.May include whitespaces, hyphens, apostrophes, commas, quotes, dots, slashes and semicolons.Required (if available) unless market or regional mandate restricts sending this information.1-PA: Required unless market or regional mandate restricts sending this information.02-NPA: Required (if available) unless market or regional mandate restricts sending this information.
addrLine2String50NoSecond line of the street address or equivalent local portion of the Cardholder billing address associated with the card used for this purchase. Required (if available) unless market or regional mandate restricts sending this information.
customerYesCustomer data.
emailString256YesEmail address of the customer.Field is Optional for wallets where setting in PM "May omit customer email" is enabled.
deviceNoCustomer's device.
fingerprintString256NoThe fingerprint of device.
localeString2NoPreferred locale for the payment page (ISO 639-1 language code).The default locale (en or other locale if it's set as default in Merchant account) will be applied if the selected locale (received in request) is not supported. Supported locales are: ar, az, bg, cs, de, el, en, es, fr, hu, hy, id, it, ja, ka, ko, ms, nl, pl, pt, ro, ru, sr, sv, th, tr, uk, vi, zh.
homePhoneString818NoThe home phone number provided by the Cardholder. Required (if available) unless market or regional mandate restricts sending this information.Characters format: recommended to send phone number in following format "+1 111111111" with country code and subscriber sections (only digits are accepted) of the number, "+" as prefix and "space" as delimiter.Refer to ITU-E.164 for additional information on format and length.
workPhoneString818NoThe work phone number provided by the Cardholder. Required (if available) unless market or regional mandate restricts sending this information.Characters format: recommended to send phone number in following format "+1 111111111" with country code and subscriber sections (only digits are accepted) of the number, "+" as prefix and "space" as delimiter.Refer to ITU-E.164 for additional information on format and length.
returnUrlsNoReturn URLs are the URLs where customer returns by pressing “Back to the shop” or “Cancel” button in Payment Page mode and redirected automatically in Gateway mode.
returnUrlString512NoOverrides default success URL, decline URL, cancel URL (only in Payment page mode), inprocess URL.Return URL can be used separately or together with other url parameters.
successUrlString512NoOverrides default success URL only.
declineUrlString512NoOverrides default decline URL only.
cancelUrlString512NoOverrides default cancel URL only.
inprocessUrlString512NoSpecial URL for In process status of transaction.
settingsNoSettings parameters.
cardholderNoDefines the cardholder name input field element on the form.
requiredBooleanNoSupported values:• true - customer must enter a valid cardholder name• false - cardholder name is an optional field

PayBySavedCard data

PayBySavedCard widget accepts the following parameters:

FieldSubfield 1Subfield 2TypeMin. lengthMax. lengthIs mandatoryDescription
tokenString128YesSaved card token.
lastDigitsString44YesThe 4 last digits of saved card.
merchantNameString150NoMerchant order data.
merchantOrderYesMerchant order data.
3.1.0

16 days ago

3.0.1

16 days ago

2.17.0

2 months ago

3.0.0-next.0

2 months ago

2.16.0

3 months ago

2.15.0

4 months ago

2.13.0

10 months ago

2.14.0

7 months ago

2.11.0

12 months ago

2.12.0

11 months ago

2.9.1

1 year ago

2.10.0

1 year ago

2.9.0

1 year ago

2.8.0

1 year ago

2.7.0

1 year ago

2.6.0

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.0-next.2

3 years ago

2.0.0-next.1

3 years ago

2.0.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago