Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ All notable changes to this project are documented in this file.

### Added

- **Google Pay `DIRECT` tokenization.** `PaymentRequest` and `usePaymentCheckout` add
`googlePayTokenization`. `{ type: 'direct', publicKey }` has Google encrypt the token with your
own EC public key (`protocolVersion: "ECv2"`), for a PCI DSS compliant server that decrypts it;
it needs Google's approval. A missing `publicKey` fails with `'CONFIGURATION'` in every
environment, and `PRODUCTION` then needs no gateway values. Omitted or `{ type: 'gateway' }`
sends the same request as before. See
[Direct tokenization](https://gmi-software.github.io/react-native-pay/docs/setup/android-google-pay#direct-tokenization)
([#89](https://github.com/gmi-software/react-native-pay/issues/89)).
- **ISO 3166-2 region codes in Google Pay addresses.** `CNPostalAddress` adds
`isoAdministrativeArea`, the region as an ISO 3166-2 code such as `'US-CA'`, for tax and shipping
systems that need a code rather than the free-text `state`. Android now requests full billing
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ interface UsePaymentCheckoutConfig {
googlePayEnvironment?: "TEST" | "PRODUCTION";
googlePayGateway?: string;
googlePayGatewayMerchantId?: string;
googlePayTokenization?: GooglePayTokenization; // Default: gateway. { type: "direct", publicKey } to decrypt yourself
googlePayAllowedAuthMethods?: GooglePayAuthMethod[]; // Default: ['PAN_ONLY', 'CRYPTOGRAM_3DS']
googlePayAllowPrepaidCards?: boolean; // false leaves prepaid cards out. Default: true
googlePayCheckoutOption?: GooglePayCheckoutOption; // Sheet button label. Default: Google Pay picks
Expand Down Expand Up @@ -807,6 +808,7 @@ interface PaymentRequest {
googlePayEnvironment?: "TEST" | "PRODUCTION";
googlePayGateway?: string;
googlePayGatewayMerchantId?: string;
googlePayTokenization?: GooglePayTokenization; // who encrypts the token
googlePayAllowedAuthMethods?: string[]; // GooglePayAuthMethod values
googlePayAllowPrepaidCards?: boolean; // false leaves prepaid cards out
googlePayCheckoutOption?: GooglePayCheckoutOption; // the sheet's button label
Expand Down Expand Up @@ -906,6 +908,14 @@ type GooglePayCheckoutOption =
| "completeImmediatePurchase"
| "continueToReview";

// Who encrypts the Google Pay token (Android). 'direct' needs Google's approval,
// PCI DSS compliance and your base64 EC public key; your server decrypts the token.
type GooglePayTokenizationType = "gateway" | "direct";
interface GooglePayTokenization {
type: GooglePayTokenizationType;
publicKey?: string; // required for 'direct'
}

// Payment Method Type
type PaymentMethodType = "unknown" | "debit" | "credit" | "prepaid" | "store";

Expand Down
23 changes: 23 additions & 0 deletions docs/docs/api/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ interface PaymentRequest {
googlePayEnvironment?: 'TEST' | 'PRODUCTION'
googlePayGateway?: string
googlePayGatewayMerchantId?: string
googlePayTokenization?: GooglePayTokenization // default: gateway
googlePayAllowedAuthMethods?: string[] // GooglePayAuthMethod values
googlePayAllowPrepaidCards?: boolean // default: true
googlePayCheckoutOption?: GooglePayCheckoutOption // the sheet's button label
Expand All @@ -108,6 +109,8 @@ Without `googlePayEnvironment`, Android uses `'TEST'`. When it is omitted, an An

`supportedNetworks` takes [`PaymentNetwork`](#paymentnetwork) names, matched ignoring case, and limits the cards the payer can choose on both platforms. A name that is not a `PaymentNetwork` fails the payment with `code: 'CONFIGURATION'` and an `error` that contains `Unknown payment network "<value>". Use a PaymentNetwork value such as "visa" or "mastercard"`. A network the platform does not offer is left out, so one cross-platform list works: Android drops `cartesBancaires`, for example. The payment fails when no network is left.

`googlePayTokenization` sets who encrypts the Google Pay token: your gateway, from `googlePayGateway` and `googlePayGatewayMerchantId`, or your own server with `'direct'`. See [`GooglePayTokenization`](#googlepaytokenization). Omitted, it is `'gateway'`. Android only.

`googlePayAllowedAuthMethods` takes [`GooglePayAuthMethod`](#googlepayauthmethod) values and defaults to both. Android only.

`googlePayAllowPrepaidCards: false` leaves prepaid cards out of the Google Pay sheet, for a gateway or risk policy that refuses them. Sent as Google Pay's `allowPrepaidCards`. Omitted or `true`, prepaid cards are accepted. Android only: Apple Pay cannot leave prepaid cards out.
Expand Down Expand Up @@ -449,6 +452,26 @@ Any other value fails the payment on both platforms with `code: 'CONFIGURATION'`

---

## GooglePayTokenization

Who encrypts the Google Pay token, used in `googlePayTokenization` (Android only). Sent as the card's `tokenizationSpecification`.

```ts
type GooglePayTokenizationType = 'gateway' | 'direct'

interface GooglePayTokenization {
type: GooglePayTokenizationType
publicKey?: string // required for 'direct'
}
```

- `'gateway'` — Google encrypts the token for your payment gateway, named by `googlePayGateway` and `googlePayGatewayMerchantId`. Google Pay calls it `PAYMENT_GATEWAY`. The same request as leaving `googlePayTokenization` out; `publicKey` is ignored.
- `'direct'` — Google encrypts the token with your own public key, and your server decrypts it. Sent as `{"type":"DIRECT","parameters":{"protocolVersion":"ECv2","publicKey":"<publicKey>"}}`; the gateway fields are ignored. It needs Google's approval and PCI DSS compliance. See [Decrypt the token yourself](/docs/guides/server-processing#decrypt-the-token-yourself-google-pay-direct).

With `'direct'`, a missing or blank `publicKey` fails the payment with `code: 'CONFIGURATION'` and an `error` that contains `googlePayTokenization.publicKey is required for 'direct' tokenization`, in `TEST` too: unlike the gateway, there is no example key to fall back to. In `PRODUCTION`, `'direct'` still needs `googlePayMerchantId`, but not `googlePayGateway` or `googlePayGatewayMerchantId`. Another `type` fails the payment on both platforms with `code: 'CONFIGURATION'`. iOS ignores the rest.

---

## MerchantCapability

Merchant capabilities, used in `merchantCapabilities`. They come from Apple Pay; Android only reads `'Credit'` and `'Debit'`.
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/api/use-payment-checkout.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface UsePaymentCheckoutConfig {
googlePayEnvironment?: 'TEST' | 'PRODUCTION'
googlePayGateway?: string
googlePayGatewayMerchantId?: string
googlePayTokenization?: GooglePayTokenization // default: gateway
googlePayAllowedAuthMethods?: GooglePayAuthMethod[] // default: both
googlePayAllowPrepaidCards?: boolean // default: true
googlePayCheckoutOption?: GooglePayCheckoutOption // the sheet's button label
Expand All @@ -53,6 +54,7 @@ interface UsePaymentCheckoutConfig {
- **merchantName** — The business name shown to the payer. On iOS, Apple Pay labels the total with it, so the sheet reads "Pay *merchantName*". On Android, it is the merchant name on the Google Pay sheet. Without it, iOS uses your app's display name (`CFBundleDisplayName`) and Android uses the app's label. Set it on both platforms.
- **totalLabel** — Android only. The label of the total in the Google Pay sheet, such as `'Razem'`. Defaults to `'Total'`. iOS labels the total with `merchantName`. See [PaymentRequest](/docs/api/types#paymentrequest).
- **supportedNetworks** — The card networks the payer can choose, as [PaymentNetwork](/docs/api/types#paymentnetwork) names. Both platforms honour it. A network the platform does not offer is left out, and an unknown name fails the payment. Pass the same list to [`GooglePayButton`](/docs/api/components#googlepaybutton-android-only).
- **googlePayTokenization** — Android only. Who encrypts the Google Pay token. Omitted or `{ type: 'gateway' }`, your gateway does, from `googlePayGateway` and `googlePayGatewayMerchantId`. `{ type: 'direct', publicKey }` has Google encrypt it with your own key, for a PCI DSS compliant server that decrypts it; it needs Google's approval. A missing `publicKey` fails with a `'CONFIGURATION'` error. See [GooglePayTokenization](/docs/api/types#googlepaytokenization).
- **googlePayAllowedAuthMethods** — Android only. Which Google Pay cards to accept: `'PAN_ONLY'` (saved to the Google account), `'CRYPTOGRAM_3DS'` (tokenized on the device), or both, the default. See [GooglePayAuthMethod](/docs/api/types#googlepayauthmethod).
- **googlePayAllowPrepaidCards** — Android only. `false` leaves prepaid cards out of the Google Pay sheet, for a gateway or risk policy that refuses them; without it, the payer learns only when the charge fails. Defaults to `true`. Pass the same value to [`GooglePayButton`](/docs/api/components#googlepaybutton-android-only).
- **googlePayCheckoutOption** — Android only. The label of the Google Pay sheet's button: `'default'` ("Continue" or "Pay", as when it is omitted), `'completeImmediatePurchase'` ("Pay now") or `'continueToReview'` ("Review Order"). `'completeImmediatePurchase'` needs a final total: with a `'pending'` item, `startPayment()` fails with a `'CONFIGURATION'` error before the sheet opens. See [GooglePayCheckoutOption](/docs/api/types#googlepaycheckoutoption).
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ No. The library works in bare React Native too. The Expo plugin only simplifies
Yes. Omit `enableGooglePay` for iOS-only (`false` removes an entry another plugin added); omit plugin `merchantIdentifier` for Android-only. In code, only render the button for the platform you support.

**Which gateways are supported for Google Pay?**
Any gateway that supports the [Google Pay API](https://developers.google.com/pay/api/android) and the gateway token format. Commonly used: Stripe, Braintree, Square, Adyen, Authorize.net, Checkout.com. Set `googlePayMerchantId`, `googlePayGateway`, and `googlePayGatewayMerchantId` accordingly.
Any gateway that supports the [Google Pay API](https://developers.google.com/pay/api/android) and the gateway token format. Commonly used: Stripe, Braintree, Square, Adyen, Authorize.net, Checkout.com. Set `googlePayMerchantId`, `googlePayGateway`, and `googlePayGatewayMerchantId` accordingly. A PCI DSS compliant merchant that decrypts tokens itself can use [`'direct'` tokenization](/docs/setup/android-google-pay#direct-tokenization) instead.

**Where do I report issues?**
[GitHub Issues](https://github.com/gmi-software/react-native-pay/issues).
10 changes: 10 additions & 0 deletions docs/docs/guides/server-processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ app.post('/process-payment', async (req, res) => {
- Handling failures and refunds.
- Provider-specific walkthroughs in [Przelewy24 Apple Pay + Google Pay cookbook](/docs/integrations/przelewy24).

## Decrypt the token yourself (Google Pay `DIRECT`)

With [`googlePayTokenization: { type: 'direct', publicKey }`](/docs/setup/android-google-pay#direct-tokenization), no gateway decrypts the Google Pay token: your server does. `token.paymentData` is then Google's `ECv2` payment method token, a JSON string with `protocolVersion`, `signature`, `intermediateSigningKey` and `signedMessage`.

- Verify the token before you decrypt it. Check the `intermediateSigningKey` signatures against Google's root signing keys, check that the intermediate key has not expired, and check `signature` with the intermediate signing key. That signature covers a length-prefixed string of the sender ID (`Google`), your recipient ID, the protocol version and `signedMessage`, not `signedMessage` alone. Reject the token if any check fails. Tink does this for you; on another stack, follow the verification steps in Google's guide.
- Decrypt it with the private key that matches `publicKey`. Google recommends Tink's [`apps-paymentmethodtoken`](https://developers.google.com/pay/api/android/guides/resources/payment-data-cryptography#using-tink) library (Java), with `protocolVersion("ECv2")`. For `PRODUCTION` tokens, the recipient ID is `merchant:<your Google Pay merchant ID>` and the signing keys are Google's production keys. `TEST` tokens use Google's test signing keys; the library sends no merchant ID in `TEST`, so take the recipient ID for them from Google's guide.
Comment thread
jkasprzyk17 marked this conversation as resolved.
Resolved
- Check `messageExpiration` before you charge.
- The decrypted message holds the card number and, for `CRYPTOGRAM_3DS` cards, a cryptogram. It is card data: your servers must be PCI DSS compliant.
- Rotate the key every year. Google encrypts with the key in the request, so serve `publicKey` from your server. Keep the old private key for at least eight days after you remove the old public key from the Google Pay & Wallet Console, so it can decrypt tokens made with the old key. See Google's [key rotation](https://developers.google.com/pay/api/android/guides/resources/payment-data-cryptography#key-rotation) section for the full steps.

## Security

- Use **HTTPS** and authenticate the client (e.g. session or API key).
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/guides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Some gateways, such as Stripe, Braintree, and Adyen, show their own test cards i

- **Availability.** With `existingPaymentMethodRequired`, `isReadyToPay` [always returns `true` in `TEST`](https://developers.google.com/pay/api/android/reference/request-objects#IsReadyToPayRequest), so `hasActiveCard` is `true` even with no card. An emulator with no Google account signed in answers `false` instead. You can't test the "no card" path of a signed-in user in `TEST`.
- **A live charge.** `TEST` tokens never carry real card data. With your gateway's test values, its test environment can process them, but nothing is charged.
- **Your production request.** The library sends `googlePayMerchantId` and requires `googlePayMerchantId`, `googlePayGateway`, and `googlePayGatewayMerchantId` only in `PRODUCTION`. A missing value fails with, for example, `googlePayMerchantId is required in PRODUCTION`, which you only see in a `PRODUCTION` build.
- **Your production request.** The library sends `googlePayMerchantId` and requires `googlePayMerchantId`, `googlePayGateway`, and `googlePayGatewayMerchantId` only in `PRODUCTION`; with [`'direct'` tokenization](/docs/setup/android-google-pay#direct-tokenization) it requires `googlePayMerchantId` and no gateway values. A missing value fails with, for example, `googlePayMerchantId is required in PRODUCTION`, which you only see in a `PRODUCTION` build.

### Production access

Expand All @@ -94,9 +94,9 @@ Google Pay only works in `PRODUCTION` after Google approves your app. Google's [
1. In the [Google Pay & Wallet Console](https://pay.google.com/business/console), choose the **Merchant** business type and complete your business profile.
2. Open **Google Pay API**, then **Get started**, and accept the Google Pay API Terms of Service and Acceptable Use Policy. Your Google Pay merchant ID then appears in the Console. Pass it as `googlePayMerchantId`.
3. Go through the [integration checklist](https://developers.google.com/pay/api/android/guides/test-and-deploy/integration-checklist) against your `TEST` build.
4. Under **Google Pay API → Integrations → Integrate with your Android app**, pick your app and the **Gateway** integration type. The Console only lists apps published on Google Play under the same Google account.
4. Under **Google Pay API → Integrations → Integrate with your Android app**, pick your app and the integration type: **Gateway** if a payment service provider decrypts the token, or **Direct** with [`'direct'` tokenization](/docs/setup/android-google-pay#direct-tokenization), where you register your public key. The Console only lists apps published on Google Play under the same Google account.
5. Upload screenshots of your `TEST` integration, and submit the app for approval.
6. Once approved, set `googlePayEnvironment: 'PRODUCTION'` and your production gateway values, sign the app with your release key, and publish it on Google Play. Google says the debug key doesn't work in `PRODUCTION`.
6. Once approved, set `googlePayEnvironment: 'PRODUCTION'` and your production gateway values (or your production `publicKey` with `'direct'`), sign the app with your release key, and publish it on Google Play. Google says the debug key doesn't work in `PRODUCTION`.

Until your app has production access, the sheet shows an "Unrecognized App" error. To find out why a `PRODUCTION` request fails, read the merchant error log:

Expand Down
Loading
Loading