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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _usePaymentQr = require("../hooks/usePaymentQr");
|
|
9
|
+
var _classNames = _interopRequireDefault(require("../utils/classNames"));
|
|
10
|
+
var _getPrefixCls = require("../utils/getPrefixCls");
|
|
11
|
+
var _icons = require("../icons");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
+
const prefix = (0, _getPrefixCls.getPrefixCls)('pix-qrcode');
|
|
15
|
+
const PixEnhanced = ({
|
|
16
|
+
pixCode,
|
|
17
|
+
tipText = '请使用银行App扫码支付',
|
|
18
|
+
showCopyButton = true,
|
|
19
|
+
className,
|
|
20
|
+
style,
|
|
21
|
+
qrProps = {},
|
|
22
|
+
showCode = false,
|
|
23
|
+
copyText,
|
|
24
|
+
copiedText,
|
|
25
|
+
confirmText,
|
|
26
|
+
onConfirm,
|
|
27
|
+
onCopy,
|
|
28
|
+
onCopyError,
|
|
29
|
+
actionClassNames = {},
|
|
30
|
+
actionStyles = {}
|
|
31
|
+
}) => {
|
|
32
|
+
const {
|
|
33
|
+
imageUrl,
|
|
34
|
+
loading,
|
|
35
|
+
failed
|
|
36
|
+
} = (0, _usePaymentQr.usePaymentQr)(pixCode, false, qrProps);
|
|
37
|
+
const [copied, setCopied] = (0, _react.useState)(false);
|
|
38
|
+
const timer = (0, _react.useRef)();
|
|
39
|
+
const mounted = (0, _react.useRef)(false);
|
|
40
|
+
(0, _react.useEffect)(() => {
|
|
41
|
+
mounted.current = true;
|
|
42
|
+
return () => {
|
|
43
|
+
mounted.current = false;
|
|
44
|
+
if (timer.current) clearTimeout(timer.current);
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
const copy = async () => {
|
|
48
|
+
let succeeded = false;
|
|
49
|
+
try {
|
|
50
|
+
var _navigator$clipboard;
|
|
51
|
+
if ((_navigator$clipboard = navigator.clipboard) !== null && _navigator$clipboard !== void 0 && _navigator$clipboard.writeText) {
|
|
52
|
+
await navigator.clipboard.writeText(pixCode);
|
|
53
|
+
succeeded = true;
|
|
54
|
+
}
|
|
55
|
+
} catch {
|
|
56
|
+
/* 继续尝试兼容复制方式。 */
|
|
57
|
+
}
|
|
58
|
+
if (!succeeded) {
|
|
59
|
+
const textarea = document.createElement('textarea');
|
|
60
|
+
textarea.value = pixCode;
|
|
61
|
+
textarea.style.position = 'fixed';
|
|
62
|
+
textarea.style.opacity = '0';
|
|
63
|
+
document.body.appendChild(textarea);
|
|
64
|
+
try {
|
|
65
|
+
textarea.select();
|
|
66
|
+
succeeded = document.execCommand('copy');
|
|
67
|
+
} catch {
|
|
68
|
+
succeeded = false;
|
|
69
|
+
} finally {
|
|
70
|
+
textarea.remove();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!mounted.current) return;
|
|
74
|
+
if (!succeeded) {
|
|
75
|
+
onCopyError === null || onCopyError === void 0 || onCopyError();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
setCopied(true);
|
|
79
|
+
if (timer.current) clearTimeout(timer.current);
|
|
80
|
+
timer.current = setTimeout(() => setCopied(false), 2000);
|
|
81
|
+
onCopy === null || onCopy === void 0 || onCopy();
|
|
82
|
+
};
|
|
83
|
+
if (loading) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, qrProps.loadingContent ?? null);
|
|
84
|
+
if (failed) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, qrProps.errorContent ?? null);
|
|
85
|
+
const {
|
|
86
|
+
classNames: names = {},
|
|
87
|
+
styles = {}
|
|
88
|
+
} = qrProps;
|
|
89
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
90
|
+
className: (0, _classNames.default)(prefix, className, names.root),
|
|
91
|
+
style: {
|
|
92
|
+
...style,
|
|
93
|
+
...styles.root
|
|
94
|
+
}
|
|
95
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
96
|
+
className: (0, _classNames.default)(`${prefix}__container`, names.container),
|
|
97
|
+
style: {
|
|
98
|
+
position: 'relative',
|
|
99
|
+
width: qrProps.size,
|
|
100
|
+
height: qrProps.size,
|
|
101
|
+
...styles.container
|
|
102
|
+
}
|
|
103
|
+
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
104
|
+
className: (0, _classNames.default)(`${prefix}__image`, names.image),
|
|
105
|
+
style: styles.image,
|
|
106
|
+
src: imageUrl,
|
|
107
|
+
alt: "PIX\u652F\u4ED8\u4E8C\u7EF4\u7801"
|
|
108
|
+
}), qrProps.overlay !== undefined ? /*#__PURE__*/_react.default.createElement("div", {
|
|
109
|
+
className: names.overlay,
|
|
110
|
+
style: {
|
|
111
|
+
position: 'absolute',
|
|
112
|
+
left: '50%',
|
|
113
|
+
top: '50%',
|
|
114
|
+
transform: 'translate(-50%, -50%)',
|
|
115
|
+
...styles.overlay
|
|
116
|
+
}
|
|
117
|
+
}, qrProps.overlay) : null), showCode ? /*#__PURE__*/_react.default.createElement("code", {
|
|
118
|
+
className: (0, _classNames.default)(`${prefix}__code`, actionClassNames.code),
|
|
119
|
+
style: actionStyles.code
|
|
120
|
+
}, pixCode) : null, tipText ? /*#__PURE__*/_react.default.createElement("span", {
|
|
121
|
+
className: (0, _classNames.default)(`${prefix}__tip`, names.tip),
|
|
122
|
+
style: styles.tip
|
|
123
|
+
}, tipText) : null, showCopyButton ? /*#__PURE__*/_react.default.createElement("div", {
|
|
124
|
+
className: `${prefix}__code-section`
|
|
125
|
+
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
126
|
+
type: "button",
|
|
127
|
+
className: (0, _classNames.default)(`${prefix}__copy-btn`, {
|
|
128
|
+
[`${prefix}__copy-btn--copied`]: copied
|
|
129
|
+
}, actionClassNames.copy),
|
|
130
|
+
style: actionStyles.copy,
|
|
131
|
+
onClick: copy
|
|
132
|
+
}, copied ? /*#__PURE__*/_react.default.createElement(_icons.IconCheck, {
|
|
133
|
+
className: `${prefix}__copy-icon`
|
|
134
|
+
}) : /*#__PURE__*/_react.default.createElement(_icons.IconCopy, {
|
|
135
|
+
className: `${prefix}__copy-icon`
|
|
136
|
+
}), /*#__PURE__*/_react.default.createElement("span", null, copied ? copiedText ?? '已复制' : copyText ?? '复制 PIX Code'))) : null, confirmText !== undefined ? /*#__PURE__*/_react.default.createElement("button", {
|
|
137
|
+
type: "button",
|
|
138
|
+
className: (0, _classNames.default)(`${prefix}__confirm-btn`, actionClassNames.confirm),
|
|
139
|
+
style: actionStyles.confirm,
|
|
140
|
+
onClick: onConfirm
|
|
141
|
+
}, confirmText) : null);
|
|
142
|
+
};
|
|
143
|
+
var _default = exports.default = /*#__PURE__*/_react.default.memo(PixEnhanced);
|
package/dist/lib/Pix/pix.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _classNames = _interopRequireDefault(require("../utils/classNames"));
|
|
9
|
+
var _pixEnhanced = _interopRequireDefault(require("./pix-enhanced"));
|
|
9
10
|
var _qrcode = _interopRequireDefault(require("../utils/qrcode"));
|
|
10
11
|
var _icons = require("../icons");
|
|
11
12
|
var _getPrefixCls = require("../utils/getPrefixCls");
|
|
@@ -89,4 +90,8 @@ const PixQrCode = ({
|
|
|
89
90
|
className: `${classPrefix}__copy-icon`
|
|
90
91
|
}), /*#__PURE__*/_react.default.createElement("span", null, copied ? '已复制' : '复制 PIX Code'))));
|
|
91
92
|
};
|
|
92
|
-
|
|
93
|
+
const PixEntry = props => {
|
|
94
|
+
const enhanced = props.qrProps !== undefined || props.showCode !== undefined || props.copyText !== undefined || props.copiedText !== undefined || props.confirmText !== undefined || props.onConfirm !== undefined || props.onCopy !== undefined || props.onCopyError !== undefined || props.actionClassNames !== undefined || props.actionStyles !== undefined;
|
|
95
|
+
return enhanced ? /*#__PURE__*/_react.default.createElement(_pixEnhanced.default, props) : /*#__PURE__*/_react.default.createElement(PixQrCode, props);
|
|
96
|
+
};
|
|
97
|
+
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(PixEntry);
|
|
@@ -67,3 +67,14 @@
|
|
|
67
67
|
height: 16px;
|
|
68
68
|
flex-shrink: 0;
|
|
69
69
|
}
|
|
70
|
+
.pay-pix-qrcode__code {
|
|
71
|
+
display: block;
|
|
72
|
+
max-width: 100%;
|
|
73
|
+
overflow-wrap: anywhere;
|
|
74
|
+
padding: 8px;
|
|
75
|
+
}
|
|
76
|
+
.pay-pix-qrcode__confirm-btn {
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
margin-top: 12px;
|
|
79
|
+
padding: 8px 16px;
|
|
80
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.pay-pix-qrcode{display:flex;flex-direction:column;align-items:center}.pay-pix-qrcode__container{background-color:#fff;border-radius:8px;display:flex;justify-content:center;align-items:center;width:180px;height:180px}.pay-pix-qrcode__image{width:100%;height:100%;object-fit:cover}.pay-pix-qrcode__tip{text-align:center;color:#333;font-size:14px;line-height:20px;margin-top:12px}.pay-pix-qrcode__code-section{width:100%;max-width:320px;margin-top:16px}.pay-pix-qrcode__copy-btn{width:100%;padding:10px 16px;border:1px solid #32bcad;background-color:#fff;color:#32bcad;border-radius:8px;font-size:13px;font-weight:600;cursor:pointer;transition:.2s;display:flex;align-items:center;justify-content:center;gap:6px}.pay-pix-qrcode__copy-btn:hover{background-color:rgba(50,188,173,.06)}.pay-pix-qrcode__copy-btn:active{background-color:rgba(50,188,173,.12)}.pay-pix-qrcode__copy-btn--copied{color:#2ecc71;border-color:#2ecc71;background-color:rgba(46,204,113,.04)}.pay-pix-qrcode__copy-btn--copied:hover{background-color:rgba(46,204,113,.08)}.pay-pix-qrcode__copy-btn--copied:active{background-color:rgba(46,204,113,.14)}.pay-pix-qrcode__copy-icon{width:16px;height:16px;flex-shrink:0}
|
|
1
|
+
.pay-pix-qrcode{display:flex;flex-direction:column;align-items:center}.pay-pix-qrcode__container{background-color:#fff;border-radius:8px;display:flex;justify-content:center;align-items:center;width:180px;height:180px}.pay-pix-qrcode__image{width:100%;height:100%;object-fit:cover}.pay-pix-qrcode__tip{text-align:center;color:#333;font-size:14px;line-height:20px;margin-top:12px}.pay-pix-qrcode__code-section{width:100%;max-width:320px;margin-top:16px}.pay-pix-qrcode__copy-btn{width:100%;padding:10px 16px;border:1px solid #32bcad;background-color:#fff;color:#32bcad;border-radius:8px;font-size:13px;font-weight:600;cursor:pointer;transition:.2s;display:flex;align-items:center;justify-content:center;gap:6px}.pay-pix-qrcode__copy-btn:hover{background-color:rgba(50,188,173,.06)}.pay-pix-qrcode__copy-btn:active{background-color:rgba(50,188,173,.12)}.pay-pix-qrcode__copy-btn--copied{color:#2ecc71;border-color:#2ecc71;background-color:rgba(46,204,113,.04)}.pay-pix-qrcode__copy-btn--copied:hover{background-color:rgba(46,204,113,.08)}.pay-pix-qrcode__copy-btn--copied:active{background-color:rgba(46,204,113,.14)}.pay-pix-qrcode__copy-icon{width:16px;height:16px;flex-shrink:0}.pay-pix-qrcode__code{display:block;max-width:100%;overflow-wrap:anywhere;padding:8px}.pay-pix-qrcode__confirm-btn{cursor:pointer;margin-top:12px;padding:8px 16px}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useStripeCheckout = void 0;
|
|
8
|
+
var _usePaymentExecution = require("../../hooks/usePaymentExecution");
|
|
9
|
+
var _usePaymentRedirect = require("../../hooks/usePaymentRedirect");
|
|
10
|
+
var _useLatestCallback = require("../../hooks/useLatestCallback");
|
|
11
|
+
var _enums = require("../../shared/enums");
|
|
12
|
+
var _payment = require("../../shared/entitys/payment");
|
|
13
|
+
/**
|
|
14
|
+
* @zh 打开 Stripe 托管支付页面,不自动下单。
|
|
15
|
+
* @en Open hosted Stripe checkout; no automatic order creation.
|
|
16
|
+
* @since 1.2.0
|
|
17
|
+
*/
|
|
18
|
+
const useStripeCheckout = (options = {}) => {
|
|
19
|
+
const execution = (0, _usePaymentExecution.usePaymentExecution)(options);
|
|
20
|
+
const redirect = (0, _usePaymentRedirect.usePaymentRedirect)(options.redirectOptions);
|
|
21
|
+
const openCheckout = (0, _useLatestCallback.useLatestCallback)(source => execution.run(async context => {
|
|
22
|
+
const target = typeof source === 'function' ? await source(context.signal) : source;
|
|
23
|
+
if (!context.isCurrent()) return;
|
|
24
|
+
if (target === null) {
|
|
25
|
+
execution.cancel();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!target || typeof target.url !== 'string') throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InvalidParameters, 'A payment URL is required.');
|
|
29
|
+
redirect.open(target.url);
|
|
30
|
+
}));
|
|
31
|
+
const closeCheckout = (0, _useLatestCallback.useLatestCallback)(() => {
|
|
32
|
+
execution.cancel();
|
|
33
|
+
redirect.close();
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
...execution,
|
|
37
|
+
openCheckout,
|
|
38
|
+
closeCheckout
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
exports.useStripeCheckout = useStripeCheckout;
|
package/dist/lib/Stripe/index.js
CHANGED
|
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
+
StripeCheckoutButton: true,
|
|
7
8
|
StripePopup: true,
|
|
8
9
|
StripeButton: true,
|
|
9
|
-
StripeModal: true
|
|
10
|
+
StripeModal: true,
|
|
11
|
+
useStripeCheckout: true
|
|
10
12
|
};
|
|
11
13
|
Object.defineProperty(exports, "StripeButton", {
|
|
12
14
|
enumerable: true,
|
|
@@ -14,6 +16,12 @@ Object.defineProperty(exports, "StripeButton", {
|
|
|
14
16
|
return _stripeButton.default;
|
|
15
17
|
}
|
|
16
18
|
});
|
|
19
|
+
Object.defineProperty(exports, "StripeCheckoutButton", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _stripeCheckoutButton.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
17
25
|
Object.defineProperty(exports, "StripeModal", {
|
|
18
26
|
enumerable: true,
|
|
19
27
|
get: function () {
|
|
@@ -27,6 +35,13 @@ Object.defineProperty(exports, "StripePopup", {
|
|
|
27
35
|
}
|
|
28
36
|
});
|
|
29
37
|
exports.default = void 0;
|
|
38
|
+
Object.defineProperty(exports, "useStripeCheckout", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _useStripeCheckout.useStripeCheckout;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
var _stripeCheckoutButton = _interopRequireDefault(require("./stripe-checkout-button"));
|
|
30
45
|
var _stripe = _interopRequireDefault(require("./stripe"));
|
|
31
46
|
var _stripePopup = _interopRequireDefault(require("./stripe-popup"));
|
|
32
47
|
var _stripeButton = _interopRequireDefault(require("./stripe-button"));
|
|
@@ -43,8 +58,10 @@ Object.keys(_interface).forEach(function (key) {
|
|
|
43
58
|
}
|
|
44
59
|
});
|
|
45
60
|
});
|
|
61
|
+
var _useStripeCheckout = require("./hooks/useStripeCheckout");
|
|
46
62
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
47
63
|
const StripeComponent = Object.assign({}, _stripe.default, {
|
|
64
|
+
CheckoutButton: _stripeCheckoutButton.default,
|
|
48
65
|
Button: _stripeButton.default,
|
|
49
66
|
Popup: _stripePopup.default,
|
|
50
67
|
Modal: _stripeModal.default
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _useManagedOrder = require("../hooks/useManagedOrder");
|
|
7
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
9
|
var _stripePopup = _interopRequireDefault(require("./stripe-popup"));
|
|
9
10
|
var _stripeModal = _interopRequireDefault(require("./stripe-modal"));
|
|
@@ -19,6 +20,7 @@ const StripeButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
19
20
|
stripePopupProps,
|
|
20
21
|
stripeModalProps,
|
|
21
22
|
createOrder,
|
|
23
|
+
executionOptions,
|
|
22
24
|
...others
|
|
23
25
|
} = props;
|
|
24
26
|
const stripeButtonRef = (0, _react.useRef)(null);
|
|
@@ -35,6 +37,7 @@ const StripeButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
35
37
|
},
|
|
36
38
|
closePopup: () => {
|
|
37
39
|
var _stripePopupRef$curre2;
|
|
40
|
+
if (executionOptions) managed.cancel();
|
|
38
41
|
(_stripePopupRef$curre2 = stripePopupRef.current) === null || _stripePopupRef$curre2 === void 0 || _stripePopupRef$curre2.close();
|
|
39
42
|
},
|
|
40
43
|
openModal: options => {
|
|
@@ -43,10 +46,18 @@ const StripeButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
43
46
|
},
|
|
44
47
|
closeModal: () => {
|
|
45
48
|
var _stripeModalRef$curre2;
|
|
49
|
+
if (executionOptions) managed.cancel();
|
|
46
50
|
(_stripeModalRef$curre2 = stripeModalRef.current) === null || _stripeModalRef$curre2 === void 0 || _stripeModalRef$curre2.close();
|
|
47
51
|
},
|
|
48
52
|
current: stripeButtonRef.current
|
|
49
53
|
}));
|
|
54
|
+
const managed = (0, _useManagedOrder.useManagedOrder)(createOrder, target => {
|
|
55
|
+
if (target.clientSecret && target.stripeKey) {
|
|
56
|
+
var _stripeModalRef$curre3, _stripePopupRef$curre3;
|
|
57
|
+
if (displayType === 'modal') (_stripeModalRef$curre3 = stripeModalRef.current) === null || _stripeModalRef$curre3 === void 0 || _stripeModalRef$curre3.open(target);else (_stripePopupRef$curre3 = stripePopupRef.current) === null || _stripePopupRef$curre3 === void 0 || _stripePopupRef$curre3.open(target);
|
|
58
|
+
}
|
|
59
|
+
}, executionOptions, target => typeof target.clientSecret === 'string' && Boolean(target.clientSecret.trim()) && typeof target.stripeKey === 'string' && Boolean(target.stripeKey.trim()));
|
|
60
|
+
const managedRun = managed.run;
|
|
50
61
|
const handlePayCreateOrder = (0, _react.useCallback)(async () => {
|
|
51
62
|
if (createOrder) {
|
|
52
63
|
// 1. 业务侧创建订单,获取参数
|
|
@@ -54,17 +65,22 @@ const StripeButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
54
65
|
if (options !== null && options !== void 0 && options.clientSecret && options !== null && options !== void 0 && options.stripeKey) {
|
|
55
66
|
// 2. 唤起弹窗
|
|
56
67
|
if (displayType === 'modal') {
|
|
57
|
-
var _stripeModalRef$
|
|
58
|
-
(_stripeModalRef$
|
|
68
|
+
var _stripeModalRef$curre4;
|
|
69
|
+
(_stripeModalRef$curre4 = stripeModalRef.current) === null || _stripeModalRef$curre4 === void 0 || _stripeModalRef$curre4.open(options);
|
|
59
70
|
} else {
|
|
60
|
-
var _stripePopupRef$
|
|
61
|
-
(_stripePopupRef$
|
|
71
|
+
var _stripePopupRef$curre4;
|
|
72
|
+
(_stripePopupRef$curre4 = stripePopupRef.current) === null || _stripePopupRef$curre4 === void 0 || _stripePopupRef$curre4.open(options);
|
|
62
73
|
}
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
}, [createOrder, displayType]);
|
|
66
77
|
const handleClick = (0, _react.useCallback)(e => {
|
|
67
78
|
if (createOrder) {
|
|
79
|
+
if (executionOptions) {
|
|
80
|
+
onClick === null || onClick === void 0 || onClick(e);
|
|
81
|
+
if (e.defaultPrevented) return;
|
|
82
|
+
return managedRun().then(() => undefined);
|
|
83
|
+
}
|
|
68
84
|
handlePayCreateOrder();
|
|
69
85
|
} else {
|
|
70
86
|
if (displayType === 'modal') {
|
|
@@ -72,25 +88,27 @@ const StripeButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
72
88
|
const clientSecret = stripeModalProps === null || stripeModalProps === void 0 || (_stripeModalProps$str = stripeModalProps.stripeProps) === null || _stripeModalProps$str === void 0 ? void 0 : _stripeModalProps$str.clientSecret;
|
|
73
89
|
const stripeKey = stripeModalProps === null || stripeModalProps === void 0 || (_stripeModalProps$str2 = stripeModalProps.stripeProps) === null || _stripeModalProps$str2 === void 0 ? void 0 : _stripeModalProps$str2.stripeKey;
|
|
74
90
|
if (clientSecret && stripeKey) {
|
|
75
|
-
var _stripeModalRef$
|
|
76
|
-
stripeModalRef === null || stripeModalRef === void 0 || (_stripeModalRef$
|
|
91
|
+
var _stripeModalRef$curre5;
|
|
92
|
+
stripeModalRef === null || stripeModalRef === void 0 || (_stripeModalRef$curre5 = stripeModalRef.current) === null || _stripeModalRef$curre5 === void 0 || _stripeModalRef$curre5.open();
|
|
77
93
|
}
|
|
78
94
|
} else {
|
|
79
95
|
var _stripePopupProps$str, _stripePopupProps$str2;
|
|
80
96
|
const clientSecret = stripePopupProps === null || stripePopupProps === void 0 || (_stripePopupProps$str = stripePopupProps.stripeProps) === null || _stripePopupProps$str === void 0 ? void 0 : _stripePopupProps$str.clientSecret;
|
|
81
97
|
const stripeKey = stripePopupProps === null || stripePopupProps === void 0 || (_stripePopupProps$str2 = stripePopupProps.stripeProps) === null || _stripePopupProps$str2 === void 0 ? void 0 : _stripePopupProps$str2.stripeKey;
|
|
82
98
|
if (clientSecret && stripeKey) {
|
|
83
|
-
var _stripePopupRef$
|
|
84
|
-
stripePopupRef === null || stripePopupRef === void 0 || (_stripePopupRef$
|
|
99
|
+
var _stripePopupRef$curre5;
|
|
100
|
+
stripePopupRef === null || stripePopupRef === void 0 || (_stripePopupRef$curre5 = stripePopupRef.current) === null || _stripePopupRef$curre5 === void 0 || _stripePopupRef$curre5.open();
|
|
85
101
|
}
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
onClick === null || onClick === void 0 || onClick(e);
|
|
89
|
-
}, [onClick, createOrder, handlePayCreateOrder, displayType, stripeModalProps, stripePopupProps]);
|
|
105
|
+
}, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, displayType, stripeModalProps, stripePopupProps]);
|
|
90
106
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Button.default, _extends({
|
|
91
107
|
ref: stripeButtonRef,
|
|
92
108
|
onClick: handleClick
|
|
93
|
-
}, others
|
|
109
|
+
}, others, {
|
|
110
|
+
loading: executionOptions ? managed.loading || others.loading : others.loading
|
|
111
|
+
}), children), displayType === 'popup' && /*#__PURE__*/_react.default.createElement(_stripePopup.default, _extends({
|
|
94
112
|
ref: stripePopupRef
|
|
95
113
|
}, stripePopupProps)), displayType === 'modal' && /*#__PURE__*/_react.default.createElement(_stripeModal.default, _extends({
|
|
96
114
|
ref: stripeModalRef
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _Button = _interopRequireDefault(require("../Button"));
|
|
10
|
+
var _useStripeCheckout = require("./hooks/useStripeCheckout");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
13
|
+
/**
|
|
14
|
+
* @zh Stripe 托管支付按钮,复用 useStripeCheckout。
|
|
15
|
+
* @en Hosted Stripe button sharing useStripeCheckout.
|
|
16
|
+
* @since 1.2.0
|
|
17
|
+
*/
|
|
18
|
+
const StripeCheckoutButton = props => {
|
|
19
|
+
const {
|
|
20
|
+
url,
|
|
21
|
+
createOrder,
|
|
22
|
+
redirectOptions,
|
|
23
|
+
beforePay,
|
|
24
|
+
onLoadingChange,
|
|
25
|
+
onPaymentError,
|
|
26
|
+
onCancel,
|
|
27
|
+
children = 'Stripe',
|
|
28
|
+
onClick,
|
|
29
|
+
loading,
|
|
30
|
+
...buttonProps
|
|
31
|
+
} = props;
|
|
32
|
+
const checkout = (0, _useStripeCheckout.useStripeCheckout)({
|
|
33
|
+
redirectOptions,
|
|
34
|
+
beforePay,
|
|
35
|
+
onLoadingChange,
|
|
36
|
+
onPaymentError,
|
|
37
|
+
onCancel
|
|
38
|
+
});
|
|
39
|
+
return /*#__PURE__*/_react.default.createElement(_Button.default, _extends({}, buttonProps, {
|
|
40
|
+
loading: checkout.loading || loading,
|
|
41
|
+
onClick: async event => {
|
|
42
|
+
event.persist();
|
|
43
|
+
await (onClick === null || onClick === void 0 ? void 0 : onClick(event));
|
|
44
|
+
if (!event.defaultPrevented) await checkout.openCheckout(createOrder ?? {
|
|
45
|
+
url: url ?? ''
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}), children);
|
|
49
|
+
};
|
|
50
|
+
var _default = exports.default = /*#__PURE__*/_react.default.memo(StripeCheckoutButton);
|
|
@@ -17,6 +17,7 @@ const StripeModal = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
17
17
|
stripeProps: propsStripeProps,
|
|
18
18
|
visible,
|
|
19
19
|
onClose,
|
|
20
|
+
closeOnComplete = false,
|
|
20
21
|
className,
|
|
21
22
|
...rest
|
|
22
23
|
} = props;
|
|
@@ -49,7 +50,17 @@ const StripeModal = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
49
50
|
onClose === null || onClose === void 0 || onClose();
|
|
50
51
|
},
|
|
51
52
|
footer: null
|
|
52
|
-
}, rest), _stripeProps && /*#__PURE__*/_react.default.createElement(_stripe.default, _stripeProps
|
|
53
|
+
}, rest), _stripeProps && /*#__PURE__*/_react.default.createElement(_stripe.default, _extends({}, _stripeProps, {
|
|
54
|
+
checkoutEvents: closeOnComplete ? {
|
|
55
|
+
..._stripeProps.checkoutEvents,
|
|
56
|
+
onComplete: () => {
|
|
57
|
+
var _stripeProps$checkout, _stripeProps$checkout2;
|
|
58
|
+
(_stripeProps$checkout = _stripeProps.checkoutEvents) === null || _stripeProps$checkout === void 0 || (_stripeProps$checkout2 = _stripeProps$checkout.onComplete) === null || _stripeProps$checkout2 === void 0 || _stripeProps$checkout2.call(_stripeProps$checkout);
|
|
59
|
+
if (!isControlled) setUncontrolledVisible(false);
|
|
60
|
+
onClose === null || onClose === void 0 || onClose();
|
|
61
|
+
}
|
|
62
|
+
} : _stripeProps.checkoutEvents
|
|
63
|
+
})));
|
|
53
64
|
});
|
|
54
65
|
StripeModal.displayName = 'StripeModal';
|
|
55
66
|
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(StripeModal);
|
|
@@ -16,6 +16,7 @@ const StripePopup = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
16
16
|
const {
|
|
17
17
|
visible: controlledVisible,
|
|
18
18
|
onClose,
|
|
19
|
+
closeOnComplete = false,
|
|
19
20
|
closeOnMaskClick = true,
|
|
20
21
|
className,
|
|
21
22
|
bodyStyle,
|
|
@@ -56,7 +57,17 @@ const StripePopup = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
56
57
|
overflowY: 'scroll',
|
|
57
58
|
...bodyStyle
|
|
58
59
|
}
|
|
59
|
-
}, others), _stripeProps && /*#__PURE__*/_react.default.createElement(_stripe.default, _stripeProps
|
|
60
|
+
}, others), _stripeProps && /*#__PURE__*/_react.default.createElement(_stripe.default, _extends({}, _stripeProps, {
|
|
61
|
+
checkoutEvents: closeOnComplete ? {
|
|
62
|
+
..._stripeProps.checkoutEvents,
|
|
63
|
+
onComplete: () => {
|
|
64
|
+
var _stripeProps$checkout, _stripeProps$checkout2;
|
|
65
|
+
(_stripeProps$checkout = _stripeProps.checkoutEvents) === null || _stripeProps$checkout === void 0 || (_stripeProps$checkout2 = _stripeProps$checkout.onComplete) === null || _stripeProps$checkout2 === void 0 || _stripeProps$checkout2.call(_stripeProps$checkout);
|
|
66
|
+
if (!isControlled) setUncontrolledVisible(false);
|
|
67
|
+
onClose === null || onClose === void 0 || onClose();
|
|
68
|
+
}
|
|
69
|
+
} : _stripeProps.checkoutEvents
|
|
70
|
+
})));
|
|
60
71
|
});
|
|
61
72
|
StripePopup.displayName = 'StripePopup';
|
|
62
73
|
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(StripePopup);
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _reactStripeJs = require("@stripe/react-stripe-js");
|
|
9
9
|
var _stripeJs = require("@stripe/stripe-js");
|
|
10
|
+
var _useLatestCallback = require("../hooks/useLatestCallback");
|
|
10
11
|
var _classNames = _interopRequireDefault(require("../utils/classNames"));
|
|
11
12
|
var _getPrefixCls = require("../utils/getPrefixCls");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -16,9 +17,17 @@ const Stripe = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
16
17
|
const {
|
|
17
18
|
stripeKey,
|
|
18
19
|
clientSecret,
|
|
20
|
+
checkoutEvents,
|
|
21
|
+
instanceKey,
|
|
19
22
|
className = '',
|
|
20
23
|
...others
|
|
21
24
|
} = props;
|
|
25
|
+
const events = (0, _react.useRef)(checkoutEvents);
|
|
26
|
+
events.current = checkoutEvents;
|
|
27
|
+
const onComplete = (0, _useLatestCallback.useLatestCallback)(() => {
|
|
28
|
+
var _events$current, _events$current$onCom;
|
|
29
|
+
return (_events$current = events.current) === null || _events$current === void 0 || (_events$current$onCom = _events$current.onComplete) === null || _events$current$onCom === void 0 ? void 0 : _events$current$onCom.call(_events$current);
|
|
30
|
+
});
|
|
22
31
|
const stripeRef = (0, _react.useRef)(null);
|
|
23
32
|
(0, _react.useImperativeHandle)(ref, () => stripeRef.current);
|
|
24
33
|
const stripePromise = (0, _react.useMemo)(() => {
|
|
@@ -27,15 +36,35 @@ const Stripe = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
27
36
|
}
|
|
28
37
|
return _stripeJs.loadStripe === null || _stripeJs.loadStripe === void 0 ? void 0 : (0, _stripeJs.loadStripe)(stripeKey);
|
|
29
38
|
}, [stripeKey]);
|
|
39
|
+
const observeCheckout = Boolean(checkoutEvents);
|
|
40
|
+
(0, _react.useEffect)(() => {
|
|
41
|
+
if (!observeCheckout || !stripePromise) return;
|
|
42
|
+
let active = true;
|
|
43
|
+
Promise.resolve(stripePromise).then(instance => {
|
|
44
|
+
var _events$current2, _events$current2$onIn, _events$current3, _events$current3$onIn;
|
|
45
|
+
if (!active) return;
|
|
46
|
+
if (instance) (_events$current2 = events.current) === null || _events$current2 === void 0 || (_events$current2$onIn = _events$current2.onInitialized) === null || _events$current2$onIn === void 0 || _events$current2$onIn.call(_events$current2);else (_events$current3 = events.current) === null || _events$current3 === void 0 || (_events$current3$onIn = _events$current3.onInitializationError) === null || _events$current3$onIn === void 0 || _events$current3$onIn.call(_events$current3);
|
|
47
|
+
}).catch(() => {
|
|
48
|
+
var _events$current4, _events$current4$onIn;
|
|
49
|
+
if (active) (_events$current4 = events.current) === null || _events$current4 === void 0 || (_events$current4$onIn = _events$current4.onInitializationError) === null || _events$current4$onIn === void 0 || _events$current4$onIn.call(_events$current4);
|
|
50
|
+
});
|
|
51
|
+
return () => {
|
|
52
|
+
active = false;
|
|
53
|
+
};
|
|
54
|
+
}, [stripePromise, observeCheckout]);
|
|
30
55
|
const classNames = (0, _classNames.default)((0, _getPrefixCls.getPrefixCls)('pay-stripe'), className);
|
|
31
56
|
return /*#__PURE__*/_react.default.createElement("div", _extends({
|
|
32
57
|
ref: stripeRef
|
|
33
58
|
}, others, {
|
|
34
59
|
className: classNames
|
|
35
60
|
}), clientSecret && stripePromise && /*#__PURE__*/_react.default.createElement(_reactStripeJs.EmbeddedCheckoutProvider, {
|
|
61
|
+
key: instanceKey,
|
|
36
62
|
stripe: stripePromise,
|
|
37
63
|
options: {
|
|
38
|
-
clientSecret
|
|
64
|
+
clientSecret,
|
|
65
|
+
...(observeCheckout ? {
|
|
66
|
+
onComplete
|
|
67
|
+
} : {})
|
|
39
68
|
}
|
|
40
69
|
}, /*#__PURE__*/_react.default.createElement(_reactStripeJs.EmbeddedCheckout, null)));
|
|
41
70
|
});
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _useManagedOrder = require("../hooks/useManagedOrder");
|
|
7
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
9
|
var _classNames = _interopRequireDefault(require("../utils/classNames"));
|
|
9
10
|
var _wechatModal = _interopRequireDefault(require("./wechat-modal"));
|
|
@@ -19,6 +20,7 @@ const WechatButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
19
20
|
children = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_icons.IconWechatPay, null), "\u5FAE\u4FE1\u652F\u4ED8"),
|
|
20
21
|
onClick,
|
|
21
22
|
createOrder,
|
|
23
|
+
executionOptions,
|
|
22
24
|
modalProps,
|
|
23
25
|
...others
|
|
24
26
|
} = props;
|
|
@@ -35,32 +37,45 @@ const WechatButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
35
37
|
},
|
|
36
38
|
closeModal: () => {
|
|
37
39
|
var _wechatModalRef$curre2;
|
|
40
|
+
if (executionOptions) managed.cancel();
|
|
38
41
|
(_wechatModalRef$curre2 = wechatModalRef.current) === null || _wechatModalRef$curre2 === void 0 || _wechatModalRef$curre2.close();
|
|
39
42
|
},
|
|
40
43
|
current: wechatButtonRef.current
|
|
41
44
|
}));
|
|
45
|
+
const managed = (0, _useManagedOrder.useManagedOrder)(createOrder, target => {
|
|
46
|
+
var _wechatModalRef$curre3;
|
|
47
|
+
(_wechatModalRef$curre3 = wechatModalRef.current) === null || _wechatModalRef$curre3 === void 0 || _wechatModalRef$curre3.open(target);
|
|
48
|
+
}, executionOptions, target => typeof target.wechatUrl === 'string' && Boolean(target.wechatUrl.trim()));
|
|
49
|
+
const managedRun = managed.run;
|
|
42
50
|
const handlePayCreateOrder = (0, _react.useCallback)(async () => {
|
|
43
51
|
if (createOrder) {
|
|
44
|
-
var _wechatModalRef$
|
|
52
|
+
var _wechatModalRef$curre4;
|
|
45
53
|
const options = await createOrder();
|
|
46
|
-
(_wechatModalRef$
|
|
54
|
+
(_wechatModalRef$curre4 = wechatModalRef.current) === null || _wechatModalRef$curre4 === void 0 || _wechatModalRef$curre4.open(options);
|
|
47
55
|
}
|
|
48
56
|
}, [createOrder]);
|
|
49
57
|
const handleClick = (0, _react.useCallback)(e => {
|
|
50
58
|
var _modalProps$wechatPro;
|
|
51
59
|
if (createOrder) {
|
|
60
|
+
if (executionOptions) {
|
|
61
|
+
onClick === null || onClick === void 0 || onClick(e);
|
|
62
|
+
if (e.defaultPrevented) return;
|
|
63
|
+
return managedRun().then(() => undefined);
|
|
64
|
+
}
|
|
52
65
|
handlePayCreateOrder();
|
|
53
66
|
} else if (modalProps !== null && modalProps !== void 0 && (_modalProps$wechatPro = modalProps.wechatProps) !== null && _modalProps$wechatPro !== void 0 && _modalProps$wechatPro.wechatUrl) {
|
|
54
|
-
var _wechatModalRef$
|
|
55
|
-
wechatModalRef === null || wechatModalRef === void 0 || (_wechatModalRef$
|
|
67
|
+
var _wechatModalRef$curre5;
|
|
68
|
+
wechatModalRef === null || wechatModalRef === void 0 || (_wechatModalRef$curre5 = wechatModalRef.current) === null || _wechatModalRef$curre5 === void 0 || _wechatModalRef$curre5.open();
|
|
56
69
|
}
|
|
57
70
|
onClick === null || onClick === void 0 || onClick(e);
|
|
58
|
-
}, [onClick, createOrder, handlePayCreateOrder, modalProps]);
|
|
71
|
+
}, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, modalProps]);
|
|
59
72
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Button.default, _extends({
|
|
60
73
|
ref: wechatButtonRef,
|
|
61
74
|
className: (0, _classNames.default)((0, _getPrefixCls.getPrefixCls)('wechat-btn'), className),
|
|
62
75
|
onClick: handleClick
|
|
63
|
-
}, others
|
|
76
|
+
}, others, {
|
|
77
|
+
loading: executionOptions ? managed.loading || others.loading : others.loading
|
|
78
|
+
}), children), /*#__PURE__*/_react.default.createElement(_wechatModal.default, _extends({
|
|
64
79
|
ref: wechatModalRef
|
|
65
80
|
}, modalProps)));
|
|
66
81
|
});
|