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:
eventName | Description |
---|---|
initialized | Fired when the PaymentFields Widget has been initialized. |
inputEvent | Fired when an input event occurs in one of the payment iFrames. |
validationResultChanged | Fired when validation has occurred and the result has changed. |
challengeShown | Fired when 3D Secure 2 challenge content is shown in the configured element. |
challengeHidden | Fired when 3D Secure 2 challenge content is hidden. |
tokenize | Fired 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
)
Property | Type | Description |
---|---|---|
fieldCode | String | Indicates which field has fired the event: number , cvv , account or other. |
eventType | String | The 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
)
Property | Type | Description |
---|---|---|
cardType | String | Detected credit card type: 'visa', 'american_express', 'master', etc. |
isNumberValid | Boolean | Is the card number fully validated. |
isNumberPotentiallyValid | Boolean | Is the card number potentially valid - meaning it is partially populated and so far the digits conform to a known credit card format. |
isCvvValid | Boolean | Is the card code (CVV) fully validated. |
isCvvPotentiallyValid | Boolean | Is 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
Property | Type | Description |
---|---|---|
isSuccessful | Boolean | Indicates if tokenization of the sensitive payment data was successful. |
isTokenizeSuccessful | Boolean | Indicates if tokenization of the sensitive payment data was successful. |
isThreeDsAuthenticationSuccessful | Boolean | Indicates if 3D Secure 2 authentication was successful. |
tokenString | String | This is the token string which uniquely identifies the tokenized payment data. |
creditCard | Object | This property is present when the tokenized payment data represents a credit card. It contains details about the credit card. |
creditCard.isNumberValid | Boolean | Is the credit card number valid (based on Luhn algorithm check). |
creditCard.isCvvValid | Boolean | Is the credit card CVV valid. |
creditCard.cardType | String | Credit card brand type. Only included if the card number is valid. For example: visa |
creditCard.cardIssuerIdentificationNumber | String | This 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.cardLastDigits | String | This is the last 4 digits of the credit card number. For example: 1111 |
threeDsAuthenticationResponse | Object | This 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. |