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 initializes Google Pay, displays the native payment sheet, and handles the transaction result.ApplePayButton– a component for iOS that manages the Apple Pay session, displays the payment sheet, and processes the transaction.
GooglePay
Overview
Purpose - GooglePayBtn handles the initialization and execution of Google Pay payments on Android. It interacts with the Google Pay API and the Nuvei backend.
Where it is used - Used on checkout screens as a quick-pay option for Android users.
Behavior
- Checks for Google Pay availability.
- Initializes a Google Pay payment session.
- Displays the native Google Pay payment sheet.
- Collects the payment token and sends it to Nuvei for processing.
- Handles success and error callbacks.
What the component does
-
Initialization
- Accepts
nvPaymentMerchantSettingsand callback handlers (onSuccess,onError). - Retrieves the current
simplyConnectI18NSettingsfor localized button text.
- Accepts
-
Google Pay Flow
- When the user taps the button:
- Calls
initGooglePayto prepare the environment. - Calls
isGooglePaySupportedto verify if Google Pay is available. - If supported, calls
createGooglePayPaymentto show the native payment sheet. - Receives a payment token from Google.
- Calls
- When the user taps the button:
-
Transaction Processing
- Sends the Google Pay token and transaction details to Nuvei via
doClientPayment. - On success ->
onSuccess(response)is called. - On failure ->
onError(error)is called.
- Sends the Google Pay token and transaction details to Nuvei via
Data structure
Request
initGooglePay parameters:
testEnv: Boolean indicating whether to use the test environment.merchantName: Merchant's display name.countryCode: Merchant's country code.
createGooglePayPayment parameters:
amount: Total amount.currencyCode: Currency code.googlePayGateway: Gateway name (e.g., 'nuvei').googlePayGatewayMerchantId: Nuvei merchant site ID.
Integration
import { GooglePayBtn } from 'react-native-nuvei';
<GooglePayBtn
nvPayment={nvPaymentMerchantSettings}
onSuccess={handleSuccess}
onError={handleError}
/>
Error handling
- Logs errors if Google Pay is not supported on the device.
- Handles user cancellation or payment failure in the native sheet.
- Forwards Nuvei backend errors to the
onErrorcallback.
ApplePay
Overview
Purpose - ApplePayButton manages Apple Pay transactions on iOS devices. It handles session creation, the native payment sheet, and transaction verification.
Where it is used - Used on checkout screens as a quick-pay option for iOS users.
Behavior
- Verifies Apple Pay availability.
- Creates an Apple Pay payment request.
- Displays the native Apple Pay sheet.
- Processes the payment token through Nuvei.
- Handles success and error outcomes.
What the component does
-
Setup
- Accepts
nvPaymentMerchantSettings,applePayMerchantId, and callbacks. - Uses localized text for the button label.
- Accepts
-
Apple Pay Flow
- Tapping the button:
- Verifies if Apple Pay can make payments.
- Configures a
PaymentRequestwith amount, currency, and merchant ID. - Displays the Apple Pay sheet using
showPaymentRequest.
- Tapping the button:
-
Transaction Verification
- After user authorization, the payment token is sent to Nuvei via
doClientPayment. - On successful backend response ->
onSuccessis called, and the Apple Pay sheet is dismissed with a success status. - On failure ->
onErroris called, and the sheet is dismissed with a failure status.
- After user authorization, the payment token is sent to Nuvei via
Data structure
Request
PaymentRequest configuration:
merchantIdentifier: Your Apple Pay Merchant ID.countryCode: Merchant's country code.currencyCode: Transaction currency.paymentSummaryItems: Array of items withlabelandamount.
Integration
import { ApplePayButton } from 'react-native-nuvei';
<ApplePayButton
nvPayment={nvPaymentMerchantSettings}
applePayMerchantId="merchant.com.example"
onSuccess={handleSuccess}
onError={handleError}
/>
Error handling
- Catches errors during session initialization.
- Handles cases where the user cancels the payment sheet.
- Forwards Nuvei transaction errors to the
onErrorcallback.