pay-sdk-react 1.1.14 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +241 -78
- package/README.zh-CN.md +243 -79
- package/dist/css/index.css +11 -0
- package/dist/css/index.min.css +1 -1
- package/dist/es/Airwallex/airwallex-button.js +48 -16
- package/dist/es/Airwallex/airwallex-checkout-button.d.ts +4 -0
- package/dist/es/Airwallex/airwallex-checkout-button.js +73 -0
- package/dist/es/Airwallex/airwallex-managed.d.ts +4 -0
- package/dist/es/Airwallex/airwallex-managed.js +87 -0
- package/dist/es/Airwallex/airwallex-modal.js +7 -3
- package/dist/es/Airwallex/airwallex-popup.js +7 -3
- package/dist/es/Airwallex/airwallex.d.ts +1 -3
- package/dist/es/Airwallex/airwallex.js +10 -1
- package/dist/es/Airwallex/hooks/useAirwallexCheckout.d.ts +7 -0
- package/dist/es/Airwallex/hooks/useAirwallexCheckout.js +155 -0
- package/dist/es/Airwallex/index.d.ts +4 -0
- package/dist/es/Airwallex/index.js +5 -1
- package/dist/es/Airwallex/interface.d.ts +146 -0
- package/dist/es/Alipay/alipay-button.js +26 -7
- package/dist/es/Alipay/alipay.js +39 -12
- package/dist/es/Alipay/interface.d.ts +26 -1
- package/dist/es/Paypal/index.d.ts +2 -0
- package/dist/es/Paypal/index.js +3 -1
- package/dist/es/Paypal/interface.d.ts +40 -0
- package/dist/es/Paypal/paypal-button.js +24 -3
- package/dist/es/Paypal/paypal-smart-button.d.ts +4 -0
- package/dist/es/Paypal/paypal-smart-button.js +48 -0
- package/dist/es/Payssion/interface.d.ts +7 -0
- package/dist/es/Payssion/payssion-button.js +25 -4
- package/dist/es/Pix/interface.d.ts +67 -0
- package/dist/es/Pix/pix-button.js +26 -7
- package/dist/es/Pix/pix-enhanced.d.ts +4 -0
- package/dist/es/Pix/pix-enhanced.js +182 -0
- package/dist/es/Pix/pix.d.ts +1 -1
- package/dist/es/Pix/pix.js +6 -1
- package/dist/es/Pix/style/index.css +11 -0
- package/dist/es/Pix/style/index.min.css +1 -1
- package/dist/es/Stripe/hooks/useStripeCheckout.d.ts +7 -0
- package/dist/es/Stripe/hooks/useStripeCheckout.js +86 -0
- package/dist/es/Stripe/index.d.ts +4 -0
- package/dist/es/Stripe/index.js +5 -1
- package/dist/es/Stripe/interface.d.ts +120 -0
- package/dist/es/Stripe/stripe-button.js +32 -10
- package/dist/es/Stripe/stripe-checkout-button.d.ts +4 -0
- package/dist/es/Stripe/stripe-checkout-button.js +70 -0
- package/dist/es/Stripe/stripe-modal.js +19 -2
- package/dist/es/Stripe/stripe-popup.js +13 -2
- package/dist/es/Stripe/stripe.js +38 -4
- package/dist/es/Wechat/interface.d.ts +13 -0
- package/dist/es/Wechat/wechat-button.js +26 -7
- package/dist/es/Wechat/wechat-content.d.ts +4 -0
- package/dist/es/Wechat/wechat-content.js +61 -0
- package/dist/es/Wechat/wechat.d.ts +1 -1
- package/dist/es/Wechat/wechat.js +5 -1
- package/dist/es/hooks/useLatestCallback.d.ts +1 -0
- package/dist/es/hooks/useLatestCallback.js +8 -0
- package/dist/es/hooks/useManagedOrder.d.ts +8 -0
- package/dist/es/hooks/useManagedOrder.js +67 -0
- package/dist/es/hooks/usePaymentExecution.d.ts +13 -0
- package/dist/es/hooks/usePaymentExecution.js +176 -0
- package/dist/es/hooks/usePaymentQr.d.ts +6 -0
- package/dist/es/hooks/usePaymentQr.js +52 -0
- package/dist/es/hooks/usePaymentRedirect.d.ts +5 -0
- package/dist/es/hooks/usePaymentRedirect.js +83 -0
- package/dist/es/index.d.ts +33 -6
- package/dist/es/index.js +19 -1
- package/dist/es/pay-modal/interface.d.ts +22 -2
- package/dist/es/pay-modal/pay-modal.js +36 -16
- package/dist/es/shared/entitys/payment.d.ts +227 -0
- package/dist/es/shared/entitys/payment.js +75 -0
- package/dist/es/shared/enums/index.d.ts +1 -88
- package/dist/es/shared/enums/index.js +1 -91
- package/dist/es/shared/enums/payment.d.ts +162 -0
- package/dist/es/shared/enums/payment.js +168 -0
- package/dist/es/shared/index.d.ts +2 -0
- package/dist/es/shared/index.js +2 -1
- package/dist/lib/Airwallex/airwallex-button.js +31 -10
- package/dist/lib/Airwallex/airwallex-checkout-button.js +52 -0
- package/dist/lib/Airwallex/airwallex-managed.js +86 -0
- package/dist/lib/Airwallex/airwallex-modal.js +4 -2
- package/dist/lib/Airwallex/airwallex-popup.js +4 -2
- package/dist/lib/Airwallex/airwallex.js +9 -1
- package/dist/lib/Airwallex/hooks/useAirwallexCheckout.js +83 -0
- package/dist/lib/Airwallex/index.js +18 -1
- package/dist/lib/Alipay/alipay-button.js +21 -6
- package/dist/lib/Alipay/alipay.js +36 -9
- package/dist/lib/Paypal/index.js +17 -1
- package/dist/lib/Paypal/paypal-button.js +19 -2
- package/dist/lib/Paypal/paypal-smart-button.js +45 -0
- package/dist/lib/Payssion/payssion-button.js +20 -3
- package/dist/lib/Pix/pix-button.js +21 -6
- package/dist/lib/Pix/pix-enhanced.js +143 -0
- package/dist/lib/Pix/pix.js +6 -1
- package/dist/lib/Pix/style/index.css +11 -0
- package/dist/lib/Pix/style/index.min.css +1 -1
- package/dist/lib/Stripe/hooks/useStripeCheckout.js +41 -0
- package/dist/lib/Stripe/index.js +18 -1
- package/dist/lib/Stripe/stripe-button.js +28 -10
- package/dist/lib/Stripe/stripe-checkout-button.js +50 -0
- package/dist/lib/Stripe/stripe-modal.js +12 -1
- package/dist/lib/Stripe/stripe-popup.js +12 -1
- package/dist/lib/Stripe/stripe.js +30 -1
- package/dist/lib/Wechat/wechat-button.js +21 -6
- package/dist/lib/Wechat/wechat-content.js +65 -0
- package/dist/lib/Wechat/wechat.js +3 -1
- package/dist/lib/hooks/useLatestCallback.js +13 -0
- package/dist/lib/hooks/useManagedOrder.js +29 -0
- package/dist/lib/hooks/usePaymentExecution.js +113 -0
- package/dist/lib/hooks/usePaymentQr.js +51 -0
- package/dist/lib/hooks/usePaymentRedirect.js +87 -0
- package/dist/lib/index.js +57 -1
- package/dist/lib/pay-modal/pay-modal.js +33 -16
- package/dist/lib/shared/entitys/payment.js +61 -0
- package/dist/lib/shared/enums/index.js +11 -91
- package/dist/lib/shared/enums/payment.js +172 -0
- package/dist/lib/shared/index.js +12 -1
- package/dist/umd/pay-sdk-react.umd.js +6488 -7731
- package/dist/umd/pay-sdk-react.umd.js.map +1 -1
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -144,47 +144,11 @@ const AlipayComponent = () => {
|
|
|
144
144
|
export default AlipayComponent;
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
#### Method 3:
|
|
147
|
+
#### Method 3: Customize the button and its dialog
|
|
148
148
|
|
|
149
|
-
Use
|
|
149
|
+
Use `Alipay.Button` with `children`, `className`, and `style` to customize the trigger. Configure its scan dialog via `modalProps` or call `openModal` / `closeModal` on the button ref.
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
import { useRef, useState } from 'react';
|
|
153
|
-
import { Alipay, AlipayModalRef } from 'pay-sdk-react';
|
|
154
|
-
|
|
155
|
-
const formHtml = '<form ... />';
|
|
156
|
-
|
|
157
|
-
const AlipayComponent = () => {
|
|
158
|
-
const modalRef = useRef<AlipayModalRef>(null);
|
|
159
|
-
|
|
160
|
-
const [modalVisible, setModalVisible] = useState(false);
|
|
161
|
-
|
|
162
|
-
const createOrder = async () => {
|
|
163
|
-
const res = await fetch('/create-order', {
|
|
164
|
-
method: 'POST',
|
|
165
|
-
});
|
|
166
|
-
modalRef.current?.open({ formHtml: res.htmlStr });
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
return (
|
|
170
|
-
<div className="alipay-component">
|
|
171
|
-
<h3>Custom Button - Trigger modal with visible prop</h3>
|
|
172
|
-
<button onClick={() => setModalVisible(true)}>Custom Button</button>
|
|
173
|
-
<Alipay.Modal
|
|
174
|
-
visible={modalVisible}
|
|
175
|
-
onClose={() => setModalVisible(false)}
|
|
176
|
-
alipayProps={{ formHtml }}
|
|
177
|
-
/>
|
|
178
|
-
<h3>Custom Button - Trigger modal with ref open method</h3>
|
|
179
|
-
<button onClick={() => createOrder()}>Custom Button</button>
|
|
180
|
-
<Alipay.Modal ref={modalRef} />
|
|
181
|
-
</div>
|
|
182
|
-
);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export default AlipayComponent;
|
|
186
|
-
|
|
187
|
-
```
|
|
151
|
+
Existing custom triggers can continue to use `Alipay.Modal` or import `AlipayModal` directly and control visibility through `visible` or the ref.
|
|
188
152
|
|
|
189
153
|
#### Method 4: Custom integration
|
|
190
154
|
|
|
@@ -352,47 +316,11 @@ const WechatComponent = () => {
|
|
|
352
316
|
export default WechatComponent;
|
|
353
317
|
```
|
|
354
318
|
|
|
355
|
-
#### Method 3:
|
|
356
|
-
|
|
357
|
-
Use your own button, and call the modal component to display the QR code. After the user scans the QR code to complete payment, WeChat will notify the business backend of the payment result.
|
|
358
|
-
|
|
359
|
-
```typescript
|
|
360
|
-
import { useRef, useState } from 'react';
|
|
361
|
-
import { Wechat, WechatModalRef } from 'pay-sdk-react';
|
|
362
|
-
|
|
363
|
-
const wechatUrl = 'weixin://wxpay...';
|
|
364
|
-
|
|
365
|
-
const WechatComponent = () => {
|
|
366
|
-
const modalRef = useRef<WechatModalRef>(null);
|
|
367
|
-
|
|
368
|
-
const [modalVisible, setModalVisible] = useState(false);
|
|
369
|
-
|
|
370
|
-
const createOrder = async () => {
|
|
371
|
-
const res = await fetch('/create-order', {
|
|
372
|
-
method: 'POST',
|
|
373
|
-
});
|
|
374
|
-
modalRef.current?.open({ wechatUrl: res.url });
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
return (
|
|
378
|
-
<div className="wechat-component">
|
|
379
|
-
<h3>Custom Button - Trigger modal with visible prop</h3>
|
|
380
|
-
<button onClick={() => setModalVisible(true)}>Custom Button</button>
|
|
381
|
-
<Wechat.Modal
|
|
382
|
-
visible={modalVisible}
|
|
383
|
-
onClose={() => setModalVisible(false)}
|
|
384
|
-
wechatProps={{ wechatUrl }}
|
|
385
|
-
/>
|
|
319
|
+
#### Method 3: Customize the button and its dialog
|
|
386
320
|
|
|
387
|
-
|
|
388
|
-
<button onClick={() => createOrder()}>Custom Button</button>
|
|
389
|
-
<Wechat.Modal ref={modalRef} />
|
|
390
|
-
</div>
|
|
391
|
-
);
|
|
392
|
-
};
|
|
321
|
+
Use `Wechat.Button` with `children`, `className`, and `style` to customize the trigger. Configure its scan dialog via `modalProps` or call `openModal` / `closeModal` on the button ref.
|
|
393
322
|
|
|
394
|
-
|
|
395
|
-
```
|
|
323
|
+
Existing custom triggers can continue to use `Wechat.Modal` or import `WechatModal` directly and control visibility through `visible` or the ref.
|
|
396
324
|
|
|
397
325
|
#### Method 4: Custom integration
|
|
398
326
|
|
|
@@ -1293,3 +1221,238 @@ const PayssionComponent = () => {
|
|
|
1293
1221
|
|
|
1294
1222
|
export default PayssionComponent;
|
|
1295
1223
|
```
|
|
1224
|
+
|
|
1225
|
+
# Development and Maintenance
|
|
1226
|
+
|
|
1227
|
+
Read [AGENTS.md](./AGENTS.md) before maintaining this SDK. The [pay-sdk-development skill](./.agents/skills/pay-sdk-development/SKILL.md) describes the agent development and review workflow.
|
|
1228
|
+
|
|
1229
|
+
Changes should preserve compatibility with the existing public API and update both READMEs, the relevant Storybook scenarios, and version records. Use `@since` for the first supported version of a new public API and `@deprecated` with a replacement when an API is explicitly deprecated. Releases follow [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html).
|
|
1230
|
+
|
|
1231
|
+
## Payment execution extensions (1.2.0)
|
|
1232
|
+
|
|
1233
|
+
These extensions were introduced in version 1.2.0. New APIs and properties use `@since 1.2.0`.
|
|
1234
|
+
|
|
1235
|
+
Existing PC scan dialog exports `WechatModal`, `AlipayModal`, `Wechat.Modal`, and `Alipay.Modal` remain supported, along with `WechatModalRef` and `AlipayModalRef`. To configure the dialog built into a payment button, use `modalProps` on `WechatButton` or `AlipayButton`.
|
|
1236
|
+
|
|
1237
|
+
The SDK executes payment URLs, QR presentation, trusted payment HTML, Stripe embedded checkout, Airwallex embedded/hosted checkout, and associated loading, cancellation, errors, and resources. The application owns identity, region, available channels, order creation, subscription decisions, final order verification, and entitlements. Frontend `completed`, URL opening, window closure, and provider completion are distinct from a verified paid order.
|
|
1238
|
+
|
|
1239
|
+
### Entry points and compatibility
|
|
1240
|
+
|
|
1241
|
+
| API | Behavior | First supported |
|
|
1242
|
+
| ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
|
|
1243
|
+
| `useStripeCheckout`, `Stripe.CheckoutButton`, `StripeCheckoutButton` | Execute a backend-created Checkout URL without a publishable key. Existing Stripe embedded components remain available | 1.2.0 |
|
|
1244
|
+
| `useAirwallexCheckout`, `Airwallex.CheckoutButton`, `AirwallexCheckoutButton` | Execute a URL or official `@airwallex/components-sdk` hosted credentials. Existing embedded and URL APIs remain | 1.2.0 |
|
|
1245
|
+
| `Paypal.SmartButton`, `PaypalSmartButton`, `Paypal.Provider`, `PaypalProvider` | Official PayPal React buttons and script provider. Existing `PaypalButton` and namespace `Paypal.Button` execute URLs | 1.2.0 |
|
|
1246
|
+
| PC button `executionOptions` | Opt-in managed **createOrder** flow for Wechat, Alipay, Pix, Stripe, Airwallex, PaypalButton, and PayssionButton. Omission preserves the legacy path | 1.2.0 |
|
|
1247
|
+
| QR, Pix action, Alipay appearance, Modal slots | Optional presentation configuration, without application-specific channels or CDN mappings | 1.2.0 |
|
|
1248
|
+
| Modal `title: ReactNode` | Existing string titles continue working | 1.2.0 (type extension) |
|
|
1249
|
+
|
|
1250
|
+
Hooks are named exports from `pay-sdk-react`, implemented under each provider's `hooks/` directory. Buttons share those hooks. A hook renders no DOM and never creates an order or opens checkout on mount. Import through the package root and declared CSS exports; internal `pay-sdk-react/es/...` paths are not public exports.
|
|
1251
|
+
|
|
1252
|
+
```tsx
|
|
1253
|
+
import {
|
|
1254
|
+
useStripeCheckout,
|
|
1255
|
+
Stripe,
|
|
1256
|
+
Airwallex,
|
|
1257
|
+
OpenPayUrlMode,
|
|
1258
|
+
} from 'pay-sdk-react';
|
|
1259
|
+
import 'pay-sdk-react/css/index.css';
|
|
1260
|
+
|
|
1261
|
+
const Checkout = () => {
|
|
1262
|
+
const { openCheckout, closeCheckout, loading, error } = useStripeCheckout({
|
|
1263
|
+
redirectOptions: { openMode: OpenPayUrlMode.Href },
|
|
1264
|
+
});
|
|
1265
|
+
return (
|
|
1266
|
+
<>
|
|
1267
|
+
<button
|
|
1268
|
+
disabled={loading}
|
|
1269
|
+
onClick={() =>
|
|
1270
|
+
openCheckout(async (signal) => {
|
|
1271
|
+
const response = await fetch('/your-api/create-stripe-checkout', {
|
|
1272
|
+
method: 'POST',
|
|
1273
|
+
signal,
|
|
1274
|
+
});
|
|
1275
|
+
if (!response.ok) throw new Error('Unable to create checkout');
|
|
1276
|
+
const data = await response.json();
|
|
1277
|
+
return { url: data.checkoutUrl };
|
|
1278
|
+
})
|
|
1279
|
+
}
|
|
1280
|
+
>
|
|
1281
|
+
Continue to payment
|
|
1282
|
+
</button>
|
|
1283
|
+
<button onClick={closeCheckout}>Cancel frontend execution</button>
|
|
1284
|
+
{error ? <span>{error.code}</span> : null}
|
|
1285
|
+
</>
|
|
1286
|
+
);
|
|
1287
|
+
};
|
|
1288
|
+
|
|
1289
|
+
<Stripe.CheckoutButton
|
|
1290
|
+
url={checkoutUrl}
|
|
1291
|
+
redirectOptions={{ openMode: OpenPayUrlMode.Href }}
|
|
1292
|
+
/>;
|
|
1293
|
+
<Airwallex.CheckoutButton
|
|
1294
|
+
initOptions={{ env: 'demo' }}
|
|
1295
|
+
target={{
|
|
1296
|
+
checkout: {
|
|
1297
|
+
mode: 'payment',
|
|
1298
|
+
intent_id: paymentIntentId,
|
|
1299
|
+
client_secret: clientSecret,
|
|
1300
|
+
currency: 'USD',
|
|
1301
|
+
successUrl: returnUrl,
|
|
1302
|
+
},
|
|
1303
|
+
}}
|
|
1304
|
+
/>;
|
|
1305
|
+
```
|
|
1306
|
+
|
|
1307
|
+
The caller supplies valid backend-created parameters matching the provider session mode. For Airwallex recurring checkout, pass `mode:'recurring'`, `customer_id`, `client_secret`, `currency`, and supported `recurringOptions`. The SDK passes the official options through without creating subscription plans. Keep SDK environment and initialization configuration consistent across the page.
|
|
1308
|
+
|
|
1309
|
+
### Checkout and shared execution API
|
|
1310
|
+
|
|
1311
|
+
All additions below first appear in **1.2.0**. Properties are optional unless marked required.
|
|
1312
|
+
|
|
1313
|
+
| API | Type | Required / default | Meaning |
|
|
1314
|
+
| ------------------------------- | ------------------------------------------------------------------ | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1315
|
+
| `openCheckout(source)` | `CheckoutSource<T> => Promise<PaymentExecutionResult>` | Source required | Stripe accepts `{url}`; Airwallex accepts exclusive `{url}` or `{checkout}`. A factory receives AbortSignal and returns a target, Promise, or null |
|
|
1316
|
+
| `closeCheckout()` | `() => void` | — | Cancel pending execution and close the owned window |
|
|
1317
|
+
| `cancel()` | `() => void` | — | Cancel frontend work without closing an already-open window or cancelling a business order |
|
|
1318
|
+
| `loading / status / error` | `boolean / PaymentExecutionStatus / PaymentExecutionError or null` | `false / Idle / null` | Instance execution state. Errors omit raw credentials and payment HTML |
|
|
1319
|
+
| Result `status / value / error` | State / optional value / optional error | Status required | Idle, Pending, Completed, Cancelled, Failed describe frontend stages. Checkout does not return business payment success |
|
|
1320
|
+
| `beforePay` | `() => boolean or Promise<boolean>` | Continue | false stops execution before createOrder |
|
|
1321
|
+
| `onLoadingChange` | `(loading:boolean)=>void` | None | Covers validation, target creation, initialization and redirect invocation, not subsequent payment waiting |
|
|
1322
|
+
| `onPaymentError` | `(error:PaymentExecutionError)=>void` | None | Same failure as the returned Failed result; execution errors are returned rather than thrown |
|
|
1323
|
+
| `onCancel` | `()=>void` | None | Explicit cancellation, beforePay false or null source; unmount cleans up silently |
|
|
1324
|
+
| `redirectOptions` | `PaymentRedirectOptions` | See below | URL opening and window configuration; not used to control official hosted credentials |
|
|
1325
|
+
| Airwallex `initOptions` | `Omit<SDKOptions,'enabledElements'>` | Official defaults | SDK enables payments; explicitly choose the environment when possible |
|
|
1326
|
+
| Stripe button `url` | `string` | None | Direct HTTP(S) URL, or use createOrder |
|
|
1327
|
+
| Airwallex button `target` | `AirwallexCheckoutTarget` | None | Direct URL or hosted credentials, or use createOrder |
|
|
1328
|
+
| Both buttons `createOrder` | `(signal)=>Promise<T or null>` | None | Runs on click, takes precedence over url/target. Base Button disabled/loading/children props also work |
|
|
1329
|
+
|
|
1330
|
+
A duplicate call while pending returns Pending without creating another order. Cancellation/unmount aborts the signal and ignores late results. Whether the business request stops depends on the caller using that signal. Cancellation updates state immediately; a business Promise ignoring abort must still settle itself. The SDK cannot undo an order or a provider charge. Consumer callbacks should not throw.
|
|
1331
|
+
|
|
1332
|
+
Error codes are InvalidParameters, BrowserUnavailable, WindowBlocked, InitializationFailed, and ExecutionFailed. Retry by invoking again. URLs allow HTTP(S), including relative URLs; use the existing H5 components for native app protocols.
|
|
1333
|
+
|
|
1334
|
+
| Redirect field | Type | Default | Meaning (all 1.2.0) |
|
|
1335
|
+
| ----------------------------- | ------------------------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
1336
|
+
| `openMode` | `OpenPayUrlMode` | Href | URL supports Href / Replace / Window. Official Airwallex credential checkout only supports current-page navigation; other modes return a parameter error |
|
|
1337
|
+
| `windowName / windowFeatures` | `string` | Isolated instance name / browser default | Window mode; manually sharing a name may cause browser window reuse |
|
|
1338
|
+
| `closeWindowOnUnmount` | `boolean` | true | Close only the owned window; false leaves it open |
|
|
1339
|
+
| `onOpen` | `(url:string)=>void` | None | URL opening was invoked, not payment success. Not emitted for credential checkout |
|
|
1340
|
+
| `onWindowClose` | `()=>void` | None | User window closure detected by polling; explicit close/unmount does not emit it |
|
|
1341
|
+
| `allowedMessageOrigins` | `string[]` | None | Required together with messageValidator to receive messages |
|
|
1342
|
+
| `messageValidator` | `(event:MessageEvent)=>boolean` | None | After source/origin checks, validate the current order/nonce, rather than a static success string |
|
|
1343
|
+
| `onMessage` | `(event:MessageEvent)=>void` | None | Trusted message from the owned window passing validation; still verify the order on the backend |
|
|
1344
|
+
|
|
1345
|
+
Browsers may block new windows, particularly after slow asynchronous order creation. Handle WindowBlocked and offer current-page retry. Ordinary rerenders do not reopen windows; opening again first closes the owned window. Current-page navigation cannot observe the subsequent provider interface.
|
|
1346
|
+
|
|
1347
|
+
### QR, HTML, Modal and method presentation
|
|
1348
|
+
|
|
1349
|
+
Every addition in this table is optional and first supported in **1.2.0**. Omitted configuration retains legacy defaults.
|
|
1350
|
+
|
|
1351
|
+
| Property | Type | Default | Meaning |
|
|
1352
|
+
| ------------------------------------- | ---------------------------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
1353
|
+
| Wechat / Pix `qrProps` | PaymentQrAppearance | None | size:number, overlay:ReactNode, loadingContent/errorContent:ReactNode, onQrReady:(imageUrl)=>void, onQrError:()=>void, all optional |
|
|
1354
|
+
| QR `classNames / styles` | Slot maps | None | root/container/image/tip/overlay. size is square; the caller sizes overlays to preserve scannability |
|
|
1355
|
+
| Pix `showCode` | boolean | false | Show the full code. Existing showCopyButton controls only the copy button |
|
|
1356
|
+
| Pix `copyText / copiedText` | ReactNode | Legacy labels | Before/after copy content; may contain translated text |
|
|
1357
|
+
| Pix `onCopy / onCopyError` | ()=>void | None | Copy outcome; failed fallback does not report success and temporary DOM is removed |
|
|
1358
|
+
| Pix `confirmText / onConfirm` | ReactNode / ()=>void | None | Providing confirmText shows an action; callback expresses user intent only |
|
|
1359
|
+
| Pix `actionClassNames / actionStyles` | Slot maps | None | code/copy/confirm |
|
|
1360
|
+
| Alipay `classNames / styles` | Slot maps | None | root/iframe/tip; override legacy wrapperStyle/iframeStyle. Cannot style provider iframe internals |
|
|
1361
|
+
| Alipay `loadingContent` | ReactNode | Legacy spinner | When configured, new HTML restarts loading until iframe load |
|
|
1362
|
+
| Alipay `onFrameLoad / onFrameError` | ()=>void | None | Browser-observable load/error, not payment outcome; cross-origin observability is limited |
|
|
1363
|
+
| Modal `title` | ReactNode | Legacy default | String or rich title; string consumers need no migration |
|
|
1364
|
+
| Modal `classNames / styles` | Slot maps | None | root/mask/content/close/icon/title/description/body/footer; styles merge after style/contentStyle |
|
|
1365
|
+
| Modal `closeIcon / closeLabel` | ReactNode / string | × / 关闭 | Close content and accessible name; showClose still applies |
|
|
1366
|
+
| Payssion `children` | ReactNode | Payssion content | Pass the complete button content. Explicit null, an empty string, and 0 are rendered as supplied. Set the mask title with `maskProps.title`. |
|
|
1367
|
+
|
|
1368
|
+
```tsx
|
|
1369
|
+
import { Wechat, Pix, PayssionButton } from 'pay-sdk-react';
|
|
1370
|
+
<Wechat.Button
|
|
1371
|
+
modalProps={{
|
|
1372
|
+
title: <strong>Scan with WeChat Pay</strong>,
|
|
1373
|
+
styles: { content: { width: 420 }, title: { color: '#1677ff' } },
|
|
1374
|
+
wechatProps: {
|
|
1375
|
+
wechatUrl: code,
|
|
1376
|
+
qrProps: { size: 220, overlay: <BrandIcon /> },
|
|
1377
|
+
},
|
|
1378
|
+
}}
|
|
1379
|
+
/>;
|
|
1380
|
+
<Pix
|
|
1381
|
+
pixCode={pixCode}
|
|
1382
|
+
showCode
|
|
1383
|
+
copyText="Copy code"
|
|
1384
|
+
copiedText="Copied"
|
|
1385
|
+
confirmText="Check order"
|
|
1386
|
+
onConfirm={checkBusinessOrder}
|
|
1387
|
+
qrProps={{ size: 220 }}
|
|
1388
|
+
/>;
|
|
1389
|
+
<PayssionButton payssionUrl={paymentUrl} maskProps={{ title: 'OXXO' }}>
|
|
1390
|
+
<img src={logoUrl} alt="" width={80} height={24} />
|
|
1391
|
+
Pay with OXXO
|
|
1392
|
+
</PayssionButton>;
|
|
1393
|
+
```
|
|
1394
|
+
|
|
1395
|
+
`executionOptions` enhances only async createOrder on legacy PC buttons: synchronous duplicate-call lock, loading, ignored late results, error notification, and retry. It does not replace legacy PayMask window handling; use Checkout hooks for the new URL window lifecycle. Existing closeModal/closePopup/closePayment refs also cancel pending creation. Direct parameters/ref paths without createOrder remain legacy, so beforePay does not intercept them. Managed onClick runs first and preventDefault stops creation; omission retains the old callback order.
|
|
1396
|
+
|
|
1397
|
+
### Embedded events and official PayPal buttons
|
|
1398
|
+
|
|
1399
|
+
All new fields below first appear in **1.2.0**.
|
|
1400
|
+
|
|
1401
|
+
| Property | Type | Required / default | Meaning |
|
|
1402
|
+
| --------------------------------------------------------------------------------------- | ------------------------------- | ------------------ | --------------------------------------------------------------------------------------------------------------- |
|
|
1403
|
+
| Stripe checkoutEvents `onInitialized / onInitializationError` | ()=>void | None | Stripe.js initialized/failed, not iframe visibility |
|
|
1404
|
+
| Stripe checkoutEvents `onComplete` | ()=>void | None | Official EmbeddedCheckout completion, not backend verification |
|
|
1405
|
+
| Stripe `instanceKey` | string | None | Explicitly replace the Provider session; change alongside clientSecret |
|
|
1406
|
+
| Stripe Modal/Popup `closeOnComplete` | boolean | false | Request close on completion; controlled visible remains caller-owned |
|
|
1407
|
+
| Airwallex `instanceOptions` | {containerId?:string} | None | Pass {} to opt into isolated DOM mounting, listeners and unmount cleanup; omission retains legacy behavior |
|
|
1408
|
+
| Airwallex Modal/Popup `closeOnSuccess / closeOnError` | boolean | true / true | Control automatic closure of uncontrolled overlays; controlled consumers update visible from onSuccess/onError |
|
|
1409
|
+
| PayPal `scriptOptions` | Official ScriptProvider options | None | Local Provider if supplied; otherwise an outer Paypal.Provider is required. Prefer one shared Provider per page |
|
|
1410
|
+
| PayPal `loadingContent / errorContent` | ReactNode | Official behavior | Script-loading/failure presentation |
|
|
1411
|
+
| PayPal `onScriptError` | ()=>void | None | Script failure, distinct from PayPalButtons onError |
|
|
1412
|
+
| Official createOrder/createSubscription/onApprove/onCancel/onError/style/disabled, etc. | Official PayPalButtonsProps | Official defaults | Passed through; caller handles creation, capture, approval and subscription confirmation. No automatic capture |
|
|
1413
|
+
|
|
1414
|
+
```tsx
|
|
1415
|
+
import { Paypal } from 'pay-sdk-react';
|
|
1416
|
+
<Paypal.Provider options={{ clientId: paypalClientId, currency: 'USD' }}>
|
|
1417
|
+
<Paypal.SmartButton
|
|
1418
|
+
createOrder={createPaypalOrder}
|
|
1419
|
+
onApprove={approveAndConfirmOrder}
|
|
1420
|
+
onCancel={onUserCancel}
|
|
1421
|
+
onError={showExecutionError}
|
|
1422
|
+
/>
|
|
1423
|
+
</Paypal.Provider>;
|
|
1424
|
+
```
|
|
1425
|
+
|
|
1426
|
+
Subscription buttons require official vault/intent configuration and createSubscription; do not mix order and subscription session modes.
|
|
1427
|
+
|
|
1428
|
+
### Storybook and verification
|
|
1429
|
+
|
|
1430
|
+
Payment examples are organized under `Components/{provider}/{entry}`, including the existing PC/H5 paths and the new Checkout and SmartButton entries. See the [parameter and scenario matrix](./docs/payment-storybook-matrix.md) and [machine-checkable inventory](./docs/payment-storybook-coverage.json). Storybook uses local provider, window, QR and clipboard fixtures; published SDK builds use the real implementations.
|
|
1431
|
+
|
|
1432
|
+
- `pnpm test`: Vitest/jsdom regression including duplicate calls, cancellation/unmount, trusted messages, blocked windows, StrictMode, independent instances and presentation compatibility.
|
|
1433
|
+
- `pnpm run test-storybook --url http://localhost:6006`: run sdk-test browser stories against an already-started Storybook. Does not start the server.
|
|
1434
|
+
- `pnpm run build-storybook`: build examples; does not prove play execution or real payments.
|
|
1435
|
+
- [Scenario verification matrix](./docs/checkout-verification.md) records native browser and provider sandbox boundaries.
|
|
1436
|
+
|
|
1437
|
+
The browser runner uses Playwright-managed Chromium by default. Set `PAY_SDK_CHROMIUM_PATH=/absolute/path/to/chromium` to reuse an installed executable without editing repository configuration.
|
|
1438
|
+
|
|
1439
|
+
After building, run `pnpm run test:package` to verify the CommonJS entry, SSR rendering, new namespaces, browser UMD without Node globals, declaration files and CSS. It does not create orders.
|
|
1440
|
+
|
|
1441
|
+
`scriptOptions` configures official script initialization. When changing clientId, currency or intent, explicitly change the component/Provider key or use the official shared Provider resetOptions action; ordinary rerendering does not promise script reloading.
|
|
1442
|
+
|
|
1443
|
+
### Storybook organization and maintenance
|
|
1444
|
+
|
|
1445
|
+
Under `components/shared/`, `enums/payment.ts` contains payment enums, while `entitys/payment.ts` contains shared types and the payment execution error class. Applications import the public names from the package root.
|
|
1446
|
+
|
|
1447
|
+
Public API JSDoc uses multiline blocks: `/**` and `*/` each occupy their own line, and tags such as `@zh`, `@en` and `@since` appear on separate lines above the documented declaration or field. Formatting preserves existing descriptions and introduction versions without changing types, defaults or execution behavior.
|
|
1448
|
+
|
|
1449
|
+
Every story has an explicit display name in the form “category|specific scenario”, adding parameter source, PC/H5 branch, Modal/Popup/Mask or the behavior under verification when needed. For example, “基础|支付宝 H5|直接传入表单|确认弹窗” identifies direct HTML input, while “异步|受管理下单慢响应与重复点击锁” identifies managed slow-order behavior. Basic demonstrations and automated regression cases are distinguished without numbered suffixes. Display names change; existing story IDs, links and execution behavior stay stable. The naming check covers all 529 stories and validates registered names against the inventory. See the [naming rules and examples](./docs/payment-storybook-matrix.md#场景命名).
|
|
1450
|
+
|
|
1451
|
+
New parameter cases for existing Button, Form, Modal and Popup entries live beside those entries. New execution APIs appear under `Components/Stripe/CheckoutButton`, `Components/Stripe/CheckoutHook`, the corresponding Airwallex entries, and `Components/Paypal/SmartButton`. Eight Payssion examples pass button labels and illustrative images through children, with sizes and styles set by the caller.
|
|
1452
|
+
|
|
1453
|
+
- `pnpm run typecheck:stories`: type-check every story and demo helper.
|
|
1454
|
+
- `pnpm run test:story-coverage`: validate registration, classification, explicit play functions, PaymentMethod boundaries, Airwallex Element types and SDK field-signature changes.
|
|
1455
|
+
- `pnpm run test-storybook --url http://localhost:6006`: execute all sdk-test cases against a maintainer-started Storybook.
|
|
1456
|
+
- Optionally set `PAY_SDK_STORY_FILES='Pix.stories.tsx;Wechat.stories.tsx'` for focused debugging; omit it to run the complete inventory.
|
|
1457
|
+
|
|
1458
|
+
Coverage follows implemented SDK branches, business parameters, defaults/customization, asynchronous states and owned resources. It does not enumerate arbitrary provider options, CSS values or merchant environments. Render-only galleries, interaction assertions, native pointer checks and sandbox payments are reported separately.
|