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 @@ -42,6 +42,14 @@ All notable changes to this project are documented in this file.
`code: 'CONFIGURATION'` before the sheet opens. Without the option the request is unchanged. No
effect on `recurring`, `deferred` and `automaticReload` payments. Android only
([#85](https://github.com/gmi-software/react-native-pay/issues/85)).
- **`googlePayAllowPrepaidCards`** in `PaymentRequest`, the `usePaymentCheckout` config,
`PayServiceStatusOptions` and the `GooglePayButton` props. `false` sends Google Pay's
`allowPrepaidCards: false`, so the payer can't pick a prepaid card your gateway or risk policy
would refuse. Each takes its own value, so pass the payment's value to `payServiceStatus` and
`GooglePayButton` too; `usePaymentCheckout` passes it to its availability check, and
`paymentRequest.googlePayAllowPrepaidCards` gives it for the button. Omitted or `true`, the
requests are unchanged. Android only
([#87](https://github.com/gmi-software/react-native-pay/issues/87)).
- **`PaymentError` with a `code`.** `usePaymentCheckout` now sets `error` to a `PaymentError`, an
`Error` subclass whose `code` is a `PaymentErrorCode`: `'CONFIGURATION'` for an empty cart or an
invalid request, `'UNKNOWN'` when native code threw, and the result's `code` (`'UNKNOWN'` if it
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ interface UsePaymentCheckoutConfig {
googlePayGateway?: string;
googlePayGatewayMerchantId?: string;
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
// Contact details, returned in the result (see "Shipping and contact details")
billingContactRequired?: boolean;
Expand Down Expand Up @@ -456,7 +457,7 @@ The native handler is created the first time you use `HybridPaymentHandler`, not

##### `payServiceStatus(options?: PayServiceStatusOptions): Promise<PayServiceStatus>`

Check payment service availability without blocking the JS thread. Pass the `supportedNetworks`, `merchantCapabilities`, `googlePayAllowedAuthMethods` and `googlePayEnvironment` your payment request uses. The Promise rejects with the payment's configuration error for a value the payment would refuse.
Check payment service availability without blocking the JS thread. Pass the `supportedNetworks`, `merchantCapabilities`, `googlePayAllowedAuthMethods`, `googlePayAllowPrepaidCards` and `googlePayEnvironment` your payment request uses. The Promise rejects with the payment's configuration error for a value the payment would refuse.

```typescript
import { HybridPaymentHandler } from "@gmisoftware/react-native-pay";
Expand Down Expand Up @@ -654,6 +655,7 @@ interface GooglePayButtonProps {
// The cards your payment accepts, so the button never shows another card.
supportedNetworks?: string[]; // as PaymentRequest.supportedNetworks
googlePayAllowedAuthMethods?: string[]; // as PaymentRequest.googlePayAllowedAuthMethods
googlePayAllowPrepaidCards?: boolean; // as PaymentRequest.googlePayAllowPrepaidCards
merchantCapabilities?: string[]; // as PaymentRequest.merchantCapabilities

onPress?: () => void;
Expand Down Expand Up @@ -802,6 +804,7 @@ interface PaymentRequest {
googlePayGateway?: string;
googlePayGatewayMerchantId?: string;
googlePayAllowedAuthMethods?: string[]; // GooglePayAuthMethod values
googlePayAllowPrepaidCards?: boolean; // false leaves prepaid cards out
googlePayCheckoutOption?: GooglePayCheckoutOption; // the sheet's button label
}

Expand Down
3 changes: 2 additions & 1 deletion docs/docs/api/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ Renders the Google Pay button. Only available on Android.
| `radius` | `number` | No | Corner radius in dp, like other React Native sizes. |
| `supportedNetworks` | `string[]` | No | The card networks your payment accepts, as in `PaymentRequest.supportedNetworks`. Default: `visa`, `mastercard`, `amex`, `discover`. |
| `googlePayAllowedAuthMethods` | `string[]` | No | As in `PaymentRequest.googlePayAllowedAuthMethods`. Default: both. |
| `googlePayAllowPrepaidCards` | `boolean` | No | As in `PaymentRequest.googlePayAllowPrepaidCards`. `false` leaves prepaid cards out. Default: `true`. |
| `merchantCapabilities` | `string[]` | No | As in `PaymentRequest.merchantCapabilities`. `'Debit'` without `'Credit'` leaves credit cards out. Default: every card type. |
| `onPress` | `() => void` | No | Called when the user taps the button. |
| `disabled` | `boolean` | No | Ignores taps while `true`. See [Disabled buttons](#disabled-buttons). |
| `style` | `ViewStyle` | No | Layout/style (e.g. width, height). |

The button can show the payer's card, so give it the same `supportedNetworks`, `googlePayAllowedAuthMethods` and `merchantCapabilities` as the payment, under the same names. Otherwise it may show a card the payment then refuses. With `usePaymentCheckout`, pass them from `paymentRequest`. An invalid value (an unknown network, auth method or merchant capability, an empty `supportedNetworks` or `googlePayAllowedAuthMethods` list, or no network Google Pay offers) logs a warning in development, with the same rules as the payment. The button then keeps the cards it showed before, or the default cards on the first render, and still calls the current `onPress`. An empty `merchantCapabilities` list is valid and accepts credit and debit cards.
The button can show the payer's card, so give it the same `supportedNetworks`, `googlePayAllowedAuthMethods`, `googlePayAllowPrepaidCards` and `merchantCapabilities` as the payment, under the same names. Otherwise it may show a card the payment then refuses. With `usePaymentCheckout`, pass them from `paymentRequest`. An invalid value (an unknown network, auth method or merchant capability, an empty `supportedNetworks` or `googlePayAllowedAuthMethods` list, or no network Google Pay offers) logs a warning in development, with the same rules as the payment. The button then keeps the cards it showed before, or the default cards on the first render, and still calls the current `onPress`. An empty `merchantCapabilities` list is valid and accepts credit and debit cards.

**GooglePayButtonType:**
`'buy'` | `'book'` | `'checkout'` | `'donate'` | `'order'` | `'pay'` | `'subscribe'` | `'plain'`
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/api/hybrid-payment-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const status = await HybridPaymentHandler.payServiceStatus({
- **isSupported** — The device can pay with Apple Pay / Google Pay, whether or not a card is set up.
- **hasActiveCard** — The user has a card ready on one of `supportedNetworks`.

Pass the `supportedNetworks`, `merchantCapabilities`, `googlePayAllowedAuthMethods` and `googlePayEnvironment` your payment request uses ([PayServiceStatusOptions](/docs/api/types#payservicestatusoptions)); `hasActiveCard` then counts only cards the payment accepts. Without them, both platforms ask about `visa`, `mastercard`, `amex` and `discover`. The Promise rejects with the configuration error that would fail `startPayment` for a value the payment would refuse: an unknown network, capability or auth method, or no network the platform offers. A check that fails for any other reason resolves both flags as `false`. Without `googlePayEnvironment`, Android asks the `TEST` environment, where `hasActiveCard` is `true` whether or not the user has a card. What each platform checks, and which button to show, is in [Check availability](/docs/guides/availability).
Pass the `supportedNetworks`, `merchantCapabilities`, `googlePayAllowedAuthMethods`, `googlePayAllowPrepaidCards` and `googlePayEnvironment` your payment request uses ([PayServiceStatusOptions](/docs/api/types#payservicestatusoptions)); `hasActiveCard` then counts only cards the payment accepts. Without them, both platforms ask about `visa`, `mastercard`, `amex` and `discover`. The Promise rejects with the configuration error that would fail `startPayment` for a value the payment would refuse: an unknown network, capability or auth method, or no network the platform offers. A check that fails for any other reason resolves both flags as `false`. Without `googlePayEnvironment`, Android asks the `TEST` environment, where `hasActiveCard` is `true` whether or not the user has a card. What each platform checks, and which button to show, is in [Check availability](/docs/guides/availability).

---

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

`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.

`googlePayCheckoutOption` sets the label of the Google Pay sheet's button: see [`GooglePayCheckoutOption`](#googlepaycheckoutoption). Omitted, Google Pay picks "Continue" or "Pay". Android only.

`billingContactRequired`, `shippingContactRequired`, `emailRequired` and `phoneNumberRequired` ask the payer for contact details, which come back in the result as [`PaymentDetails`](#paymentdetails). On Android, a phone number is collected with an address. See [Shipping and contact details](/docs/guides/contact-details).
Expand Down Expand Up @@ -385,6 +388,7 @@ interface PayServiceStatusOptions {
supportedNetworks?: string[] // default: ['visa', 'mastercard', 'amex', 'discover']
merchantCapabilities?: string[] // default: ['3DS']
googlePayAllowedAuthMethods?: string[] // Android only. Default: both
googlePayAllowPrepaidCards?: boolean // Android only. Default: true
googlePayEnvironment?: 'TEST' | 'PRODUCTION' // Android only. Default: 'TEST'
}
```
Expand Down
6 changes: 4 additions & 2 deletions docs/docs/api/use-payment-checkout.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface UsePaymentCheckoutConfig {
googlePayGateway?: string
googlePayGatewayMerchantId?: string
googlePayAllowedAuthMethods?: GooglePayAuthMethod[] // default: both
googlePayAllowPrepaidCards?: boolean // default: true
googlePayCheckoutOption?: GooglePayCheckoutOption // the sheet's button label
// Contact details, returned in the result
billingContactRequired?: boolean
Expand All @@ -53,9 +54,10 @@ interface UsePaymentCheckoutConfig {
- **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).
- **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).
- **merchantCapabilities** — The card types to accept and, on iOS, the payment protocols. iOS adds `'3DS'` when neither `'3DS'` nor `'EMV'` is given. On Android only `'Debit'` without `'Credit'` has an effect: it leaves credit cards out. Google Pay cannot leave debit cards out, so `['3DS', 'Credit']` accepts every card type on Android. An unknown value fails the payment on both platforms. Pass the same list to [`GooglePayButton`](/docs/api/components#googlepaybutton-android-only). See [MerchantCapability](/docs/api/types#merchantcapability).
- **supportedNetworks**, **merchantCapabilities**, **googlePayAllowedAuthMethods**, **googlePayEnvironment** — Also used for the availability check, which fails like the payment for a value the payment would refuse. Set `googlePayEnvironment: 'PRODUCTION'` in a live app: in `TEST`, Google Pay reports a card whether or not there is one. Omitted, it is `'TEST'`, and an Android release build logs a warning once per app run when `startPayment()` builds a payment. The availability check alone logs nothing.
- **supportedNetworks**, **merchantCapabilities**, **googlePayAllowedAuthMethods**, **googlePayAllowPrepaidCards**, **googlePayEnvironment** — Also used for the availability check, which fails like the payment for a value the payment would refuse. Set `googlePayEnvironment: 'PRODUCTION'` in a live app: in `TEST`, Google Pay reports a card whether or not there is one. Omitted, it is `'TEST'`, and an Android release build logs a warning once per app run when `startPayment()` builds a payment. The availability check alone logs nothing.
- **billingContactRequired**, **shippingContactRequired**, **emailRequired**, **phoneNumberRequired** — Ask the payer for a billing address, a shipping address, an email address or a phone number. They come back as `result.billingContact`, `result.shippingContact`, `result.emailAddress` and `result.phoneNumber`. See [Shipping and contact details](/docs/guides/contact-details).
- **onAuthorize** — Called with the token and the requested contact details after the user authorizes the payment. Charge it on your server and resolve with `{ status: 'success' }` or `{ status: 'failure', error }`. See [Charge before the sheet closes](/docs/guides/server-processing#charge-before-the-sheet-closes). An inline function is fine: `startPayment()` uses the one from the latest render, and a payment keeps that function until it settles, even if the config changes meanwhile.
- **onShippingAddressChange**, **onShippingMethodChange**, **onPaymentMethodChange**, **onCouponCodeChange** — Update the cart while the sheet is open, as in [`StartPaymentOptions`](/docs/api/types#startpaymentoptions). What they return changes only the sheet: `items` stays as you set it, so a coupon the payer tried and then cancelled leaves no discount behind. Inline functions are fine, as for `onAuthorize`. Android has no coupon field and differs in a few ways; see [On Android](/docs/guides/dynamic-cart#on-android). See [Update the cart in the sheet](/docs/guides/dynamic-cart#update-the-cart-in-the-sheet).
Expand Down Expand Up @@ -94,7 +96,7 @@ interface UsePaymentCheckoutReturn {

- **isSupported** — The device can pay with Apple Pay / Google Pay, whether or not a card is set up.
- **hasActiveCard** — The user has a card ready on one of `supportedNetworks`. See [PayServiceStatus](/docs/api/types#payservicestatus) for what each platform checks.
- **isCheckingStatus** — `true` until the availability check settles. The hook checks on mount and again when `supportedNetworks`, `merchantCapabilities`, `googlePayAllowedAuthMethods` or `googlePayEnvironment` change. The check never blocks the JS thread.
- **isCheckingStatus** — `true` until the availability check settles. The hook checks on mount and again when `supportedNetworks`, `merchantCapabilities`, `googlePayAllowedAuthMethods`, `googlePayAllowPrepaidCards` or `googlePayEnvironment` change. The check never blocks the JS thread.
- **refreshStatus()** — Checks availability again, for example when the app returns from Wallet after `openPaymentSetup()`. `isCheckingStatus` is `true` until it settles, and the flags keep their last values meanwhile.

Which button to show for each combination is in [Check availability](/docs/guides/availability).
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/availability.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Decide which wallet button to show before the user taps anything. The library re
| | iOS | Android |
|---|---|---|
| `isSupported` | `PKPaymentAuthorizationViewController.canMakePayments()`: hardware and parental controls allow Apple Pay | `isReadyToPay`: Google Pay is available, and the user has a card or can add one |
| `hasActiveCard` | `canMakePayments(usingNetworks:capabilities:)` with your `supportedNetworks` and `merchantCapabilities` | `isReadyToPay` with `existingPaymentMethodRequired: true` and your `supportedNetworks`, `googlePayAllowedAuthMethods` and `merchantCapabilities` |
| `hasActiveCard` | `canMakePayments(usingNetworks:capabilities:)` with your `supportedNetworks` and `merchantCapabilities` | `isReadyToPay` with `existingPaymentMethodRequired: true` and your `supportedNetworks`, `googlePayAllowedAuthMethods`, `googlePayAllowPrepaidCards` and `merchantCapabilities` |

Both flags are `false` when the check fails or, on Android, when Google Pay does not answer within 5 seconds. A value the payment would refuse rejects the `payServiceStatus` Promise with the configuration error that would fail `startPayment`: an unknown network, merchant capability or auth method, or a network list the platform offers none of (Google Pay has no `idcredit` or `privateLabel`). The hook logs the rejection and reports both flags as `false`.

Expand Down
1 change: 1 addition & 0 deletions example/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export default function TabOneScreen() {
// The cards the request accepts, so the button shows one of them.
supportedNetworks={paymentRequest.supportedNetworks}
googlePayAllowedAuthMethods={paymentRequest.googlePayAllowedAuthMethods}
googlePayAllowPrepaidCards={paymentRequest.googlePayAllowPrepaidCards}
merchantCapabilities={paymentRequest.merchantCapabilities}
onPress={handlePayment}
style={styles.payButton}
Expand Down
Loading
Loading