onTokenization Function
The onTokenization callback function will receive the result of tokenization – a single-use-token created by the Customer Vault API, which can be used to complete the payment using the Cards Payment API. The tokenization attempt may either succeed or fail, and within onTokenization you must call showSuccess and showFailure functions after authorization of the card entered in the payment sheet is complete.
The function signature is as follows:
paysafe.request.onTokenization(callback);
The function parameters are described below.
Required | Type | Description | |||||
---|---|---|---|---|---|---|---|
callback | true | function(event, error){} | User callback invoked when the tokenization information is available. | ||||
event | true | object | Contains the result of the tokenization. If failure, the object is null and the error argument contains detailed information.You must invoke showFailure to complete the process If success, you must invoke showSuccess to complete the process. | ||||
showSuccess | true | function | Function that must be invoked by the merchant to show that tokenization was successful. | ||||
showFailure | true | function | Function that must be invoked by the merchant to show that tokenization failed. | ||||
result | true | object | Tokenization result. | ||||
paymentMethod | true | string | The payment method used:"APPLEPAY" | ||||
token | true | string | Token to use to complete the payment through the Cards API. | ||||
shippingContact | false | object | Shipping contact information. Displayed if the requestShippingAddress init option is set to true. | ||||
name | true | string | Contact name. | ||||
false | string | Contact email address. | |||||
postalCode | true | string | Address post code. | ||||
countryCode | true | string | The two-uppercase-character ISO 3166 country code of the shipping address. | ||||
addressLines | false | string array | Address details. | ||||
PhoneNumber | true | string | Contact phone number. | ||||
locality | false | string | Contact city. | ||||
administrativeArea | false | string | Contact state | ||||
billingContact | false | object | Billing contact information. Displayed if the requestBillingAddress init option is set to true. | ||||
name | true | string | Contact name. | ||||
false | string | Contact email address. | |||||
postalCode | true | string | Address post code. | ||||
countryCode | true | string | The two-uppercase-character ISO 3166 country code of the billing address. | ||||
addressLines | false | string array | Address details. | ||||
phoneNumber | true | string | Contact phone number. | ||||
locality | false | string | Contact city. | ||||
administrativeArea | false | string | Contact state. | ||||
card | true | object | Details of the card used in tokenization. | ||||
network | true | string | Card network. For example: "Visa" or "Mastercard". | ||||
type | true | string | Card type. For example: "debit" or "credit". | ||||
lastDigits | true | string | Last four digits of the card number | ||||
error | N/A | object | Error object indicating failure reason: | ||||
{throws} | N/A | Throws an exception with the following errors: 9004, 9014, 9067. | |||||
{return} | false |
Apple Pay Example
This example in the TEST environment shows how to specify the appearance of the payment button. It does not include the init or showButtons code.
<html>
<head>
<script type="text/javascript" src="https://hosted.paysafe.com/request/v1/latest/paysafe.request.min.js"></script>
</head>
<body>
...
<div id="x-paysafe-apple-pay-button"></div>
...
<script>
paysafe.request.onTokenization(function (event, error) {
if (event) {
// Process the token - event.result.token
// Acknowledge - event.showSuccess() or reject event.showFailure()
event.showSuccess();
} else {
// handle error
}
});
</script>
</body>
</html>