List payment methods
Get the payment methods a session accepts, and the card brands it takes, to draw your own payment screen.
checkout.paymentMethods() returns the payment methods the session accepts, so you can draw your own list of them. checkout.acceptedCardBrands lists the card brands it takes. Both read the session the checkout loaded when you started it, without a request. The drop-in draws this list for you.
let methods = checkout.paymentMethods()
let brands = checkout.acceptedCardBrandsReturns
paymentMethods() returns an array of PayPaymentMethod, in the order the API sends them, without duplicates. Each has the API's type, for example card, applepay, or paypal, and a kind that tells you how to pay with it:
kind | Types | Pay with |
|---|---|---|
.card | card | The card fields and pay(.card(_:)). |
.wallet | applepay, googlepay | Use payWithApplePay() for applepay. googlepay is for Android apps. The iOS SDK can't pay with it, so leave it out of your list. |
.alternative | Every other type | pay(.alternative(_:)) with the method's type. It opens the method's redirect or app switch. |
Passkeys and Click to Pay aren't in the list.
In a payout setup session, the list holds the payout methods the customer can add. Their saved methods come from savedPaymentMethods().
acceptedCardBrands is an array of the card brands the session accepts, as the API names them, for example visa or mastercard. It's empty when the session doesn't restrict brands. The card fields don't check it, so use it to show the brands you take.
Neither throws.
Example
import PayCheckout
@MainActor
func paymentRows(for checkout: PayCheckout, applePay: PayApplePayConfiguration) -> [Row] {
checkout.paymentMethods().compactMap { method in
switch method.kind {
case .card:
return Row(title: "Card", action: .showCardFields)
case .wallet:
// Show Apple Pay only when the device can pay with it.
guard method.type == "applepay", checkout.canPayWithApplePay(applePay) else { return nil }
return Row(title: "Apple Pay", action: .applePay)
case .alternative:
return Row(title: method.type, action: .redirect(method.type))
}
}
}Next steps
- Card fields: Collect the card in the SDK's own inputs.
- Pay: Pay with the method the customer chose.
- Pay with Apple Pay: Offer Apple Pay and pay with it.