Subscribe Pro PaymentFields Widget API


The following documentation describes the Subscribe ProPaymentFields Widget API, including methods, events, and configuration options.

Accessing the PaymentFields Widget

Access the Subscribe Pro PaymentFields Widget by referencing the global PaymentFields object.

PaymentFields.init(config: PaymentFieldsConfig)

The Subscribe Pro PaymentFields Widget script is configured by passing a configuration object to the PaymentFields.init() function. The configuration object has the following properties:

PaymentFieldsConfig Type

interface PaymentFieldsConfig {
  apiBaseUrl?: string;
  oauthApiToken?: string;
  spVaultEnvironmentId: string;
  paymentMethodType?: PaymentMethodType;
  enableCvv?: boolean;
  enableThreeDs?: boolean;
  enablePrettyFormat?: boolean;  
  numberIframe?: {
    container: string;
    inputStyle?: string;
  };
  cvvIframe?: {
    container: string;
    inputStyle?: string;
  };
  accountIframe?: {
    container: string;
    inputStyle?: string;
  };
  threeDsChallengeIframe?: {
    container: string;
  };
}

PaymentFieldsConfig Properties

PropertyRequiredTypeDescription
apiBaseUrlStringThe URL of the Subscribe Pro API to use.
Default: https://api.subscribepro.com
oauthApiTokenStringThe OAuth API token to use for authentication. This should be a customer scoped OAuth token which was fetched server-side.
vaultEnvironmentIdYesStringThe ID of the Subscribe Pro Vault environment to use. This is a UUID which you should retrieve from the Subscribe Pro Commerce Platform environment you are using. This value is returned in an OAuth token response.
paymentMethodTypeStringThe type of payment method to tokenize. One of: credit_card, bank_account, sepa
enableCvvBooleanWhether or not to show the CVV field.
Default: true
enableThreeDsBooleanWhether or not to enable 3D Secure 2 authentication.
Default: true
enablePrettyFormatBooleanWhether or not to enable pretty formatting of the card number.
Default: true
numberIframeObjectAn object containing configuration for the card number iframe.
numberIframe.containerYesStringThe ID of the <div> element in which to place the card number iframe.
numberIframe.inputStyleStringA string containing CSS styles to apply to the card number input element.
cvvIframeObjectAn object containing configuration for the CVV iframe.
cvvIframe.containerYesStringThe ID of the <div> element in which to place the CVV iframe.
cvvIframe.inputStyleStringA string containing CSS styles to apply to the CVV input element.
accountIframeObjectAn object containing configuration for the bank account iframe.
accountIframe.containerYesStringThe ID of the <div> element in which to place the bank account iframe.
accountIframe.inputStyleStringA string containing CSS styles to apply to the bank account input element.
threeDsChallengeIframeObjectAn object containing configuration for the 3D Secure 2 challenge iframe.
threeDsChallengeIframe.containerYesStringThe ID of the <div> element in which to place the 3D Secure 2 challenge iframe.

PaymentFields.unmount()

Unmounts the PaymentFields widget iFrames from the DOM. Call PaymentFields.init() to re-mount the widget.

PaymentFields.on(eventName, callback)

This method allows you to register a callback function to be called when the specified event occurs.

Please see here for detail about each event type and the data returned to the event handler callback function: Subscribe Pro PaymentFields Widget Events

PaymentFields.tokenize(args: TokenizeArgs): TokenizeResult

Tokenizes the card data entered into the card number and CVV fields (or other payment data) and optionally initiates a 3D Secure 2 authentication flow.

TokenizeArgs

interface TokenizeArgs {
  authenticateCardholder?: boolean;
  authenticationType?: AuthenticationType;
  paymentDetails?: {
    amount: string;
  };
  cardDetails?: {
    creditcardMonth: string;
    creditcardYear: string;
  };
  customerEmail?: string;
  billingAddress?: {
    firstName: string;
    middleName?: string;
    lastName: string;
    street1?: string;
    street2?: string;
    street3?: string;
    city?: string;
    region?: string;
    postcode?: string;
    country?: string;
  };
  shippingAddress?: {
    firstName: string;
    middleName?: string;
    lastName: string;
    street1?: string;
    street2?: string;
    street3?: string;
    city?: string;
    region?: string;
    postcode?: string;
    country?: string;
  };
}

TokenizeArgs Properties

PropertyRequiredTypeDescription
authenticateCardholderBooleanWhether or not to initiate a 3D Secure 2 authentication flow.
Default: false
authenticationTypeStringThe type of 3D Secure 2 authentication to use - corresponds to whether the credit card is being collected in the context of a payment or not.
One of: payment, non_payment
Required if authenticateCardholder is true.
paymentDetailsObjectAn object containing details about the payment.
Required if authenticationType is payment.
paymentDetails.amountYesStringThe amount of the payment.
cardDetailsObjectAn object containing details about the credit card.
Required if PaymentFields configured for credit card.
cardDetails.creditcardMonthYesStringThe month of the credit card expiration date.
cardDetails.creditcardYearYesStringThe year of the credit card expiration date.
customerEmailStringThe email address of the customer.
billingAddressObjectAn object containing details about the billing address for a payment and for 3D Secure 2 authentication.
billingAddress.firstNameYesStringThe first name of the customer.
billingAddress.middleNameStringThe middle name of the customer.
billingAddress.lastNameYesStringThe last name of the customer.
billingAddress.street1StringThe first line of the street address.
billingAddress.street2StringThe second line of the street address.
billingAddress.street3StringThe third line of the street address.
billingAddress.cityStringThe city of the address.
billingAddress.regionStringThe region (state, province, etc) of the address.
billingAddress.postcodeStringThe postal code of the address.
billingAddress.countryStringThe country of the address.
shippingAddressObjectAn object containing details about the shipping address for a payment and for 3D Secure 2 authentication.
shippingAddress.firstNameYesStringThe first name of the customer.
shippingAddress.middleNameStringThe middle name of the customer.
shippingAddress.lastNameYesStringThe last name of the customer.
shippingAddress.street1StringThe first line of the street address.
shippingAddress.street2StringThe second line of the street address.
shippingAddress.street3StringThe third line of the street address.
shippingAddress.cityStringThe city of the address.
shippingAddress.regionStringThe region (state, province, etc) of the address.
shippingAddress.postcodeStringThe postal code of the address.
shippingAddress.countryStringThe country of the address.