Skip to main content

Saved cards and accounts

paymentTokens carries the session's saved instruments: cards on file and PayPal accounts the shopper vaulted earlier. They pay like a primary method.

Setup​

Artifacteu.purse:headless-checkout-android; eu.purse:headless-checkout-paypal to pay with a saved PayPal account
Client sessionCreated with a wallet session (wallet_session in the widget data) for the shopper. The server-side setup is the same as on the web: Saved payment methods
Dashboardsave_token_mode on the card method decides whether new cards can be saved
Manifest, keysNone

Pay with a saved instrument​

val tokens by checkout.paymentTokens.collectAsState()

val element = rememberPaymentElement(checkout, token, listener)
LaunchedEffect(token.id) { checkout.setPrimaryToken(token) }
if (element.hasUi) PaymentElementUi(element, Modifier.fillMaxWidth()) // CVV-only field, when required
Button(onClick = { element.submit() }, enabled = element.ready) { Text("Pay") }
TokenhasUiGate
Saved card, requiresCvv == trueA CVV-only secure fieldisPaymentFulfilled waits for a valid CVV, like a fresh card
Saved card, requiresCvv == false (network token, or the PSP does not ask)NothingPayable at selection
Saved PayPal account, isVaultedCard == falseNothingPayable at selection; submit() captures without an approval step

label, brand, maskedPan, holderName and favorite are there to render the row; checkout.iconUrl(token) gives the brand's logo. 3-D Secure may still follow a saved card payment: handle ReturnedFromRedirect as for any card.

Manage the wallet​

All suspend; each runs its network call on Dispatchers.IO.

checkout.editToken(token, name = "work card")
checkout.setTokenFavorite(token)
checkout.deleteToken(token)
checkout.deleteAllTokens()

The lists on paymentTokens and savedSecondaryTokens reflect the change without restarting the checkout. Failures are WalletOperationFailed:

CodeMeaning
MISSING_WALLET_SESSIONThe client session carries no wallet session
MISSING_TOKENThe token is not in the wallet anymore
INVALID_TOKEN_NAME, TOKEN_NAME_EXISTSThe label is empty, too long, or already used
TOKEN_NOT_REGISTERABLE, METHOD_NOT_REGISTERABLESaving is not allowed for this token or method

Save a new card​

Saving a fresh card is decided on the card method before submit: Card, save the card. Saving a gift card: Gift cards, keep the gift card. Creating a PayPal token from the app is not available.

Cards outside the Purse vault

A saved card from a pci_proxy vault that needs a CVV has no CVV form on Android and cannot be paid with. Cards vaulted by Purse are fully supported.