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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ cd example && bun install
- Keep PRs small and scoped to one objective.
- If you change public APIs, update `README.md` and any types.
- **Docs (`docs/`)**: When you add, change, or remove public API, setup steps, or user-facing behavior, create, update, or delete the relevant pages under `docs/docs/` so the Docusaurus docs stay in sync. Examples: new hook option → `docs/docs/api/use-payment-checkout.md`; plugin config change → `docs/docs/setup/expo-plugin.md`; new guide → add under `docs/docs/guides/` and reference in `docs/sidebars.ts`. All docs content is in English.
- **Code snippets** in `README.md` and `docs/docs/` must compile (`bun run check:docs`): include their imports, and wrap pay button `onPress` handlers with `callback()`. Mark a snippet that cannot compile on its own (type listings, short fragments, server code) with `no-check` after the language, as in ` ```ts no-check `. Snippets that render `ApplePayButton` or `GooglePayButton` cannot be `no-check`.
- **Code snippets** in `README.md` and `docs/docs/` must compile (`bun run check:docs`): include their imports. Mark a snippet that cannot compile on its own (type listings, short fragments, server code) with `no-check` after the language, as in ` ```ts no-check `. Snippets that render `ApplePayButton` or `GooglePayButton` cannot be `no-check`.
- If you touch native code, validate both iOS and Android paths.
- Avoid drive-by refactors and formatting-only changes.

Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ All notable changes to this project are documented in this file.
still accepts every card type on Android; `'3DS'` and `'EMV'` have no effect there. The button
and the readiness check leave credit cards out too.

- **`disabled` on `ApplePayButton` and `GooglePayButton`** ignores taps, for example while a
payment is in progress. The button looks the same: Apple's guidelines ask not to make the Apple
Pay button appear unavailable, and Google's do not allow changing the Google Pay button's color.
- **`ApplePayButtonType`, `ApplePayButtonStyle`, `GooglePayButtonType`, `GooglePayButtonTheme`,
`ApplePayButtonProps` and `GooglePayButtonProps` are exported.**

### Changed

- **`usePaymentCheckout` no longer treats a cancel as an error.** When the user closes the sheet,
Expand Down Expand Up @@ -122,6 +128,14 @@ All notable changes to this project are documented in this file.
- **iOS: `HybridPaymentHandler.openPaymentSetup()`** opens Wallet so the user can add a card, for a
"Set up Apple Pay" button (`ApplePayButton` with `buttonType="setUp"`). It does nothing on Android.

- **The pay buttons take a plain function as `onPress`: remove `callback()`.** `ApplePayButton`
and `GooglePayButton` are now React components around the native views, so
`onPress={callback(handlePay)}` becomes `onPress={handlePay}`, and the `react-native-nitro-modules`
import can go. A wrapped `onPress` still works, but no longer type-checks, and logs a warning in
development. The props are `ViewProps` plus the button's own; `hybridRef` is gone.
- **Each pay button renders nothing on the other platform,** with a warning in development, instead
of failing, since that native view does not exist there.

### Deprecated

- **`PaymentResult.transactionId`.** It is a random ID generated on the device for each successful
Expand All @@ -130,6 +144,13 @@ All notable changes to this project are documented in this file.

### Fixed

- **iOS: `ApplePayButton` keeps its `PKPaymentButton` across re-renders.** Every prop update
removed the button and created a new one, so an `onPress` with a new identity on each render
rebuilt it on every parent re-render. It is now rebuilt only when `buttonType` or `buttonStyle`
changes.
- **Android: `GooglePayButton`'s `radius` is in dp, as documented.** It was passed to Google Pay as
pixels, so corners were about a third of the requested size on a typical phone. Apps that
enlarged `radius` to compensate should set it back.
- **Android: `supportedNetworks` limits the cards the payer can choose.** Android ignored it and
always offered Visa, Mastercard, Amex and Discover, so a merchant whose gateway refuses Amex
still received Amex tokens, and JCB or Interac could not be enabled. The payment request, the
Expand Down
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ import {
formatAmount,
} from '@gmisoftware/react-native-pay'
import { Platform, View, Text, Button, ActivityIndicator } from 'react-native'
import { callback } from 'react-native-nitro-modules'

