Let customers choose a payout method
List a customer's saved methods in a setup session, let a payout's recipient keep one or add a new one, and read their choice on your server.
A setup session your server creates with payout: true lets a payout's recipient choose where their payouts go. Start a checkout with that session's client_secret. checkout.session.isPayout is then true, checkout.paymentMethods() lists the payout methods they can add, and checkout.savedPaymentMethods() lists their saved methods that payouts can go to.
The recipient keeps a saved method with checkout.pay() and a 'savedPaymentMethod' request, or adds a new one with a 'card' or 'alternative' request. The drop-in offers both, with the saved methods on top.
In other setup sessions, checkout.savedPaymentMethods() lists the customer's saved payment methods, and keeping one makes it their default. In sale and authorization sessions, it lists the saved methods the customer can pay with. See Pay with a saved payment method. The list comes from the session that PayCheckout.create() loaded, so the method is synchronous.
const saved = checkout.savedPaymentMethods()Returns
Returns a fresh array of PaySavedPaymentMethod objects in the API's order. Mutating the returned objects doesn't affect the checkout's internal state. What the array holds depends on the session:
| Session | checkout.savedPaymentMethods() |
|---|---|
| A payout setup session | The customer's saved methods that payouts can go to. |
| Another setup session | The customer's saved payment methods. |
| A sale or authorization session | The customer's saved cards that haven't expired, and their other saved methods the session can pay. See Pay with a saved payment method. |
It's empty when the session wasn't created for a customer, or the customer has no saved methods the session can use. Each method has these fields:
| Field | Type | Description |
|---|---|---|
id | string | The saved method's ID, for checkout.pay({ type: 'savedPaymentMethod', id }). |
type | string | The method's type, for example card, us_bank_account, paypal, or cashapp. |
isDefault | boolean | true for the customer's default method. |
card | object | null | Card details (brand as the API names it, for example visa, last4, expiryMonth, and expiryYear, each a string or null). |
bankAccount | object | null | Bank account details (bankName, last4, country, and currency, each a string or null). |
email | string | null | The account's email, for methods that have one, such as PayPal. |
details | Record<string, string> | The method's other details as the API sends them, with snake_case keys and string values. |
requiresCvc | boolean | true when paying with this card needs its CVV. See Ask for the CVV. Always false in a setup session, and for a method that isn't a card. |
Once checkout.presentDropIn() resolves, the list leaves out any method the customer removed in the sheet. They can remove methods there when you pass allowsRemovingSavedPaymentMethods.
Read the choice on your server
Keeping a saved method resolves 'succeeded', with the method's id in result.ids.paymentMethod. Use that ID for your UI only, and tell your server the recipient is done. Your server reads their choice from Pay.com:
- A saved method they kept becomes the customer's default. Read it from the customer's
default_sourcewith Retrieve a customer. - A new method they added completes the setup session. Retrieve the setup session, or wait for the
setup_session.completedevent. Itspayment_methodis the new method.
Then your server creates the payout with that method as the destination.
Example
import { useState } from 'react'
import { Button, Text, View } from 'react-native'
import type { PayCheckout, PaySavedPaymentMethod } from '@pay-com/react-native'
function label(method: PaySavedPaymentMethod): string {
if (method.card) return `${method.card.brand ?? 'Card'} ending ${method.card.last4 ?? ''}`
if (method.bankAccount) return `${method.bankAccount.bankName ?? 'Bank account'} ending ${method.bankAccount.last4 ?? ''}`
return method.email ? `${method.type} (${method.email})` : method.type
}
export function PayoutMethodPicker({ checkout, onChosen }: { checkout: PayCheckout; onChosen: () => void }) {
const [message, setMessage] = useState<string | null>(null)
async function keep(id: string) {
try {
const result = await checkout.pay({ type: 'savedPaymentMethod', id })
if (result.status === 'succeeded') onChosen() // your server reads the customer's default_source
else if (result.status === 'failed') setMessage('That method could not be saved. Try again.')
} catch {
setMessage('Something went wrong. Try again.') // nothing was sent
}
}
async function openDropIn() {
try {
const result = await checkout.presentDropIn()
if (result.status === 'succeeded') onChosen() // your server reads the choice
} catch {
setMessage('Something went wrong. Try again.') // the sheet didn't open
}
}
return (
<View>
{checkout.savedPaymentMethods().map((method) => (
<Button
key={method.id}
title={method.isDefault ? `${label(method)} (default)` : label(method)}
onPress={() => keep(method.id)}
/>
))}
<Button title="Add a payout method" onPress={openDropIn} />
{message ? <Text>{message}</Text> : null}
</View>
)
}Next steps
- Let recipients choose a payout method: The server side, with the payout setup session and the payout.
- checkout.pay(): The
'savedPaymentMethod'request and what it rejects with. - Pay with a saved payment method: Charge a saved method in a sale or authorization session.
- Present the drop-in: Let the drop-in show the saved methods.
- Change the drop-in's text: The texts the drop-in shows in a payout session.