Subscribe Pro PaymentFields Widget Events


The Subscribe Pro PaymentFields Widget fires numerous events during its lifecycle. You can register event handlers for these events using the PaymentFields.on() method.

List of Events

The following events are fired by the Subscribe Pro PaymentFields Widget:

eventNameDescription
initializedFired when the PaymentFields Widget has been initialized.
inputEventFired when an input event occurs in one of the payment iFrames.
validationResultChangedFired when validation has occurred and the result has changed.
challengeShownFired when 3D Secure 2 challenge content is shown in the configured element.
challengeHiddenFired when 3D Secure 2 challenge content is hidden.
tokenizeFired when the tokenize() method completes.

Event: initialized

This event if fired after the PaymentFields Widget is completely initialized and ready to use.

No arguments are passed to the callback function.

Example

PaymentFields.on('initialized', () => {
  console.log('PaymentFields was initialized.');
});

Event: inputEvent

This event is fired when an input event occurs inside one the fields inside one of the hosted iFrames.

Example

IframeClient.on('inputEvent', (args) => {
  console.log('Iframe inputEvent received.', args);
});

Example of args

{
  "fieldCode": "number",
  "eventType": "focus"
}

Properties of the args Object (for inputEvent)

PropertyTypeDescription
fieldCodeStringIndicates which field has fired the event: number, cvv, account or other.
eventTypeStringThe name of the event which was fired by the browser on the <input> element. The following events are passed through: focus, blur, input.

Event: validationResultChanged

Event is fired when validation of credit card number and CVV has occurred and the result has changed (for example when a card number goes from being invalid to valid).

Example

IframeClient.on('validationResultChanged', (args) => {
  console.log('In on.validationResultChanged.');
  console.log(args?.validationResult);
});

Example of args

{
  "validationResult": {
    "cardType": "american_express",
    "isNumberValid": true,
    "isNumberPotentiallyValid": true,
    "isCvvValid": false,
    "isCvvPotentiallyValid": true
  }
}

Properties of the args.validationResult Object (for validationResultChanged)

PropertyTypeDescription
cardTypeStringDetected credit card type: 'visa', 'american_express', 'master', etc.
isNumberValidBooleanIs the card number fully validated.
isNumberPotentiallyValidBooleanIs the card number potentially valid - meaning it is partially populated and so far the digits conform to a known credit card format.
isCvvValidBooleanIs the card code (CVV) fully validated.
isCvvPotentiallyValidBooleanIs the card code (CVV) potentially valid.

Event: challengeShown

This event is fired when 3D Secure 2 challenge content is shown in the configured element.

No arguments are passed to the callback function.

Example

PaymentFields.on('challengeShown', () => {
  console.log('PaymentFields challengeShown event received.');
});

Event: challengeHidden

This event is fired when 3D Secure 2 challenge content is hidden.

No arguments are passed to the callback function.

Example

PaymentFields.on('challengeHidden', () => {
  console.log('PaymentFields challengeHidden event received.');
});

Event: tokenize

Event is fired when tokenization of the sensitive payment data is complete. Event will return details about success or failure of the tokenization operation as well as details about the tokenized payment data and 3D Secure 2 authentication operation.

Example tokenize Event Handler

PaymentFields.on('tokenize', (result: TokenizeResult) => {
  console.log('PaymentFields tokenize event received.', result);
});

Example TokenizeResult

{
  "isSuccessful": true,
  "isTokenizeSuccessful": true,
  "isThreeDsAuthenticationSuccessful": true,
  "tokenString": "XXXX",
  "creditCard": {
    "cardType": "visa",
    "isNumberValid": true,
    "isCvvValid": true,
    "cardIssuerIdentificationNumber": "411111",
    "cardLastDigits": "1111"
  },
  "threeDsAuthenticationResponse": {
    ...
  }
}

TokenizeResult Type

interface TokenizeResult {
  isSuccessful: Boolean;
  isTokenizeSuccessful: Boolean;
  isThreeDsAuthenticationSuccessful: Boolean;
  tokenString?: String;
  creditCard?: any;
  threeDsAuthenticationResponse: any;
}

TokenizeResult Properties

PropertyTypeDescription
isSuccessfulBooleanIndicates if tokenization of the sensitive payment data was successful.
isTokenizeSuccessfulBooleanIndicates if tokenization of the sensitive payment data was successful.
isThreeDsAuthenticationSuccessfulBooleanIndicates if 3D Secure 2 authentication was successful.
tokenStringStringThis is the token string which uniquely identifies the tokenized payment data.
creditCardObjectThis property is present when the tokenized payment data represents a credit card. It contains details about the credit card.
creditCard.isNumberValidBooleanIs the credit card number valid (based on Luhn algorithm check).
creditCard.isCvvValidBooleanIs the credit card CVV valid.
creditCard.cardTypeStringCredit card brand type. Only included if the card number is valid. For example: visa
creditCard.cardIssuerIdentificationNumberStringThis is the Bank Identification Number (BIN) of the credit card. This is typically the first 6 digits of the credit card number. For example: 411111
creditCard.cardLastDigitsStringThis is the last 4 digits of the credit card number. For example: 1111
threeDsAuthenticationResponseObjectThis property is present when 3D Secure 2 authentication was performed. It contains details about the authentication response from the Subscribe Pro Commerce Platform APIs and ultimately from the 3D Secure authentication servers.