ApplePay / GooglePay
Description
This module handles digital wallet payments for both Android (Google Pay) and iOS (Apple Pay). It provides UI buttons that trigger the native wallet interface and process the payment securely through the Nuvei backend.
The module consists of two main parts:
GooglePayButton– a component for Android that usesPaymentRequestto check availability and display the Google Pay sheet, then processes the token viainitPaymentandclientPaymentAppleGooglePay.ApplePayButton– a component for iOS that uses theuseApplePayhook to open the Apple Pay sheet and processes the payment token viaclientPaymentAppleGooglePay.
GooglePay
Overview
Purpose - GooglePayButton handles the initialization and execution of Google Pay payments on Android. It interacts with the PaymentRequest API from the Nuvei SDK and the Nuvei backend.
Where it is used - Used on checkout screens as a quick-pay option for Android users.
What the component does
At a high level, this component checks Google Pay availability via paymentRequest.canMakePayment(), displays the native Google Pay sheet via paymentRequest.show(), collects the payment token and sends it to Nuvei for processing in two sequential backend calls (initPayment then clientPaymentAppleGooglePay), shows a ModalBackdrop while backend calls are in flight, and handles success and error callbacks.
-
Initialization
- Accepts
nvPayment(NVPaymentGooglePay),onSuccess,onError,countryCode, and optionalallowedPaymentMethods,theme,type,radius,style,sourceApplication. - Reads
environment(staging/prod) fromuseNuveiContext(). - Builds a
PaymentRequestusinggooglePayRequestData(merchant info + country code) andpaymentDetails(amount + currency).
- Accepts
-
Google Pay Flow (onPress)
- Validates required props with
validateProps(). - Calls
paymentRequest.canMakePayment().- If
false→ callsonError({ reason: 'Google Pay unavailable' }). - If
true→ callsshowPaymentForm().
- If
- Validates required props with
-
showPaymentForm()
- Calls
paymentRequest.show()to display the native Google Pay sheet. - Extracts
paymentMethodDatafrom the response asmobileToken. - Passes it to
handleClientPayment(mobileToken).
- Calls
-
handleClientPayment(mobileToken)
- Sets
isLoading = true. - Calls
initPayment(initPaymentBody)whereinitPaymentBodyincludes:paymentOption.card.externalTokenwithexternalTokenProvider: 'GooglePay'and themobileToken.paymentOption.useInitPayment: true.
- If
initPaymentfails or returnsDECLINED→ callsonErrorand returns. - If
initPaymentsucceeds → callsclientPaymentAppleGooglePay(body, sourceApplication). - If
clientPaymentAppleGooglePaysucceeds → callsonSuccess(response). - If it fails or returns
DECLINED→ callsonError(errorObj). - Resets
isLoading = falsein afinallyblock.
- Sets
Data structure
Props
type GooglePayButtonProps = {
nvPayment: NVPaymentGooglePay; // Required — payment and merchant details
onSuccess: (res: any) => void; // Required
onError: (error: any) => void; // Required
countryCode: string; // Required — merchant's country code
allowedPaymentMethods?: any; // Array of allowed payment methods
theme?: 'LIGHT' | 'DARK' | any;
type?: any;
radius?: number;
style?: any;
sourceApplication?: SourceApplication; // Defaults to SourceApplication.GOOGLE_PAY
};
NVPaymentGooglePay requires: sessionToken, merchantId, merchantSiteId, amount, currency.
Internal request body for initPayment
const initPaymentBody: NVPaymentBody = {
currency: nvPayment.currency,
merchantId: String(nvPayment.merchantId),
merchantSiteId: nvPayment.merchantSiteId,
paymentOption: {
card: {
externalToken: {
externalTokenProvider: 'GooglePay',
mobileToken: mobileToken,
},
},
useInitPayment: true,
},
sessionToken: nvPayment.sessionToken,
sourceApplication,
};
Integration
import { GooglePayButton } from 'react-native-nuvei';
<GooglePayButton
nvPayment={nvPaymentData}
onSuccess={handleSuccess}
onError={handleError}
countryCode="US"
/>
Error handling
canMakePayment()returnsfalse→onError({ reason: 'Google Pay unavailable' }).- Any exception from
canMakePayment()orshow()→ error forwarded toonError. initPaymentstatus notSUCCESSortransactionStatus === 'DECLINED'→onErrorwithstatus: 'ERROR'or'DECLINED'.clientPaymentAppleGooglePayfailure →onErrorwith error details.
ApplePay
Overview
Purpose - ApplePayButton manages Apple Pay transactions on iOS devices. It uses the useApplePay hook to open the Apple Pay sheet and processes the payment token through clientPaymentAppleGooglePay.
Where it is used - Used on checkout screens as a quick-pay option for iOS users.
What the component does
At a high level, this component renders a tappable Apple Pay image button. On press, it validates props and calls onApplePay() (from useApplePay) with payment values and merchant ID. The handlePayment callback in useApplePay receives the Apple Pay response, sends it to clientPaymentAppleGooglePay, and calls onSuccess or onError based on the backend response.
-
Setup
- Accepts
nvPayment(NVPaymentApplePay | null),applePayMerchantId,onSuccess,onError,countryCode, and optionalsourceApplication. - Initializes the
useApplePayhook with ahandlePaymentcallback andisCreateSub: false.
- Accepts
-
handlePayment callback (called by useApplePay after user authorizes)
- Builds the
clientPaymentAppleGooglePayrequest body:country: countryCodeplatform: 'IOS'mobileToken: JSON.stringify({ paymentData: paymentResponse })- merchant identifiers, session token, currency, billing/shipping addresses, user details
- Calls
clientPaymentAppleGooglePay(body, sourceApplication). - If response status is not
SUCCESSortransactionStatus === 'DECLINED'→ callsonError(errorObj). - On success → calls
onSuccess(responseClientPayment).
- Builds the
-
initiateApplePay() (onPress handler)
- Validates required props with
validateProps(). - Calls
onApplePay({ paymentValues, merchantId })where:paymentValuescontainscountry,currency,amount, andlabel: 'Test Product'.merchantIdisapplePayMerchantId.
- Catches errors and calls
onErrorwith structured error objects.
- Validates required props with
Data structure
Props
type ApplePayButtonType = {
nvPayment: NVPaymentApplePay | null; // Required — payment and merchant details
applePayMerchantId: string; // Required — Apple Pay merchant identifier
onSuccess: (res: any) => void; // Required
onError: (res: any) => void; // Required
countryCode: string; // Required — merchant's country code
sourceApplication?: SourceApplication; // Defaults to SourceApplication.APPLE_PAY
};
NVPaymentApplePay requires: sessionToken, merchantId, merchantSiteId, amount, currency.
clientPaymentAppleGooglePay request body
const body = {
country: countryCode,
platform: 'IOS',
mobileToken: JSON.stringify({ paymentData: paymentResponse }),
merchantId: nvPayment?.merchantId,
sessionToken: nvPayment?.sessionToken,
merchantSiteId: nvPayment?.merchantSiteId,
email: nvPayment?.userTokenId,
currencyCode: nvPayment?.currency,
billingAddress: nvPayment?.billingAddress,
shippingAddress: nvPayment?.shippingAddress,
userDetails: nvPayment?.userDetails,
};
Integration
import { ApplePayButton } from 'react-native-nuvei';
<ApplePayButton
nvPayment={nvPaymentData}
applePayMerchantId="merchant.com.example"
onSuccess={handleSuccess}
onError={handleError}
countryCode="US"
/>
Error handling
- Any exception from
onApplePay()is caught ininitiateApplePay():- If
error.code === 10010→onError(error). - If
error.messageis present →onError({ errCode: error.message, result: 'ERROR', status: 'ERROR' }). - Otherwise →
onError(error).
- If
- Backend response
status !== SUCCESS→onErrorwithstatus: 'ERROR'. - Backend
transactionStatus === 'DECLINED'→onErrorwithstatus: 'DECLINED'.