Pay with Apple Pay or Google Pay
Turn on the drop-in's Apple Pay button on iOS and its Google Pay button on Android, and set up what each wallet needs.
The drop-in shows the Apple Pay button on iOS, and the Google Pay button on Android, above the other methods. Turn them on with the applePay and googlePay options of checkout.presentDropIn(). Each platform reads only its own option, so pass both and each platform shows its wallet. The customer pays in the wallet's own sheet, which opens with the session's current total, and presentDropIn() resolves with the result as for any other method. Pay.com decrypts the wallet's token, so the app never handles card data.
const result = await checkout.presentDropIn({
applePay: { merchantIdentifier: 'merchant.com.myshop' },
googlePay: {},
})Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
applePay | PayApplePayOptions | No | Shows the Apple Pay button on iOS. |
applePay.merchantIdentifier | string | Yes | A merchant ID from your app's Apple Pay entitlement, for example merchant.com.myshop. |
applePay.merchantCountryCode | string | No | Your country, as an ISO 3166 alpha-2 code such as US. Default: your Pay.com account's country. |
applePay.merchantDisplayName | string | No | The total's label in the Apple Pay sheet. Default: your account's statement name. |
applePay.buttonType | 'plain' | 'buy' | 'checkout' | 'book' | 'subscribe' | 'donate' | 'order' | 'continue' | 'inStore' | 'setUp' | No | The button's label. Default: 'plain', the Apple Pay mark alone. |
googlePay | PayGooglePayOptions | No | Shows the Google Pay button on Android. {} turns it on with the defaults. |
googlePay.merchantId | string | No | Your Google merchant ID. Default: the one set up with Pay.com for your account. |
googlePay.merchantName | string | No | The merchant name in the Google Pay sheet. Default: your account's statement name. |
googlePay.environment | 'test' | 'production' | No | Google Pay's environment. Default: 'production' for live sessions, 'test' for sandbox ones. |
googlePay.buttonType | 'plain' | 'buy' | 'pay' | 'checkout' | 'order' | 'subscribe' | 'book' | 'donate' | No | The button's label. Default: 'plain', the Google Pay mark alone. |
googlePay.buttonTheme | 'dark' | 'light' | No | The button's theme. Default: dark on a light sheet, light on a dark one. |
On iOS, appearance.applePayButtonStyle sets the Apple Pay button's colors. strings.orSeparator is the text between the wallet's button and the other methods.
When the button shows
The drop-in shows the wallet's button when all of these hold:
- You passed the platform's option (
applePayon iOS orgooglePayon Android). - The session offers the wallet, which means
checkout.paymentMethods()listsapplepayorgooglepay. If you pass the drop-in'spaymentMethodsoption, the wallet is in that list too. - The session takes a payment. It's a sale or authorization session with an amount and a currency, not a setup session.
- Your Pay.com account has a country. On iOS,
merchantCountryCodecan set it instead. - The device can pay with the wallet, with a card network the session accepts.
Otherwise, the sheet opens without the button.
Set up the wallets
Apple Pay needs the Apple Pay capability in your app, with the merchant ID you pass as merchantIdentifier. Pay.com must also hold that merchant ID's payment processing certificate for your account, because Pay.com decrypts the Apple Pay token.
Google Pay runs in Google's test environment for sandbox sessions. Live payments need Google's production access for your app, with your Google merchant ID, from the Google Pay & Wallet Console. The SDK already turns on the Google Pay API in the app's manifest.
Errors
presentDropIn() rejects as described in its errors. It rejects with a TypeError before the sheet opens when an option has an invalid value, such as an applePay without a non-empty merchantIdentifier, a merchantCountryCode that isn't two letters, a googlePay that isn't an object, or a buttonType, environment, or buttonTheme outside the allowed values. This validation runs on both platforms, even for the option the current platform doesn't use.
Example
import { PayCheckout, type PayResult } from '@pay-com/react-native'
export async function payWithWallets(clientSecret: string): Promise<PayResult> {
const checkout = await PayCheckout.create(clientSecret, { returnUrl: 'myshop://pay' })
try {
return await checkout.presentDropIn({
merchantDisplayName: 'My Shop',
applePay: {
merchantIdentifier: 'merchant.com.myshop',
merchantCountryCode: 'US',
buttonType: 'buy',
},
googlePay: { buttonType: 'buy' },
appearance: { applePayButtonStyle: 'black' },
})
} finally {
checkout.release()
}
}Next steps
- Present the drop-in: The sheet's other options, its result, and its errors.
- Style the drop-in: The Apple Pay button's style, with the rest of the sheet's look.
- Change the drop-in's text: The text between the wallet's button and the other methods.