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,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _usePaymentQr = require("../hooks/usePaymentQr");
|
|
9
|
+
var _classNames = _interopRequireDefault(require("../utils/classNames"));
|
|
10
|
+
var _getPrefixCls = require("../utils/getPrefixCls");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
const WechatContent = ({
|
|
13
|
+
wechatUrl,
|
|
14
|
+
wechatType = 'qrcode',
|
|
15
|
+
tipText = '请使用微信APP扫码支付',
|
|
16
|
+
className,
|
|
17
|
+
style,
|
|
18
|
+
qrProps = {}
|
|
19
|
+
}) => {
|
|
20
|
+
const {
|
|
21
|
+
imageUrl,
|
|
22
|
+
loading,
|
|
23
|
+
failed
|
|
24
|
+
} = (0, _usePaymentQr.usePaymentQr)(wechatUrl, wechatType === 'image', qrProps);
|
|
25
|
+
if (loading) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, qrProps.loadingContent ?? null);
|
|
26
|
+
if (failed) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, qrProps.errorContent ?? null);
|
|
27
|
+
const prefix = (0, _getPrefixCls.getPrefixCls)('wechat-qrcode');
|
|
28
|
+
const {
|
|
29
|
+
classNames: names = {},
|
|
30
|
+
styles = {}
|
|
31
|
+
} = qrProps;
|
|
32
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
33
|
+
className: (0, _classNames.default)(prefix, className, names.root),
|
|
34
|
+
style: {
|
|
35
|
+
...style,
|
|
36
|
+
...styles.root
|
|
37
|
+
}
|
|
38
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
39
|
+
className: (0, _classNames.default)(`${prefix}__container`, names.container),
|
|
40
|
+
style: {
|
|
41
|
+
position: 'relative',
|
|
42
|
+
width: qrProps.size,
|
|
43
|
+
height: qrProps.size,
|
|
44
|
+
...styles.container
|
|
45
|
+
}
|
|
46
|
+
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
47
|
+
className: (0, _classNames.default)(`${prefix}__image`, names.image),
|
|
48
|
+
style: styles.image,
|
|
49
|
+
src: imageUrl,
|
|
50
|
+
alt: "\u5FAE\u4FE1\u652F\u4ED8\u4E8C\u7EF4\u7801"
|
|
51
|
+
}), qrProps.overlay !== undefined ? /*#__PURE__*/_react.default.createElement("div", {
|
|
52
|
+
className: names.overlay,
|
|
53
|
+
style: {
|
|
54
|
+
position: 'absolute',
|
|
55
|
+
left: '50%',
|
|
56
|
+
top: '50%',
|
|
57
|
+
transform: 'translate(-50%, -50%)',
|
|
58
|
+
...styles.overlay
|
|
59
|
+
}
|
|
60
|
+
}, qrProps.overlay) : null), tipText ? /*#__PURE__*/_react.default.createElement("span", {
|
|
61
|
+
className: (0, _classNames.default)(`${prefix}__tip`, names.tip),
|
|
62
|
+
style: styles.tip
|
|
63
|
+
}, tipText) : null);
|
|
64
|
+
};
|
|
65
|
+
var _default = exports.default = /*#__PURE__*/_react.default.memo(WechatContent);
|
|
@@ -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 _wechatContent = _interopRequireDefault(require("./wechat-content"));
|
|
9
10
|
var _qrcode = _interopRequireDefault(require("../utils/qrcode"));
|
|
10
11
|
var _getPrefixCls = require("../utils/getPrefixCls");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -44,4 +45,5 @@ const WechatQrCode = ({
|
|
|
44
45
|
className: `${classPrefix}__tip`
|
|
45
46
|
}, tipText));
|
|
46
47
|
};
|
|
47
|
-
|
|
48
|
+
const WechatEntry = props => props.qrProps ? /*#__PURE__*/_react.default.createElement(_wechatContent.default, props) : /*#__PURE__*/_react.default.createElement(WechatQrCode, props);
|
|
49
|
+
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(WechatEntry);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useLatestCallback = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
const useLatestCallback = callback => {
|
|
9
|
+
const latest = (0, _react.useRef)(callback);
|
|
10
|
+
latest.current = callback;
|
|
11
|
+
return (0, _react.useCallback)((...args) => latest.current(...args), []);
|
|
12
|
+
};
|
|
13
|
+
exports.useLatestCallback = useLatestCallback;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useManagedOrder = void 0;
|
|
7
|
+
var _usePaymentExecution = require("./usePaymentExecution");
|
|
8
|
+
var _useLatestCallback = require("./useLatestCallback");
|
|
9
|
+
var _enums = require("../shared/enums");
|
|
10
|
+
var _payment = require("../shared/entitys/payment");
|
|
11
|
+
const useManagedOrder = (factory, receive, options, validate) => {
|
|
12
|
+
const execution = (0, _usePaymentExecution.usePaymentExecution)(options);
|
|
13
|
+
const run = (0, _useLatestCallback.useLatestCallback)(() => execution.run(async context => {
|
|
14
|
+
if (!factory) throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InvalidParameters, 'createOrder is required for managed order execution.');
|
|
15
|
+
const target = await factory();
|
|
16
|
+
if (!context.isCurrent()) return;
|
|
17
|
+
if (target == null) {
|
|
18
|
+
execution.cancel();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (validate && !validate(target)) throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InvalidParameters, 'Invalid payment parameters returned by createOrder.');
|
|
22
|
+
receive(target);
|
|
23
|
+
}));
|
|
24
|
+
return {
|
|
25
|
+
...execution,
|
|
26
|
+
run
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.useManagedOrder = useManagedOrder;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.usePaymentExecution = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _enums = require("../shared/enums");
|
|
10
|
+
var _payment = require("../shared/entitys/payment");
|
|
11
|
+
var _useLatestCallback = require("./useLatestCallback");
|
|
12
|
+
const usePaymentExecution = (options = {}) => {
|
|
13
|
+
const latest = (0, _react.useRef)(options);
|
|
14
|
+
latest.current = options;
|
|
15
|
+
const mounted = (0, _react.useRef)(false);
|
|
16
|
+
const sequence = (0, _react.useRef)(0);
|
|
17
|
+
const pending = (0, _react.useRef)(false);
|
|
18
|
+
const controller = (0, _react.useRef)();
|
|
19
|
+
const [status, setStatus] = (0, _react.useState)(_enums.PaymentExecutionStatus.Idle);
|
|
20
|
+
const [error, setError] = (0, _react.useState)(null);
|
|
21
|
+
const cancel = (0, _useLatestCallback.useLatestCallback)(() => {
|
|
22
|
+
var _controller$current;
|
|
23
|
+
const wasPending = pending.current;
|
|
24
|
+
sequence.current += 1;
|
|
25
|
+
(_controller$current = controller.current) === null || _controller$current === void 0 || _controller$current.abort();
|
|
26
|
+
pending.current = false;
|
|
27
|
+
if (mounted.current && wasPending) {
|
|
28
|
+
var _latest$current$onLoa, _latest$current, _latest$current$onCan, _latest$current2;
|
|
29
|
+
setStatus(_enums.PaymentExecutionStatus.Cancelled);
|
|
30
|
+
(_latest$current$onLoa = (_latest$current = latest.current).onLoadingChange) === null || _latest$current$onLoa === void 0 || _latest$current$onLoa.call(_latest$current, false);
|
|
31
|
+
(_latest$current$onCan = (_latest$current2 = latest.current).onCancel) === null || _latest$current$onCan === void 0 || _latest$current$onCan.call(_latest$current2);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
(0, _react.useEffect)(() => {
|
|
35
|
+
mounted.current = true;
|
|
36
|
+
return () => {
|
|
37
|
+
var _controller$current2;
|
|
38
|
+
mounted.current = false;
|
|
39
|
+
sequence.current += 1;
|
|
40
|
+
(_controller$current2 = controller.current) === null || _controller$current2 === void 0 || _controller$current2.abort();
|
|
41
|
+
pending.current = false;
|
|
42
|
+
};
|
|
43
|
+
}, []);
|
|
44
|
+
const run = (0, _useLatestCallback.useLatestCallback)(async task => {
|
|
45
|
+
if (!mounted.current) return {
|
|
46
|
+
status: _enums.PaymentExecutionStatus.Cancelled
|
|
47
|
+
};
|
|
48
|
+
if (pending.current) return {
|
|
49
|
+
status: _enums.PaymentExecutionStatus.Pending
|
|
50
|
+
};
|
|
51
|
+
const id = ++sequence.current;
|
|
52
|
+
const request = new AbortController();
|
|
53
|
+
controller.current = request;
|
|
54
|
+
pending.current = true;
|
|
55
|
+
setError(null);
|
|
56
|
+
setStatus(_enums.PaymentExecutionStatus.Pending);
|
|
57
|
+
const isCurrent = () => mounted.current && sequence.current === id && !request.signal.aborted;
|
|
58
|
+
let result;
|
|
59
|
+
try {
|
|
60
|
+
var _latest$current$onLoa2, _latest$current3, _latest$current$befor, _latest$current4;
|
|
61
|
+
(_latest$current$onLoa2 = (_latest$current3 = latest.current).onLoadingChange) === null || _latest$current$onLoa2 === void 0 || _latest$current$onLoa2.call(_latest$current3, true);
|
|
62
|
+
const permitted = await ((_latest$current$befor = (_latest$current4 = latest.current).beforePay) === null || _latest$current$befor === void 0 ? void 0 : _latest$current$befor.call(_latest$current4));
|
|
63
|
+
if (!isCurrent()) return {
|
|
64
|
+
status: _enums.PaymentExecutionStatus.Cancelled
|
|
65
|
+
};
|
|
66
|
+
if (permitted === false) {
|
|
67
|
+
result = {
|
|
68
|
+
status: _enums.PaymentExecutionStatus.Cancelled
|
|
69
|
+
};
|
|
70
|
+
} else {
|
|
71
|
+
const value = await task({
|
|
72
|
+
signal: request.signal,
|
|
73
|
+
isCurrent
|
|
74
|
+
});
|
|
75
|
+
if (!isCurrent()) return {
|
|
76
|
+
status: _enums.PaymentExecutionStatus.Cancelled
|
|
77
|
+
};
|
|
78
|
+
result = {
|
|
79
|
+
status: _enums.PaymentExecutionStatus.Completed,
|
|
80
|
+
value
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
} catch (cause) {
|
|
84
|
+
if (!isCurrent()) return {
|
|
85
|
+
status: _enums.PaymentExecutionStatus.Cancelled
|
|
86
|
+
};
|
|
87
|
+
const failure = cause instanceof _payment.PaymentExecutionError ? cause : new _payment.PaymentExecutionError(_enums.PaymentErrorCode.ExecutionFailed, 'Payment execution failed.');
|
|
88
|
+
result = {
|
|
89
|
+
status: _enums.PaymentExecutionStatus.Failed,
|
|
90
|
+
error: failure
|
|
91
|
+
};
|
|
92
|
+
setError(failure);
|
|
93
|
+
} finally {
|
|
94
|
+
if (isCurrent()) pending.current = false;
|
|
95
|
+
}
|
|
96
|
+
if (isCurrent()) {
|
|
97
|
+
var _latest$current$onLoa3, _latest$current5, _latest$current$onPay, _latest$current6, _latest$current$onCan2, _latest$current7;
|
|
98
|
+
setStatus(result.status);
|
|
99
|
+
(_latest$current$onLoa3 = (_latest$current5 = latest.current).onLoadingChange) === null || _latest$current$onLoa3 === void 0 || _latest$current$onLoa3.call(_latest$current5, false);
|
|
100
|
+
if (result.error) (_latest$current$onPay = (_latest$current6 = latest.current).onPaymentError) === null || _latest$current$onPay === void 0 || _latest$current$onPay.call(_latest$current6, result.error);
|
|
101
|
+
if (result.status === _enums.PaymentExecutionStatus.Cancelled) (_latest$current$onCan2 = (_latest$current7 = latest.current).onCancel) === null || _latest$current$onCan2 === void 0 || _latest$current$onCan2.call(_latest$current7);
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
run,
|
|
107
|
+
cancel,
|
|
108
|
+
status,
|
|
109
|
+
error,
|
|
110
|
+
loading: status === _enums.PaymentExecutionStatus.Pending
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
exports.usePaymentExecution = usePaymentExecution;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.usePaymentQr = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _qrcode = _interopRequireDefault(require("../utils/qrcode"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
const usePaymentQr = (value, image, options) => {
|
|
11
|
+
const callbacks = (0, _react.useRef)(options);
|
|
12
|
+
callbacks.current = options;
|
|
13
|
+
const [state, setState] = (0, _react.useState)({
|
|
14
|
+
imageUrl: '',
|
|
15
|
+
loading: true,
|
|
16
|
+
failed: false
|
|
17
|
+
});
|
|
18
|
+
(0, _react.useEffect)(() => {
|
|
19
|
+
let active = true;
|
|
20
|
+
setState({
|
|
21
|
+
imageUrl: '',
|
|
22
|
+
loading: true,
|
|
23
|
+
failed: false
|
|
24
|
+
});
|
|
25
|
+
const task = image ? Promise.resolve(value) : (0, _qrcode.default)(value);
|
|
26
|
+
task.then(imageUrl => {
|
|
27
|
+
var _callbacks$current$on, _callbacks$current;
|
|
28
|
+
if (!active) return;
|
|
29
|
+
setState({
|
|
30
|
+
imageUrl,
|
|
31
|
+
loading: false,
|
|
32
|
+
failed: false
|
|
33
|
+
});
|
|
34
|
+
(_callbacks$current$on = (_callbacks$current = callbacks.current).onQrReady) === null || _callbacks$current$on === void 0 || _callbacks$current$on.call(_callbacks$current, imageUrl);
|
|
35
|
+
}).catch(() => {
|
|
36
|
+
var _callbacks$current$on2, _callbacks$current2;
|
|
37
|
+
if (!active) return;
|
|
38
|
+
setState({
|
|
39
|
+
imageUrl: '',
|
|
40
|
+
loading: false,
|
|
41
|
+
failed: true
|
|
42
|
+
});
|
|
43
|
+
(_callbacks$current$on2 = (_callbacks$current2 = callbacks.current).onQrError) === null || _callbacks$current$on2 === void 0 || _callbacks$current$on2.call(_callbacks$current2);
|
|
44
|
+
});
|
|
45
|
+
return () => {
|
|
46
|
+
active = false;
|
|
47
|
+
};
|
|
48
|
+
}, [value, image]);
|
|
49
|
+
return state;
|
|
50
|
+
};
|
|
51
|
+
exports.usePaymentQr = usePaymentQr;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.usePaymentRedirect = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _enums = require("../shared/enums");
|
|
10
|
+
var _payment = require("../shared/entitys/payment");
|
|
11
|
+
var _useLatestCallback = require("./useLatestCallback");
|
|
12
|
+
let nextWindowId = 0;
|
|
13
|
+
const usePaymentRedirect = (options = {}) => {
|
|
14
|
+
const latest = (0, _react.useRef)(options);
|
|
15
|
+
latest.current = options;
|
|
16
|
+
const owned = (0, _react.useRef)(null);
|
|
17
|
+
const monitor = (0, _react.useRef)();
|
|
18
|
+
const name = (0, _react.useRef)();
|
|
19
|
+
const clearMonitor = () => {
|
|
20
|
+
if (monitor.current !== undefined) clearInterval(monitor.current);
|
|
21
|
+
monitor.current = undefined;
|
|
22
|
+
};
|
|
23
|
+
const close = (0, _useLatestCallback.useLatestCallback)(() => {
|
|
24
|
+
var _owned$current;
|
|
25
|
+
clearMonitor();
|
|
26
|
+
(_owned$current = owned.current) === null || _owned$current === void 0 || _owned$current.close();
|
|
27
|
+
owned.current = null;
|
|
28
|
+
});
|
|
29
|
+
const open = (0, _useLatestCallback.useLatestCallback)(rawUrl => {
|
|
30
|
+
var _latest$current$onOpe, _latest$current2;
|
|
31
|
+
if (typeof window === 'undefined') throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.BrowserUnavailable, 'A browser is required.');
|
|
32
|
+
let url;
|
|
33
|
+
try {
|
|
34
|
+
url = new URL(rawUrl, window.location.href);
|
|
35
|
+
} catch {
|
|
36
|
+
throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InvalidParameters, 'Invalid payment URL.');
|
|
37
|
+
}
|
|
38
|
+
if (!(rawUrl !== null && rawUrl !== void 0 && rawUrl.trim()) || !['https:', 'http:'].includes(url.protocol)) {
|
|
39
|
+
throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InvalidParameters, 'Payment URL must use HTTP or HTTPS.');
|
|
40
|
+
}
|
|
41
|
+
const mode = latest.current.openMode ?? _enums.OpenPayUrlMode.Href;
|
|
42
|
+
if (mode === _enums.OpenPayUrlMode.Window) {
|
|
43
|
+
close();
|
|
44
|
+
if (!name.current) name.current = `pay_sdk_${++nextWindowId}`;
|
|
45
|
+
const child = window.open(url.href, latest.current.windowName ?? name.current, latest.current.windowFeatures);
|
|
46
|
+
if (!child) throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.WindowBlocked, 'The payment window was blocked.');
|
|
47
|
+
owned.current = child;
|
|
48
|
+
monitor.current = setInterval(() => {
|
|
49
|
+
var _owned$current2;
|
|
50
|
+
if ((_owned$current2 = owned.current) !== null && _owned$current2 !== void 0 && _owned$current2.closed) {
|
|
51
|
+
var _latest$current$onWin, _latest$current;
|
|
52
|
+
clearMonitor();
|
|
53
|
+
owned.current = null;
|
|
54
|
+
(_latest$current$onWin = (_latest$current = latest.current).onWindowClose) === null || _latest$current$onWin === void 0 || _latest$current$onWin.call(_latest$current);
|
|
55
|
+
}
|
|
56
|
+
}, 500);
|
|
57
|
+
} else if (mode === _enums.OpenPayUrlMode.Replace) {
|
|
58
|
+
window.location.replace(url.href);
|
|
59
|
+
} else if (mode === _enums.OpenPayUrlMode.Href) {
|
|
60
|
+
window.location.assign(url.href);
|
|
61
|
+
} else {
|
|
62
|
+
throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InvalidParameters, 'Unsupported opening mode.');
|
|
63
|
+
}
|
|
64
|
+
(_latest$current$onOpe = (_latest$current2 = latest.current).onOpen) === null || _latest$current$onOpe === void 0 || _latest$current$onOpe.call(_latest$current2, url.href);
|
|
65
|
+
});
|
|
66
|
+
(0, _react.useEffect)(() => {
|
|
67
|
+
const onMessage = event => {
|
|
68
|
+
var _config$allowedMessag, _config$onMessage;
|
|
69
|
+
const config = latest.current;
|
|
70
|
+
if (!owned.current || event.source !== owned.current || !((_config$allowedMessag = config.allowedMessageOrigins) !== null && _config$allowedMessag !== void 0 && _config$allowedMessag.includes(event.origin)) || !config.messageValidator) return;
|
|
71
|
+
if (config.messageValidator(event)) (_config$onMessage = config.onMessage) === null || _config$onMessage === void 0 || _config$onMessage.call(config, event);
|
|
72
|
+
};
|
|
73
|
+
window.addEventListener('message', onMessage);
|
|
74
|
+
return () => {
|
|
75
|
+
var _owned$current3;
|
|
76
|
+
window.removeEventListener('message', onMessage);
|
|
77
|
+
clearMonitor();
|
|
78
|
+
if (latest.current.closeWindowOnUnmount !== false) (_owned$current3 = owned.current) === null || _owned$current3 === void 0 || _owned$current3.close();
|
|
79
|
+
owned.current = null;
|
|
80
|
+
};
|
|
81
|
+
}, []);
|
|
82
|
+
return {
|
|
83
|
+
open,
|
|
84
|
+
close
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
exports.usePaymentRedirect = usePaymentRedirect;
|
package/dist/lib/index.js
CHANGED
|
@@ -10,13 +10,20 @@ var _exportNames = {
|
|
|
10
10
|
Alipay: true,
|
|
11
11
|
Wechat: true,
|
|
12
12
|
Pix: true,
|
|
13
|
+
Paypal: true,
|
|
13
14
|
PaypalButton: true,
|
|
15
|
+
PaypalSmartButton: true,
|
|
16
|
+
PaypalProvider: true,
|
|
14
17
|
StripeButton: true,
|
|
15
18
|
StripePopup: true,
|
|
16
19
|
StripeModal: true,
|
|
20
|
+
StripeCheckoutButton: true,
|
|
21
|
+
useStripeCheckout: true,
|
|
17
22
|
AirwallexButton: true,
|
|
18
23
|
AirwallexPopup: true,
|
|
19
24
|
AirwallexModal: true,
|
|
25
|
+
AirwallexCheckoutButton: true,
|
|
26
|
+
useAirwallexCheckout: true,
|
|
20
27
|
PayssionButton: true,
|
|
21
28
|
MWechatButton: true,
|
|
22
29
|
MAlipayButton: true,
|
|
@@ -36,6 +43,12 @@ Object.defineProperty(exports, "AirwallexButton", {
|
|
|
36
43
|
return _Airwallex.AirwallexButton;
|
|
37
44
|
}
|
|
38
45
|
});
|
|
46
|
+
Object.defineProperty(exports, "AirwallexCheckoutButton", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return _Airwallex.AirwallexCheckoutButton;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
39
52
|
Object.defineProperty(exports, "AirwallexModal", {
|
|
40
53
|
enumerable: true,
|
|
41
54
|
get: function () {
|
|
@@ -86,12 +99,25 @@ Object.defineProperty(exports, "PayButton", {
|
|
|
86
99
|
return _PayButton.default;
|
|
87
100
|
}
|
|
88
101
|
});
|
|
102
|
+
exports.Paypal = void 0;
|
|
89
103
|
Object.defineProperty(exports, "PaypalButton", {
|
|
90
104
|
enumerable: true,
|
|
91
105
|
get: function () {
|
|
92
106
|
return _Paypal.PaypalButton;
|
|
93
107
|
}
|
|
94
108
|
});
|
|
109
|
+
Object.defineProperty(exports, "PaypalProvider", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _Paypal.PaypalProvider;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, "PaypalSmartButton", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return _Paypal.PaypalSmartButton;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
95
121
|
Object.defineProperty(exports, "PayssionButton", {
|
|
96
122
|
enumerable: true,
|
|
97
123
|
get: function () {
|
|
@@ -118,6 +144,12 @@ Object.defineProperty(exports, "StripeButton", {
|
|
|
118
144
|
return _Stripe.StripeButton;
|
|
119
145
|
}
|
|
120
146
|
});
|
|
147
|
+
Object.defineProperty(exports, "StripeCheckoutButton", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function () {
|
|
150
|
+
return _Stripe.StripeCheckoutButton;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
121
153
|
Object.defineProperty(exports, "StripeModal", {
|
|
122
154
|
enumerable: true,
|
|
123
155
|
get: function () {
|
|
@@ -143,6 +175,18 @@ Object.defineProperty(exports, "WechatModal", {
|
|
|
143
175
|
return _Wechat.WechatModal;
|
|
144
176
|
}
|
|
145
177
|
});
|
|
178
|
+
Object.defineProperty(exports, "useAirwallexCheckout", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function () {
|
|
181
|
+
return _Airwallex.useAirwallexCheckout;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
Object.defineProperty(exports, "useStripeCheckout", {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
get: function () {
|
|
187
|
+
return _Stripe.useStripeCheckout;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
146
190
|
var _Paypal = require("./Paypal");
|
|
147
191
|
var _Stripe = _interopRequireWildcard(require("./Stripe"));
|
|
148
192
|
var _Airwallex = _interopRequireWildcard(require("./Airwallex"));
|
|
@@ -169,11 +213,13 @@ Object.keys(_shared).forEach(function (key) {
|
|
|
169
213
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
170
214
|
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); }
|
|
171
215
|
const Stripe = exports.Stripe = Object.assign({}, _Stripe.default, {
|
|
216
|
+
CheckoutButton: _Stripe.StripeCheckoutButton,
|
|
172
217
|
Button: _Stripe.StripeButton,
|
|
173
218
|
Popup: _Stripe.StripePopup,
|
|
174
219
|
Modal: _Stripe.StripeModal
|
|
175
220
|
});
|
|
176
221
|
const Airwallex = exports.Airwallex = Object.assign({}, _Airwallex.default, {
|
|
222
|
+
CheckoutButton: _Airwallex.AirwallexCheckoutButton,
|
|
177
223
|
Button: _Airwallex.AirwallexButton,
|
|
178
224
|
Popup: _Airwallex.AirwallexPopup,
|
|
179
225
|
Modal: _Airwallex.AirwallexModal
|
|
@@ -192,4 +238,14 @@ const Wechat = exports.Wechat = Object.assign({}, _Wechat.default, {
|
|
|
192
238
|
const Pix = exports.Pix = Object.assign({}, _Pix.default, {
|
|
193
239
|
Button: _Pix.PixButton,
|
|
194
240
|
Modal: _Pix.PixModal
|
|
195
|
-
});
|
|
241
|
+
});
|
|
242
|
+
/**
|
|
243
|
+
* @zh PayPal 独立入口保留原 URL 按钮。
|
|
244
|
+
* @en PayPal namespace keeps the legacy URL button.
|
|
245
|
+
* @since 1.2.0
|
|
246
|
+
*/
|
|
247
|
+
const Paypal = exports.Paypal = {
|
|
248
|
+
Button: _Paypal.PaypalButton,
|
|
249
|
+
SmartButton: _Paypal.PaypalSmartButton,
|
|
250
|
+
Provider: _Paypal.PaypalProvider
|
|
251
|
+
};
|
|
@@ -46,7 +46,11 @@ const PayModal = props => {
|
|
|
46
46
|
style,
|
|
47
47
|
contentClassName,
|
|
48
48
|
contentStyle,
|
|
49
|
-
container
|
|
49
|
+
container,
|
|
50
|
+
classNames: slots = {},
|
|
51
|
+
styles = {},
|
|
52
|
+
closeIcon,
|
|
53
|
+
closeLabel = '关闭'
|
|
50
54
|
} = props;
|
|
51
55
|
const {
|
|
52
56
|
className: retryButtonClassName,
|
|
@@ -75,8 +79,8 @@ const PayModal = props => {
|
|
|
75
79
|
};
|
|
76
80
|
}
|
|
77
81
|
}, [visible, container]);
|
|
78
|
-
const classNames = (0, _classNames.default)(classPrefix, className);
|
|
79
|
-
const contentClassNames = (0, _classNames.default)(`${classPrefix}__content`, contentClassName);
|
|
82
|
+
const classNames = (0, _classNames.default)(classPrefix, className, slots.root);
|
|
83
|
+
const contentClassNames = (0, _classNames.default)(`${classPrefix}__content`, contentClassName, slots.content);
|
|
80
84
|
const handleMaskClose = (0, _react.useCallback)(() => {
|
|
81
85
|
if (maskClosable) onClose === null || onClose === void 0 || onClose();
|
|
82
86
|
}, [maskClosable, onClose]);
|
|
@@ -90,31 +94,44 @@ const PayModal = props => {
|
|
|
90
94
|
}, finishButtonPropsRest), finishButtonChildren);
|
|
91
95
|
const footerContent = (0, _is.isFunction)(footer) ? footer(retryButtonNode, finishButtonNode) : footer || /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, retryButtonNode, finishButtonNode);
|
|
92
96
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
93
|
-
className: `${classPrefix}__actions
|
|
97
|
+
className: (0, _classNames.default)(`${classPrefix}__actions`, slots.footer),
|
|
98
|
+
style: styles.footer
|
|
94
99
|
}, footerContent);
|
|
95
100
|
};
|
|
96
101
|
if (!visible || !el.current) return null;
|
|
97
102
|
const modalContent = /*#__PURE__*/_react.default.createElement("div", {
|
|
98
103
|
className: classNames,
|
|
99
|
-
style:
|
|
104
|
+
style: {
|
|
105
|
+
...style,
|
|
106
|
+
...styles.root
|
|
107
|
+
}
|
|
100
108
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
101
|
-
className: `${classPrefix}__mask`,
|
|
109
|
+
className: (0, _classNames.default)(`${classPrefix}__mask`, slots.mask),
|
|
110
|
+
style: styles.mask,
|
|
102
111
|
onClick: handleMaskClose
|
|
103
112
|
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
104
113
|
className: contentClassNames,
|
|
105
|
-
style:
|
|
114
|
+
style: {
|
|
115
|
+
...contentStyle,
|
|
116
|
+
...styles.content
|
|
117
|
+
}
|
|
106
118
|
}, showClose && /*#__PURE__*/_react.default.createElement("button", {
|
|
107
|
-
className: `${classPrefix}__close`,
|
|
119
|
+
className: (0, _classNames.default)(`${classPrefix}__close`, slots.close),
|
|
120
|
+
style: styles.close,
|
|
108
121
|
onClick: onClose,
|
|
109
|
-
"aria-label":
|
|
110
|
-
},
|
|
111
|
-
className: `${classPrefix}__icon
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
"aria-label": closeLabel
|
|
123
|
+
}, closeIcon === undefined ? '×' : closeIcon), icon && /*#__PURE__*/_react.default.createElement("div", {
|
|
124
|
+
className: (0, _classNames.default)(`${classPrefix}__icon`, slots.icon),
|
|
125
|
+
style: styles.icon
|
|
126
|
+
}, icon), title !== undefined && title !== null && title !== false && title !== '' ? /*#__PURE__*/_react.default.createElement("div", {
|
|
127
|
+
className: (0, _classNames.default)(`${classPrefix}__title`, slots.title),
|
|
128
|
+
style: styles.title
|
|
129
|
+
}, title) : null, desc && /*#__PURE__*/_react.default.createElement("div", {
|
|
130
|
+
className: (0, _classNames.default)(`${classPrefix}__desc`, slots.description),
|
|
131
|
+
style: styles.description
|
|
116
132
|
}, desc), children && /*#__PURE__*/_react.default.createElement("div", {
|
|
117
|
-
className: `${classPrefix}__content-wrapper
|
|
133
|
+
className: (0, _classNames.default)(`${classPrefix}__content-wrapper`, slots.body),
|
|
134
|
+
style: styles.body
|
|
118
135
|
}, children), renderFooter()));
|
|
119
136
|
return /*#__PURE__*/_reactDom.default.createPortal(modalContent, el.current);
|
|
120
137
|
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PaymentExecutionError = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @zh 分区域样式,不传时保留原样。
|
|
9
|
+
* @en Semantic styles; omitted values preserve defaults.
|
|
10
|
+
* @since 1.2.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @zh 二维码展示配置。
|
|
15
|
+
* @en QR presentation options.
|
|
16
|
+
* @since 1.2.0
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @zh 支付执行错误;不包含支付凭证。
|
|
21
|
+
* @en Execution error without credentials.
|
|
22
|
+
* @since 1.2.0
|
|
23
|
+
*/
|
|
24
|
+
class PaymentExecutionError extends Error {
|
|
25
|
+
constructor(code, message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.code = code;
|
|
28
|
+
this.name = 'PaymentExecutionError';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @zh 可选的受管理执行配置。
|
|
34
|
+
* @en Optional managed execution options.
|
|
35
|
+
* @since 1.2.0
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @zh 每次执行的显式结果。
|
|
40
|
+
* @en Explicit execution result.
|
|
41
|
+
* @since 1.2.0
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @zh 执行 Hook 的公开状态。
|
|
46
|
+
* @en Public execution state.
|
|
47
|
+
* @since 1.2.0
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @zh URL 跳转配置,仅用于 URL 分支。
|
|
52
|
+
* @en Redirect options for URL targets only.
|
|
53
|
+
* @since 1.2.0
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @zh 已有目标或获取目标的回调;null 表示中止。
|
|
58
|
+
* @en Target or factory; null stops execution.
|
|
59
|
+
* @since 1.2.0
|
|
60
|
+
*/
|
|
61
|
+
exports.PaymentExecutionError = PaymentExecutionError;
|