Tokenize
The tokenize method returns a PaymentHandle result, which will resolve to a single-use payment handle representing the customer's sensitive card data. The payment handle can be used by the Payments API to take payments. Single-use handles are valid for only 5 minutes and are not consumed by verification. See Payments with a Handle for more details.
The tokenize function has the following signatures:
/**
* Coroutine to create a payment handle result object as a suspended function; with merchant,
* transaction and credit card data retrieved from the user interface widgets.
*/
@JvmSynthetic
suspend fun tokenize(
cardTokenizeOptions: PSCardTokenizeOptions,
): PSResult<String>
/**
* Creates a payment handle using a callback; with merchant, transaction and credit card data
* retrieved from the user interface widgets.
*
* @param lifecycleOwner Utility object to create coroutine and emit the result in the callback.
* @param callback Result object with success/failure methods to handle payment handle service.
*/
fun tokenize(
lifecycleOwner: LifecycleOwner,
cardTokenizeOptions: PSCardTokenizeOptions,
callback: PSResultCallback<String>
)
The tokenize() function provides a convenient method for tokenizing sensitive card data, ensuring secure payment processing. When called, the function returns a PSResult that resolves to a single-use payment handle. This handle can then be utilized by the Payments API for payment transactions. It's important to note that single-use handles are valid for only 15 minutes and are not consumed during verification.
Parameters:
- options: An instance of PSCardTokenizeOptions containing various parameters for tokenization, such as the payment amount, transaction type, payment type, merchant reference number, customer details, merchant descriptor, account ID, ThreeDS information, and single-use customer token.
The PSCardTokenizeOptions structure provides a comprehensive set of options for configuring the tokenization process.
Options
Parameter | Required | Type | Description |
---|---|---|---|
amount | true | Int | The payment amount is in minor units to charge the customer's card. Use the correct minor units amount for the merchant account currency. For example, to process US $10.99, this value should be 1099. To process 1000 Japanese Yen, this value should be 1000. To process 10.139 Tunisian dinar, this value should be 10139. Min = 1 Max = 999999999 |
currencyCode | true | String | The currencyCode accepts 3 letter abbreviations of the ISO standard currencies. |
accountId | conditional | String | The id of the selected merchant account to use to process the payment. If you are a merchant, then this field is required only if you have more than one account configured for the same payment method and currency. If you are a partner using a shared API key, then this field is mandatory. |
transactionType | true | TransactionType | This specifies the transaction type for which the Payment Handle is created. Possible values are:
|
merchantRefNum | true | String | A unique identifier is provided by the merchant for every transaction in Paysafe Android SDK. |
false | BillingDetails | Card billing address - additional details for the billingDetails object can be found in the Payments API documentation. | |
false | Profile | This is the profile of the customer - additional details for the profile object can be found in the Payments API documentation. | |
false | MerchantDescriptor | This is a merchant descriptor that is displayed on a customer’s card statement. | |
singleUseCustomerToken | false | String | This is the singleUseCustomerToken that the merchant generated using the Create a Single-Use Customer Token request. Specify this parameter when you want to use a saved card. |
paymentTokenFrom | false | String | This is single-use payment handle associated with the customer. Specify this parameter when you want to use a saved card. |
renderType | false | RenderType | Specify the render type that the device supports for displaying specific challenge user interfaces within the SDK. The list of all the render types:
|
simulator | false | SimulatorType | The simulator only applies in the test environment and its default value is INTERNAL. In the production environment, the simulator value is disregarded even if provided, and the experience will be the same as if the simulator value was set to EXTERNAL. SimulatorType is an enum type with the following cases:
If omitted, defaults to .EXTERNAL. |
BillingDetails
Parameter | Required | Type | Description |
---|---|---|---|
country | true | String | Country of billing address |
zip | true | String | Zip code of the address |
state | false | String | State/province/region of the address |
city | false | String | City in which the address is located |
street | false | String | The first line of the street address |
street2 | false | String | The second line of the street address |
phone | false | String | The phone number of the customer |
nickname | false | String | The nickname of the customer |
Profile
Parameter | Required | Type | Description |
---|---|---|---|
firstName | false | String | This is the customer’s first name. |
lastName | false | String | This is the customer’s last name. |
false | String | This is the customer’s email address. | |
phone | false | String | This is the customer’s phone number. |
MerchantDescriptor
Parameter | Required | Type | Description |
---|---|---|---|
dynamicDescriptor | true | String | This is a merchant descriptor that is displayed on a customer’s card statement |
phone | false | String | This is the merchant’s phone number, which is appended to the merchant descriptor on a customer’s card statement. |
PaymentAccountDetails
Parameter | Required | Type | Description |
---|---|---|---|
createdDate | false | String | This is the date that the cardholder opened the account with the 3DS Requestor. The ISO 8601 date format is expected, i.e., YYYY-MM-DD. |
createdRange | false | CreatedRange | This indicates the length of time that the payment account was enrolled in the cardholder’s account with the 3DS Requestor. CreatedRange is an enum with the following cases:
|
PriorThreeDSAuthentication
Parameter | Required | Type | Description |
---|---|---|---|
data | false | String | This field is reserved for future iterations of 3D Secure 2. length <= 2048 chars |
method | false | ThreeDSAuthentication | This is the mechanism used previously by the cardholder to authenticate to the 3DS Requestor. Possible values are:
|
id | false | String | This is a previous authentication ID for the cardholder. length <= 36 chars |
time | false | String | This is the date and time of the cardholder authentication. The ISO 8601 date format is expected, i.e., YYYY-MM-DD-THH:MM:SSZ. |
TravelDetails
Parameter | Required | Type | Description |
---|---|---|---|
isAirTravel | false | Boolean | This indicates whether the transaction is an air travel related purchase, e.g., a ticket purchase. If omitted, defaults to false. |
airlineCarrier | conditional | String | This is the selected airline carrier. Note: This element is required only if isAirTravel=true. length <= 256 chars |
departureDate | conditional | String | This is the date of departure in the time zone of the departure location. The ISO 8601 date format is expected, i.e., YYYY-MM-DD. Note: This element is required only if isAirTravel=true. |
destination | conditional | String | This is the airport code of the destination airport. Note: This element is required only if isAirTravel=true. length <= 5 chars |
origin | conditional | String | This is the airport code of the originating airport. Note: This element is required only if isAirTravel=true. length <= 5 chars |
passengerFirstName | conditional | String | This is the first name of the cardholder from the billing details. Note: This element is required only if isAirTravel=true. length <= 99 chars |
passengerLastName | conditional | String | This is the last name of the cardholder from the billing details. Note: This element is required only if isAirTravel=true. length <= 99 chars |
/// Payment amount in minor units
let amount = totalPrice * 100
val cardTokenizeOptions = PSCardTokenizeOptions(
amount = amount,
currencyCode = "USD",
transactionType = TransactionType.PAYMENT,
merchantRefNum = "<merchant-ref-num>",
billingDetails = BillingDetails(
nickName = "nickName",
street = "street",
city = "city",
state = "AL",
country = "US",
zip = "12345"
),
profile = Profile(
firstName = "firstName",
lastName = "lastName",
email = "email@mail.com",
phone = "0123456789"
),
accountId = Consts.CARDS_ACCOUNT_ID,
merchantDescriptor = MerchantDescriptor(
dynamicDescriptor = "dynamicDescriptor",
phone = "0123456789"
)
renderType = RenderType.BOTH
)
Call tokenize method
For coroutine implementations, we employ a sealed class response structure with PSResult to encapsulate both success and error scenarios.
Paysafe Android SDK offers multiple ways of handling async flows for tokenize:
cardController?.tokenize(this, cardTokenizeOptions, object : PSResultCallback<String> {
override fun onSuccess(value: String?) {
// Calls /payments endpoint to complete the payments flow
}
override fun onFailure(exception: Exception) {
// do something with exception
}
})
val paymentHandleResult = cardController?.tokenize(cardTokenizeOptions)
when (paymentHandleResult) {
is PSResult.Success -> TODO("Complete payment with payment handle token value: ${paymentHandleResult.value}")
is PSResult.Failure -> TODO("Do Something with Exception: ${paymentHandleResult.exception}")
}
Tokenization with 3D Secure
3D Secure 2 provides an improved, seamless way to authenticate customers while adding support for mobile applications and for biometric and token validation, and streamlining the checkout experience using “frictionless” authentication. See the 3D Secure 2 documentation for full details on implementing 3D Secure 2.
You must first be configured by Paysafe Group in order to use 3D Secure 2. 3D Secure 2 is supported only for Visa, Mastercard, and American Express.
With 3D Secure 2, you can pass in some additional optional parameters in the threeDS object for Paysafe SDK:
- authenticationPurpose – Only two values are permitted: .paymentTransaction (default value) and
- .instalmentTransaction for maxAuthorizationsForInstalmentPayment parameter
- billingCycle
The card holderName parameter is mandatory in order to use 3D Secure 2.
See the authentication object in the 3D Secure 2 API documentation for a description of these parameters.
/// Payment amount in minor units
val amount = totalPrice * 100
val cardTokenizeOptions = PSCardTokenizeOptions(
amount = amount,
currencyCode = "USD",
transactionType = TransactionType.PAYMENT,
merchantRefNum = "<merchant-ref-num>",
billingDetails = BillingDetails(
nickName = "Jax Billing Address",
street = "5335 Gate Pkwy",
city = "Jacksonville",
state = "FL",
country = "US",
zip = "32256"
),
profile = Profile(
firstName = "joe",
lastName = "Doe",
email = "joe.doe@paysafe.com",
phone = "18003270093"
),
accountId = Consts.CARDS_ACCOUNT_ID,
merchantDescriptor = MerchantDescriptor(
dynamicDescriptor = "dynamicDescriptor",
phone = "0123456789"
),
renderType = RenderType.BOTH,
threeDS = ThreeDS(
merchantUrl = "https://merchant.com/url/path",
authenticationPurpose = AuthenticationPurpose.PAYMENT_TRANSACTION,
maxAuthorizationsForInstalmentPayment = 2,
electronicDelivery = ElectronicDelivery(
isElectronicDelivery = true,
email = "example@example.com"
),
messageCategory = MessageCategory.payment,
requestorChallengePreference = RequestorChallengePreference.NO_PREFERENCE,
userLogin = UserLogin(
data = "Some up to 2048 bytes undefined data",
authenticationMethod = AuthenticationMethod.NO_LOGIN,
time = "2014-01-26T10:32:28Z"
),
transactionIntent = TransactionIntent.GOODS_OR_SERVICE_PURCHASE,
initialPurchaseTime = "2014-01-26T10:32:28Z",
orderItemDetails = OrderItemDetails(
preOrderItemAvailabilityDate = "2014-01-26",
preOrderPurchaseIndicator = "MERCHANDISE_AVAILABLE",
reorderItemsIndicator = "FIRST_TIME_ORDER",
shippingIndicator = "SHIP_TO_BILLING_ADDRESS"
),
purchasedGiftCardDetails = PurchasedGiftCardDetails(
amount = 1234,
count = 2,
currency = "ARS"
),
priorThreeDSAuthentication = PriorThreeDSAuthentication(
data = "Some up to 2048 bytes undefined data",
method = ThreeDSMethod.FRICTIONLESS_AUTHENTICATION,
id = "123e4567-e89b-12d3-a456-426655440001",
time = "2014-01-26T10:32:28Z"
),
shippingDetailsUsage = ShippingDetailsUsage(
cardHolderNameMatch = true,
initialUsageDate = "2014-01-26",
initialUsageRange = UsageRange.CURRENT_TRANSACTION
),
suspiciousAccountActivity = true,
totalPurchasesSixMonthCount = 1,
transactionCountForPreviousDay = 1,
transactionCountForPreviousYear = 3,
travelDetails = TravelDetails(
isAirTravel = true,
airlineCarrier = "Windsor",
departureDate = "2014-01-26",
destination = "SOF",
origin = "BCN",
passengerFirstName = "Joe",
passengerLastName = "Doe"
)
)
)
NOTE: For 3D Secure enrolled cards, the customer may be shown an overlay window from their card issuer to authorize the payment. 3D Secure 2 is supported only for Visa, Mastercard, and American Express.
Tokenization exceptions
Error code | Display message | Detailed message | Comments |
---|---|---|---|
9003 | There was an error (9003), please contact our support. | Invalid ${field} field value(s). | *added "field" word, *added "value(s)" instead of "value"
Thrown when merchant skips field validations and tries to tokenize invalid using fields.
Important: This exception is thrown also when the backend request fails with
5068 - Either you submitted a request that is missing a mandatory field or the value of a field does not match the format expected. 7508 - You submitted an invalid card number or brand or combination of card number and brand with your request.
|
9125 | There was an error (9125), please contact our support. | Unsupported card brand used |
|
9040 | There was an error (9040), please contact our support. | Authentication result is not accepted for the provided account |
|
9054 | There was an error (9054), please contact our support. | Amount should be a number greater than 0 no longer than 11 characters | The amount value should be a positive number. |
9136 | There was an error (9136), please contact our support. | Tokenization is already in progress. | Whenever merchant calls tokenize before the previous one has completed |
9098 | There was an error (9098), please contact our support. | Invalid parameter in merchantDescriptor.dynamicDescriptor | String value should have <= 20 characters. |
9099 | There was an error (9099), please contact our support. | Invalid parameter in merchantDescriptor.phone | String value should have <= 13 characters. |
9112 | There was an error (9112), please contact our support. | Profile firstName should be valid | String value should have <= 80 characters. |
9113 | There was an error (9113), please contact our support. | Profile lastName should be valid | String value should have <= 80 characters. |
9119 | There was an error (9119), please contact our support. | Profile email should be valid | Use the following regex to check: |