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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["className", "children", "onClick", "payssionUrl", "createOrder", "maskProps"],
|
|
1
|
+
var _excluded = ["className", "children", "onClick", "payssionUrl", "createOrder", "executionOptions", "maskProps"],
|
|
2
2
|
_excluded2 = ["onClose"];
|
|
3
3
|
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); }
|
|
4
4
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
@@ -13,6 +13,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
13
13
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
14
14
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
15
15
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
16
|
+
import { useManagedOrder } from '../hooks/useManagedOrder';
|
|
16
17
|
import React, { forwardRef, memo, useCallback, useImperativeHandle, useRef, useState } from 'react';
|
|
17
18
|
import cs from '../utils/classNames';
|
|
18
19
|
import PayMask from '../PayMask';
|
|
@@ -26,6 +27,7 @@ var PayssionButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
26
27
|
onClick = props.onClick,
|
|
27
28
|
propsPayssionUrl = props.payssionUrl,
|
|
28
29
|
createOrder = props.createOrder,
|
|
30
|
+
executionOptions = props.executionOptions,
|
|
29
31
|
maskProps = props.maskProps,
|
|
30
32
|
others = _objectWithoutProperties(props, _excluded);
|
|
31
33
|
var _ref = maskProps || {},
|
|
@@ -53,11 +55,21 @@ var PayssionButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
53
55
|
}
|
|
54
56
|
},
|
|
55
57
|
closePayment: function closePayment() {
|
|
58
|
+
if (executionOptions) managed.cancel();
|
|
56
59
|
setShowMask(false);
|
|
57
60
|
},
|
|
58
61
|
current: payssionButtonRef.current
|
|
59
62
|
};
|
|
60
63
|
});
|
|
64
|
+
var managed = useManagedOrder(createOrder, function (target) {
|
|
65
|
+
if (target.payssionUrl) {
|
|
66
|
+
setPayssionUrl(target.payssionUrl);
|
|
67
|
+
setShowMask(true);
|
|
68
|
+
}
|
|
69
|
+
}, executionOptions, function (target) {
|
|
70
|
+
return typeof target.payssionUrl === 'string' && Boolean(target.payssionUrl.trim());
|
|
71
|
+
});
|
|
72
|
+
var managedRun = managed.run;
|
|
61
73
|
var handlePayCreateOrder = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
62
74
|
var _yield$createOrder, _payssionUrl;
|
|
63
75
|
return _regenerator().w(function (_context) {
|
|
@@ -90,24 +102,33 @@ var PayssionButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
90
102
|
}, [propsPayssionUrl]);
|
|
91
103
|
var handleClick = useCallback(function (e) {
|
|
92
104
|
if (createOrder) {
|
|
105
|
+
if (executionOptions) {
|
|
106
|
+
onClick === null || onClick === void 0 || onClick(e);
|
|
107
|
+
if (e.defaultPrevented) return;
|
|
108
|
+
return managedRun().then(function () {
|
|
109
|
+
return undefined;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
93
112
|
handlePayCreateOrder();
|
|
94
113
|
} else {
|
|
95
114
|
handleOpen();
|
|
96
115
|
}
|
|
97
116
|
onClick === null || onClick === void 0 || onClick(e);
|
|
98
|
-
}, [onClick, createOrder, handlePayCreateOrder, handleOpen]);
|
|
117
|
+
}, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, handleOpen]);
|
|
99
118
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({
|
|
100
119
|
ref: payssionButtonRef,
|
|
101
120
|
className: cs(getPrefixCls('payssion-btn'), className),
|
|
102
121
|
onClick: handleClick
|
|
103
|
-
}, others
|
|
122
|
+
}, others, {
|
|
123
|
+
loading: executionOptions ? managed.loading || others.loading : others.loading
|
|
124
|
+
}), children), payssionUrl && showMask && /*#__PURE__*/React.createElement(PayMask, _extends({
|
|
104
125
|
visible: showMask,
|
|
105
126
|
onClose: function onClose() {
|
|
106
127
|
setShowMask(false);
|
|
107
128
|
_onClose === null || _onClose === void 0 || _onClose();
|
|
108
129
|
},
|
|
109
130
|
payUrl: payssionUrl,
|
|
110
|
-
title:
|
|
131
|
+
title: "Payssion"
|
|
111
132
|
}, restMaskProps)));
|
|
112
133
|
});
|
|
113
134
|
PayssionButton.displayName = 'PayssionButton';
|
|
@@ -1,7 +1,68 @@
|
|
|
1
|
+
import type { PaymentExecutionOptions, PaymentQrAppearance } from '../shared/entitys/payment';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { PayModalProps } from '../pay-modal';
|
|
3
4
|
import { ButtonProps, ButtonRef } from '../Button';
|
|
4
5
|
export interface PixProps {
|
|
6
|
+
/**
|
|
7
|
+
* @zh 二维码展示配置。
|
|
8
|
+
* @en QR presentation options.
|
|
9
|
+
* @since 1.2.0
|
|
10
|
+
*/
|
|
11
|
+
qrProps?: PaymentQrAppearance;
|
|
12
|
+
/**
|
|
13
|
+
* @zh 显示完整支付码,默认 false。
|
|
14
|
+
* @en Show code text, default false.
|
|
15
|
+
* @since 1.2.0
|
|
16
|
+
*/
|
|
17
|
+
showCode?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* @zh 复制前后文案,未传使用旧文案。
|
|
20
|
+
* @en Copy labels, omitted keeps legacy text.
|
|
21
|
+
* @since 1.2.0
|
|
22
|
+
*/
|
|
23
|
+
copyText?: React.ReactNode;
|
|
24
|
+
/**
|
|
25
|
+
* @zh 复制成功后的内容,默认保留原文案。
|
|
26
|
+
* @en Content after copying; defaults to legacy text.
|
|
27
|
+
* @since 1.2.0
|
|
28
|
+
*/
|
|
29
|
+
copiedText?: React.ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* @zh 提供时显示确认按钮,仅触发调用方查询。
|
|
32
|
+
* @en Optional confirmation action, caller checks order.
|
|
33
|
+
* @since 1.2.0
|
|
34
|
+
*/
|
|
35
|
+
confirmText?: React.ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* @zh 确认操作通知,不表示已支付。
|
|
38
|
+
* @en Confirmation action notification, not payment success.
|
|
39
|
+
* @since 1.2.0
|
|
40
|
+
*/
|
|
41
|
+
onConfirm?: () => void;
|
|
42
|
+
/**
|
|
43
|
+
* @zh 复制结果事件。
|
|
44
|
+
* @en Copy outcome callbacks.
|
|
45
|
+
* @since 1.2.0
|
|
46
|
+
*/
|
|
47
|
+
onCopy?: () => void;
|
|
48
|
+
/**
|
|
49
|
+
* @zh 复制失败通知,不伪造复制成功。
|
|
50
|
+
* @en Copy failure notification.
|
|
51
|
+
* @since 1.2.0
|
|
52
|
+
*/
|
|
53
|
+
onCopyError?: () => void;
|
|
54
|
+
/**
|
|
55
|
+
* @zh 文本及操作区样式。
|
|
56
|
+
* @en Code and action appearance.
|
|
57
|
+
* @since 1.2.0
|
|
58
|
+
*/
|
|
59
|
+
actionClassNames?: Partial<Record<'code' | 'copy' | 'confirm', string>>;
|
|
60
|
+
/**
|
|
61
|
+
* @zh 支付码、复制和确认按钮的区域样式。
|
|
62
|
+
* @en Styles for code, copy, and confirmation areas.
|
|
63
|
+
* @since 1.2.0
|
|
64
|
+
*/
|
|
65
|
+
actionStyles?: Partial<Record<'code' | 'copy' | 'confirm', React.CSSProperties>>;
|
|
5
66
|
/**
|
|
6
67
|
* @zh PIX 支付码字符串(后端返回的 code_url)
|
|
7
68
|
* @en PIX payment code string (code_url returned by backend)
|
|
@@ -31,6 +92,12 @@ export interface PixProps {
|
|
|
31
92
|
style?: React.CSSProperties;
|
|
32
93
|
}
|
|
33
94
|
export interface PixButtonProps extends ButtonProps {
|
|
95
|
+
/**
|
|
96
|
+
* @zh 显式启用受管理的 createOrder 流程;未传保持旧行为。
|
|
97
|
+
* @en Opt-in managed createOrder execution; omitted preserves legacy behavior.
|
|
98
|
+
* @since 1.2.0
|
|
99
|
+
*/
|
|
100
|
+
executionOptions?: PaymentExecutionOptions;
|
|
34
101
|
/**
|
|
35
102
|
* @zh 创建订单函数,返回 Pix 所需参数
|
|
36
103
|
* @en Function to create order, returns Pix required params
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["className", "children", "onClick", "createOrder", "modalProps"];
|
|
1
|
+
var _excluded = ["className", "children", "onClick", "createOrder", "executionOptions", "modalProps"];
|
|
2
2
|
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); }
|
|
3
3
|
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
4
4
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
|
|
@@ -6,6 +6,7 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
|
|
|
6
6
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
7
7
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
8
8
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
9
|
+
import { useManagedOrder } from '../hooks/useManagedOrder';
|
|
9
10
|
import React, { forwardRef, memo, useCallback, useImperativeHandle, useRef } from 'react';
|
|
10
11
|
import cs from '../utils/classNames';
|
|
11
12
|
import PixModal from './pix-modal';
|
|
@@ -18,6 +19,7 @@ var PixButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
18
19
|
children = _props$children === void 0 ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(IconPix, null), "PIX") : _props$children,
|
|
19
20
|
onClick = props.onClick,
|
|
20
21
|
createOrder = props.createOrder,
|
|
22
|
+
executionOptions = props.executionOptions,
|
|
21
23
|
modalProps = props.modalProps,
|
|
22
24
|
others = _objectWithoutProperties(props, _excluded);
|
|
23
25
|
var pixButtonRef = useRef(null);
|
|
@@ -34,13 +36,21 @@ var PixButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
34
36
|
},
|
|
35
37
|
closeModal: function closeModal() {
|
|
36
38
|
var _pixModalRef$current2;
|
|
39
|
+
if (executionOptions) managed.cancel();
|
|
37
40
|
(_pixModalRef$current2 = pixModalRef.current) === null || _pixModalRef$current2 === void 0 || _pixModalRef$current2.close();
|
|
38
41
|
},
|
|
39
42
|
current: pixButtonRef.current
|
|
40
43
|
};
|
|
41
44
|
});
|
|
45
|
+
var managed = useManagedOrder(createOrder, function (target) {
|
|
46
|
+
var _pixModalRef$current3;
|
|
47
|
+
(_pixModalRef$current3 = pixModalRef.current) === null || _pixModalRef$current3 === void 0 || _pixModalRef$current3.open(target);
|
|
48
|
+
}, executionOptions, function (target) {
|
|
49
|
+
return typeof target.pixCode === 'string' && Boolean(target.pixCode.trim());
|
|
50
|
+
});
|
|
51
|
+
var managedRun = managed.run;
|
|
42
52
|
var handlePayCreateOrder = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
43
|
-
var _pixModalRef$
|
|
53
|
+
var _pixModalRef$current4, options;
|
|
44
54
|
return _regenerator().w(function (_context) {
|
|
45
55
|
while (1) switch (_context.n) {
|
|
46
56
|
case 0:
|
|
@@ -52,7 +62,7 @@ var PixButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
52
62
|
return createOrder();
|
|
53
63
|
case 1:
|
|
54
64
|
options = _context.v;
|
|
55
|
-
(_pixModalRef$
|
|
65
|
+
(_pixModalRef$current4 = pixModalRef.current) === null || _pixModalRef$current4 === void 0 || _pixModalRef$current4.open(options);
|
|
56
66
|
case 2:
|
|
57
67
|
return _context.a(2);
|
|
58
68
|
}
|
|
@@ -61,18 +71,27 @@ var PixButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
61
71
|
var handleClick = useCallback(function (e) {
|
|
62
72
|
var _modalProps$pixProps;
|
|
63
73
|
if (createOrder) {
|
|
74
|
+
if (executionOptions) {
|
|
75
|
+
onClick === null || onClick === void 0 || onClick(e);
|
|
76
|
+
if (e.defaultPrevented) return;
|
|
77
|
+
return managedRun().then(function () {
|
|
78
|
+
return undefined;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
64
81
|
handlePayCreateOrder();
|
|
65
82
|
} else if (modalProps !== null && modalProps !== void 0 && (_modalProps$pixProps = modalProps.pixProps) !== null && _modalProps$pixProps !== void 0 && _modalProps$pixProps.pixCode) {
|
|
66
|
-
var _pixModalRef$
|
|
67
|
-
pixModalRef === null || pixModalRef === void 0 || (_pixModalRef$
|
|
83
|
+
var _pixModalRef$current5;
|
|
84
|
+
pixModalRef === null || pixModalRef === void 0 || (_pixModalRef$current5 = pixModalRef.current) === null || _pixModalRef$current5 === void 0 || _pixModalRef$current5.open();
|
|
68
85
|
}
|
|
69
86
|
onClick === null || onClick === void 0 || onClick(e);
|
|
70
|
-
}, [onClick, createOrder, handlePayCreateOrder, modalProps]);
|
|
87
|
+
}, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, modalProps]);
|
|
71
88
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({
|
|
72
89
|
ref: pixButtonRef,
|
|
73
90
|
className: cs(getPrefixCls('pix-btn'), className),
|
|
74
91
|
onClick: handleClick
|
|
75
|
-
}, others
|
|
92
|
+
}, others, {
|
|
93
|
+
loading: executionOptions ? managed.loading || others.loading : others.loading
|
|
94
|
+
}), children), /*#__PURE__*/React.createElement(PixModal, _extends({
|
|
76
95
|
ref: pixModalRef
|
|
77
96
|
}, modalProps)));
|
|
78
97
|
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PixProps } from './interface';
|
|
3
|
+
declare const _default: React.MemoExoticComponent<({ pixCode, tipText, showCopyButton, className, style, qrProps, showCode, copyText, copiedText, confirmText, onConfirm, onCopy, onCopyError, actionClassNames, actionStyles, }: PixProps) => import("react/jsx-runtime").JSX.Element>;
|
|
4
|
+
export default _default;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
8
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
|
|
9
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
10
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
11
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
12
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
17
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
18
|
+
import { usePaymentQr } from '../hooks/usePaymentQr';
|
|
19
|
+
import cs from '../utils/classNames';
|
|
20
|
+
import { getPrefixCls } from '../utils/getPrefixCls';
|
|
21
|
+
import { IconCheck, IconCopy } from '../icons';
|
|
22
|
+
var prefix = getPrefixCls('pix-qrcode');
|
|
23
|
+
var PixEnhanced = function PixEnhanced(_ref) {
|
|
24
|
+
var _qrProps$loadingConte, _qrProps$errorContent;
|
|
25
|
+
var pixCode = _ref.pixCode,
|
|
26
|
+
_ref$tipText = _ref.tipText,
|
|
27
|
+
tipText = _ref$tipText === void 0 ? '请使用银行App扫码支付' : _ref$tipText,
|
|
28
|
+
_ref$showCopyButton = _ref.showCopyButton,
|
|
29
|
+
showCopyButton = _ref$showCopyButton === void 0 ? true : _ref$showCopyButton,
|
|
30
|
+
className = _ref.className,
|
|
31
|
+
style = _ref.style,
|
|
32
|
+
_ref$qrProps = _ref.qrProps,
|
|
33
|
+
qrProps = _ref$qrProps === void 0 ? {} : _ref$qrProps,
|
|
34
|
+
_ref$showCode = _ref.showCode,
|
|
35
|
+
showCode = _ref$showCode === void 0 ? false : _ref$showCode,
|
|
36
|
+
copyText = _ref.copyText,
|
|
37
|
+
copiedText = _ref.copiedText,
|
|
38
|
+
confirmText = _ref.confirmText,
|
|
39
|
+
onConfirm = _ref.onConfirm,
|
|
40
|
+
onCopy = _ref.onCopy,
|
|
41
|
+
onCopyError = _ref.onCopyError,
|
|
42
|
+
_ref$actionClassNames = _ref.actionClassNames,
|
|
43
|
+
actionClassNames = _ref$actionClassNames === void 0 ? {} : _ref$actionClassNames,
|
|
44
|
+
_ref$actionStyles = _ref.actionStyles,
|
|
45
|
+
actionStyles = _ref$actionStyles === void 0 ? {} : _ref$actionStyles;
|
|
46
|
+
var _usePaymentQr = usePaymentQr(pixCode, false, qrProps),
|
|
47
|
+
imageUrl = _usePaymentQr.imageUrl,
|
|
48
|
+
loading = _usePaymentQr.loading,
|
|
49
|
+
failed = _usePaymentQr.failed;
|
|
50
|
+
var _useState = useState(false),
|
|
51
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
52
|
+
copied = _useState2[0],
|
|
53
|
+
setCopied = _useState2[1];
|
|
54
|
+
var timer = useRef();
|
|
55
|
+
var mounted = useRef(false);
|
|
56
|
+
useEffect(function () {
|
|
57
|
+
mounted.current = true;
|
|
58
|
+
return function () {
|
|
59
|
+
mounted.current = false;
|
|
60
|
+
if (timer.current) clearTimeout(timer.current);
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
var copy = /*#__PURE__*/function () {
|
|
64
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
65
|
+
var succeeded, _navigator$clipboard, textarea, _t;
|
|
66
|
+
return _regenerator().w(function (_context) {
|
|
67
|
+
while (1) switch (_context.n) {
|
|
68
|
+
case 0:
|
|
69
|
+
succeeded = false;
|
|
70
|
+
_context.p = 1;
|
|
71
|
+
if (!((_navigator$clipboard = navigator.clipboard) !== null && _navigator$clipboard !== void 0 && _navigator$clipboard.writeText)) {
|
|
72
|
+
_context.n = 3;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
_context.n = 2;
|
|
76
|
+
return navigator.clipboard.writeText(pixCode);
|
|
77
|
+
case 2:
|
|
78
|
+
succeeded = true;
|
|
79
|
+
case 3:
|
|
80
|
+
_context.n = 5;
|
|
81
|
+
break;
|
|
82
|
+
case 4:
|
|
83
|
+
_context.p = 4;
|
|
84
|
+
_t = _context.v;
|
|
85
|
+
case 5:
|
|
86
|
+
if (!succeeded) {
|
|
87
|
+
textarea = document.createElement('textarea');
|
|
88
|
+
textarea.value = pixCode;
|
|
89
|
+
textarea.style.position = 'fixed';
|
|
90
|
+
textarea.style.opacity = '0';
|
|
91
|
+
document.body.appendChild(textarea);
|
|
92
|
+
try {
|
|
93
|
+
textarea.select();
|
|
94
|
+
succeeded = document.execCommand('copy');
|
|
95
|
+
} catch (_unused2) {
|
|
96
|
+
succeeded = false;
|
|
97
|
+
} finally {
|
|
98
|
+
textarea.remove();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (mounted.current) {
|
|
102
|
+
_context.n = 6;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return _context.a(2);
|
|
106
|
+
case 6:
|
|
107
|
+
if (succeeded) {
|
|
108
|
+
_context.n = 7;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
onCopyError === null || onCopyError === void 0 || onCopyError();
|
|
112
|
+
return _context.a(2);
|
|
113
|
+
case 7:
|
|
114
|
+
setCopied(true);
|
|
115
|
+
if (timer.current) clearTimeout(timer.current);
|
|
116
|
+
timer.current = setTimeout(function () {
|
|
117
|
+
return setCopied(false);
|
|
118
|
+
}, 2000);
|
|
119
|
+
onCopy === null || onCopy === void 0 || onCopy();
|
|
120
|
+
case 8:
|
|
121
|
+
return _context.a(2);
|
|
122
|
+
}
|
|
123
|
+
}, _callee, null, [[1, 4]]);
|
|
124
|
+
}));
|
|
125
|
+
return function copy() {
|
|
126
|
+
return _ref2.apply(this, arguments);
|
|
127
|
+
};
|
|
128
|
+
}();
|
|
129
|
+
if (loading) return /*#__PURE__*/React.createElement(React.Fragment, null, (_qrProps$loadingConte = qrProps.loadingContent) !== null && _qrProps$loadingConte !== void 0 ? _qrProps$loadingConte : null);
|
|
130
|
+
if (failed) return /*#__PURE__*/React.createElement(React.Fragment, null, (_qrProps$errorContent = qrProps.errorContent) !== null && _qrProps$errorContent !== void 0 ? _qrProps$errorContent : null);
|
|
131
|
+
var _qrProps$classNames = qrProps.classNames,
|
|
132
|
+
names = _qrProps$classNames === void 0 ? {} : _qrProps$classNames,
|
|
133
|
+
_qrProps$styles = qrProps.styles,
|
|
134
|
+
styles = _qrProps$styles === void 0 ? {} : _qrProps$styles;
|
|
135
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
136
|
+
className: cs(prefix, className, names.root),
|
|
137
|
+
style: _objectSpread(_objectSpread({}, style), styles.root)
|
|
138
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
139
|
+
className: cs("".concat(prefix, "__container"), names.container),
|
|
140
|
+
style: _objectSpread({
|
|
141
|
+
position: 'relative',
|
|
142
|
+
width: qrProps.size,
|
|
143
|
+
height: qrProps.size
|
|
144
|
+
}, styles.container)
|
|
145
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
146
|
+
className: cs("".concat(prefix, "__image"), names.image),
|
|
147
|
+
style: styles.image,
|
|
148
|
+
src: imageUrl,
|
|
149
|
+
alt: "PIX\u652F\u4ED8\u4E8C\u7EF4\u7801"
|
|
150
|
+
}), qrProps.overlay !== undefined ? /*#__PURE__*/React.createElement("div", {
|
|
151
|
+
className: names.overlay,
|
|
152
|
+
style: _objectSpread({
|
|
153
|
+
position: 'absolute',
|
|
154
|
+
left: '50%',
|
|
155
|
+
top: '50%',
|
|
156
|
+
transform: 'translate(-50%, -50%)'
|
|
157
|
+
}, styles.overlay)
|
|
158
|
+
}, qrProps.overlay) : null), showCode ? /*#__PURE__*/React.createElement("code", {
|
|
159
|
+
className: cs("".concat(prefix, "__code"), actionClassNames.code),
|
|
160
|
+
style: actionStyles.code
|
|
161
|
+
}, pixCode) : null, tipText ? /*#__PURE__*/React.createElement("span", {
|
|
162
|
+
className: cs("".concat(prefix, "__tip"), names.tip),
|
|
163
|
+
style: styles.tip
|
|
164
|
+
}, tipText) : null, showCopyButton ? /*#__PURE__*/React.createElement("div", {
|
|
165
|
+
className: "".concat(prefix, "__code-section")
|
|
166
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
167
|
+
type: "button",
|
|
168
|
+
className: cs("".concat(prefix, "__copy-btn"), _defineProperty({}, "".concat(prefix, "__copy-btn--copied"), copied), actionClassNames.copy),
|
|
169
|
+
style: actionStyles.copy,
|
|
170
|
+
onClick: copy
|
|
171
|
+
}, copied ? /*#__PURE__*/React.createElement(IconCheck, {
|
|
172
|
+
className: "".concat(prefix, "__copy-icon")
|
|
173
|
+
}) : /*#__PURE__*/React.createElement(IconCopy, {
|
|
174
|
+
className: "".concat(prefix, "__copy-icon")
|
|
175
|
+
}), /*#__PURE__*/React.createElement("span", null, copied ? copiedText !== null && copiedText !== void 0 ? copiedText : '已复制' : copyText !== null && copyText !== void 0 ? copyText : '复制 PIX Code'))) : null, confirmText !== undefined ? /*#__PURE__*/React.createElement("button", {
|
|
176
|
+
type: "button",
|
|
177
|
+
className: cs("".concat(prefix, "__confirm-btn"), actionClassNames.confirm),
|
|
178
|
+
style: actionStyles.confirm,
|
|
179
|
+
onClick: onConfirm
|
|
180
|
+
}, confirmText) : null);
|
|
181
|
+
};
|
|
182
|
+
export default /*#__PURE__*/React.memo(PixEnhanced);
|
package/dist/es/Pix/pix.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PixProps } from './interface';
|
|
3
|
-
declare const _default: React.
|
|
3
|
+
declare const _default: React.MemoExoticComponent<(props: PixProps) => import("react/jsx-runtime").JSX.Element>;
|
|
4
4
|
export default _default;
|
package/dist/es/Pix/pix.js
CHANGED
|
@@ -14,6 +14,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
14
14
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
15
15
|
import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
16
16
|
import cs from '../utils/classNames';
|
|
17
|
+
import PixEnhanced from './pix-enhanced';
|
|
17
18
|
import makeQrcode from '../utils/qrcode';
|
|
18
19
|
import { IconCopy, IconCheck } from '../icons';
|
|
19
20
|
import { getPrefixCls } from '../utils/getPrefixCls';
|
|
@@ -117,4 +118,8 @@ var PixQrCode = function PixQrCode(_ref) {
|
|
|
117
118
|
className: "".concat(classPrefix, "__copy-icon")
|
|
118
119
|
}), /*#__PURE__*/React.createElement("span", null, copied ? '已复制' : '复制 PIX Code'))));
|
|
119
120
|
};
|
|
120
|
-
|
|
121
|
+
var PixEntry = function PixEntry(props) {
|
|
122
|
+
var 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;
|
|
123
|
+
return enhanced ? /*#__PURE__*/React.createElement(PixEnhanced, props) : /*#__PURE__*/React.createElement(PixQrCode, props);
|
|
124
|
+
};
|
|
125
|
+
export default /*#__PURE__*/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,7 @@
|
|
|
1
|
+
import { UseStripeCheckoutOptions, UseStripeCheckoutReturn } from '../interface';
|
|
2
|
+
/**
|
|
3
|
+
* @zh 打开 Stripe 托管支付页面,不自动下单。
|
|
4
|
+
* @en Open hosted Stripe checkout; no automatic order creation.
|
|
5
|
+
* @since 1.2.0
|
|
6
|
+
*/
|
|
7
|
+
export declare const useStripeCheckout: (options?: UseStripeCheckoutOptions) => UseStripeCheckoutReturn;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
10
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { var o = function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); }; o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine2(e, r, n, t); }
|
|
11
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
12
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
13
|
+
import { usePaymentExecution } from '../../hooks/usePaymentExecution';
|
|
14
|
+
import { usePaymentRedirect } from '../../hooks/usePaymentRedirect';
|
|
15
|
+
import { useLatestCallback } from '../../hooks/useLatestCallback';
|
|
16
|
+
import { PaymentErrorCode } from '../../shared/enums';
|
|
17
|
+
import { PaymentExecutionError } from '../../shared/entitys/payment';
|
|
18
|
+
/**
|
|
19
|
+
* @zh 打开 Stripe 托管支付页面,不自动下单。
|
|
20
|
+
* @en Open hosted Stripe checkout; no automatic order creation.
|
|
21
|
+
* @since 1.2.0
|
|
22
|
+
*/
|
|
23
|
+
export var useStripeCheckout = function useStripeCheckout() {
|
|
24
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25
|
+
var execution = usePaymentExecution(options);
|
|
26
|
+
var redirect = usePaymentRedirect(options.redirectOptions);
|
|
27
|
+
var openCheckout = useLatestCallback(function (source) {
|
|
28
|
+
return execution.run(/*#__PURE__*/function () {
|
|
29
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context) {
|
|
30
|
+
var target, _t;
|
|
31
|
+
return _regenerator().w(function (_context) {
|
|
32
|
+
while (1) switch (_context.n) {
|
|
33
|
+
case 0:
|
|
34
|
+
if (!(typeof source === 'function')) {
|
|
35
|
+
_context.n = 2;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
_context.n = 1;
|
|
39
|
+
return source(context.signal);
|
|
40
|
+
case 1:
|
|
41
|
+
_t = _context.v;
|
|
42
|
+
_context.n = 3;
|
|
43
|
+
break;
|
|
44
|
+
case 2:
|
|
45
|
+
_t = source;
|
|
46
|
+
case 3:
|
|
47
|
+
target = _t;
|
|
48
|
+
if (context.isCurrent()) {
|
|
49
|
+
_context.n = 4;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
return _context.a(2);
|
|
53
|
+
case 4:
|
|
54
|
+
if (!(target === null)) {
|
|
55
|
+
_context.n = 5;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
execution.cancel();
|
|
59
|
+
return _context.a(2);
|
|
60
|
+
case 5:
|
|
61
|
+
if (!(!target || typeof target.url !== 'string')) {
|
|
62
|
+
_context.n = 6;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'A payment URL is required.');
|
|
66
|
+
case 6:
|
|
67
|
+
redirect.open(target.url);
|
|
68
|
+
case 7:
|
|
69
|
+
return _context.a(2);
|
|
70
|
+
}
|
|
71
|
+
}, _callee);
|
|
72
|
+
}));
|
|
73
|
+
return function (_x) {
|
|
74
|
+
return _ref.apply(this, arguments);
|
|
75
|
+
};
|
|
76
|
+
}());
|
|
77
|
+
});
|
|
78
|
+
var closeCheckout = useLatestCallback(function () {
|
|
79
|
+
execution.cancel();
|
|
80
|
+
redirect.close();
|
|
81
|
+
});
|
|
82
|
+
return _objectSpread(_objectSpread({}, execution), {}, {
|
|
83
|
+
openCheckout: openCheckout,
|
|
84
|
+
closeCheckout: closeCheckout
|
|
85
|
+
});
|
|
86
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import StripeCheckoutButton from './stripe-checkout-button';
|
|
1
2
|
import Stripe from './stripe';
|
|
2
3
|
import StripePopup from './stripe-popup';
|
|
3
4
|
import StripeButton from './stripe-button';
|
|
4
5
|
import StripeModal from './stripe-modal';
|
|
5
6
|
export * from './interface';
|
|
6
7
|
type StripeComponentType = typeof Stripe & {
|
|
8
|
+
CheckoutButton: typeof StripeCheckoutButton;
|
|
7
9
|
Button: typeof StripeButton;
|
|
8
10
|
Popup: typeof StripePopup;
|
|
9
11
|
Modal: typeof StripeModal;
|
|
@@ -11,3 +13,5 @@ type StripeComponentType = typeof Stripe & {
|
|
|
11
13
|
declare const StripeComponent: StripeComponentType;
|
|
12
14
|
export default StripeComponent;
|
|
13
15
|
export { StripeButton, StripePopup, StripeModal };
|
|
16
|
+
export { StripeCheckoutButton };
|
|
17
|
+
export { useStripeCheckout } from './hooks/useStripeCheckout';
|