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
| Artifact | eu.purse:headless-checkout-android; eu.purse:headless-checkout-paypal to pay with a saved PayPal account |
| Client session | Created 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 |
| Dashboard | save_token_mode on the card method decides whether new cards can be saved |
| Manifest, keys | None |
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") }
| Token | hasUi | Gate |
|---|---|---|
Saved card, requiresCvv == true | A CVV-only secure field | isPaymentFulfilled waits for a valid CVV, like a fresh card |
Saved card, requiresCvv == false (network token, or the PSP does not ask) | Nothing | Payable at selection |
Saved PayPal account, isVaultedCard == false | Nothing | Payable 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:
| Code | Meaning |
|---|---|
MISSING_WALLET_SESSION | The client session carries no wallet session |
MISSING_TOKEN | The token is not in the wallet anymore |
INVALID_TOKEN_NAME, TOKEN_NAME_EXISTS | The label is empty, too long, or already used |
TOKEN_NOT_REGISTERABLE, METHOD_NOT_REGISTERABLE | Saving 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.
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.