Present the drop-in
Show a ready-made Material 3 payment sheet over your activity, where the customer selects a method and pays, and get the result when it closes.
PayDropIn is a ready-made payment sheet for a checkout. present() shows it over your activity as a Material 3 bottom sheet. The customer selects a method, then pays with one button. The sheet shows 3DS challenges and redirects over it, shows failures and lets the customer try again, and returns the result when it closes. See What the customer sees. Use it instead of building your own UI from checkout.paymentMethods(), the card fields, and checkout.pay().
A returning customer sees their saved payment methods first. See A returning customer.
The drop-in is in the pay-dropin module, which brings in pay-elements, pay-threeds, and pay-googlepay. present is a suspend function, so call it from a coroutine.
import com.pay.sdk.dropin.PayDropIn
val dropIn = PayDropIn(checkout, PayDropIn.Configuration(merchantDisplayName = "My Shop"))
val result: PayResult = dropIn.present(activity)Parameters
PayDropIn(checkout, configuration) takes:
| Parameter | Type | Required | Description |
|---|---|---|---|
checkout | PayCheckout | Yes | The checkout to pay, from PayCheckout.create(). |
configuration | PayDropIn.Configuration | No | The sheet's options. See PayDropIn.Configuration. Default: PayDropIn.Configuration(). |
present(activity) takes:
| Parameter | Type | Required | Description |
|---|---|---|---|
activity | ComponentActivity | Yes | The activity the sheet, 3DS challenges, and redirects show over. |
PayDropIn.Configuration
PayDropIn.Configuration holds the sheet's options.
| Parameter | Type | Required | Description |
|---|---|---|---|
merchantDisplayName | String? | No | Your shop's name, shown above the total and in the save-card switch ("Save card for future use at My Shop"). Default: null, for the total alone. |
cardholderName | PayDropIn.CardholderName | No | Controls the cardholder name field (HIDDEN, OPTIONAL, or REQUIRED). Default: OPTIONAL. |
saveCard | PayDropIn.SaveCard | No | AUTOMATIC shows a switch to save the card, except in a setup session, a recurring session, or a session whose setup_future_usage is on_session, which saves the card anyway. HIDDEN never shows it. Default: AUTOMATIC. |
paymentMethods | List<String>? | No | The payment method types to offer, by their API names, for example listOf("card", "paypal"). The session's order is kept, and saved methods are filtered by type too. Keep googlepay in the list to show the Google Pay button. Default: null, for every method the drop-in can show. |
allowsRemovingSavedPaymentMethods | Boolean | No | Shows Edit above saved methods, so the customer can remove them after confirming. See Remove a saved payment method. Default: false. |
secureScreen | Boolean | No | Sets FLAG_SECURE on the sheet's window, so screenshots and screen recordings don't show it. Default: false. |
googlePay | PayGooglePayConfiguration? | No | Shows Google's Google Pay button above the other methods, when the session offers Google Pay and PayGooglePay.isReadyToPay() returns true. See PayGooglePayConfiguration. Default: null, for no Google Pay. |
appearance | PayDropInAppearance | No | The sheet's colors, corners, and fonts. Default: Material 3, in light or dark mode. See Style the drop-in. |
strings | PayDropInStrings | No | The sheet's texts. Default: English. See Change the drop-in's text. |
beforePay | (suspend (PayPaymentMethod) -> Boolean)? | No | Runs when the customer taps the pay button, immediately before the SDK submits the payment, receiving the chosen method (a saved method as a PayPaymentMethod of its type, or Google Pay as googlepay). Return false to stop. Nothing is sent, and the sheet stays open without a message. For Google Pay, it runs before Google's sheet opens, and that sheet shows the new total. For the other methods, a tap that changes the amount isn't charged. The customer taps again, and beforePay runs again, so set the amount rather than adding to it. See When the amount changes. If it throws, the sheet closes and present throws the exception. Default: null. |
Returns
present returns a PayResult when the sheet closes:
| Result | When |
|---|---|
PayResult.Succeeded(ids) | A payment succeeded, and the sheet closes itself. ids are what checkout.pay() returned. |
PayResult.Processing(ids) | A payment has no final outcome yet, and the sheet closes itself. Your server decides. |
PayResult.Canceled | The customer dismissed the sheet using its close button, by swiping it down, by tapping outside it, or with the back button. |
PayResult.Failed(error) | The customer closed the sheet after a failure that left nothing else to do, or the sheet couldn't open. See Errors. |
The customer can't close the sheet while a payment runs. When they close a 3DS challenge, a redirect, or the Google Pay sheet, the drop-in stays open, without a message, so they can choose again. You can call present again after it returns.
Errors
present doesn't throw a PayError. It returns PayError cases in PayResult.Failed(error).
| Error | When |
|---|---|
PayError.PaymentInProgress | This drop-in's sheet is already showing. Returned immediately. |
PayError.Unsupported(detail) | The drop-in has no available payment methods (no card, redirect method, saved method, or Google Pay). Returned immediately. |
PayError.Declined(decline) | The session's last attempt was declined (decline.maxAttemptsReached), and the customer closed the sheet. Other declines show in the sheet, and the customer can try again. |
PayError.SessionExpired | The session expired, and the customer closed the sheet. |
PayError.SessionAlreadyCompleted(status), PayError.PaymentEnded(status) | The session can't be paid anymore, and the customer closed the sheet. |
Other failures, such as PayError.Network, show a message in the sheet, and the customer can try again.
What the customer sees
The drop-in is a Material 3 modal bottom sheet, as tall as its content, that moves up with the keyboard.
From top to bottom
The sheet stacks these parts, and shows each one only when it applies.
- The top. At checkout, your
merchantDisplayNameon the left, Close on the right, and the total under them. In a setup or payout session, "Payment" or "Payout method" on the left, with Edit, when the customer can remove saved methods, and Close on the right. - Google Pay, Google's own button, when you set up
googlePay, the session offers it, and the device can pay. It has "or" under it when other methods follow, and a tap opens Google's sheet immediately. - Saved payment methods, in setup and payout sessions. Each row has the method's logo and name, a card also its "Expires MM/YY", and the customer's default reads "Default". At checkout, a returning customer sees theirs in a carousel instead, and the methods below under Other ways to pay.
- Pay with (or Get paid with in a payout session) lists Card followed by the redirect methods in the session's order, each with its logo and a radio button. Apple Pay never shows. There's no list when Card is the only choice.
- Card information appears while Card is selected, showing outlined fields with floating labels and autofill. The number is first with the card's brand at its end, followed by the expiration date and CVV side by side, and the name field (optional by default).
- The save-card switch, under the card and off by default ("Save card for future use at My Shop"). It isn't shown in a setup or recurring session, or when the session's
setup_future_usageison_session. - The failure message, after a failed attempt.
- One button, pinned above the keyboard. There's none when Google Pay is the only method. Under it, the card brands the session accepts, when it lists them.
In a payout session:
A returning customer
At checkout, a customer with saved payment methods sees them first, and pays with the one chosen.
- Your
merchantDisplayName, with Close on the right, and the total under it. - Google Pay, Google's own button, when you set up
googlePay, the session offers it, and the device can pay, with "or" under it. - The carousel of saved methods shows the chosen method at full size with neighboring methods cropped beside it. It doesn't wrap. The first method sits at the start with the next two after it, and the last sits at the end. A card shows its card art when the card network sends it, and a drawn card otherwise. A PayPal or bank account shows only its logo while cropped. Swiping or tapping a cropped method brings it into the main slot and selects it. The carousel holds up to five methods, starting with the default followed by the others in the order Pay.com lists them. A method picked on Payment methods moves into the main slot (if it isn't among the five, it's added first).
- The chosen method's name, for example "Visa •••• 4242", with Change. Under the name, "Default" for the customer's default. Otherwise a card's expiration date and issuer, as in "Expires 08/29 · Example Bank", "Bank account" for a bank account, or else the account's email.
- A CVV field, labeled "CVV for Visa •••• 4242", when the session checks CVVs and Pay.com doesn't hold one for the card.
- One button labeled Pay €24.90.
Change opens Payment methods at full height in the same sheet, listing every unexpired saved method with a radio button on each row. Choosing a row goes back with that method in the carousel, and Back goes back without a change.
When the customer can remove saved methods, Edit is at the top right of Payment methods. Edit becomes Done, and each row's radio button becomes a delete button.
The last group, Other ways to pay, names the session's other methods, for example "Card, PayPal, iDEAL". It shows when the session has other methods, and hides while Edit is on. It opens the Other ways to pay page containing the card form, those methods, their own Pay button, and the accepted card brands underneath. Google Pay stays on the first page, and Back returns to Payment methods.
States
The sheet changes as the customer selects methods and pays.
| State | What the customer sees |
|---|---|
| The sheet opens | At checkout, a returning customer's default saved method, large in the carousel. Otherwise their default saved method selected, or else the first row. |
| Another method is selected | The card fields and the switch collapse, and come back with Card. |
| Card is the only method | The fields, without a list. |
| Google Pay is the only method | Its button alone. |
| The card details are wrong | "Card number is invalid", "Expiry date is invalid", or "CVV must be 3 or 4 digits" under the field immediately. After a tap on Pay, incomplete fields also display their validation messages, empty ones read "Required", the first gets focus, and nothing is sent. |
| Paying | A spinner in the button the customer tapped. Everything is disabled, and the sheet can't be closed. |
| 3DS, a redirect, or Google Pay | Its screen opens over the sheet. A cancel returns to the sheet, with no message. |
| Declined | "Your payment method has been declined." The customer can try again. |
| The total changed | "The total has changed. Check the new total, then pay again." The button shows the new total, and nothing was charged. |
| Another failure | "Check your connection and try again." or "Something went wrong. Please try again." |
| The session can't be paid anymore | "You have reached the maximum number of payment attempts.", "The session has expired and payment can no longer be made.", or "This payment can no longer be completed." Everything but Close is disabled. |
| A setup or payout session | Saved methods first. Using one makes it the customer's default, as in Let customers choose a payout method. |
| Removing a saved method | Edit becomes Done, and each saved row shows a red delete button. The customer confirms "Remove Visa •••• 4242?" with Remove, or taps Cancel. Once nothing is left to select, the sheet closes as Canceled. |
| Removing a saved method at checkout | On Payment methods, Edit becomes Done and each row's radio button a delete button. The customer confirms "Remove Visa •••• 4242?" with Remove, or taps Cancel. If the chosen method is removed, the default, or else the first, takes its place. When the customer removes their last saved method, the sheet switches to the new-customer view. |
| Large text | From a 150% font size, a list of the carousel's methods, with a radio button on each row, replaces the carousel, with Change under it. |
| Success | The sheet closes automatically and returns the PayResult so your app can display confirmation. |
The button
The button's label depends on the session and the selected method.
| Session and selection | The button reads |
|---|---|
| A payment | Pay €10.00, or Pay when the session has no amount or currency |
| A setup session, with a new method | Add your payment method |
| A setup session, with a saved method | Use payment method |
| A payout session, with any method | Use payment method |
Logos
The sheet shows the same logos as Pay.com.js. They're bundled in pay-elements, so nothing is downloaded.
| Where | What it shows |
|---|---|
| A method's row | The method's logo, as Pay.com.js shows it. A method without a logo of its own shows its monogram, as Pay.com.js does (up to two initials of its name on a white card, for example BD for Bacs Direct Debit). |
| The Card row | A card. |
| A saved method's row | The card's brand, or the method's logo. Without either, a monogram. |
| A saved method at checkout | A card's art, when the card network sends it, or else a drawn card in the brand's color, with the issuer or brand, the last 4 digits, the expiration date, and the brand's mark. PayPal and bank accounts show their logo on a white card in light mode, and a dark gray one in dark mode. |
| The card number field | The detected card brand at the end of the field (Visa, Mastercard, American Express, or Discover), or a generic card icon. TalkBack reads the brand's name. |
| Under the button | When the session takes cards and lists accepted brands, the logos for Visa, Mastercard, Discover, and American Express appear under the button. Other brands aren't shown there. TalkBack reads them as "Accepted cards: Visa, Mastercard". |
Your methodIcons replace the logo or monogram on every row of their type. An icon for card replaces the Card row's and the saved cards'. A redirect method's row reads the method's name, as Pay.com.js shows it, unless you set one in strings.methodNames. Its monogram takes its initials from the name the row shows.
When the amount changes
The drop-in checks the session's total when the sheet opens and again before it charges.
- When the sheet opens, it reads the session's total again, for up to 5 seconds. If it can't, it opens with the total it has, and still checks before it charges.
- When
beforePayor your server changes the total, nothing is charged at the old one. The Pay button shows the new total, under "The total has changed. Check the new total, then pay again.", and the customer taps again. beforePayruns again on that tap, so set the amount rather than adding to it.- Google Pay opens with the new total. If the total changes while Google's sheet is open, nothing is charged and the drop-in shows the same message.
present doesn't return AmountChanged. The customer pays again or closes the sheet. See When the amount changes for the check itself.
Example
class CheckoutActivity : ComponentActivity() {
private val viewModel: CheckoutViewModel by viewModels()
private fun showDropIn() {
val checkout = viewModel.checkout.value ?: return
val dropIn = PayDropIn(
checkout,
PayDropIn.Configuration(
merchantDisplayName = "My Shop",
// The sandbox. For live payments, leave environment out and set your merchantId.
googlePay = PayGooglePayConfiguration(environment = PayGooglePayConfiguration.Environment.TEST),
beforePay = { viewModel.cartIsStillValid() }, // Your own last check, for example stock
),
)
lifecycleScope.launch {
when (val result = dropIn.present(this@CheckoutActivity)) {
is PayResult.Succeeded -> showReceipt(result.ids) // A hint: your server confirms first
is PayResult.Processing -> showPending(result.ids) // Your server decides
PayResult.Canceled -> Unit // The customer closed the sheet
is PayResult.Failed -> showMessage(result.error) // The session can't be paid anymore
}
}
}
}Next steps
- Style the drop-in: Its colors, corners, fonts, and card fields.
- Change the drop-in's text: Translate the sheet, or change its wording.
- Pay with Google Pay: The Google Pay options.
- Handle the return URL: Let redirect payment methods come back to your app.