Skip to Content
Docs

Present the drop-in

Show a ready-made payment sheet over a checkout, with the session's methods, the card form, and the Pay button, and get the result when it closes.

PayDropIn is a ready-made payment sheet over a checkout, and present(from:) shows it and returns the result when it closes. Use it instead of building your own screen from the payment methods, the card fields, and pay. Link the PayDropIn product, which depends on PayCheckout, PayCore, and PayElements.

The sheet is built from system parts. For what it shows, from top to bottom and in each state, see What the customer sees. A returning customer sees their saved payment methods first. See A returning customer.

The customer selects a method, then pays. 3DS challenges and redirects open over the sheet. After a decline, the sheet shows a message and the customer can try again. When the session can't be paid anymore, the sheet disables everything but closing.

PayDropIn runs on the main actor.

let dropIn = PayDropIn(checkout: checkout, configuration: .init(merchantDisplayName: "My Shop"))
let result = await dropIn.present(from: self)

Parameters

ParameterTypeRequiredDescription
checkoutPayCheckoutYesThe checkout to pay with.
configurationPayDropIn.ConfigurationNoWhat the sheet shows. Default: Configuration(). It's also dropIn.configuration, which you can change before you present.
configuration.merchantDisplayNameString?NoYour name, above the total and in the save-card label, for example "Save card for future use at My Shop". Default: nil, for the total alone and "Save card for future use".
configuration.cardholderNamePayDropIn.CardholderNameNoControls the cardholder name field (.hidden, .optional, or .required). Default: .optional.
configuration.saveCardPayDropIn.SaveCardNo.automatic shows the save-card switch unless the session saves the card anyway (its setup_future_usage is on_session, or it's a recurring session) or only saves it (a setup session). .hidden never shows it. Default: .automatic.
configuration.paymentMethods[String]?NoShow only these types, for example ["card", "paypal"], ignoring case and in the session's order. It filters the saved methods by their type too, and Apple Pay shows only if the list includes applepay. Default: nil, every method.
configuration.allowsRemovingSavedPaymentMethodsBoolNoShows Edit over the saved methods, so the customer can remove them after confirming. Default: false.
configuration.applePayPayApplePayConfiguration?NoShows the Apple Pay button above the other methods when the session offers Apple Pay and canPayWithApplePay is true. Its buttonType sets the button. Default: nil, no Apple Pay.
configuration.appearancePayDropInAppearanceNoColors, fonts, shapes, and icons. Default: the system look. See Style the drop-in.
configuration.stringsPayDropInStringsNoEvery text the sheet shows, in English by default. See Change the drop-in's text.
configuration.beforePay(@MainActor (PayPaymentMethod) async -> Bool)?NoRuns immediately before the SDK submits the payment, with the method the customer chose, for example to update the session's amount on your server. Return false to stop. The sheet stays open, with no message. For Apple Pay, it runs before the Apple Pay 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. Default: nil.
presenterUIViewControllerYesThe view controller to present the sheet over (passed to present(from:)). If it's already presenting another controller, the sheet opens over that.

Returns

present(from:) returns a PayResult once the sheet has closed:

ResultWhen
.succeeded, .processingThe customer paid, the payment is pending, or in a setup session their payment method was saved or chosen. The sheet closes by itself.
.canceledThe customer closed the sheet.
.failed(PayError)The session can't be paid anymore and the customer closed the sheet. Create a new session to try again. Or the sheet wasn't shown. See Errors.

When the customer cancels a 3DS challenge or a redirect, the sheet stays open so they can try again.

PayResult is a hint for your UI, not the source of truth. Fulfill an order only after your server retrieves the session with Retrieve a payment session or receives the signed payment_session.completed webhook. For a setup session, use Retrieve a setup session or the setup_session.completed webhook.

Errors

present(from:) doesn't throw. It returns these immediately, without showing the sheet:

ErrorWhen
unsupportedThe drop-in has no available payment methods (no method passes paymentMethods, the session offers only Google Pay, or Apple Pay is its only method and isn't configured or available).
paymentInProgressThis drop-in is already showing.

These errors end the sheet's payments. It shows a message and disables everything but closing, and present returns the error when the customer closes it.

ErrorWhen
declined, with maxAttemptsReachedThe session's last attempt was declined.
sessionExpiredThe session expired.
sessionAlreadyCompleted, paymentEndedThe session was already paid, or the payment ended without being paid.

Other errors, such as a decline with attempts left or a network failure, show a message in the sheet, and the customer can try again.

What the customer sees

The drop-in is a system page sheet with a grabber and a navigation bar. On iOS 16 and later, it opens at the height of its content. On iOS 15, it opens at half height, or at full height when the session takes cards. It grows to full height while the customer types. On every version, a new customer's sheet at checkout opens at full height when the session takes cards, and its content scrolls above the pinned button.

Illustration of the iOS drop-in for a new customer: Close, Example shop and €24.90, an Apple Pay button, "or", a Pay with list with Card selected, PayPal, and iDEAL, each with its logo, the card fields, and a Pay €24.90 button with the accepted card brands under it.

From top to bottom

The sheet stacks these parts, and shows each one only when it applies.

  1. The top. At checkout, Close on the left, then your merchantDisplayName and the total. In a setup or payout session, the title, "Payment" or "Payout method", centered, with Close on the left, and Edit on the right when the customer can remove saved methods.
  2. Apple Pay, when you set it up, the session offers it, and the device can pay, with "or" under it when other methods follow.
  3. 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.
  4. Pay with (or Get paid with in a payout session) lists Card followed by the redirect methods in the session's order, each row with its logo. A checkmark marks the selected row. There's no list when Card is the only choice.
  5. Card information appears while Card is selected, presenting one grouped list with the card number, the expiration date and CVV side by side, and the name field (optional by default). Each input is labeled by its placeholder, and the number shows the card's brand at its end.
  6. 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_usage is on_session.
  7. The failure message, after a failed attempt.
  8. One button, pinned above the keyboard. There's none when Apple Pay is the only method. Under it, the card brands the session accepts, when it lists them.

In a payout session:

Illustration of the iOS drop-in titled Payout method, with Close on the left and Edit on the right: saved methods with a default Visa card ending in 4242 selected, a PayPal account, and a bank account, each with its logo, a Get paid with list of Card and PayPal, a Use payment method button, and the accepted card brands under it.

A returning customer

At checkout, a customer with saved payment methods sees them first, and pays with the one in front.

Illustration of the iOS drop-in for a returning customer: Close, Example shop and €24.90, an Apple Pay button, "or", a carousel of saved methods with a Visa card in front, the name Visa ending in 4242, a Change payment method button, and a Pay €24.90 button.Illustration of the iOS drop-in's Payment methods page: Back, the title, and Edit, the saved methods as tiles in two columns (a Visa card, chosen, with a checkmark, then a Mastercard, a PayPal account, and a bank account), and an Other ways to pay row.
  1. Close, on the left, then your merchantDisplayName and the total.
  2. Apple Pay, when you set it up, the session offers it, and the device can pay, with "or" under it.
  3. The carousel of saved methods shows the chosen method in front with neighboring methods behind it. A card shows its card art when the card network sends it, and a drawn card otherwise. Swiping or tapping a card behind brings it to the front. The carousel holds up to five methods, starting with the default followed by the others in the order Pay.com lists them. Picking another method on Payment methods puts it in front.
  4. The chosen method's name, for example "Visa •••• 4242", and Change payment method.
  5. A CVV field, when the session checks CVVs and Pay.com doesn't hold one for the card.
  6. One button labeled Pay €24.90.

Change payment method opens Payment methods, listing every unexpired saved method as tiles in two columns with a checkmark on the chosen one. Tapping a tile goes back with that method in front, and Back goes back without a change.

When the customer can remove saved methods, Edit is on the right of Payment methods. It puts a remove control on each tile.

The last row, Other ways to pay, opens the card form and the session's other payment methods, with their own Pay button and, under it, the card brands the session accepts.

States

The sheet changes as the customer selects methods and pays.

StateWhat the customer sees
The sheet opensAt checkout, a returning customer's default saved method, in front of the carousel. Otherwise their default saved method selected, or else the first row.
Another method is selectedThe card form and its switch collapse, and come back with Card.
Card is the only methodThe form, without a list.
Apple Pay is the only methodIts 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 input immediately. After a tap on Pay, incomplete fields also display their validation messages, empty ones read "Required", and the first gets focus.
PayingA spinner in the Pay button, or the Apple Pay sheet's own progress. Everything is disabled, and the sheet can't be closed.
3DS or a redirectIts 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 sessionSaved methods first. Using one makes it the customer's default.
Removing a saved methodEdit shows a red minus on each saved row. 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 checkoutOn Payment methods, Edit shows a remove control on each tile. The customer confirms "Remove Visa •••• 4242?" with Remove, or taps Cancel, and a spinner shows on the tile while it's removed. 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 textAt accessibility text sizes, a list headed "Saved" replaces the carousel and method name, showing every saved method with a checkmark on the chosen one and Change payment method underneath. Payment methods shows its tiles in one column.
SuccessThe 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 selectionThe button reads
A paymentPay €10.00, or Pay when the session has no amount or currency
A setup session, with a new methodAdd your payment method
A setup session, with a saved methodUse payment method
A payout session, with any methodUse payment method

Logos

The sheet shows the same logos as Pay.com.js. They're bundled in PayElements, so nothing is downloaded.

WhereWhat it shows
A method's rowThe 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 rowA card.
A saved method's rowThe card's brand, or the method's logo. Without either, a monogram.
A saved method at checkoutA 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 inputThe detected card brand at the end of the field (Visa, Mastercard, American Express, or Discover), or a generic card icon. VoiceOver reads the brand after the input's label.
Under the buttonWhen 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. VoiceOver 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 beforePay or 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.
  • beforePay runs again on that tap, so set the amount rather than adding to it.
  • Apple Pay opens with the new total. If the total changes while the Apple Pay sheet is open, that sheet closes 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

import PayCheckout
import PayCore
import PayDropIn
import UIKit

extension CartViewController {
    // clientSecret comes from your server, which created the session.
    func checkoutTapped(clientSecret: String) async {
        do throws(PayError) {
            let checkout = try await PayCheckout(
                clientSecret: clientSecret,
                configuration: .init(returnURL: URL(string: "myshop://pay")!)
            )
            var configuration = PayDropIn.Configuration(merchantDisplayName: "My Shop")
            configuration.applePay = PayApplePayConfiguration(merchantIdentifier: "merchant.com.myshop")
            configuration.beforePay = { [weak self] _ in
                await self?.reserveStock() ?? false   // Return false to stop without a message
            }

            switch await PayDropIn(checkout: checkout, configuration: configuration).present(from: self) {
            case .succeeded(let ids), .processing(let ids):
                showConfirmation(ids)         // A hint: your server confirms before fulfilling
            case .canceled:
                break                         // The customer closed the sheet
            case .failed(let error):
                showMessage(error.localizedDescription)   // Create a new session to try again
            }
        } catch {
            showMessage(error.localizedDescription)       // The checkout couldn't start
        }
    }
}

Next steps

Was this page helpful?