Android / Google Pay
Behaviour of android/src/main/java/com/margelo/nitro/pay/*.kt at v0.0.16.
The TEST environment default
private fun determineEnvironment(envConfig: GooglePayEnvironment?): Int {
return when (envConfig) {
GooglePayEnvironment.PRODUCTION -> WalletConstants.ENVIRONMENT_PRODUCTION
GooglePayEnvironment.TEST, null -> WalletConstants.ENVIRONMENT_TEST
}
}null and 'TEST' collapse to the same branch. Omitting googlePayEnvironment runs your
production build against Google Pay's test environment. There is no warning, and the payment
sheet looks normal.
What happens in TEST:
- Tokens are test tokens. Your gateway rejects them, or worse, accepts them into a sandbox while the user believes they have paid.
merchantIdis omitted entirely frommerchantInfo— it is added only inPRODUCTION.googlePayGatewayandgooglePayGatewayMerchantIdfall back to the placeholder constants"example"and"exampleGatewayMerchantId".merchantNamefalls back to"Example Merchant", which the user sees in the sheet.
So a request with no Google configuration at all still opens a working-looking sheet. That is convenient for a demo and dangerous for a release.
PRODUCTION validates up front and throws if anything is missing:
require(!request.googlePayMerchantId.isNullOrBlank()) // "googlePayMerchantId is required in PRODUCTION"
require(!request.googlePayGateway.isNullOrBlank()) // "googlePayGateway is required in PRODUCTION"
require(!request.googlePayGatewayMerchantId.isNullOrBlank()) // "googlePayGatewayMerchantId is required in PRODUCTION"Those throws are caught by startPayment and surface as
Failed to start payment: <message> with success: false.
Check this first whenever an Android payment "works but never charges", or a token is rejected by the gateway.
supportedNetworks is ignored
GooglePayRequestBuilder.createAllowedCardNetworks() returns a fixed array:
put(PaymentConstants.NETWORK_VISA) // "VISA"
put(PaymentConstants.NETWORK_MASTERCARD) // "MASTERCARD"
put(PaymentConstants.NETWORK_AMEX) // "AMEX"
put(PaymentConstants.NETWORK_DISCOVER) // "DISCOVER"PaymentRequest.supportedNetworks is never read anywhere in android/. Requesting JCB, Maestro,
Elo, or Interac has no effect on Android — those cards simply will not be offered. On iOS the same
field is honoured, so the two platforms will show different card lists from identical JavaScript.
allowedAuthMethods is likewise fixed to ["PAN_ONLY", "CRYPTOGRAM_3DS"].
canMakePayments does not check the device
override fun canMakePayments(usingNetworks: Array<String>): Boolean {
return usingNetworks.any { network ->
PaymentConstants.SUPPORTED_NETWORKS.contains(network.lowercase())
}
}SUPPORTED_NETWORKS is listOf("visa", "mastercard", "amex", "discover"). That is the whole
implementation: a case-insensitive string comparison. It never touches PaymentsClient, never
asks whether Google Pay is installed, and never checks for a saved card.
canMakePayments(['visa']) returns true on a device with no Google Pay at all.
Use payServiceStatus() instead on Android — that one does call isReadyToPay.
payServiceStatus() blocks
It is declared synchronous in the Nitro spec, and its Android implementation does:
Tasks.await(task, 5, TimeUnit.SECONDS)twice — once with existingPaymentMethodRequired = false (→ canSetupCards) and once with
true (→ canMakePayments). Each is a network-backed Play Services call.
Consequences:
- Worst case ~10 seconds of blocking on the calling thread.
- Because the call is synchronous JSI, that thread is the JavaScript thread. The UI stops responding, and a long enough stall on the main thread can produce an ANR.
usePaymentCheckoutcalls it in a mount effect, so any screen using the hook inherits the stall at mount.
Mitigations, in order of preference:
- Do not read availability on a screen's critical path. Check it before navigating to checkout, or on app idle, and cache the result.
- If you use the hook, mount it only on the checkout screen — not in a layout or provider that mounts early.
- Show a loading state;
isCheckingStatusis exposed for exactly this.
On failure it catches, logs "Error checking status", and returns
{ canMakePayments: false, canSetupCards: false } — so a timeout looks identical to an
unsupported device.
Also note the first call uses currentEnvironment, which is initialised to ENVIRONMENT_TEST and
only updated by a startPayment. An availability check before the first payment therefore always
queries the test environment.
The payment flow
Wallet.getPaymentsClient(context, WalletOptions.setEnvironment(environment))GooglePayRequestBuilder.createPaymentDataRequest(request, environment)builds the JSONlogPaymentRequest(...)writes it to logcat (see below)reactContext.currentActivity—nullgivesNo activity available to show payment UIAutoResolveHelper.resolveTask(client.loadPaymentData(request), activity, 991)onActivityResultwith request code991
Result handling:
resultCode |
Outcome |
|---|---|
RESULT_OK |
PaymentData.getFromIntent → mapped to a success result; a null intent gives No payment data received |
RESULT_CANCELED |
Payment cancelled by user |
AutoResolveHelper.RESULT_ERROR |
Payment error: <statusMessage>, or Unknown error |
| anything else | Payment failed with result code: <n> |
All of these resolve the promise with success: false. None reject.
The handler registers itself as an ActivityEventListener in init, so a PaymentHandler
instance must outlive the sheet. Since HybridPaymentHandler is created at module scope, that
holds in practice.
paymentPromise is a single nullable field. A second startPayment while a sheet is open
overwrites it and the first promise never settles.
The request JSON
{
"apiVersion": 2,
"apiVersionMinor": 0,
"merchantInfo": {
"merchantName": "<merchantName | \"Example Merchant\">",
"merchantId": "<googlePayMerchantId — PRODUCTION only>"
},
"allowedPaymentMethods": [{
"type": "CARD",
"parameters": {
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
"allowedCardNetworks": ["VISA", "MASTERCARD", "AMEX", "DISCOVER"]
},
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "<googlePayGateway | \"example\">",
"gatewayMerchantId": "<googlePayGatewayMerchantId | \"exampleGatewayMerchantId\">"
}
}
}],
"transactionInfo": {
"totalPriceStatus": "FINAL",
"totalPrice": "<sum of paymentItems, \"%.2f\" in Locale.US>",
"totalPriceLabel": "Total",
"currencyCode": "<currencyCode>",
"countryCode": "<countryCode>",
"displayItems": [
{ "label": "...", "type": "LINE_ITEM | PENDING", "price": "..." }
]
}
}Notes:
totalPriceStatusis alwaysFINAL, even if every item is'pending'.totalPriceLabelis always the literal"Total".- Prices format with
Locale.US, so the decimal separator is always.regardless of device locale — which is what Google Pay requires. tokenizationSpecification.typeis alwaysPAYMENT_GATEWAY.DIRECTtokenization (decrypting tokens yourself) is not supported.
Ignored request fields
shippingType, shippingMethods, billingContactRequired, shippingContactRequired, and
applePayMerchantIdentifier are all unread on Android. Google Pay's own shipping and billing
address options are not exposed.
The token
PaymentToken(
paymentMethod = ...,
transactionIdentifier = UUID.randomUUID().toString(),
paymentData = tokenizationData.getString("token")
)paymentDatais Google'stokenizationData.token— forPAYMENT_GATEWAYthis is normally a gateway-specific JSON string, not base64. The README's claim thatpaymentDatais always base64 is true for iOS only.transactionIdentifierandPaymentResult.transactionIdare two different freshly generated UUIDs. Neither comes from Google.paymentMethod.typeis always'unknown';secureElementPassandbillingAddressare alwaysnull.displayNameis"<cardNetwork> <cardDetails>", e.g."VISA ••••1234".mapCardNetworkrecognises VISA, MASTERCARD, AMEX, DISCOVER, JCB, MAESTRO, ELECTRON, ELO, and INTERAC, and falls back toPaymentNetwork.VISAfor anything else — including"privateLabel"and the"unknown"default. Never usenetworkfor business logic on Android.
A JSONException while parsing gives Failed to parse payment data: <message>.
GooglePayButton
GooglePayButtonFactory uses the official
com.google.android.gms.wallet.button.PayButton, so branding compliance comes for free.
Native defaults, despite TypeScript marking both props required: buttonType is BUY, theme is
DARK, radius is null.
HybridGooglePayButton logs to logcat under HybridGooglePayButton — including
"Button reused - props unchanged", which is useful for confirming recycling behaviour.
The spec is { android: 'kotlin' }, so the component exists on Android only.
AndroidManifest
The library's own manifest is empty. The required
com.google.android.gms.wallet.api.enabled meta-data comes from the Expo config plugin with
enableGooglePay: true, or from your own manifest in bare React Native:
<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />Missing that meta-data is the most common cause of "Google Pay isn't available".
Logging
Log.d(PaymentConstants.TAG_PAYMENT_HANDLER, "Payment request: $request")Tags: HybridPaymentHandler and HybridGooglePayButton.
adb logcat -s HybridPaymentHandler:V HybridGooglePayButton:VThis is genuinely the fastest way to diagnose Android payment problems — the log line shows the exact JSON, so you can read off the environment, gateway, and merchant ID actually being used.
It is not gated on BuildConfig.DEBUG. The token is not logged, but merchant and gateway IDs
and line-item labels are. See security.md.
Emulator
An emulator with Google Play Services can install Google Pay and show the sheet with test cards in
ENVIRONMENT_TEST. It cannot produce a chargeable token. Emulator images without Play Services
fail isReadyToPay outright. See testing.md.