pay-sdk-react 1.1.14 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +241 -78
- package/README.zh-CN.md +243 -79
- package/dist/css/index.css +11 -0
- package/dist/css/index.min.css +1 -1
- package/dist/es/Airwallex/airwallex-button.js +48 -16
- package/dist/es/Airwallex/airwallex-checkout-button.d.ts +4 -0
- package/dist/es/Airwallex/airwallex-checkout-button.js +73 -0
- package/dist/es/Airwallex/airwallex-managed.d.ts +4 -0
- package/dist/es/Airwallex/airwallex-managed.js +87 -0
- package/dist/es/Airwallex/airwallex-modal.js +7 -3
- package/dist/es/Airwallex/airwallex-popup.js +7 -3
- package/dist/es/Airwallex/airwallex.d.ts +1 -3
- package/dist/es/Airwallex/airwallex.js +10 -1
- package/dist/es/Airwallex/hooks/useAirwallexCheckout.d.ts +7 -0
- package/dist/es/Airwallex/hooks/useAirwallexCheckout.js +155 -0
- package/dist/es/Airwallex/index.d.ts +4 -0
- package/dist/es/Airwallex/index.js +5 -1
- package/dist/es/Airwallex/interface.d.ts +146 -0
- package/dist/es/Alipay/alipay-button.js +26 -7
- package/dist/es/Alipay/alipay.js +39 -12
- package/dist/es/Alipay/interface.d.ts +26 -1
- package/dist/es/Paypal/index.d.ts +2 -0
- package/dist/es/Paypal/index.js +3 -1
- package/dist/es/Paypal/interface.d.ts +40 -0
- package/dist/es/Paypal/paypal-button.js +24 -3
- package/dist/es/Paypal/paypal-smart-button.d.ts +4 -0
- package/dist/es/Paypal/paypal-smart-button.js +48 -0
- package/dist/es/Payssion/interface.d.ts +7 -0
- package/dist/es/Payssion/payssion-button.js +25 -4
- package/dist/es/Pix/interface.d.ts +67 -0
- package/dist/es/Pix/pix-button.js +26 -7
- package/dist/es/Pix/pix-enhanced.d.ts +4 -0
- package/dist/es/Pix/pix-enhanced.js +182 -0
- package/dist/es/Pix/pix.d.ts +1 -1
- package/dist/es/Pix/pix.js +6 -1
- package/dist/es/Pix/style/index.css +11 -0
- package/dist/es/Pix/style/index.min.css +1 -1
- package/dist/es/Stripe/hooks/useStripeCheckout.d.ts +7 -0
- package/dist/es/Stripe/hooks/useStripeCheckout.js +86 -0
- package/dist/es/Stripe/index.d.ts +4 -0
- package/dist/es/Stripe/index.js +5 -1
- package/dist/es/Stripe/interface.d.ts +120 -0
- package/dist/es/Stripe/stripe-button.js +32 -10
- package/dist/es/Stripe/stripe-checkout-button.d.ts +4 -0
- package/dist/es/Stripe/stripe-checkout-button.js +70 -0
- package/dist/es/Stripe/stripe-modal.js +19 -2
- package/dist/es/Stripe/stripe-popup.js +13 -2
- package/dist/es/Stripe/stripe.js +38 -4
- package/dist/es/Wechat/interface.d.ts +13 -0
- package/dist/es/Wechat/wechat-button.js +26 -7
- package/dist/es/Wechat/wechat-content.d.ts +4 -0
- package/dist/es/Wechat/wechat-content.js +61 -0
- package/dist/es/Wechat/wechat.d.ts +1 -1
- package/dist/es/Wechat/wechat.js +5 -1
- package/dist/es/hooks/useLatestCallback.d.ts +1 -0
- package/dist/es/hooks/useLatestCallback.js +8 -0
- package/dist/es/hooks/useManagedOrder.d.ts +8 -0
- package/dist/es/hooks/useManagedOrder.js +67 -0
- package/dist/es/hooks/usePaymentExecution.d.ts +13 -0
- package/dist/es/hooks/usePaymentExecution.js +176 -0
- package/dist/es/hooks/usePaymentQr.d.ts +6 -0
- package/dist/es/hooks/usePaymentQr.js +52 -0
- package/dist/es/hooks/usePaymentRedirect.d.ts +5 -0
- package/dist/es/hooks/usePaymentRedirect.js +83 -0
- package/dist/es/index.d.ts +33 -6
- package/dist/es/index.js +19 -1
- package/dist/es/pay-modal/interface.d.ts +22 -2
- package/dist/es/pay-modal/pay-modal.js +36 -16
- package/dist/es/shared/entitys/payment.d.ts +227 -0
- package/dist/es/shared/entitys/payment.js +75 -0
- package/dist/es/shared/enums/index.d.ts +1 -88
- package/dist/es/shared/enums/index.js +1 -91
- package/dist/es/shared/enums/payment.d.ts +162 -0
- package/dist/es/shared/enums/payment.js +168 -0
- package/dist/es/shared/index.d.ts +2 -0
- package/dist/es/shared/index.js +2 -1
- package/dist/lib/Airwallex/airwallex-button.js +31 -10
- package/dist/lib/Airwallex/airwallex-checkout-button.js +52 -0
- package/dist/lib/Airwallex/airwallex-managed.js +86 -0
- package/dist/lib/Airwallex/airwallex-modal.js +4 -2
- package/dist/lib/Airwallex/airwallex-popup.js +4 -2
- package/dist/lib/Airwallex/airwallex.js +9 -1
- package/dist/lib/Airwallex/hooks/useAirwallexCheckout.js +83 -0
- package/dist/lib/Airwallex/index.js +18 -1
- package/dist/lib/Alipay/alipay-button.js +21 -6
- package/dist/lib/Alipay/alipay.js +36 -9
- package/dist/lib/Paypal/index.js +17 -1
- package/dist/lib/Paypal/paypal-button.js +19 -2
- package/dist/lib/Paypal/paypal-smart-button.js +45 -0
- package/dist/lib/Payssion/payssion-button.js +20 -3
- package/dist/lib/Pix/pix-button.js +21 -6
- package/dist/lib/Pix/pix-enhanced.js +143 -0
- package/dist/lib/Pix/pix.js +6 -1
- package/dist/lib/Pix/style/index.css +11 -0
- package/dist/lib/Pix/style/index.min.css +1 -1
- package/dist/lib/Stripe/hooks/useStripeCheckout.js +41 -0
- package/dist/lib/Stripe/index.js +18 -1
- package/dist/lib/Stripe/stripe-button.js +28 -10
- package/dist/lib/Stripe/stripe-checkout-button.js +50 -0
- package/dist/lib/Stripe/stripe-modal.js +12 -1
- package/dist/lib/Stripe/stripe-popup.js +12 -1
- package/dist/lib/Stripe/stripe.js +30 -1
- package/dist/lib/Wechat/wechat-button.js +21 -6
- package/dist/lib/Wechat/wechat-content.js +65 -0
- package/dist/lib/Wechat/wechat.js +3 -1
- package/dist/lib/hooks/useLatestCallback.js +13 -0
- package/dist/lib/hooks/useManagedOrder.js +29 -0
- package/dist/lib/hooks/usePaymentExecution.js +113 -0
- package/dist/lib/hooks/usePaymentQr.js +51 -0
- package/dist/lib/hooks/usePaymentRedirect.js +87 -0
- package/dist/lib/index.js +57 -1
- package/dist/lib/pay-modal/pay-modal.js +33 -16
- package/dist/lib/shared/entitys/payment.js +61 -0
- package/dist/lib/shared/enums/index.js +11 -91
- package/dist/lib/shared/enums/payment.js +172 -0
- package/dist/lib/shared/index.js +12 -1
- package/dist/umd/pay-sdk-react.umd.js +6488 -7731
- package/dist/umd/pay-sdk-react.umd.js.map +1 -1
- package/package.json +17 -3
package/dist/es/Stripe/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
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
|
var StripeComponent = Object.assign({}, Stripe, {
|
|
8
|
+
CheckoutButton: StripeCheckoutButton,
|
|
7
9
|
Button: StripeButton,
|
|
8
10
|
Popup: StripePopup,
|
|
9
11
|
Modal: StripeModal
|
|
10
12
|
});
|
|
11
13
|
export default StripeComponent;
|
|
12
|
-
export { StripeButton, StripePopup, StripeModal };
|
|
14
|
+
export { StripeButton, StripePopup, StripeModal };
|
|
15
|
+
export { StripeCheckoutButton };
|
|
16
|
+
export { useStripeCheckout } from './hooks/useStripeCheckout';
|
|
@@ -1,8 +1,46 @@
|
|
|
1
|
+
import type { CheckoutSource, PaymentExecutionOptions, PaymentExecutionReturn, PaymentExecutionResult, PaymentRedirectOptions } from '../shared/entitys/payment';
|
|
1
2
|
import { ButtonProps, ButtonRef } from '../Button';
|
|
2
3
|
import { HTMLAttributes } from 'react';
|
|
3
4
|
import { PayModalProps } from '../pay-modal';
|
|
4
5
|
import { PayPopupBaseProps } from '../pay-popup';
|
|
6
|
+
/**
|
|
7
|
+
* @zh 内嵌执行事件,不代表业务订单状态。
|
|
8
|
+
* @en Embedded execution events, not order state.
|
|
9
|
+
* @since 1.2.0
|
|
10
|
+
*/
|
|
11
|
+
export interface StripeCheckoutEvents {
|
|
12
|
+
/**
|
|
13
|
+
* @zh Stripe.js 初始化完成,不表示 iframe 已可见。
|
|
14
|
+
* @en Stripe.js initialized, not iframe visibility.
|
|
15
|
+
* @since 1.2.0
|
|
16
|
+
*/
|
|
17
|
+
onInitialized?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* @zh Stripe.js 初始化失败。
|
|
20
|
+
* @en Stripe.js initialization failed.
|
|
21
|
+
* @since 1.2.0
|
|
22
|
+
*/
|
|
23
|
+
onInitializationError?: () => void;
|
|
24
|
+
/**
|
|
25
|
+
* @zh Stripe 报告内嵌结账完成,业务仍需确认订单。
|
|
26
|
+
* @en Stripe reports checkout completion; the caller still verifies the order.
|
|
27
|
+
* @since 1.2.0
|
|
28
|
+
*/
|
|
29
|
+
onComplete?: () => void;
|
|
30
|
+
}
|
|
5
31
|
export interface BasesStripeProps {
|
|
32
|
+
/**
|
|
33
|
+
* @zh 内嵌事件配置。
|
|
34
|
+
* @en Embedded events.
|
|
35
|
+
* @since 1.2.0
|
|
36
|
+
*/
|
|
37
|
+
checkoutEvents?: StripeCheckoutEvents;
|
|
38
|
+
/**
|
|
39
|
+
* @zh 显式更换会话实例。
|
|
40
|
+
* @en Explicit session instance key.
|
|
41
|
+
* @since 1.2.0
|
|
42
|
+
*/
|
|
43
|
+
instanceKey?: string;
|
|
6
44
|
/**
|
|
7
45
|
* @zh Stripe 支付的 clientSecret
|
|
8
46
|
* @en The clientSecret for Stripe payment
|
|
@@ -28,6 +66,12 @@ export type StripeProps = BasesStripeProps & HTMLAttributes<HTMLDivElement>;
|
|
|
28
66
|
* @en Props for Stripe popup component
|
|
29
67
|
*/
|
|
30
68
|
export interface StripePopupProps extends PayPopupBaseProps {
|
|
69
|
+
/**
|
|
70
|
+
* @zh 完成后关闭,默认 false。
|
|
71
|
+
* @en Close on completion, default false.
|
|
72
|
+
* @since 1.2.0
|
|
73
|
+
*/
|
|
74
|
+
closeOnComplete?: boolean;
|
|
31
75
|
/**
|
|
32
76
|
* @zh Stripe 属性
|
|
33
77
|
* @en Stripe props
|
|
@@ -58,6 +102,12 @@ export interface StripePopupRef {
|
|
|
58
102
|
*/
|
|
59
103
|
export type CreateOrderStripeFn = () => Promise<BasesStripeProps>;
|
|
60
104
|
export interface StripeButtonProps extends ButtonProps {
|
|
105
|
+
/**
|
|
106
|
+
* @zh 显式启用受管理的 createOrder 流程;未传保持旧行为。
|
|
107
|
+
* @en Opt-in managed createOrder execution; omitted preserves legacy behavior.
|
|
108
|
+
* @since 1.2.0
|
|
109
|
+
*/
|
|
110
|
+
executionOptions?: PaymentExecutionOptions;
|
|
61
111
|
/**
|
|
62
112
|
* @zh 显示类型,默认值为 "modal"
|
|
63
113
|
* @en Display type, default is "modal"
|
|
@@ -103,6 +153,12 @@ export interface StripeButtonRef extends ButtonRef {
|
|
|
103
153
|
closePopup: () => void;
|
|
104
154
|
}
|
|
105
155
|
export interface StripeModalProps extends PayModalProps {
|
|
156
|
+
/**
|
|
157
|
+
* @zh 完成后关闭,默认 false。
|
|
158
|
+
* @en Close on completion, default false.
|
|
159
|
+
* @since 1.2.0
|
|
160
|
+
*/
|
|
161
|
+
closeOnComplete?: boolean;
|
|
106
162
|
/**
|
|
107
163
|
* @zh Stripe 属性
|
|
108
164
|
* @en Stripe props
|
|
@@ -110,3 +166,67 @@ export interface StripeModalProps extends PayModalProps {
|
|
|
110
166
|
stripeProps?: BasesStripeProps;
|
|
111
167
|
}
|
|
112
168
|
export type StripeModalRef = StripePopupRef;
|
|
169
|
+
/**
|
|
170
|
+
* @zh Stripe 托管支付目标,无需公钥。
|
|
171
|
+
* @en Hosted Stripe target, no publishable key required.
|
|
172
|
+
* @since 1.2.0
|
|
173
|
+
*/
|
|
174
|
+
export interface StripeCheckoutTarget {
|
|
175
|
+
/**
|
|
176
|
+
* @zh 托管支付 HTTP(S) 地址。
|
|
177
|
+
* @en Hosted payment HTTP(S) URL.
|
|
178
|
+
* @since 1.2.0
|
|
179
|
+
*/
|
|
180
|
+
url: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* @zh 托管执行配置,默认不自动打开。
|
|
184
|
+
* @en Hosted execution options; never opens on mount.
|
|
185
|
+
* @since 1.2.0
|
|
186
|
+
*/
|
|
187
|
+
export interface UseStripeCheckoutOptions extends PaymentExecutionOptions {
|
|
188
|
+
/**
|
|
189
|
+
* @zh URL 打开模式与窗口事件配置。
|
|
190
|
+
* @en URL opening mode and window events.
|
|
191
|
+
* @since 1.2.0
|
|
192
|
+
*/
|
|
193
|
+
redirectOptions?: PaymentRedirectOptions;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* @zh 执行结果不代表订单支付成功。
|
|
197
|
+
* @en Execution result is not order success.
|
|
198
|
+
* @since 1.2.0
|
|
199
|
+
*/
|
|
200
|
+
export interface UseStripeCheckoutReturn extends PaymentExecutionReturn {
|
|
201
|
+
/**
|
|
202
|
+
* @zh 显式执行目标或创建回调,返回前端阶段结果。
|
|
203
|
+
* @en Execute a target or factory and return its frontend result.
|
|
204
|
+
* @since 1.2.0
|
|
205
|
+
*/
|
|
206
|
+
openCheckout: (source: CheckoutSource<StripeCheckoutTarget>) => Promise<PaymentExecutionResult>;
|
|
207
|
+
/**
|
|
208
|
+
* @zh 取消待执行任务并关闭当前实例拥有的窗口。
|
|
209
|
+
* @en Cancel pending execution and close the owned window.
|
|
210
|
+
* @since 1.2.0
|
|
211
|
+
*/
|
|
212
|
+
closeCheckout: () => void;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @zh Stripe 托管支付按钮。
|
|
216
|
+
* @en Hosted Stripe checkout button.
|
|
217
|
+
* @since 1.2.0
|
|
218
|
+
*/
|
|
219
|
+
export interface StripeCheckoutButtonProps extends ButtonProps, UseStripeCheckoutOptions {
|
|
220
|
+
/**
|
|
221
|
+
* @zh 托管支付 HTTP(S) 地址。
|
|
222
|
+
* @en Hosted payment HTTP(S) URL.
|
|
223
|
+
* @since 1.2.0
|
|
224
|
+
*/
|
|
225
|
+
url?: string;
|
|
226
|
+
/**
|
|
227
|
+
* @zh 由点击触发的异步目标创建回调,null 表示取消。
|
|
228
|
+
* @en Click-triggered async target factory; null cancels.
|
|
229
|
+
* @since 1.2.0
|
|
230
|
+
*/
|
|
231
|
+
createOrder?: (signal: AbortSignal) => Promise<StripeCheckoutTarget | null>;
|
|
232
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["children", "onClick", "displayType", "stripePopupProps", "stripeModalProps", "createOrder"];
|
|
1
|
+
var _excluded = ["children", "onClick", "displayType", "stripePopupProps", "stripeModalProps", "createOrder", "executionOptions"];
|
|
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 StripePopup from './stripe-popup';
|
|
11
12
|
import StripeModal from './stripe-modal';
|
|
@@ -19,6 +20,7 @@ var StripeButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
19
20
|
stripePopupProps = props.stripePopupProps,
|
|
20
21
|
stripeModalProps = props.stripeModalProps,
|
|
21
22
|
createOrder = props.createOrder,
|
|
23
|
+
executionOptions = props.executionOptions,
|
|
22
24
|
others = _objectWithoutProperties(props, _excluded);
|
|
23
25
|
var stripeButtonRef = useRef(null);
|
|
24
26
|
var stripePopupRef = useRef(null);
|
|
@@ -35,6 +37,7 @@ var StripeButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
35
37
|
},
|
|
36
38
|
closePopup: function 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: function openModal(options) {
|
|
@@ -43,13 +46,23 @@ var StripeButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
43
46
|
},
|
|
44
47
|
closeModal: function 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
|
};
|
|
50
54
|
});
|
|
55
|
+
var managed = useManagedOrder(createOrder, function (target) {
|
|
56
|
+
if (target.clientSecret && target.stripeKey) {
|
|
57
|
+
var _stripeModalRef$curre3, _stripePopupRef$curre3;
|
|
58
|
+
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);
|
|
59
|
+
}
|
|
60
|
+
}, executionOptions, function (target) {
|
|
61
|
+
return typeof target.clientSecret === 'string' && Boolean(target.clientSecret.trim()) && typeof target.stripeKey === 'string' && Boolean(target.stripeKey.trim());
|
|
62
|
+
});
|
|
63
|
+
var managedRun = managed.run;
|
|
51
64
|
var handlePayCreateOrder = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
52
|
-
var options, _stripeModalRef$
|
|
65
|
+
var options, _stripeModalRef$curre4, _stripePopupRef$curre4;
|
|
53
66
|
return _regenerator().w(function (_context) {
|
|
54
67
|
while (1) switch (_context.n) {
|
|
55
68
|
case 0:
|
|
@@ -64,9 +77,9 @@ var StripeButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
64
77
|
if (options !== null && options !== void 0 && options.clientSecret && options !== null && options !== void 0 && options.stripeKey) {
|
|
65
78
|
// 2. 唤起弹窗
|
|
66
79
|
if (displayType === 'modal') {
|
|
67
|
-
(_stripeModalRef$
|
|
80
|
+
(_stripeModalRef$curre4 = stripeModalRef.current) === null || _stripeModalRef$curre4 === void 0 || _stripeModalRef$curre4.open(options);
|
|
68
81
|
} else {
|
|
69
|
-
(_stripePopupRef$
|
|
82
|
+
(_stripePopupRef$curre4 = stripePopupRef.current) === null || _stripePopupRef$curre4 === void 0 || _stripePopupRef$curre4.open(options);
|
|
70
83
|
}
|
|
71
84
|
}
|
|
72
85
|
case 2:
|
|
@@ -76,6 +89,13 @@ var StripeButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
76
89
|
})), [createOrder, displayType]);
|
|
77
90
|
var handleClick = useCallback(function (e) {
|
|
78
91
|
if (createOrder) {
|
|
92
|
+
if (executionOptions) {
|
|
93
|
+
onClick === null || onClick === void 0 || onClick(e);
|
|
94
|
+
if (e.defaultPrevented) return;
|
|
95
|
+
return managedRun().then(function () {
|
|
96
|
+
return undefined;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
79
99
|
handlePayCreateOrder();
|
|
80
100
|
} else {
|
|
81
101
|
if (displayType === 'modal') {
|
|
@@ -83,25 +103,27 @@ var StripeButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
83
103
|
var clientSecret = stripeModalProps === null || stripeModalProps === void 0 || (_stripeModalProps$str = stripeModalProps.stripeProps) === null || _stripeModalProps$str === void 0 ? void 0 : _stripeModalProps$str.clientSecret;
|
|
84
104
|
var stripeKey = stripeModalProps === null || stripeModalProps === void 0 || (_stripeModalProps$str2 = stripeModalProps.stripeProps) === null || _stripeModalProps$str2 === void 0 ? void 0 : _stripeModalProps$str2.stripeKey;
|
|
85
105
|
if (clientSecret && stripeKey) {
|
|
86
|
-
var _stripeModalRef$
|
|
87
|
-
stripeModalRef === null || stripeModalRef === void 0 || (_stripeModalRef$
|
|
106
|
+
var _stripeModalRef$curre5;
|
|
107
|
+
stripeModalRef === null || stripeModalRef === void 0 || (_stripeModalRef$curre5 = stripeModalRef.current) === null || _stripeModalRef$curre5 === void 0 || _stripeModalRef$curre5.open();
|
|
88
108
|
}
|
|
89
109
|
} else {
|
|
90
110
|
var _stripePopupProps$str, _stripePopupProps$str2;
|
|
91
111
|
var _clientSecret = stripePopupProps === null || stripePopupProps === void 0 || (_stripePopupProps$str = stripePopupProps.stripeProps) === null || _stripePopupProps$str === void 0 ? void 0 : _stripePopupProps$str.clientSecret;
|
|
92
112
|
var _stripeKey = stripePopupProps === null || stripePopupProps === void 0 || (_stripePopupProps$str2 = stripePopupProps.stripeProps) === null || _stripePopupProps$str2 === void 0 ? void 0 : _stripePopupProps$str2.stripeKey;
|
|
93
113
|
if (_clientSecret && _stripeKey) {
|
|
94
|
-
var _stripePopupRef$
|
|
95
|
-
stripePopupRef === null || stripePopupRef === void 0 || (_stripePopupRef$
|
|
114
|
+
var _stripePopupRef$curre5;
|
|
115
|
+
stripePopupRef === null || stripePopupRef === void 0 || (_stripePopupRef$curre5 = stripePopupRef.current) === null || _stripePopupRef$curre5 === void 0 || _stripePopupRef$curre5.open();
|
|
96
116
|
}
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
onClick === null || onClick === void 0 || onClick(e);
|
|
100
|
-
}, [onClick, createOrder, handlePayCreateOrder, displayType, stripeModalProps, stripePopupProps]);
|
|
120
|
+
}, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, displayType, stripeModalProps, stripePopupProps]);
|
|
101
121
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({
|
|
102
122
|
ref: stripeButtonRef,
|
|
103
123
|
onClick: handleClick
|
|
104
|
-
}, others
|
|
124
|
+
}, others, {
|
|
125
|
+
loading: executionOptions ? managed.loading || others.loading : others.loading
|
|
126
|
+
}), children), displayType === 'popup' && /*#__PURE__*/React.createElement(StripePopup, _extends({
|
|
105
127
|
ref: stripePopupRef
|
|
106
128
|
}, stripePopupProps)), displayType === 'modal' && /*#__PURE__*/React.createElement(StripeModal, _extends({
|
|
107
129
|
ref: stripeModalRef
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
var _excluded = ["url", "createOrder", "redirectOptions", "beforePay", "onLoadingChange", "onPaymentError", "onCancel", "children", "onClick", "loading"];
|
|
4
|
+
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); }
|
|
5
|
+
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 }; })(); }
|
|
6
|
+
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); }
|
|
7
|
+
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); }
|
|
8
|
+
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); }); }; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import Button from '../Button';
|
|
13
|
+
import { useStripeCheckout } from './hooks/useStripeCheckout';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @zh Stripe 托管支付按钮,复用 useStripeCheckout。
|
|
17
|
+
* @en Hosted Stripe button sharing useStripeCheckout.
|
|
18
|
+
* @since 1.2.0
|
|
19
|
+
*/
|
|
20
|
+
var StripeCheckoutButton = function StripeCheckoutButton(props) {
|
|
21
|
+
var url = props.url,
|
|
22
|
+
createOrder = props.createOrder,
|
|
23
|
+
redirectOptions = props.redirectOptions,
|
|
24
|
+
beforePay = props.beforePay,
|
|
25
|
+
onLoadingChange = props.onLoadingChange,
|
|
26
|
+
onPaymentError = props.onPaymentError,
|
|
27
|
+
onCancel = props.onCancel,
|
|
28
|
+
_props$children = props.children,
|
|
29
|
+
children = _props$children === void 0 ? 'Stripe' : _props$children,
|
|
30
|
+
onClick = props.onClick,
|
|
31
|
+
loading = props.loading,
|
|
32
|
+
buttonProps = _objectWithoutProperties(props, _excluded);
|
|
33
|
+
var checkout = useStripeCheckout({
|
|
34
|
+
redirectOptions: redirectOptions,
|
|
35
|
+
beforePay: beforePay,
|
|
36
|
+
onLoadingChange: onLoadingChange,
|
|
37
|
+
onPaymentError: onPaymentError,
|
|
38
|
+
onCancel: onCancel
|
|
39
|
+
});
|
|
40
|
+
return /*#__PURE__*/React.createElement(Button, _extends({}, buttonProps, {
|
|
41
|
+
loading: checkout.loading || loading,
|
|
42
|
+
onClick: (/*#__PURE__*/function () {
|
|
43
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(event) {
|
|
44
|
+
return _regenerator().w(function (_context) {
|
|
45
|
+
while (1) switch (_context.n) {
|
|
46
|
+
case 0:
|
|
47
|
+
event.persist();
|
|
48
|
+
_context.n = 1;
|
|
49
|
+
return onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
50
|
+
case 1:
|
|
51
|
+
if (event.defaultPrevented) {
|
|
52
|
+
_context.n = 2;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
_context.n = 2;
|
|
56
|
+
return checkout.openCheckout(createOrder !== null && createOrder !== void 0 ? createOrder : {
|
|
57
|
+
url: url !== null && url !== void 0 ? url : ''
|
|
58
|
+
});
|
|
59
|
+
case 2:
|
|
60
|
+
return _context.a(2);
|
|
61
|
+
}
|
|
62
|
+
}, _callee);
|
|
63
|
+
}));
|
|
64
|
+
return function (_x) {
|
|
65
|
+
return _ref.apply(this, arguments);
|
|
66
|
+
};
|
|
67
|
+
}())
|
|
68
|
+
}), children);
|
|
69
|
+
};
|
|
70
|
+
export default /*#__PURE__*/React.memo(StripeCheckoutButton);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
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
|
+
var _excluded = ["stripeProps", "visible", "onClose", "closeOnComplete", "className"];
|
|
2
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
|
+
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); }
|
|
3
9
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
4
10
|
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."); }
|
|
5
11
|
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; } }
|
|
@@ -17,6 +23,8 @@ var StripeModal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
17
23
|
var propsStripeProps = props.stripeProps,
|
|
18
24
|
visible = props.visible,
|
|
19
25
|
_onClose = props.onClose,
|
|
26
|
+
_props$closeOnComplet = props.closeOnComplete,
|
|
27
|
+
closeOnComplete = _props$closeOnComplet === void 0 ? false : _props$closeOnComplet,
|
|
20
28
|
className = props.className,
|
|
21
29
|
rest = _objectWithoutProperties(props, _excluded);
|
|
22
30
|
var stripeRef = useRef(null);
|
|
@@ -56,7 +64,16 @@ var StripeModal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
56
64
|
_onClose === null || _onClose === void 0 || _onClose();
|
|
57
65
|
},
|
|
58
66
|
footer: null
|
|
59
|
-
}, rest), _stripeProps && /*#__PURE__*/React.createElement(Stripe, _stripeProps
|
|
67
|
+
}, rest), _stripeProps && /*#__PURE__*/React.createElement(Stripe, _extends({}, _stripeProps, {
|
|
68
|
+
checkoutEvents: closeOnComplete ? _objectSpread(_objectSpread({}, _stripeProps.checkoutEvents), {}, {
|
|
69
|
+
onComplete: function onComplete() {
|
|
70
|
+
var _stripeProps$checkout, _stripeProps$checkout2;
|
|
71
|
+
(_stripeProps$checkout = _stripeProps.checkoutEvents) === null || _stripeProps$checkout === void 0 || (_stripeProps$checkout2 = _stripeProps$checkout.onComplete) === null || _stripeProps$checkout2 === void 0 || _stripeProps$checkout2.call(_stripeProps$checkout);
|
|
72
|
+
if (!isControlled) setUncontrolledVisible(false);
|
|
73
|
+
_onClose === null || _onClose === void 0 || _onClose();
|
|
74
|
+
}
|
|
75
|
+
}) : _stripeProps.checkoutEvents
|
|
76
|
+
})));
|
|
60
77
|
});
|
|
61
78
|
StripeModal.displayName = 'StripeModal';
|
|
62
79
|
export default /*#__PURE__*/memo(StripeModal);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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
|
-
var _excluded = ["visible", "onClose", "closeOnMaskClick", "className", "bodyStyle", "stripeProps"];
|
|
2
|
+
var _excluded = ["visible", "onClose", "closeOnComplete", "closeOnMaskClick", "className", "bodyStyle", "stripeProps"];
|
|
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 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
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; }
|
|
@@ -22,6 +22,8 @@ import { getPrefixCls } from '../utils/getPrefixCls';
|
|
|
22
22
|
var StripePopup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
23
23
|
var controlledVisible = props.visible,
|
|
24
24
|
_onClose = props.onClose,
|
|
25
|
+
_props$closeOnComplet = props.closeOnComplete,
|
|
26
|
+
closeOnComplete = _props$closeOnComplet === void 0 ? false : _props$closeOnComplet,
|
|
25
27
|
_props$closeOnMaskCli = props.closeOnMaskClick,
|
|
26
28
|
closeOnMaskClick = _props$closeOnMaskCli === void 0 ? true : _props$closeOnMaskCli,
|
|
27
29
|
className = props.className,
|
|
@@ -69,7 +71,16 @@ var StripePopup = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
69
71
|
height: '40vh',
|
|
70
72
|
overflowY: 'scroll'
|
|
71
73
|
}, bodyStyle)
|
|
72
|
-
}, others), _stripeProps && /*#__PURE__*/React.createElement(Stripe, _stripeProps
|
|
74
|
+
}, others), _stripeProps && /*#__PURE__*/React.createElement(Stripe, _extends({}, _stripeProps, {
|
|
75
|
+
checkoutEvents: closeOnComplete ? _objectSpread(_objectSpread({}, _stripeProps.checkoutEvents), {}, {
|
|
76
|
+
onComplete: function onComplete() {
|
|
77
|
+
var _stripeProps$checkout, _stripeProps$checkout2;
|
|
78
|
+
(_stripeProps$checkout = _stripeProps.checkoutEvents) === null || _stripeProps$checkout === void 0 || (_stripeProps$checkout2 = _stripeProps$checkout.onComplete) === null || _stripeProps$checkout2 === void 0 || _stripeProps$checkout2.call(_stripeProps$checkout);
|
|
79
|
+
if (!isControlled) setUncontrolledVisible(false);
|
|
80
|
+
_onClose === null || _onClose === void 0 || _onClose();
|
|
81
|
+
}
|
|
82
|
+
}) : _stripeProps.checkoutEvents
|
|
83
|
+
})));
|
|
73
84
|
});
|
|
74
85
|
StripePopup.displayName = 'StripePopup';
|
|
75
86
|
export default /*#__PURE__*/memo(StripePopup);
|
package/dist/es/Stripe/stripe.js
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
|
|
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
|
+
var _excluded = ["stripeKey", "clientSecret", "checkoutEvents", "instanceKey", "className"];
|
|
2
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
|
+
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); }
|
|
3
9
|
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; }
|
|
4
10
|
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; }
|
|
5
|
-
import React, { memo, useImperativeHandle, useMemo, useRef } from 'react';
|
|
11
|
+
import React, { memo, useImperativeHandle, useMemo, useEffect, useRef } from 'react';
|
|
6
12
|
import { EmbeddedCheckout, EmbeddedCheckoutProvider } from '@stripe/react-stripe-js';
|
|
7
13
|
import { loadStripe } from '@stripe/stripe-js';
|
|
14
|
+
import { useLatestCallback } from '../hooks/useLatestCallback';
|
|
8
15
|
import cs from '../utils/classNames';
|
|
9
16
|
import { getPrefixCls } from '../utils/getPrefixCls';
|
|
10
17
|
var Stripe = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
11
18
|
var stripeKey = props.stripeKey,
|
|
12
19
|
clientSecret = props.clientSecret,
|
|
20
|
+
checkoutEvents = props.checkoutEvents,
|
|
21
|
+
instanceKey = props.instanceKey,
|
|
13
22
|
_props$className = props.className,
|
|
14
23
|
className = _props$className === void 0 ? '' : _props$className,
|
|
15
24
|
others = _objectWithoutProperties(props, _excluded);
|
|
25
|
+
var events = useRef(checkoutEvents);
|
|
26
|
+
events.current = checkoutEvents;
|
|
27
|
+
var onComplete = useLatestCallback(function () {
|
|
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
|
+
});
|
|
16
31
|
var stripeRef = useRef(null);
|
|
17
32
|
useImperativeHandle(ref, function () {
|
|
18
33
|
return stripeRef.current;
|
|
@@ -23,16 +38,35 @@ var Stripe = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
23
38
|
}
|
|
24
39
|
return loadStripe === null || loadStripe === void 0 ? void 0 : loadStripe(stripeKey);
|
|
25
40
|
}, [stripeKey]);
|
|
41
|
+
var observeCheckout = Boolean(checkoutEvents);
|
|
42
|
+
useEffect(function () {
|
|
43
|
+
if (!observeCheckout || !stripePromise) return;
|
|
44
|
+
var active = true;
|
|
45
|
+
Promise.resolve(stripePromise).then(function (instance) {
|
|
46
|
+
var _events$current2, _events$current2$onIn, _events$current3, _events$current3$onIn;
|
|
47
|
+
if (!active) return;
|
|
48
|
+
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);
|
|
49
|
+
}).catch(function () {
|
|
50
|
+
var _events$current4, _events$current4$onIn;
|
|
51
|
+
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);
|
|
52
|
+
});
|
|
53
|
+
return function () {
|
|
54
|
+
active = false;
|
|
55
|
+
};
|
|
56
|
+
}, [stripePromise, observeCheckout]);
|
|
26
57
|
var classNames = cs(getPrefixCls('pay-stripe'), className);
|
|
27
58
|
return /*#__PURE__*/React.createElement("div", _extends({
|
|
28
59
|
ref: stripeRef
|
|
29
60
|
}, others, {
|
|
30
61
|
className: classNames
|
|
31
62
|
}), clientSecret && stripePromise && /*#__PURE__*/React.createElement(EmbeddedCheckoutProvider, {
|
|
63
|
+
key: instanceKey,
|
|
32
64
|
stripe: stripePromise,
|
|
33
|
-
options: {
|
|
65
|
+
options: _objectSpread({
|
|
34
66
|
clientSecret: clientSecret
|
|
35
|
-
}
|
|
67
|
+
}, observeCheckout ? {
|
|
68
|
+
onComplete: onComplete
|
|
69
|
+
} : {})
|
|
36
70
|
}, /*#__PURE__*/React.createElement(EmbeddedCheckout, null)));
|
|
37
71
|
});
|
|
38
72
|
Stripe.displayName = 'Stripe';
|
|
@@ -1,7 +1,14 @@
|
|
|
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 WechatProps {
|
|
6
|
+
/**
|
|
7
|
+
* @zh 启用可定制且受管理的二维码展示。
|
|
8
|
+
* @en Enable customizable managed QR content.
|
|
9
|
+
* @since 1.2.0
|
|
10
|
+
*/
|
|
11
|
+
qrProps?: PaymentQrAppearance;
|
|
5
12
|
/**
|
|
6
13
|
* @zh 传入的是二维码字符串还是二维码图片url
|
|
7
14
|
* @en Whether the input is a QR code string or a QR code image URL
|
|
@@ -31,6 +38,12 @@ export interface WechatProps {
|
|
|
31
38
|
style?: React.CSSProperties;
|
|
32
39
|
}
|
|
33
40
|
export interface WechatButtonProps extends ButtonProps {
|
|
41
|
+
/**
|
|
42
|
+
* @zh 显式启用受管理的 createOrder 流程;未传保持旧行为。
|
|
43
|
+
* @en Opt-in managed createOrder execution; omitted preserves legacy behavior.
|
|
44
|
+
* @since 1.2.0
|
|
45
|
+
*/
|
|
46
|
+
executionOptions?: PaymentExecutionOptions;
|
|
34
47
|
/**
|
|
35
48
|
* @zh 创建订单函数,返回 Paypal 所需参数
|
|
36
49
|
* @en Function to create order, returns Paypal required params
|