Skip to Content
Docs

List payment methods

Get the payment methods a session accepts, in the API's order, and the card brands it takes, to build your own list of methods.

checkout.paymentMethods() returns the payment methods the session accepts, so you can build your own list with the card fields, a button for each redirect payment method, and Google Pay. checkout.acceptedCardBrands lists the card brands the session takes.

Both read what PayCheckout.create() loaded, so they don't call Pay.com. The drop-in builds this list for you.

val methods: List<PayPaymentMethod> = checkout.paymentMethods()
val brands: List<String> = checkout.acceptedCardBrands

Returns

paymentMethods() returns a list of PayPaymentMethod, in the order the API returns them, without duplicates. Each one has the API's type, such as card or paypal, and a kind that tells you how to pay with it:

kindHow to pay with it
CARDShow the card fields, then pay with PayPaymentRequest.Card(controller) through checkout.pay().
WALLETFor googlepay, see Pay with Google Pay. Apple Pay (applepay) doesn't run on Android, so leave it out of your list.
ALTERNATIVEPay with PayPaymentRequest.Alternative(method.type) through checkout.pay(), which opens the method's page.

acceptedCardBrands lists the card brands the session takes, as the API names them, for example visa. It's empty when the session doesn't limit brands. The card fields don't check it, so use it to tell the customer which cards you take.

Example

@Composable
fun PaymentMethodList(checkout: PayCheckout, onPay: (PayPaymentRequest) -> Unit) {
    val methods = remember(checkout) { checkout.paymentMethods() }
    val card = remember { PayCardController() }
    val state by card.state.collectAsState()

    Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
        methods.forEach { method ->
            when (method.kind) {
                PayPaymentMethod.Kind.CARD -> Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
                    PayCardNumberField(card)
                    Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
                        PayExpiryField(card, Modifier.weight(1f))
                        PayCvcField(card, Modifier.weight(1f))
                    }
                    Button(onClick = { onPay(PayPaymentRequest.Card(card)) }, enabled = state.isComplete) {
                        Text("Pay by card")
                    }
                }
                PayPaymentMethod.Kind.ALTERNATIVE ->
                    OutlinedButton(onClick = { onPay(PayPaymentRequest.Alternative(method.type)) }) {
                        Text(displayName(method.type)) // Your own name for each type, such as "PayPal"
                    }
                PayPaymentMethod.Kind.WALLET -> Unit // Google Pay has its own button: see payWithGooglePay()
            }
        }
    }
}

Next steps

Was this page helpful?