function CheckoutScreen() {
const {
Expand Down Expand Up @@ -286,15 +285,15 @@ function CheckoutScreen() {
<ApplePayButton
buttonType="buy"
buttonStyle="black"
onPress={callback(handlePay)}
onPress={handlePay}
style={{ width: '100%', height: 48 }}
/>
) : (
<GooglePayButton
buttonType="buy"
theme="dark"
radius={4}
onPress={callback(handlePay)}
onPress={handlePay}
style={{ width: '100%', height: 48 }}
/>
)
Expand Down Expand Up @@ -565,7 +564,7 @@ iOS only: opens Wallet so the user can add a card. Call it from an `ApplePayButt

### Button Components

Both buttons are Nitro views, so `onPress` must be wrapped with `callback()` from `react-native-nitro-modules`. A bare function does not reach the native button, and tapping it does nothing.
Each button renders nothing on the other platform and, in development, logs a warning. `disabled` makes the button ignore taps, for example while a payment is in progress. It does not dim the button: Apple's guidelines ask not to make the Apple Pay button appear unavailable, and Google's do not allow changing the Google Pay button's color.

#### `ApplePayButton` (iOS)

Expand All @@ -592,7 +591,8 @@ interface ApplePayButtonProps {

buttonStyle: "white" | "whiteOutline" | "black";

onPress?: () => void; // wrap with callback() from react-native-nitro-modules
onPress?: () => void;
disabled?: boolean; // ignores taps while true
style?: ViewStyle;
}
```
Expand All @@ -601,7 +601,6 @@ interface ApplePayButtonProps {

```tsx
import { ApplePayButton } from "@gmisoftware/react-native-pay";
import { callback } from "react-native-nitro-modules";

const handlePayment = async () => {
// Call startPayment() from usePaymentCheckout here
Expand All @@ -610,7 +609,7 @@ const handlePayment = async () => {
<ApplePayButton
buttonType="buy"
buttonStyle="black"
onPress={callback(handlePayment)}
onPress={handlePayment}
style={{ width: '100%', height: 48 }}
/>
```
Expand Down Expand Up @@ -642,7 +641,8 @@ interface GooglePayButtonProps {
googlePayAllowedAuthMethods?: string[]; // as PaymentRequest.googlePayAllowedAuthMethods
merchantCapabilities?: string[]; // as PaymentRequest.merchantCapabilities

onPress?: () => void; // wrap with callback() from react-native-nitro-modules
onPress?: () => void;
disabled?: boolean; // ignores taps while true
style?: ViewStyle;
}
```
Expand All @@ -651,7 +651,6 @@ interface GooglePayButtonProps {

```tsx
import { GooglePayButton } from "@gmisoftware/react-native-pay";
import { callback } from "react-native-nitro-modules";

const handlePayment = async () => {
// Call startPayment() from usePaymentCheckout here
Expand All @@ -661,7 +660,7 @@ const handlePayment = async () => {
buttonType="buy"
theme="dark"
radius={8}
onPress={callback(handlePayment)}
onPress={handlePayment}
style={{ width: '100%', height: 48 }}
/>
```
Expand Down Expand Up @@ -966,7 +965,6 @@ import {
GooglePayButton,
} from '@gmisoftware/react-native-pay'
import { Platform } from 'react-native'
import { callback } from 'react-native-nitro-modules'

// 1. Check availability, against the environment you pay in
const { isSupported } = await HybridPaymentHandler.payServiceStatus({
Expand Down Expand Up @@ -1007,21 +1005,21 @@ const handlePayment = async () => {
}
}

// 4. Render the button. onPress must be wrapped with callback().
// 4. Render the button.
function PaymentButton() {
if (!isSupported) return null

return Platform.OS === 'ios' ? (
<ApplePayButton
buttonType="buy"
buttonStyle="black"
onPress={callback(handlePayment)}
onPress={handlePayment}
/>
) : (
<GooglePayButton
buttonType="subscribe"
theme="dark"
onPress={callback(handlePayment)}
onPress={handlePayment}
/>
)
}
Expand Down
53 changes: 36 additions & 17 deletions docs/docs/api/components.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Button components

Native payment buttons: **ApplePayButton** (iOS) and **GooglePayButton** (Android). Use the one that matches the platform; the library does not render both on the same screen.
Native payment buttons: **ApplePayButton** (iOS) and **GooglePayButton** (Android). Use the one that matches the platform. On the other platform a button renders nothing and, in development, logs a warning.

## ApplePayButton (iOS only)

Expand All @@ -12,7 +12,8 @@ Renders the system Apple Pay button. Only available on iOS.
|------|------|----------|-------------|
| `buttonType` | `ApplePayButtonType` | Yes | Button label type. |
| `buttonStyle` | `ApplePayButtonStyle` | Yes | Visual style. |
| `onPress` | `() => void`, wrapped with `callback()` | No | Called when the user taps the button. Must be wrapped, see [Nitro and onPress](#nitro-and-onpress). |
| `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). |

**ApplePayButtonType:**
Expand All @@ -25,7 +26,6 @@ Renders the system Apple Pay button. Only available on iOS.

```tsx
import { ApplePayButton } from '@gmisoftware/react-native-pay'
import { callback } from 'react-native-nitro-modules'

const handlePayment = async () => {
// Call startPayment() from usePaymentCheckout here
Expand All @@ -34,15 +34,11 @@ const handlePayment = async () => {
<ApplePayButton
buttonType="buy"
buttonStyle="black"
onPress={callback(handlePayment)}
onPress={handlePayment}
style={{ width: '100%', height: 48 }}
/>
```

### Nitro and onPress

`ApplePayButton` is a Nitro view, so `onPress` must be wrapped with `callback()` from `react-native-nitro-modules`. A bare function does not reach the native button, and tapping it does nothing. See [Troubleshooting: Nitro callback for onPress](/docs/troubleshooting#nitro-callback-for-onpress).

---

## GooglePayButton (Android only)
Expand All @@ -55,11 +51,12 @@ Renders the Google Pay button. Only available on Android.
|------|------|----------|-------------|
| `buttonType` | `GooglePayButtonType` | Yes | Button label type. |
| `theme` | `'dark' \| 'light'` | Yes | Button theme. |
| `radius` | `number` | No | Corner radius in dp. |
| `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. |
| `merchantCapabilities` | `string[]` | No | As in `PaymentRequest.merchantCapabilities`. `'Debit'` without `'Credit'` leaves credit cards out. Default: every card type. |
| `onPress` | `() => void`, wrapped with `callback()` | No | Called when the user taps the button. Must be wrapped, see [Nitro and onPress](#nitro-and-onpress). |
| `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`. With an unknown network, auth method or merchant capability, the button keeps its previous configuration, or does not appear on the first render, and logs an error in debug builds.
Expand All @@ -71,7 +68,6 @@ The button can show the payer's card, so give it the same `supportedNetworks`, `

```tsx
import { GooglePayButton } from '@gmisoftware/react-native-pay'
import { callback } from 'react-native-nitro-modules'

const handlePayment = async () => {
// Call startPayment() from usePaymentCheckout here
Expand All @@ -82,14 +78,38 @@ const handlePayment = async () => {
theme="dark"
radius={8}
supportedNetworks={['visa', 'mastercard']}
onPress={callback(handlePayment)}
onPress={handlePayment}
style={{ width: '100%', height: 48 }}
/>
```

### Nitro and onPress
---

## Disabled buttons

Same as Apple: `onPress` must be wrapped, as in `onPress={callback(handlePayment)}`. See [Troubleshooting: Nitro callback for onPress](/docs/troubleshooting#nitro-callback-for-onpress).
With `disabled`, the button ignores taps, for example while a payment is in progress. It looks the same as an enabled button. Apple's [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/apple-pay) ask you not to make the Apple Pay button appear unavailable, and Google's [brand guidelines](https://developers.google.com/pay/api/android/guides/brand-guidelines) do not allow changing the Google Pay button's color. If the payment cannot start yet, for example before the payer picks a size, Apple suggests keeping the button enabled and explaining the problem after the tap.

```tsx
import { ApplePayButton, usePaymentCheckout } from '@gmisoftware/react-native-pay'

function PayButton() {
const { startPayment, isProcessing } = usePaymentCheckout({
merchantName: 'Your Store',
currencyCode: 'USD',
countryCode: 'US',
})

return (
<ApplePayButton
buttonType="buy"
buttonStyle="black"
onPress={startPayment}
disabled={isProcessing}
style={{ width: '100%', height: 48 }}
/>
)
}
```

---

Expand All @@ -100,7 +120,6 @@ Render one button per platform:
```tsx
import { Platform } from 'react-native'
import { ApplePayButton, GooglePayButton } from '@gmisoftware/react-native-pay'
import { callback } from 'react-native-nitro-modules'

const handlePayment = async () => {
// Call startPayment() from usePaymentCheckout here
Expand All @@ -109,9 +128,9 @@ const handlePayment = async () => {
const style = { width: '100%', height: 48 } as const

{Platform.OS === 'ios' ? (
<ApplePayButton buttonType="buy" buttonStyle="black" onPress={callback(handlePayment)} style={style} />
<ApplePayButton buttonType="buy" buttonStyle="black" onPress={handlePayment} style={style} />
) : (
<GooglePayButton buttonType="buy" theme="dark" onPress={callback(handlePayment)} style={style} />
<GooglePayButton buttonType="buy" theme="dark" onPress={handlePayment} style={style} />
)}
```

Expand Down
10 changes: 4 additions & 6 deletions docs/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
GooglePayButton,
usePaymentCheckout,
} from '@gmisoftware/react-native-pay'
import { callback } from 'react-native-nitro-modules'

const {
isSupported,
Expand Down Expand Up @@ -51,15 +50,15 @@ const handlePayment = async () => {
<ApplePayButton
buttonType="buy"
buttonStyle="black"
onPress={callback(handlePayment)}
onPress={handlePayment}
style={{ width: '100%', height: 56 }}
/>
) : (
<GooglePayButton
buttonType="buy"
theme="dark"
radius={8}
onPress={callback(handlePayment)}
onPress={handlePayment}
style={{ width: '100%', height: 56 }}
/>
)}
Expand All @@ -71,7 +70,6 @@ const handlePayment = async () => {
- **Status** — Check whether the device can make payments or only set up cards.
- **Cart UI** — Add/clear items and display total.
- **Result handling** — Success and error messages; reset and clear cart after success.
- **Nitro `callback`** — Buttons use `callback(handlePayment)` (see [Troubleshooting: Nitro callback for onPress](/docs/troubleshooting#nitro-callback-for-onpress)).

## Run the example

Expand Down Expand Up @@ -102,10 +100,10 @@ Use the checkout screen in the example app as a reference for:
2. Shows a loading state while `isCheckingStatus` is true.
3. Renders “Quick Add” buttons that call `addItems` or `addItem`.
4. Displays the cart (items + total) and a “Clear” action.
5. Renders **ApplePayButton** on iOS and **GooglePayButton** on Android with `callback(handlePayment)`.
5. Renders **ApplePayButton** on iOS and **GooglePayButton** on Android with `onPress={handlePayment}`.
6. On successful payment, shows an alert and calls `reset()` and `clearItems()`.

Copy these patterns into your app: config setup, cart handling, button usage, and native-safe `onPress` handlers.
Copy these patterns into your app: config setup, cart handling, and button usage.

## Plugin config in the example

Expand Down
7 changes: 3 additions & 4 deletions docs/docs/guides/availability.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ In the example below, the checkout screen owns the hook and the cart, and `Walle
```tsx
import { useEffect } from 'react'
import { AppState, Button, Platform, View } from 'react-native'
import { callback } from 'react-native-nitro-modules'
import {
ApplePayButton,
GooglePayButton,
Expand Down Expand Up @@ -80,7 +79,7 @@ function WalletButton({ checkout }: { checkout: UsePaymentCheckoutReturn }) {
<GooglePayButton
buttonType="buy"
theme="dark"
onPress={callback(startPayment)}
onPress={startPayment}
/>
)
}
Expand All @@ -89,13 +88,13 @@ function WalletButton({ checkout }: { checkout: UsePaymentCheckoutReturn }) {
<ApplePayButton
buttonType="buy"
buttonStyle="black"
onPress={callback(startPayment)}
onPress={startPayment}
/>
) : (
<ApplePayButton
buttonType="setUp"
buttonStyle="black"
onPress={callback(() => HybridPaymentHandler.openPaymentSetup())}
onPress={() => HybridPaymentHandler.openPaymentSetup()}
/>
)
}
Expand Down
Loading
Loading