Saved Cards Integration
The Paysafe Android SDK's Saved Cards functionality allows customers to complete payments faster using a saved card from their customer profile.
Saving a card to the Customer profile
After successfully generating a single-use payment handle for a card payment method using the mobile SDK, you have the option to add it to a customer profile based on the customer's intentions.
- For a new customer, use Create a Profile Using a Single-Use Token to create a new customer profile and add the card details from the payment token.
- For an existing customer, use Create a Card Using a Single-Use Token to add the card details from the payment token to an existing customer profile.
- We recommend either making a successful payment using the token or verifying that the token corresponds to a valid card before adding it to the customer profile.
Tokenize with optional fields
If the customer wants to pay with a new card, you can display the Card Number and Expiry Date fields. These fields will become required if the singleUseCustomerToken and paymentTokenFrom are not passed in the tokenize function call.
Based on your requirements, the CVV field can be the only field that is set if needed.
If the customer already has a profile created in the Payments API, and there are cards associated with this profile, you can use Paysafe.js to tokenize a selected saved card by passing a single-use customer token and single-use payment handle to the tokenize function. A single-Use Customer Token is a temporary token representing the customer's profile. It is used to prevent exposing the customer id and multi-use payment token at the front end. A single-use payment handle is a temporary token representing the card details of the customer, located in the paymentHandles object from the response of the single-use customer token creation. If the customer's profile contains multiple cards, you must pass the correct single-use payment handle based on the customer's intentions.
Before you perform tokenization, complete these steps:
- Create a Single-Use Customer token on your back end (BE) server.
- Retrieve the singleUseCustomerToken and the selected card paymentHandleToken from the response.
- Send both tokens to your front end (FE).
- Pass them to the tokenize function using the singleUseCustomerToken and paymentTokenFrom parameters in the options object.
Usage example
/// Payment amount in minor units
val amount = totalPrice * 100
let options = PSCardTokenizeOptions(
amount = amount,
currencyCode = "USD",
transactionType = TransactionType.PAYMENT,
merchantRefNum = PaysafeSDK.getMerchantReferenceNumber(),
billingDetails = BillingDetails(
nickName = "Jax Billing Address",
street = "5335 Gate Pkwy",
city = "Jacksonville",
state = "FL",
country = "US",
zip = "32256"
),
profile = Profile(
firstName = "firstName",
lastName = "lastName",
locale = ProfileLocale.EN_GB,
dateOfBirth = DateOfBirth(
day = 1,
month = 1,
year = 1990
),
email = "john.doe@paysafe.com",
phone = "18003270093"
),
accountId = Consts.CARDS_ACCOUNT_ID,
merchantDescriptor = MerchantDescriptor(
dynamicDescriptor = "dynamicDescriptor",
phone = "18003270093"
),
shippingDetails = ShippingDetails(
shipMethod = ShippingMethod.NEXT_DAY_OR_OVERNIGHT,
street = "5335 Gate Pkwy",
street2 = "5335 Gate Pkwy",
city = "Jacksonville",
state = "FL",
countryCode = "US",
zip = "32256",
),
singleUseCustomerToken = "<singleUseCustomerToken>",
paymentHandleTokenFrom = "<paymentHandleTokenFrom>",
renderType = RenderType.BOTH,
threeDS = ThreeDS(
merchantUrl = "<merchantUrl>",
"deviceChannel": "BROWSER",
"messageCategory": "PAYMENT",
"authenticationPurpose": "PAYMENT_TRANSACTION"
)
)
cardController?.tokenize(this, cardTokenizeOptions, object : PSResultCallback<PaymentHandle> {
override fun onSuccess(value: PaymentHandle?) {
// do something with result
}
override fun onFailure(exception: Exception) {
// do something with exception
}
})