pay-sdk-react 1.1.13 → 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 +465 -84
- package/README.zh-CN.md +466 -85
- package/dist/css/index.css +86 -6
- 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/Airwallex/style/index.css +2 -2
- package/dist/es/Airwallex/style/index.min.css +1 -1
- 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/Alipay/style/index.css +2 -2
- package/dist/es/Alipay/style/index.min.css +1 -1
- package/dist/es/MAlipay/style/index.css +2 -2
- package/dist/es/MAlipay/style/index.min.css +1 -1
- package/dist/es/MPix/index.d.ts +2 -0
- package/dist/es/MPix/index.js +2 -0
- package/dist/es/MPix/interface.d.ts +44 -0
- package/dist/es/MPix/interface.js +1 -0
- package/dist/es/MPix/m-pix-button.d.ts +6 -0
- package/dist/es/MPix/m-pix-button.js +159 -0
- package/dist/es/MPix/style/index.css +256 -0
- package/dist/es/MPix/style/index.d.ts +1 -0
- package/dist/es/MPix/style/index.js +1 -0
- package/dist/es/MPix/style/index.min.css +1 -0
- package/dist/es/MWeChat/style/index.css +2 -2
- package/dist/es/MWeChat/style/index.min.css +1 -1
- package/dist/es/PayButton/index.js +12 -0
- package/dist/es/PayButton/interface.d.ts +28 -2
- 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/index.d.ts +11 -0
- package/dist/es/Pix/index.js +10 -0
- package/dist/es/Pix/interface.d.ts +147 -0
- package/dist/es/Pix/interface.js +1 -0
- package/dist/es/Pix/pix-button.d.ts +6 -0
- package/dist/es/Pix/pix-button.js +99 -0
- package/dist/es/Pix/pix-enhanced.d.ts +4 -0
- package/dist/es/Pix/pix-enhanced.js +182 -0
- package/dist/es/Pix/pix-modal.d.ts +6 -0
- package/dist/es/Pix/pix-modal.js +57 -0
- package/dist/es/Pix/pix.d.ts +4 -0
- package/dist/es/Pix/pix.js +125 -0
- package/dist/es/Pix/style/index.css +80 -0
- package/dist/es/Pix/style/index.d.ts +1 -0
- package/dist/es/Pix/style/index.js +1 -0
- package/dist/es/Pix/style/index.min.css +1 -0
- 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/Stripe/style/index.css +2 -2
- package/dist/es/Stripe/style/index.min.css +1 -1
- package/dist/es/Wechat/interface.d.ts +13 -0
- package/dist/es/Wechat/style/index.css +2 -2
- package/dist/es/Wechat/style/index.min.css +1 -1
- 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/confirm-modal/style/index.css +2 -2
- package/dist/es/confirm-modal/style/index.min.css +1 -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/icons/IconCheck/index.d.ts +4 -0
- package/dist/es/icons/IconCheck/index.js +22 -0
- package/dist/es/icons/IconCopy/index.d.ts +4 -0
- package/dist/es/icons/IconCopy/index.js +27 -0
- package/dist/es/icons/IconPix/index.d.ts +4 -0
- package/dist/es/icons/IconPix/index.js +33 -0
- package/dist/es/icons/index.d.ts +3 -0
- package/dist/es/icons/index.js +4 -1
- package/dist/es/index.d.ts +50 -6
- package/dist/es/index.js +28 -1
- package/dist/es/pay-modal/interface.d.ts +22 -2
- package/dist/es/pay-modal/pay-modal.js +36 -16
- package/dist/es/pay-modal/style/index.css +2 -2
- package/dist/es/pay-modal/style/index.min.css +1 -1
- 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 -78
- package/dist/es/shared/enums/index.js +1 -81
- 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/Airwallex/style/index.css +2 -2
- package/dist/lib/Airwallex/style/index.min.css +1 -1
- package/dist/lib/Alipay/alipay-button.js +21 -6
- package/dist/lib/Alipay/alipay.js +36 -9
- package/dist/lib/Alipay/style/index.css +2 -2
- package/dist/lib/Alipay/style/index.min.css +1 -1
- package/dist/lib/MAlipay/style/index.css +2 -2
- package/dist/lib/MAlipay/style/index.min.css +1 -1
- package/dist/lib/MPix/index.js +28 -0
- package/dist/lib/MPix/interface.js +5 -0
- package/dist/lib/MPix/m-pix-button.js +127 -0
- package/dist/lib/MPix/style/index.css +256 -0
- package/dist/lib/MPix/style/index.js +3 -0
- package/dist/lib/MPix/style/index.min.css +1 -0
- package/dist/lib/MWeChat/style/index.css +2 -2
- package/dist/lib/MWeChat/style/index.min.css +1 -1
- package/dist/lib/PayButton/index.js +12 -0
- 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/index.js +43 -0
- package/dist/lib/Pix/interface.js +5 -0
- package/dist/lib/Pix/pix-button.js +83 -0
- package/dist/lib/Pix/pix-enhanced.js +143 -0
- package/dist/lib/Pix/pix-modal.js +50 -0
- package/dist/lib/Pix/pix.js +97 -0
- package/dist/lib/Pix/style/index.css +80 -0
- package/dist/lib/Pix/style/index.js +3 -0
- package/dist/lib/Pix/style/index.min.css +1 -0
- 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/Stripe/style/index.css +2 -2
- package/dist/lib/Stripe/style/index.min.css +1 -1
- package/dist/lib/Wechat/style/index.css +2 -2
- package/dist/lib/Wechat/style/index.min.css +1 -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/confirm-modal/style/index.css +2 -2
- package/dist/lib/confirm-modal/style/index.min.css +1 -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/icons/IconCheck/index.js +27 -0
- package/dist/lib/icons/IconCopy/index.js +32 -0
- package/dist/lib/icons/IconPix/index.js +38 -0
- package/dist/lib/icons/index.js +25 -1
- package/dist/lib/index.js +86 -1
- package/dist/lib/pay-modal/pay-modal.js +33 -16
- package/dist/lib/pay-modal/style/index.css +2 -2
- package/dist/lib/pay-modal/style/index.min.css +1 -1
- package/dist/lib/shared/entitys/payment.js +61 -0
- package/dist/lib/shared/enums/index.js +11 -81
- 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 +10455 -11463
- package/dist/umd/pay-sdk-react.umd.js.map +1 -1
- package/package.json +44 -25
package/README.md
CHANGED
|
@@ -6,20 +6,24 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
6
6
|
|
|
7
7
|
# Features
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
## Comprehensive
|
|
11
|
-
|
|
10
|
+
|
|
11
|
+
Supports mainstream payment methods such as Alipay, WeChat Pay, PayPal, Stripe, Payssion, Airwallex, and PIX, covering the vast majority of business scenarios.
|
|
12
12
|
|
|
13
13
|
## Cross-Platform Compatibility
|
|
14
|
+
|
|
14
15
|
Available for H5, PC, and App scenarios, adaptable to multiple platforms to meet diverse business needs.
|
|
15
16
|
|
|
16
17
|
## TypeScript Friendly
|
|
18
|
+
|
|
17
19
|
All components are written in TypeScript, ensuring type safety and an excellent development experience.
|
|
18
20
|
|
|
19
21
|
## Multiple Integration Forms
|
|
22
|
+
|
|
20
23
|
Supports payment buttons, modals, QR codes, forms, popups, modals, overlays, and more. Flexible combinations to suit various business scenarios.
|
|
21
24
|
|
|
22
25
|
# Install
|
|
26
|
+
|
|
23
27
|
[npm package](https://www.npmjs.com/package/pay-sdk-react)
|
|
24
28
|
|
|
25
29
|
```shell
|
|
@@ -53,6 +57,7 @@ ReactDOM.render(<App />, document.getElementById('app'));
|
|
|
53
57
|
```
|
|
54
58
|
|
|
55
59
|
### On-Demand Loading
|
|
60
|
+
|
|
56
61
|
Using babel-plugin-import
|
|
57
62
|
|
|
58
63
|
#### 1. Install
|
|
@@ -61,8 +66,8 @@ Using babel-plugin-import
|
|
|
61
66
|
npm i babel-plugin-import -D
|
|
62
67
|
```
|
|
63
68
|
|
|
64
|
-
|
|
65
69
|
#### 2. Add Configuration: Component and Style On-demand Import
|
|
70
|
+
|
|
66
71
|
Add the following to your babel config:
|
|
67
72
|
|
|
68
73
|
```js
|
|
@@ -82,9 +87,11 @@ plugins: [
|
|
|
82
87
|
# Payment Scenarios & Usage
|
|
83
88
|
|
|
84
89
|
## Alipay
|
|
90
|
+
|
|
85
91
|
### PC
|
|
86
92
|
|
|
87
93
|
#### Method 1: Use the provided Pay Button
|
|
94
|
+
|
|
88
95
|
Import the Pay Button, click to trigger a modal displaying the Alipay QR code. After the user scans the QR code to complete payment, Alipay will notify the business backend of the payment result.
|
|
89
96
|
|
|
90
97
|
```typescript
|
|
@@ -112,7 +119,9 @@ export default AlipayComponent;
|
|
|
112
119
|
```
|
|
113
120
|
|
|
114
121
|
#### Method 2: Use a Alipay button
|
|
122
|
+
|
|
115
123
|
Import Alipay, Alipay.Button click to trigger a modal displaying the Alipay QR code. After the user scans the QR code to complete payment, Alipay will notify the business backend of the payment result.
|
|
124
|
+
|
|
116
125
|
```typescript
|
|
117
126
|
import { Alipay } from 'pay-sdk-react';
|
|
118
127
|
|
|
@@ -135,49 +144,14 @@ const AlipayComponent = () => {
|
|
|
135
144
|
export default AlipayComponent;
|
|
136
145
|
```
|
|
137
146
|
|
|
147
|
+
#### Method 3: Customize the button and its dialog
|
|
138
148
|
|
|
139
|
-
|
|
140
|
-
Use your own button, and call the modal component to display the QR code. After the user scans the QR code to complete payment, Alipay will notify the business backend of the payment result.
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
import { useRef, useState } from 'react';
|
|
144
|
-
import { Alipay, AlipayModalRef } from 'pay-sdk-react';
|
|
145
|
-
|
|
146
|
-
const formHtml = '<form ... />';
|
|
147
|
-
|
|
148
|
-
const AlipayComponent = () => {
|
|
149
|
-
const modalRef = useRef<AlipayModalRef>(null);
|
|
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
|
-
|
|
153
|
-
const createOrder = async () => {
|
|
154
|
-
const res = await fetch('/create-order', {
|
|
155
|
-
method: 'POST',
|
|
156
|
-
});
|
|
157
|
-
modalRef.current?.open({ formHtml: res.htmlStr });
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
return (
|
|
161
|
-
<div className="alipay-component">
|
|
162
|
-
<h3>Custom Button - Trigger modal with visible prop</h3>
|
|
163
|
-
<button onClick={() => setModalVisible(true)}>Custom Button</button>
|
|
164
|
-
<Alipay.Modal
|
|
165
|
-
visible={modalVisible}
|
|
166
|
-
onClose={() => setModalVisible(false)}
|
|
167
|
-
alipayProps={{ formHtml }}
|
|
168
|
-
/>
|
|
169
|
-
<h3>Custom Button - Trigger modal with ref open method</h3>
|
|
170
|
-
<button onClick={() => createOrder()}>Custom Button</button>
|
|
171
|
-
<Alipay.Modal ref={modalRef} />
|
|
172
|
-
</div>
|
|
173
|
-
);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
export default AlipayComponent;
|
|
177
|
-
|
|
178
|
-
```
|
|
151
|
+
Existing custom triggers can continue to use `Alipay.Modal` or import `AlipayModal` directly and control visibility through `visible` or the ref.
|
|
179
152
|
|
|
180
153
|
#### Method 4: Custom integration
|
|
154
|
+
|
|
181
155
|
Directly import the QR code component and customize the integration and display timing. After the user scans the QR code to complete payment, Alipay will notify the business backend of the payment result.
|
|
182
156
|
|
|
183
157
|
```typescript
|
|
@@ -199,6 +173,7 @@ export default AlipayComponent;
|
|
|
199
173
|
### H5
|
|
200
174
|
|
|
201
175
|
#### Method 1: PayButton
|
|
176
|
+
|
|
202
177
|
Import the PayButton, click to trigger a waiting modal (or overlay), auto-submit the iframe form to launch the Alipay app, or open in browser if the app is not installed. After the user completes payment, Alipay will notify the business backend of the payment result. Result handling: supports both modal and overlay.
|
|
203
178
|
|
|
204
179
|
```typescript
|
|
@@ -230,6 +205,7 @@ export default MAlipayComponent;
|
|
|
230
205
|
```
|
|
231
206
|
|
|
232
207
|
#### Method 2: MAlipay.Button
|
|
208
|
+
|
|
233
209
|
Import MAlipay.Button, click to trigger a waiting modal (or overlay), auto-submit the iframe form to launch the Alipay app, or open in browser if the app is not installed. After the user completes payment, Alipay will notify the business backend of the payment result.
|
|
234
210
|
|
|
235
211
|
```typescript
|
|
@@ -260,8 +236,8 @@ const MAlipayComponent = () => {
|
|
|
260
236
|
export default MAlipayComponent;
|
|
261
237
|
```
|
|
262
238
|
|
|
263
|
-
|
|
264
239
|
#### Method 3: Custom form
|
|
240
|
+
|
|
265
241
|
Import the MAlipay form component and customize the trigger timing. After the user completes payment, Alipay will notify the business backend of the payment result.
|
|
266
242
|
|
|
267
243
|
```typescript
|
|
@@ -287,6 +263,7 @@ export default MAlipayComponent;
|
|
|
287
263
|
### PC
|
|
288
264
|
|
|
289
265
|
#### Method 1: PayButton
|
|
266
|
+
|
|
290
267
|
Import the PayButton, click to trigger a modal displaying the WeChat QR code. After the user scans the QR code to complete payment, WeChat will notify the business backend of the payment result.
|
|
291
268
|
|
|
292
269
|
```typescript
|
|
@@ -314,6 +291,7 @@ export default WechatComponent;
|
|
|
314
291
|
```
|
|
315
292
|
|
|
316
293
|
#### Method 2: Wechat.Button
|
|
294
|
+
|
|
317
295
|
Import Wechat.Button, click to trigger a modal displaying the WeChat QR code. After the user scans the QR code to complete payment, WeChat will notify the business backend of the payment result.
|
|
318
296
|
|
|
319
297
|
```typescript
|
|
@@ -338,48 +316,14 @@ const WechatComponent = () => {
|
|
|
338
316
|
export default WechatComponent;
|
|
339
317
|
```
|
|
340
318
|
|
|
341
|
-
#### Method 3:
|
|
342
|
-
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.
|
|
343
|
-
|
|
344
|
-
```typescript
|
|
345
|
-
import { useRef, useState } from 'react';
|
|
346
|
-
import { Wechat, WechatModalRef } from 'pay-sdk-react';
|
|
347
|
-
|
|
348
|
-
const wechatUrl = 'weixin://wxpay...';
|
|
349
|
-
|
|
350
|
-
const WechatComponent = () => {
|
|
351
|
-
const modalRef = useRef<WechatModalRef>(null);
|
|
352
|
-
|
|
353
|
-
const [modalVisible, setModalVisible] = useState(false);
|
|
354
|
-
|
|
355
|
-
const createOrder = async () => {
|
|
356
|
-
const res = await fetch('/create-order', {
|
|
357
|
-
method: 'POST',
|
|
358
|
-
});
|
|
359
|
-
modalRef.current?.open({ wechatUrl: res.url });
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
return (
|
|
363
|
-
<div className="wechat-component">
|
|
364
|
-
<h3>Custom Button - Trigger modal with visible prop</h3>
|
|
365
|
-
<button onClick={() => setModalVisible(true)}>Custom Button</button>
|
|
366
|
-
<Wechat.Modal
|
|
367
|
-
visible={modalVisible}
|
|
368
|
-
onClose={() => setModalVisible(false)}
|
|
369
|
-
wechatProps={{ wechatUrl }}
|
|
370
|
-
/>
|
|
319
|
+
#### Method 3: Customize the button and its dialog
|
|
371
320
|
|
|
372
|
-
|
|
373
|
-
<button onClick={() => createOrder()}>Custom Button</button>
|
|
374
|
-
<Wechat.Modal ref={modalRef} />
|
|
375
|
-
</div>
|
|
376
|
-
);
|
|
377
|
-
};
|
|
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.
|
|
378
322
|
|
|
379
|
-
|
|
380
|
-
```
|
|
323
|
+
Existing custom triggers can continue to use `Wechat.Modal` or import `WechatModal` directly and control visibility through `visible` or the ref.
|
|
381
324
|
|
|
382
325
|
#### Method 4: Custom integration
|
|
326
|
+
|
|
383
327
|
Directly import the QR code component and customize the integration and display timing. After the user scans the QR code to complete payment, WeChat will notify the business backend of the payment result.
|
|
384
328
|
|
|
385
329
|
```typescript
|
|
@@ -402,6 +346,7 @@ export default WechatComponent;
|
|
|
402
346
|
### H5
|
|
403
347
|
|
|
404
348
|
#### Method 1: PayButton
|
|
349
|
+
|
|
405
350
|
Import the PayButton, click to trigger a waiting modal (or overlay), auto-open the WeChat payment link, and auto-trigger payment in the WeChat browser. After the user completes payment, WeChat will notify the business backend of the payment result. Result handling: supports both modal and overlay.
|
|
406
351
|
|
|
407
352
|
```typescript
|
|
@@ -437,6 +382,7 @@ export default MWechatComponent;
|
|
|
437
382
|
```
|
|
438
383
|
|
|
439
384
|
#### Method 2: MWechatButton
|
|
385
|
+
|
|
440
386
|
Import MWechatButton, click to trigger a waiting modal (or overlay), auto-open the WeChat payment link, and auto-trigger payment in the WeChat browser. After the user completes payment, WeChat will notify the business backend of the payment result.
|
|
441
387
|
|
|
442
388
|
```typescript
|
|
@@ -463,6 +409,7 @@ export default MWechatComponent;
|
|
|
463
409
|
Import the PayButton, click to trigger payment, auto-open the PayPal payment link, and show a waiting overlay. After PayPal payment is completed, PayPal will redirect to the business-specified result page, and the redirect address is passed in when the business backend service calls the PayPal official payment order creation API.
|
|
464
410
|
|
|
465
411
|
### Method 1: PayButton
|
|
412
|
+
|
|
466
413
|
Import the PayButton, click to trigger payment, auto-open the PayPal payment link, and show a waiting overlay. After the user completes payment, PayPal will redirect to the business-specified result page.
|
|
467
414
|
|
|
468
415
|
```typescript
|
|
@@ -499,6 +446,7 @@ export default PaypalComponent;
|
|
|
499
446
|
```
|
|
500
447
|
|
|
501
448
|
### Method 2: PaypalButton
|
|
449
|
+
|
|
502
450
|
Import PaypalButton, click to trigger payment, auto-open the PayPal payment link, and show a waiting overlay. After the user completes payment, PayPal will redirect to the business-specified result page.
|
|
503
451
|
|
|
504
452
|
```typescript
|
|
@@ -554,6 +502,7 @@ export default PaypalComponent;
|
|
|
554
502
|
Import payment components to use Stripe payment. After Stripe payment is completed, Stripe will redirect to the business-specified result page, and the redirect address is passed in when the business backend service calls the Stripe official payment order creation API.
|
|
555
503
|
|
|
556
504
|
### Method 1: PayButton
|
|
505
|
+
|
|
557
506
|
Import the PayButton, click to trigger payment modal or popup, display Stripe payment form. After the user completes payment, Stripe will redirect to the business-specified result page.
|
|
558
507
|
|
|
559
508
|
```typescript
|
|
@@ -580,6 +529,7 @@ export default StripeComponent;
|
|
|
580
529
|
```
|
|
581
530
|
|
|
582
531
|
### Method 2: Stripe.Button
|
|
532
|
+
|
|
583
533
|
Import Stripe.Button, click to trigger payment modal or popup, display Stripe payment form. After the user completes payment, Stripe will redirect to the business-specified result page.
|
|
584
534
|
|
|
585
535
|
```typescript
|
|
@@ -603,8 +553,8 @@ const StripeComponent = () => {
|
|
|
603
553
|
export default StripeComponent;
|
|
604
554
|
```
|
|
605
555
|
|
|
606
|
-
|
|
607
556
|
### Method 3: Custom trigger popup - Recommended for mobile
|
|
557
|
+
|
|
608
558
|
Use custom button to call Stripe.Popup component, display Stripe payment form. After the user completes payment, Stripe will redirect to the business-specified result page.
|
|
609
559
|
|
|
610
560
|
```typescript
|
|
@@ -648,6 +598,7 @@ export default StripeComponent;
|
|
|
648
598
|
```
|
|
649
599
|
|
|
650
600
|
### Method 4: Custom trigger modal - Recommended for PC
|
|
601
|
+
|
|
651
602
|
Use custom button to call Stripe.Modal component, display Stripe payment form. After the user completes payment, Stripe will redirect to the business-specified result page.
|
|
652
603
|
|
|
653
604
|
```typescript
|
|
@@ -692,6 +643,7 @@ export default StripeComponent;
|
|
|
692
643
|
```
|
|
693
644
|
|
|
694
645
|
### Method 5: Stripe Form
|
|
646
|
+
|
|
695
647
|
Import the Stripe form component and customize the integration and display timing. After the user completes payment, Stripe will redirect to the business-specified result page.
|
|
696
648
|
|
|
697
649
|
```typescript
|
|
@@ -719,6 +671,7 @@ export default StripeComponent;
|
|
|
719
671
|
Import payment components to use Airwallex payment. After Airwallex payment is completed, the Airwallex payment component will callback the onSuccess method, and the business executes subsequent logic.
|
|
720
672
|
|
|
721
673
|
### Method 1: PayButton
|
|
674
|
+
|
|
722
675
|
Import the PayButton, click to trigger a popup for the payment form (recommended for mobile), or a modal for PC. After the user completes payment, the Airwallex payment component will callback the onSuccess method, and the business executes subsequent logic.
|
|
723
676
|
|
|
724
677
|
```typescript
|
|
@@ -768,6 +721,7 @@ export default AirwallexComponent;
|
|
|
768
721
|
```
|
|
769
722
|
|
|
770
723
|
### Method 2: Custom trigger popup
|
|
724
|
+
|
|
771
725
|
Use custom button to call Airwallex.Popup component, display Airwallex payment form. After the user completes payment, the Airwallex payment component will callback the onSuccess method, and the business executes subsequent logic.
|
|
772
726
|
|
|
773
727
|
```typescript
|
|
@@ -846,6 +800,7 @@ export default AirwallexComponent;
|
|
|
846
800
|
```
|
|
847
801
|
|
|
848
802
|
### Method 3: Trigger modal
|
|
803
|
+
|
|
849
804
|
Use custom button to call Airwallex.Modal component, display Airwallex payment form. After the user completes payment, the Airwallex payment component will callback the onSuccess method, and the business executes subsequent logic.
|
|
850
805
|
|
|
851
806
|
```typescript
|
|
@@ -923,8 +878,8 @@ const AirwallexComponent = () => {
|
|
|
923
878
|
export default AirwallexComponent;
|
|
924
879
|
```
|
|
925
880
|
|
|
926
|
-
|
|
927
881
|
### Method 4: Custom integration
|
|
882
|
+
|
|
928
883
|
Import the Airwallex form component and customize the integration and display timing. After the user completes payment, the Airwallex payment component will callback the onSuccess method, and the business executes subsequent logic.
|
|
929
884
|
|
|
930
885
|
```typescript
|
|
@@ -965,6 +920,7 @@ export default AirwallexComponent;
|
|
|
965
920
|
```
|
|
966
921
|
|
|
967
922
|
### Method 5: Airwallex.Button
|
|
923
|
+
|
|
968
924
|
Import the Pay Button, click to open a third-party payment link and show a waiting overlay. After the user completes payment, Airwallex will redirect to the business-specified result page.
|
|
969
925
|
|
|
970
926
|
```typescript
|
|
@@ -991,11 +947,200 @@ const AirwallexComponent = () => {
|
|
|
991
947
|
export default AirwallexComponent;
|
|
992
948
|
```
|
|
993
949
|
|
|
950
|
+
## PIX
|
|
951
|
+
|
|
952
|
+
Import payment components to use PIX payment (Brazilian instant payment system). After the user scans the PIX QR code and completes payment, the business backend will receive the payment notification.
|
|
953
|
+
|
|
954
|
+
### PC
|
|
955
|
+
|
|
956
|
+
#### Method 1: PayButton
|
|
957
|
+
|
|
958
|
+
Import the PayButton, click to trigger a modal displaying the PIX QR code. After the user scans the QR code to complete payment, the business backend will receive the payment notification.
|
|
959
|
+
|
|
960
|
+
```typescript
|
|
961
|
+
import { PayButton, PaymentMethod } from 'pay-sdk-react';
|
|
962
|
+
|
|
963
|
+
const PixComponent = () => {
|
|
964
|
+
const createOrder = async () => {
|
|
965
|
+
const res = await fetch('/create-order', {
|
|
966
|
+
method: 'POST',
|
|
967
|
+
});
|
|
968
|
+
return { pixCode: res.pixCode };
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
return (
|
|
972
|
+
<div className="pix-component">
|
|
973
|
+
<h3>PayButton - Basic Usage</h3>
|
|
974
|
+
<PayButton payMethod={PaymentMethod.PixPc} createOrder={createOrder}>
|
|
975
|
+
Pay Button
|
|
976
|
+
</PayButton>
|
|
977
|
+
</div>
|
|
978
|
+
);
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
export default PixComponent;
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
#### Method 2: Pix.Button
|
|
985
|
+
|
|
986
|
+
Import Pix.Button, click to trigger a modal displaying the PIX QR code. After the user scans the QR code to complete payment, the business backend will receive the payment notification.
|
|
987
|
+
|
|
988
|
+
```typescript
|
|
989
|
+
import { Pix } from 'pay-sdk-react';
|
|
990
|
+
|
|
991
|
+
const PixComponent = () => {
|
|
992
|
+
const createOrder = async () => {
|
|
993
|
+
const res = await fetch('/create-order', {
|
|
994
|
+
method: 'POST',
|
|
995
|
+
});
|
|
996
|
+
return { pixCode: res.pixCode };
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
return (
|
|
1000
|
+
<div className="pix-component">
|
|
1001
|
+
<h3>Pix.Button - modal</h3>
|
|
1002
|
+
<Pix.Button createOrder={createOrder}>PIX Button</Pix.Button>
|
|
1003
|
+
</div>
|
|
1004
|
+
);
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
export default PixComponent;
|
|
1008
|
+
```
|
|
1009
|
+
|
|
1010
|
+
#### Method 3: Custom button
|
|
1011
|
+
|
|
1012
|
+
Use your own button, and call the modal component to display the QR code. After the user scans the QR code to complete payment, the business backend will receive the payment notification.
|
|
1013
|
+
|
|
1014
|
+
```typescript
|
|
1015
|
+
import { useRef, useState } from 'react';
|
|
1016
|
+
import { Pix, PixModalRef } from 'pay-sdk-react';
|
|
1017
|
+
|
|
1018
|
+
const pixCode = '00020126580014br.gov.bcb.pix...';
|
|
1019
|
+
|
|
1020
|
+
const PixComponent = () => {
|
|
1021
|
+
const modalRef = useRef<PixModalRef>(null);
|
|
1022
|
+
|
|
1023
|
+
const [modalVisible, setModalVisible] = useState(false);
|
|
1024
|
+
|
|
1025
|
+
const createOrder = async () => {
|
|
1026
|
+
const res = await fetch('/create-order', {
|
|
1027
|
+
method: 'POST',
|
|
1028
|
+
});
|
|
1029
|
+
modalRef.current?.open({ pixCode: res.pixCode });
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
return (
|
|
1033
|
+
<div className="pix-component">
|
|
1034
|
+
<h3>Custom Button - Trigger modal with visible prop</h3>
|
|
1035
|
+
<button onClick={() => setModalVisible(true)}>Custom Button</button>
|
|
1036
|
+
<Pix.Modal
|
|
1037
|
+
visible={modalVisible}
|
|
1038
|
+
onClose={() => setModalVisible(false)}
|
|
1039
|
+
pixProps={{ pixCode }}
|
|
1040
|
+
/>
|
|
1041
|
+
|
|
1042
|
+
<h3>Custom Button - Trigger modal with ref open method</h3>
|
|
1043
|
+
<button onClick={() => createOrder()}>Custom Button</button>
|
|
1044
|
+
<Pix.Modal ref={modalRef} />
|
|
1045
|
+
</div>
|
|
1046
|
+
);
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
export default PixComponent;
|
|
1050
|
+
```
|
|
1051
|
+
|
|
1052
|
+
#### Method 4: Custom integration
|
|
1053
|
+
|
|
1054
|
+
Directly import the QR code component and customize the integration and display timing. After the user scans the QR code to complete payment, the business backend will receive the payment notification.
|
|
1055
|
+
|
|
1056
|
+
```typescript
|
|
1057
|
+
import { Pix } from 'pay-sdk-react';
|
|
1058
|
+
|
|
1059
|
+
const pixCode = '00020126580014br.gov.bcb.pix...';
|
|
1060
|
+
|
|
1061
|
+
const PixComponent = () => {
|
|
1062
|
+
return (
|
|
1063
|
+
<div className="pix-component">
|
|
1064
|
+
<h3>Pix Form - Custom integration</h3>
|
|
1065
|
+
<Pix pixCode={pixCode} />
|
|
1066
|
+
</div>
|
|
1067
|
+
);
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
export default PixComponent;
|
|
1071
|
+
```
|
|
1072
|
+
|
|
1073
|
+
### H5
|
|
1074
|
+
|
|
1075
|
+
#### Method 1: PayButton
|
|
1076
|
+
|
|
1077
|
+
Import the PayButton, click to trigger a waiting modal (or overlay), auto-open the PIX payment link. After the user completes payment, the business backend will receive the payment notification.
|
|
1078
|
+
|
|
1079
|
+
```typescript
|
|
1080
|
+
import { PayButton, PaymentMethod } from 'pay-sdk-react';
|
|
1081
|
+
|
|
1082
|
+
const MPixComponent = () => {
|
|
1083
|
+
const createOrder = async () => {
|
|
1084
|
+
const res = await fetch('/create-order', {
|
|
1085
|
+
method: 'POST',
|
|
1086
|
+
});
|
|
1087
|
+
return { pixCode: res.pixCode };
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
return (
|
|
1091
|
+
<div className="m-pix-component">
|
|
1092
|
+
<h3>PayButton - Basic Usage</h3>
|
|
1093
|
+
<PayButton payMethod={PaymentMethod.PixH5} createOrder={createOrder}>
|
|
1094
|
+
Pay Button
|
|
1095
|
+
</PayButton>
|
|
1096
|
+
<h3>PayButton - Mask</h3>
|
|
1097
|
+
<PayButton
|
|
1098
|
+
payMethod={PaymentMethod.PixH5}
|
|
1099
|
+
createOrder={createOrder}
|
|
1100
|
+
displayType="mask"
|
|
1101
|
+
>
|
|
1102
|
+
Pay Button
|
|
1103
|
+
</PayButton>
|
|
1104
|
+
</div>
|
|
1105
|
+
);
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
export default MPixComponent;
|
|
1109
|
+
```
|
|
1110
|
+
|
|
1111
|
+
#### Method 2: MPix.Button
|
|
1112
|
+
|
|
1113
|
+
Import MPix.Button, click to trigger a waiting modal (or overlay), auto-open the PIX payment link. After the user completes payment, the business backend will receive the payment notification.
|
|
1114
|
+
|
|
1115
|
+
```typescript
|
|
1116
|
+
import { MPixButton } from 'pay-sdk-react';
|
|
1117
|
+
|
|
1118
|
+
const pixCode = '00020126580014br.gov.bcb.pix...';
|
|
1119
|
+
|
|
1120
|
+
const MPixComponent = () => {
|
|
1121
|
+
return (
|
|
1122
|
+
<div className="m-pix-component">
|
|
1123
|
+
<h3>PIX Button - Modal</h3>
|
|
1124
|
+
<MPixButton displayType="modal" pixCode={pixCode}>
|
|
1125
|
+
PIX Button
|
|
1126
|
+
</MPixButton>
|
|
1127
|
+
<h3>PIX Button - Mask</h3>
|
|
1128
|
+
<MPixButton displayType="mask" pixCode={pixCode}>
|
|
1129
|
+
PIX Button
|
|
1130
|
+
</MPixButton>
|
|
1131
|
+
</div>
|
|
1132
|
+
);
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
export default MPixComponent;
|
|
1136
|
+
```
|
|
1137
|
+
|
|
994
1138
|
## Payssion
|
|
995
1139
|
|
|
996
1140
|
Import payment components to use Payssion payment. After Payssion payment is completed, Payssion will redirect to the business-specified result page, and the redirect address is passed in when the business backend service calls the Payssion official payment order creation API.
|
|
997
1141
|
|
|
998
1142
|
### Method 1: PayButton
|
|
1143
|
+
|
|
999
1144
|
Import the PayButton, click to open a third-party payment link and show a waiting overlay. After the user completes payment, Payssion will redirect to the business-specified result page.
|
|
1000
1145
|
|
|
1001
1146
|
```typescript
|
|
@@ -1031,6 +1176,7 @@ export default PayssionComponent;
|
|
|
1031
1176
|
```
|
|
1032
1177
|
|
|
1033
1178
|
### Method 2: PayssionButton
|
|
1179
|
+
|
|
1034
1180
|
Import PayssionButton, click to open a third-party payment link and show a waiting overlay. After the user completes payment, Payssion will redirect to the business-specified result page.
|
|
1035
1181
|
|
|
1036
1182
|
```typescript
|
|
@@ -1074,4 +1220,239 @@ const PayssionComponent = () => {
|
|
|
1074
1220
|
};
|
|
1075
1221
|
|
|
1076
1222
|
export default PayssionComponent;
|
|
1077
|
-
```
|
|
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.
|