List payment methods
Get the payment methods a session accepts, and the card brands it takes, to build your own list of ways to pay.
checkout.paymentMethods() returns the payment methods the session accepts, in the order the API sends them. Use it to build your own list when you take payments on your own screen with checkout.pay(). The drop-in builds its list from the same methods, so you don't need this method with checkout.presentDropIn().
The list comes from the session that PayCheckout.create() loaded, so the method is synchronous and doesn't call Pay.com. In a payout session, it lists the payout methods a recipient can add. See Let customers choose a payout method.
const methods = checkout.paymentMethods()Returns
Returns a fresh array of PayPaymentMethod objects. Mutating the returned objects doesn't affect the checkout's internal state.
| Field | Type | Description |
|---|---|---|
type | string | The API's payment method type, for example card, applepay, googlepay, paypal, or ideal. |
kind | 'card' | 'wallet' | 'alternative' | 'card' for card, 'wallet' for applepay and googlepay, and 'alternative' for every other type. |
Pay with the method the customer picks according to its kind:
- For
'card', show the card fields, then pay with{ type: 'card', card: fields }. - For
'alternative', pay with{ type: 'alternative', method: type }. The SDK opens the redirect or app switch the method needs. - For
'wallet', offer Apple Pay and Google Pay in the drop-in. See Pay with Apple Pay or Google Pay.
Accepted card brands
checkout.acceptedCardBrands is a readonly string[] of the card brands the session accepts, as the API names them, for example ['visa', 'mastercard']. It's empty when the session doesn't restrict brands.
Example
import { useState } from 'react'
import { Button, Text, View } from 'react-native'
import type { PayCheckout, PayPaymentMethod } from '@pay-com/react-native'
const LABELS: Record<string, string> = { card: 'Card', paypal: 'PayPal', ideal: 'iDEAL' }
export function MethodList({ checkout, onCard }: { checkout: PayCheckout; onCard: () => void }) {
const [message, setMessage] = useState<string | null>(null)
// For example [{ type: 'card', kind: 'card' }, { type: 'applepay', kind: 'wallet' },
// { type: 'paypal', kind: 'alternative' }]
const methods = checkout.paymentMethods().filter((method) => method.kind !== 'wallet')
async function payWith(method: PayPaymentMethod) {
if (method.kind === 'card') return onCard() // show the card fields
try {
const result = await checkout.pay({ type: 'alternative', method: method.type })
if (result.status === 'succeeded' || result.status === 'processing') {
setMessage('Thanks! We are confirming your payment.') // your server confirms it
} else if (result.status === 'failed') {
setMessage("The payment didn't go through. Try another method.")
}
} catch {
setMessage('Something went wrong. Try again.') // nothing was sent
}
}
return (
<View>
{methods.map((method) => (
<Button key={method.type} title={LABELS[method.type] ?? method.type} onPress={() => payWith(method)} />
))}
{message ? <Text>{message}</Text> : null}
</View>
)
}Next steps
- checkout.pay(): Pay with the method the customer picked.
- Card fields: Collect the card for a
cardmethod. - Pay with Apple Pay or Google Pay: Offer the wallets in the drop-in.