pay-sdk-react 1.1.13 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +465 -84
- package/README.zh-CN.md +466 -85
- package/dist/css/index.css +86 -6
- package/dist/css/index.min.css +1 -1
- package/dist/es/Airwallex/airwallex-button.js +48 -16
- package/dist/es/Airwallex/airwallex-checkout-button.d.ts +4 -0
- package/dist/es/Airwallex/airwallex-checkout-button.js +73 -0
- package/dist/es/Airwallex/airwallex-managed.d.ts +4 -0
- package/dist/es/Airwallex/airwallex-managed.js +87 -0
- package/dist/es/Airwallex/airwallex-modal.js +7 -3
- package/dist/es/Airwallex/airwallex-popup.js +7 -3
- package/dist/es/Airwallex/airwallex.d.ts +1 -3
- package/dist/es/Airwallex/airwallex.js +10 -1
- package/dist/es/Airwallex/hooks/useAirwallexCheckout.d.ts +7 -0
- package/dist/es/Airwallex/hooks/useAirwallexCheckout.js +155 -0
- package/dist/es/Airwallex/index.d.ts +4 -0
- package/dist/es/Airwallex/index.js +5 -1
- package/dist/es/Airwallex/interface.d.ts +146 -0
- package/dist/es/Airwallex/style/index.css +2 -2
- package/dist/es/Airwallex/style/index.min.css +1 -1
- package/dist/es/Alipay/alipay-button.js +26 -7
- package/dist/es/Alipay/alipay.js +39 -12
- package/dist/es/Alipay/interface.d.ts +26 -1
- package/dist/es/Alipay/style/index.css +2 -2
- package/dist/es/Alipay/style/index.min.css +1 -1
- package/dist/es/MAlipay/style/index.css +2 -2
- package/dist/es/MAlipay/style/index.min.css +1 -1
- package/dist/es/MPix/index.d.ts +2 -0
- package/dist/es/MPix/index.js +2 -0
- package/dist/es/MPix/interface.d.ts +44 -0
- package/dist/es/MPix/interface.js +1 -0
- package/dist/es/MPix/m-pix-button.d.ts +6 -0
- package/dist/es/MPix/m-pix-button.js +159 -0
- package/dist/es/MPix/style/index.css +256 -0
- package/dist/es/MPix/style/index.d.ts +1 -0
- package/dist/es/MPix/style/index.js +1 -0
- package/dist/es/MPix/style/index.min.css +1 -0
- package/dist/es/MWeChat/style/index.css +2 -2
- package/dist/es/MWeChat/style/index.min.css +1 -1
- package/dist/es/PayButton/index.js +12 -0
- package/dist/es/PayButton/interface.d.ts +28 -2
- package/dist/es/Paypal/index.d.ts +2 -0
- package/dist/es/Paypal/index.js +3 -1
- package/dist/es/Paypal/interface.d.ts +40 -0
- package/dist/es/Paypal/paypal-button.js +24 -3
- package/dist/es/Paypal/paypal-smart-button.d.ts +4 -0
- package/dist/es/Paypal/paypal-smart-button.js +48 -0
- package/dist/es/Payssion/interface.d.ts +7 -0
- package/dist/es/Payssion/payssion-button.js +25 -4
- package/dist/es/Pix/index.d.ts +11 -0
- package/dist/es/Pix/index.js +10 -0
- package/dist/es/Pix/interface.d.ts +147 -0
- package/dist/es/Pix/interface.js +1 -0
- package/dist/es/Pix/pix-button.d.ts +6 -0
- package/dist/es/Pix/pix-button.js +99 -0
- package/dist/es/Pix/pix-enhanced.d.ts +4 -0
- package/dist/es/Pix/pix-enhanced.js +182 -0
- package/dist/es/Pix/pix-modal.d.ts +6 -0
- package/dist/es/Pix/pix-modal.js +57 -0
- package/dist/es/Pix/pix.d.ts +4 -0
- package/dist/es/Pix/pix.js +125 -0
- package/dist/es/Pix/style/index.css +80 -0
- package/dist/es/Pix/style/index.d.ts +1 -0
- package/dist/es/Pix/style/index.js +1 -0
- package/dist/es/Pix/style/index.min.css +1 -0
- package/dist/es/Stripe/hooks/useStripeCheckout.d.ts +7 -0
- package/dist/es/Stripe/hooks/useStripeCheckout.js +86 -0
- package/dist/es/Stripe/index.d.ts +4 -0
- package/dist/es/Stripe/index.js +5 -1
- package/dist/es/Stripe/interface.d.ts +120 -0
- package/dist/es/Stripe/stripe-button.js +32 -10
- package/dist/es/Stripe/stripe-checkout-button.d.ts +4 -0
- package/dist/es/Stripe/stripe-checkout-button.js +70 -0
- package/dist/es/Stripe/stripe-modal.js +19 -2
- package/dist/es/Stripe/stripe-popup.js +13 -2
- package/dist/es/Stripe/stripe.js +38 -4
- package/dist/es/Stripe/style/index.css +2 -2
- package/dist/es/Stripe/style/index.min.css +1 -1
- package/dist/es/Wechat/interface.d.ts +13 -0
- package/dist/es/Wechat/style/index.css +2 -2
- package/dist/es/Wechat/style/index.min.css +1 -1
- package/dist/es/Wechat/wechat-button.js +26 -7
- package/dist/es/Wechat/wechat-content.d.ts +4 -0
- package/dist/es/Wechat/wechat-content.js +61 -0
- package/dist/es/Wechat/wechat.d.ts +1 -1
- package/dist/es/Wechat/wechat.js +5 -1
- package/dist/es/confirm-modal/style/index.css +2 -2
- package/dist/es/confirm-modal/style/index.min.css +1 -1
- package/dist/es/hooks/useLatestCallback.d.ts +1 -0
- package/dist/es/hooks/useLatestCallback.js +8 -0
- package/dist/es/hooks/useManagedOrder.d.ts +8 -0
- package/dist/es/hooks/useManagedOrder.js +67 -0
- package/dist/es/hooks/usePaymentExecution.d.ts +13 -0
- package/dist/es/hooks/usePaymentExecution.js +176 -0
- package/dist/es/hooks/usePaymentQr.d.ts +6 -0
- package/dist/es/hooks/usePaymentQr.js +52 -0
- package/dist/es/hooks/usePaymentRedirect.d.ts +5 -0
- package/dist/es/hooks/usePaymentRedirect.js +83 -0
- package/dist/es/icons/IconCheck/index.d.ts +4 -0
- package/dist/es/icons/IconCheck/index.js +22 -0
- package/dist/es/icons/IconCopy/index.d.ts +4 -0
- package/dist/es/icons/IconCopy/index.js +27 -0
- package/dist/es/icons/IconPix/index.d.ts +4 -0
- package/dist/es/icons/IconPix/index.js +33 -0
- package/dist/es/icons/index.d.ts +3 -0
- package/dist/es/icons/index.js +4 -1
- package/dist/es/index.d.ts +50 -6
- package/dist/es/index.js +28 -1
- package/dist/es/pay-modal/interface.d.ts +22 -2
- package/dist/es/pay-modal/pay-modal.js +36 -16
- package/dist/es/pay-modal/style/index.css +2 -2
- package/dist/es/pay-modal/style/index.min.css +1 -1
- package/dist/es/shared/entitys/payment.d.ts +227 -0
- package/dist/es/shared/entitys/payment.js +75 -0
- package/dist/es/shared/enums/index.d.ts +1 -78
- package/dist/es/shared/enums/index.js +1 -81
- package/dist/es/shared/enums/payment.d.ts +162 -0
- package/dist/es/shared/enums/payment.js +168 -0
- package/dist/es/shared/index.d.ts +2 -0
- package/dist/es/shared/index.js +2 -1
- package/dist/lib/Airwallex/airwallex-button.js +31 -10
- package/dist/lib/Airwallex/airwallex-checkout-button.js +52 -0
- package/dist/lib/Airwallex/airwallex-managed.js +86 -0
- package/dist/lib/Airwallex/airwallex-modal.js +4 -2
- package/dist/lib/Airwallex/airwallex-popup.js +4 -2
- package/dist/lib/Airwallex/airwallex.js +9 -1
- package/dist/lib/Airwallex/hooks/useAirwallexCheckout.js +83 -0
- package/dist/lib/Airwallex/index.js +18 -1
- package/dist/lib/Airwallex/style/index.css +2 -2
- package/dist/lib/Airwallex/style/index.min.css +1 -1
- package/dist/lib/Alipay/alipay-button.js +21 -6
- package/dist/lib/Alipay/alipay.js +36 -9
- package/dist/lib/Alipay/style/index.css +2 -2
- package/dist/lib/Alipay/style/index.min.css +1 -1
- package/dist/lib/MAlipay/style/index.css +2 -2
- package/dist/lib/MAlipay/style/index.min.css +1 -1
- package/dist/lib/MPix/index.js +28 -0
- package/dist/lib/MPix/interface.js +5 -0
- package/dist/lib/MPix/m-pix-button.js +127 -0
- package/dist/lib/MPix/style/index.css +256 -0
- package/dist/lib/MPix/style/index.js +3 -0
- package/dist/lib/MPix/style/index.min.css +1 -0
- package/dist/lib/MWeChat/style/index.css +2 -2
- package/dist/lib/MWeChat/style/index.min.css +1 -1
- package/dist/lib/PayButton/index.js +12 -0
- package/dist/lib/Paypal/index.js +17 -1
- package/dist/lib/Paypal/paypal-button.js +19 -2
- package/dist/lib/Paypal/paypal-smart-button.js +45 -0
- package/dist/lib/Payssion/payssion-button.js +20 -3
- package/dist/lib/Pix/index.js +43 -0
- package/dist/lib/Pix/interface.js +5 -0
- package/dist/lib/Pix/pix-button.js +83 -0
- package/dist/lib/Pix/pix-enhanced.js +143 -0
- package/dist/lib/Pix/pix-modal.js +50 -0
- package/dist/lib/Pix/pix.js +97 -0
- package/dist/lib/Pix/style/index.css +80 -0
- package/dist/lib/Pix/style/index.js +3 -0
- package/dist/lib/Pix/style/index.min.css +1 -0
- package/dist/lib/Stripe/hooks/useStripeCheckout.js +41 -0
- package/dist/lib/Stripe/index.js +18 -1
- package/dist/lib/Stripe/stripe-button.js +28 -10
- package/dist/lib/Stripe/stripe-checkout-button.js +50 -0
- package/dist/lib/Stripe/stripe-modal.js +12 -1
- package/dist/lib/Stripe/stripe-popup.js +12 -1
- package/dist/lib/Stripe/stripe.js +30 -1
- package/dist/lib/Stripe/style/index.css +2 -2
- package/dist/lib/Stripe/style/index.min.css +1 -1
- package/dist/lib/Wechat/style/index.css +2 -2
- package/dist/lib/Wechat/style/index.min.css +1 -1
- package/dist/lib/Wechat/wechat-button.js +21 -6
- package/dist/lib/Wechat/wechat-content.js +65 -0
- package/dist/lib/Wechat/wechat.js +3 -1
- package/dist/lib/confirm-modal/style/index.css +2 -2
- package/dist/lib/confirm-modal/style/index.min.css +1 -1
- package/dist/lib/hooks/useLatestCallback.js +13 -0
- package/dist/lib/hooks/useManagedOrder.js +29 -0
- package/dist/lib/hooks/usePaymentExecution.js +113 -0
- package/dist/lib/hooks/usePaymentQr.js +51 -0
- package/dist/lib/hooks/usePaymentRedirect.js +87 -0
- package/dist/lib/icons/IconCheck/index.js +27 -0
- package/dist/lib/icons/IconCopy/index.js +32 -0
- package/dist/lib/icons/IconPix/index.js +38 -0
- package/dist/lib/icons/index.js +25 -1
- package/dist/lib/index.js +86 -1
- package/dist/lib/pay-modal/pay-modal.js +33 -16
- package/dist/lib/pay-modal/style/index.css +2 -2
- package/dist/lib/pay-modal/style/index.min.css +1 -1
- package/dist/lib/shared/entitys/payment.js +61 -0
- package/dist/lib/shared/enums/index.js +11 -81
- package/dist/lib/shared/enums/payment.js +172 -0
- package/dist/lib/shared/index.js +12 -1
- package/dist/umd/pay-sdk-react.umd.js +10455 -11463
- package/dist/umd/pay-sdk-react.umd.js.map +1 -1
- package/package.json +44 -25
|
@@ -0,0 +1,155 @@
|
|
|
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 _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 }; })(); }
|
|
5
|
+
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
|
+
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; }
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
10
|
+
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); }
|
|
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 { useRef } from 'react';
|
|
14
|
+
import { usePaymentExecution } from '../../hooks/usePaymentExecution';
|
|
15
|
+
import { usePaymentRedirect } from '../../hooks/usePaymentRedirect';
|
|
16
|
+
import { useLatestCallback } from '../../hooks/useLatestCallback';
|
|
17
|
+
import { OpenPayUrlMode, PaymentErrorCode } from '../../shared/enums';
|
|
18
|
+
import { PaymentExecutionError } from '../../shared/entitys/payment';
|
|
19
|
+
/**
|
|
20
|
+
* @zh URL 跳转或官方托管 Checkout;不在挂载时执行。
|
|
21
|
+
* @en URL or official hosted checkout; no mount-time execution.
|
|
22
|
+
* @since 1.2.0
|
|
23
|
+
*/
|
|
24
|
+
export var useAirwallexCheckout = function useAirwallexCheckout() {
|
|
25
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26
|
+
var latest = useRef(options);
|
|
27
|
+
latest.current = options;
|
|
28
|
+
var initialized = useRef();
|
|
29
|
+
var execution = usePaymentExecution(options);
|
|
30
|
+
var redirect = usePaymentRedirect(options.redirectOptions);
|
|
31
|
+
var openCheckout = useLatestCallback(function (source) {
|
|
32
|
+
return execution.run(/*#__PURE__*/function () {
|
|
33
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context) {
|
|
34
|
+
var _latest$current$redir;
|
|
35
|
+
var target, params, mode, initOptions, key, value, instance, _t, _t2;
|
|
36
|
+
return _regenerator().w(function (_context) {
|
|
37
|
+
while (1) switch (_context.n) {
|
|
38
|
+
case 0:
|
|
39
|
+
if (!(typeof source === 'function')) {
|
|
40
|
+
_context.n = 2;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
_context.n = 1;
|
|
44
|
+
return source(context.signal);
|
|
45
|
+
case 1:
|
|
46
|
+
_t = _context.v;
|
|
47
|
+
_context.n = 3;
|
|
48
|
+
break;
|
|
49
|
+
case 2:
|
|
50
|
+
_t = source;
|
|
51
|
+
case 3:
|
|
52
|
+
target = _t;
|
|
53
|
+
if (context.isCurrent()) {
|
|
54
|
+
_context.n = 4;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
return _context.a(2);
|
|
58
|
+
case 4:
|
|
59
|
+
if (!(target === null)) {
|
|
60
|
+
_context.n = 5;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
execution.cancel();
|
|
64
|
+
return _context.a(2);
|
|
65
|
+
case 5:
|
|
66
|
+
if (!(target && typeof target.url === 'string')) {
|
|
67
|
+
_context.n = 6;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
redirect.open(target.url);
|
|
71
|
+
return _context.a(2);
|
|
72
|
+
case 6:
|
|
73
|
+
params = target === null || target === void 0 ? void 0 : target.checkout;
|
|
74
|
+
if (!(!(params !== null && params !== void 0 && params.client_secret) || !params.currency || (params.mode === 'recurring' ? !params.customer_id : !params.intent_id))) {
|
|
75
|
+
_context.n = 7;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'Required hosted checkout parameters are missing.');
|
|
79
|
+
case 7:
|
|
80
|
+
mode = (_latest$current$redir = latest.current.redirectOptions) === null || _latest$current$redir === void 0 ? void 0 : _latest$current$redir.openMode;
|
|
81
|
+
if (!(mode && mode !== OpenPayUrlMode.Href)) {
|
|
82
|
+
_context.n = 8;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'Official hosted checkout navigates the current page.');
|
|
86
|
+
case 8:
|
|
87
|
+
if (!(typeof window === 'undefined')) {
|
|
88
|
+
_context.n = 9;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
throw new PaymentExecutionError(PaymentErrorCode.BrowserUnavailable, 'A browser is required.');
|
|
92
|
+
case 9:
|
|
93
|
+
initOptions = _objectSpread(_objectSpread({}, latest.current.initOptions), {}, {
|
|
94
|
+
enabledElements: ['payments']
|
|
95
|
+
});
|
|
96
|
+
key = JSON.stringify(initOptions);
|
|
97
|
+
if (!initialized.current || initialized.current.key !== key) {
|
|
98
|
+
value = import('@airwallex/components-sdk').then(function (_ref2) {
|
|
99
|
+
var init = _ref2.init;
|
|
100
|
+
return init(initOptions);
|
|
101
|
+
});
|
|
102
|
+
initialized.current = {
|
|
103
|
+
key: key,
|
|
104
|
+
value: value
|
|
105
|
+
};
|
|
106
|
+
value.catch(function () {
|
|
107
|
+
var _initialized$current;
|
|
108
|
+
if (((_initialized$current = initialized.current) === null || _initialized$current === void 0 ? void 0 : _initialized$current.value) === value) initialized.current = undefined;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
_context.p = 10;
|
|
112
|
+
_context.n = 11;
|
|
113
|
+
return initialized.current.value;
|
|
114
|
+
case 11:
|
|
115
|
+
instance = _context.v;
|
|
116
|
+
_context.n = 13;
|
|
117
|
+
break;
|
|
118
|
+
case 12:
|
|
119
|
+
_context.p = 12;
|
|
120
|
+
_t2 = _context.v;
|
|
121
|
+
throw new PaymentExecutionError(PaymentErrorCode.InitializationFailed, 'Unable to initialize Airwallex.');
|
|
122
|
+
case 13:
|
|
123
|
+
if (context.isCurrent()) {
|
|
124
|
+
_context.n = 14;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return _context.a(2);
|
|
128
|
+
case 14:
|
|
129
|
+
if (instance.payments) {
|
|
130
|
+
_context.n = 15;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
throw new PaymentExecutionError(PaymentErrorCode.InitializationFailed, 'Airwallex payments are unavailable.');
|
|
134
|
+
case 15:
|
|
135
|
+
_context.n = 16;
|
|
136
|
+
return instance.payments.redirectToCheckout(params);
|
|
137
|
+
case 16:
|
|
138
|
+
return _context.a(2);
|
|
139
|
+
}
|
|
140
|
+
}, _callee, null, [[10, 12]]);
|
|
141
|
+
}));
|
|
142
|
+
return function (_x) {
|
|
143
|
+
return _ref.apply(this, arguments);
|
|
144
|
+
};
|
|
145
|
+
}());
|
|
146
|
+
});
|
|
147
|
+
var closeCheckout = useLatestCallback(function () {
|
|
148
|
+
execution.cancel();
|
|
149
|
+
redirect.close();
|
|
150
|
+
});
|
|
151
|
+
return _objectSpread(_objectSpread({}, execution), {}, {
|
|
152
|
+
openCheckout: openCheckout,
|
|
153
|
+
closeCheckout: closeCheckout
|
|
154
|
+
});
|
|
155
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import AirwallexCheckoutButton from './airwallex-checkout-button';
|
|
1
2
|
import Airwallex from './airwallex';
|
|
2
3
|
import AirwallexPopup from './airwallex-popup';
|
|
3
4
|
import AirwallexButton from './airwallex-button';
|
|
4
5
|
import AirwallexModal from './airwallex-modal';
|
|
5
6
|
export * from './interface';
|
|
6
7
|
type AirwallexComponentType = typeof Airwallex & {
|
|
8
|
+
CheckoutButton: typeof AirwallexCheckoutButton;
|
|
7
9
|
Button: typeof AirwallexButton;
|
|
8
10
|
Popup: typeof AirwallexPopup;
|
|
9
11
|
Modal: typeof AirwallexModal;
|
|
@@ -11,3 +13,5 @@ type AirwallexComponentType = typeof Airwallex & {
|
|
|
11
13
|
declare const AirwallexComponent: AirwallexComponentType;
|
|
12
14
|
export default AirwallexComponent;
|
|
13
15
|
export { AirwallexButton, AirwallexPopup, AirwallexModal };
|
|
16
|
+
export { AirwallexCheckoutButton };
|
|
17
|
+
export { useAirwallexCheckout } from './hooks/useAirwallexCheckout';
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import AirwallexCheckoutButton from './airwallex-checkout-button';
|
|
1
2
|
import Airwallex from './airwallex';
|
|
2
3
|
import AirwallexPopup from './airwallex-popup';
|
|
3
4
|
import AirwallexButton from './airwallex-button';
|
|
4
5
|
import AirwallexModal from './airwallex-modal';
|
|
5
6
|
export * from './interface';
|
|
6
7
|
var AirwallexComponent = Object.assign({}, Airwallex, {
|
|
8
|
+
CheckoutButton: AirwallexCheckoutButton,
|
|
7
9
|
Button: AirwallexButton,
|
|
8
10
|
Popup: AirwallexPopup,
|
|
9
11
|
Modal: AirwallexModal
|
|
10
12
|
});
|
|
11
13
|
export default AirwallexComponent;
|
|
12
|
-
export { AirwallexButton, AirwallexPopup, AirwallexModal };
|
|
14
|
+
export { AirwallexButton, AirwallexPopup, AirwallexModal };
|
|
15
|
+
export { AirwallexCheckoutButton };
|
|
16
|
+
export { useAirwallexCheckout } from './hooks/useAirwallexCheckout';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { InitResult, SDKOptions } from '@airwallex/components-sdk';
|
|
2
|
+
import type { CheckoutSource, PaymentExecutionOptions, PaymentExecutionReturn, PaymentExecutionResult, PaymentRedirectOptions } from '../shared/entitys/payment';
|
|
1
3
|
import { ElementOptionsTypeMap, InitOptions } from 'airwallex-payment-elements/types/airwallex';
|
|
2
4
|
import { ButtonProps, ButtonRef } from '../Button';
|
|
3
5
|
import { HTMLAttributes } from 'react';
|
|
@@ -9,6 +11,19 @@ export type AirwallexElementOption<T extends keyof ElementOptionsTypeMap = keyof
|
|
|
9
11
|
options: ElementOptionsTypeMap[T];
|
|
10
12
|
};
|
|
11
13
|
export interface AirwallexProps extends AirwallexElementOption, HTMLAttributes<HTMLDivElement> {
|
|
14
|
+
/**
|
|
15
|
+
* @zh 显式启用独立容器和实例释放。
|
|
16
|
+
* @en Opt into isolated mounting and cleanup.
|
|
17
|
+
* @since 1.2.0
|
|
18
|
+
*/
|
|
19
|
+
instanceOptions?: {
|
|
20
|
+
/**
|
|
21
|
+
* @zh 可选容器 ID;默认直接使用当前 DOM 元素。
|
|
22
|
+
* @en Optional container ID; the current DOM element is used by default.
|
|
23
|
+
* @since 1.2.0
|
|
24
|
+
*/
|
|
25
|
+
containerId?: string;
|
|
26
|
+
};
|
|
12
27
|
/**
|
|
13
28
|
* @zh 初始化选项
|
|
14
29
|
* @en Initialization options
|
|
@@ -38,6 +53,18 @@ export interface AirwallexRedirectProps {
|
|
|
38
53
|
airwallexUrl: string;
|
|
39
54
|
}
|
|
40
55
|
export interface AirwallexPopupProps extends PayPopupBaseProps {
|
|
56
|
+
/**
|
|
57
|
+
* @zh 是否在对应事件后关闭,默认保持旧值 true。
|
|
58
|
+
* @en Close on the event; legacy default true.
|
|
59
|
+
* @since 1.2.0
|
|
60
|
+
*/
|
|
61
|
+
closeOnSuccess?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* @zh 错误后请求关闭,默认 true;受控显示由调用方更新。
|
|
64
|
+
* @en Request closing on error, default true; controlled visibility is updated by the caller.
|
|
65
|
+
* @since 1.2.0
|
|
66
|
+
*/
|
|
67
|
+
closeOnError?: boolean;
|
|
41
68
|
/**
|
|
42
69
|
* @zh Airwallex 属性
|
|
43
70
|
* @en Airwallex props
|
|
@@ -63,6 +90,12 @@ export interface AirwallexPopupRef {
|
|
|
63
90
|
export type CreateOrderAirwallexEmbeddedFn = () => Promise<AirwallexProps>;
|
|
64
91
|
export type CreateOrderAirwallexRedirectFn = () => Promise<AirwallexRedirectProps>;
|
|
65
92
|
export interface AirwallexButtonRedirectProps extends ButtonProps {
|
|
93
|
+
/**
|
|
94
|
+
* @zh 显式启用受管理的 createOrder 流程;未传保持旧行为。
|
|
95
|
+
* @en Opt-in managed createOrder execution; omitted preserves legacy behavior.
|
|
96
|
+
* @since 1.2.0
|
|
97
|
+
*/
|
|
98
|
+
executionOptions?: PaymentExecutionOptions;
|
|
66
99
|
/**
|
|
67
100
|
* @zh 支付模式,redirect 会打开 Airwallex 支付页面
|
|
68
101
|
* @en Payment mode, redirect will open the Airwallex payment page
|
|
@@ -85,6 +118,12 @@ export interface AirwallexButtonRedirectProps extends ButtonProps {
|
|
|
85
118
|
createOrder?: CreateOrderAirwallexRedirectFn;
|
|
86
119
|
}
|
|
87
120
|
export interface AirwallexButtonEmbeddedBaseProps extends ButtonProps {
|
|
121
|
+
/**
|
|
122
|
+
* @zh 显式启用受管理的 createOrder 流程;未传保持旧行为。
|
|
123
|
+
* @en Opt-in managed createOrder execution; omitted preserves legacy behavior.
|
|
124
|
+
* @since 1.2.0
|
|
125
|
+
*/
|
|
126
|
+
executionOptions?: PaymentExecutionOptions;
|
|
88
127
|
/**
|
|
89
128
|
* @zh 支付模式,embedded 会打开 Airwallex 支付页面
|
|
90
129
|
* @en Payment mode, embedded will open the Airwallex payment page
|
|
@@ -146,6 +185,18 @@ export interface AirwallexButtonRef extends ButtonRef {
|
|
|
146
185
|
closePayment: () => void;
|
|
147
186
|
}
|
|
148
187
|
export interface AirwallexModalProps extends PayModalProps {
|
|
188
|
+
/**
|
|
189
|
+
* @zh 是否在对应事件后关闭,默认保持旧值 true。
|
|
190
|
+
* @en Close on the event; legacy default true.
|
|
191
|
+
* @since 1.2.0
|
|
192
|
+
*/
|
|
193
|
+
closeOnSuccess?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* @zh 错误后请求关闭,默认 true;受控显示由调用方更新。
|
|
196
|
+
* @en Request closing on error, default true; controlled visibility is updated by the caller.
|
|
197
|
+
* @since 1.2.0
|
|
198
|
+
*/
|
|
199
|
+
closeOnError?: boolean;
|
|
149
200
|
/**
|
|
150
201
|
* @zh Airwallex 属性
|
|
151
202
|
* @en Airwallex props
|
|
@@ -153,3 +204,98 @@ export interface AirwallexModalProps extends PayModalProps {
|
|
|
153
204
|
airwallexProps?: AirwallexProps;
|
|
154
205
|
}
|
|
155
206
|
export type AirwallexModalRef = AirwallexPopupRef;
|
|
207
|
+
/**
|
|
208
|
+
* @zh 官方托管参数完整透传,包括订阅配置。
|
|
209
|
+
* @en Official hosted parameters, including recurring options.
|
|
210
|
+
* @since 1.2.0
|
|
211
|
+
*/
|
|
212
|
+
export type AirwallexHostedOptions = Parameters<NonNullable<InitResult['payments']>['redirectToCheckout']>[0];
|
|
213
|
+
/**
|
|
214
|
+
* @zh URL 与官方凭证是互斥目标。
|
|
215
|
+
* @en URL and official credentials are exclusive targets.
|
|
216
|
+
* @since 1.2.0
|
|
217
|
+
*/
|
|
218
|
+
export type AirwallexCheckoutTarget = {
|
|
219
|
+
/**
|
|
220
|
+
* @zh 托管支付 HTTP(S) 地址。
|
|
221
|
+
* @en Hosted payment HTTP(S) URL.
|
|
222
|
+
* @since 1.2.0
|
|
223
|
+
*/
|
|
224
|
+
url: string;
|
|
225
|
+
/**
|
|
226
|
+
* @zh 官方托管凭证,与 URL 互斥。
|
|
227
|
+
* @en Official hosted credentials, mutually exclusive with URL.
|
|
228
|
+
* @since 1.2.0
|
|
229
|
+
*/
|
|
230
|
+
checkout?: never;
|
|
231
|
+
} | {
|
|
232
|
+
/**
|
|
233
|
+
* @zh 官方托管凭证,与 URL 互斥。
|
|
234
|
+
* @en Official hosted credentials, mutually exclusive with URL.
|
|
235
|
+
* @since 1.2.0
|
|
236
|
+
*/
|
|
237
|
+
checkout: AirwallexHostedOptions;
|
|
238
|
+
/**
|
|
239
|
+
* @zh 托管支付 HTTP(S) 地址。
|
|
240
|
+
* @en Hosted payment HTTP(S) URL.
|
|
241
|
+
* @since 1.2.0
|
|
242
|
+
*/
|
|
243
|
+
url?: never;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* @zh Airwallex 托管执行配置。
|
|
247
|
+
* @en Hosted Airwallex execution options.
|
|
248
|
+
* @since 1.2.0
|
|
249
|
+
*/
|
|
250
|
+
export interface UseAirwallexCheckoutOptions extends PaymentExecutionOptions {
|
|
251
|
+
/**
|
|
252
|
+
* @zh 仅 URL 分支使用打开模式。
|
|
253
|
+
* @en Opening mode applies to URL targets only.
|
|
254
|
+
* @since 1.2.0
|
|
255
|
+
*/
|
|
256
|
+
redirectOptions?: PaymentRedirectOptions;
|
|
257
|
+
/**
|
|
258
|
+
* @zh 官方初始化配置,未传环境时遵循官方默认值。
|
|
259
|
+
* @en Official initialization; omitted env uses official default.
|
|
260
|
+
* @since 1.2.0
|
|
261
|
+
*/
|
|
262
|
+
initOptions?: Omit<SDKOptions, 'enabledElements'>;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* @zh 托管执行状态与操作。
|
|
266
|
+
* @en Hosted execution state and actions.
|
|
267
|
+
* @since 1.2.0
|
|
268
|
+
*/
|
|
269
|
+
export interface UseAirwallexCheckoutReturn extends PaymentExecutionReturn {
|
|
270
|
+
/**
|
|
271
|
+
* @zh 显式执行目标或创建回调,返回前端阶段结果。
|
|
272
|
+
* @en Execute a target or factory and return its frontend result.
|
|
273
|
+
* @since 1.2.0
|
|
274
|
+
*/
|
|
275
|
+
openCheckout: (source: CheckoutSource<AirwallexCheckoutTarget>) => Promise<PaymentExecutionResult>;
|
|
276
|
+
/**
|
|
277
|
+
* @zh 取消待执行任务并关闭当前实例拥有的窗口。
|
|
278
|
+
* @en Cancel pending execution and close the owned window.
|
|
279
|
+
* @since 1.2.0
|
|
280
|
+
*/
|
|
281
|
+
closeCheckout: () => void;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* @zh Airwallex 托管按钮。
|
|
285
|
+
* @en Hosted Airwallex checkout button.
|
|
286
|
+
* @since 1.2.0
|
|
287
|
+
*/
|
|
288
|
+
export interface AirwallexCheckoutButtonProps extends ButtonProps, UseAirwallexCheckoutOptions {
|
|
289
|
+
/**
|
|
290
|
+
* @zh 直接执行的目标;同时传 createOrder 时回调优先。
|
|
291
|
+
* @en Direct target; createOrder takes precedence when provided.
|
|
292
|
+
* @since 1.2.0
|
|
293
|
+
*/
|
|
294
|
+
target?: AirwallexCheckoutTarget;
|
|
295
|
+
/**
|
|
296
|
+
* @zh 由点击触发的异步目标创建回调,null 表示取消。
|
|
297
|
+
* @en Click-triggered async target factory; null cancels.
|
|
298
|
+
* @since 1.2.0
|
|
299
|
+
*/
|
|
300
|
+
createOrder?: (signal: AbortSignal) => Promise<AirwallexCheckoutTarget | null>;
|
|
301
|
+
}
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
max-width: 80vw;
|
|
124
124
|
box-shadow: 0 4px 24px #0001;
|
|
125
125
|
text-align: center;
|
|
126
|
-
max-height:
|
|
126
|
+
max-height: 80vh;
|
|
127
127
|
display: flex;
|
|
128
128
|
flex-direction: column;
|
|
129
129
|
}
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
z-index: 1;
|
|
164
164
|
text-align: center;
|
|
165
165
|
overflow-y: auto;
|
|
166
|
-
flex: 1;
|
|
166
|
+
flex: 0 1 auto;
|
|
167
167
|
min-height: 0;
|
|
168
168
|
}
|
|
169
169
|
.pay-modal__actions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.pay-dot-loading{display:inline-block}.pay-button{display:inline-block;padding:7px 12px;font-size:16px;border-radius:4px;border:1px solid #eee;background:#fff;color:#333;cursor:pointer;transition:.2s;user-select:none;position:relative;text-align:center}.pay-button-content{display:flex;align-items:center;justify-content:center;gap:6px}.pay-button-block{display:block;width:100%}.pay-button-disabled{opacity:.4;cursor:not-allowed}.pay-button-loading{cursor:wait}.pay-button-loading-wrapper{display:flex;align-items:center;justify-content:center;gap:6px}.pay-button-primary{background:#1677ff;border-color:#1677ff;color:#fff}.pay-button-primary:hover{background:#409eff}.pay-button-success{background:#00b578;border-color:#00b578;color:#fff}.pay-button-danger{background:#ff3141;border-color:#ff3141;color:#fff}.pay-button-warning{background:#ff8f1f;border-color:#ff8f1f;color:#fff}.pay-button-default{background:#fff;border-color:#eee;color:#333}.pay-button-fill-outline{background:0 0;color:inherit}.pay-button-fill-none{background:0 0;border:none;color:inherit}.pay-button-mini{font-size:12px;padding:2px 8px}.pay-button-small{font-size:14px;padding:4px 10px}.pay-button-large{font-size:18px;padding:10px 18px}.pay-button-shape-rounded{border-radius:1000px}.pay-button-shape-rectangular{border-radius:0}.pay-modal{position:fixed;z-index:9999;left:0;top:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center}.pay-modal__mask{position:absolute;left:0;top:0;right:0;bottom:0;background:rgba(0,0,0,.55);z-index:0}.pay-modal__content{position:relative;z-index:1;background:#fff;border-radius:16px;padding:42px 20px 20px;min-width:280px;max-width:80vw;box-shadow:0 4px 24px #0001;text-align:center;max-height:
|
|
1
|
+
.pay-dot-loading{display:inline-block}.pay-button{display:inline-block;padding:7px 12px;font-size:16px;border-radius:4px;border:1px solid #eee;background:#fff;color:#333;cursor:pointer;transition:.2s;user-select:none;position:relative;text-align:center}.pay-button-content{display:flex;align-items:center;justify-content:center;gap:6px}.pay-button-block{display:block;width:100%}.pay-button-disabled{opacity:.4;cursor:not-allowed}.pay-button-loading{cursor:wait}.pay-button-loading-wrapper{display:flex;align-items:center;justify-content:center;gap:6px}.pay-button-primary{background:#1677ff;border-color:#1677ff;color:#fff}.pay-button-primary:hover{background:#409eff}.pay-button-success{background:#00b578;border-color:#00b578;color:#fff}.pay-button-danger{background:#ff3141;border-color:#ff3141;color:#fff}.pay-button-warning{background:#ff8f1f;border-color:#ff8f1f;color:#fff}.pay-button-default{background:#fff;border-color:#eee;color:#333}.pay-button-fill-outline{background:0 0;color:inherit}.pay-button-fill-none{background:0 0;border:none;color:inherit}.pay-button-mini{font-size:12px;padding:2px 8px}.pay-button-small{font-size:14px;padding:4px 10px}.pay-button-large{font-size:18px;padding:10px 18px}.pay-button-shape-rounded{border-radius:1000px}.pay-button-shape-rectangular{border-radius:0}.pay-modal{position:fixed;z-index:9999;left:0;top:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center}.pay-modal__mask{position:absolute;left:0;top:0;right:0;bottom:0;background:rgba(0,0,0,.55);z-index:0}.pay-modal__content{position:relative;z-index:1;background:#fff;border-radius:16px;padding:42px 20px 20px;min-width:280px;max-width:80vw;box-shadow:0 4px 24px #0001;text-align:center;max-height:80vh;display:flex;flex-direction:column}.pay-modal__close{position:absolute;right:12px;top:12px;background:0 0;border:none;font-size:32px;font-weight:500;line-height:32px;cursor:pointer;text-align:left}.pay-modal__icon{display:flex;justify-content:center;margin-bottom:8px;font-size:40px}.pay-modal__title{font-size:20px;font-weight:700;color:#222;margin-bottom:12px}.pay-modal__desc{color:#222;font-size:15px;margin-bottom:24px;line-height:1.7;text-align:left}.pay-modal__content-wrapper{position:relative;z-index:1;text-align:center;overflow-y:auto;flex:0 1 auto;min-height:0}.pay-modal__actions{display:flex;justify-content:center;gap:16px;margin-top:16px}.pay-modal__btn{min-width:96px;padding:8px 0;border-radius:24px;border:none;font-size:15px;font-weight:600;cursor:pointer;transition:background .2s}.pay-modal__btn--retry{background:#fff;color:#f25a5a;border:1.5px solid #f25a5a}.pay-modal__btn--finish{background:#f25a5a;color:#fff;border:none}.pay-mask{position:fixed;z-index:1000;left:0;top:0;right:0;bottom:0;display:flex;align-items:center;justify-content:center}.pay-icon{display:inline-block;color:inherit;width:16px;vertical-align:-2px;stroke:currentColor}.pay-icon[fill=currentColor]{fill:currentColor;stroke:none}.pay-icon[stroke=currentColor]{stroke:currentColor;fill:none}.pay-icon[fill=currentColor][stroke=currentColor]{fill:currentColor;stroke:currentColor}.pay-icon-paypal-text{width:64px;height:26px;max-width:72px;max-height:32px}.pay-icon-close{width:18px;height:18px}.pay-icon-stripe-text{width:24px;height:24px}.pay-icon-alipay{width:20px;height:20px}.pay-icon-wechat-pay{width:20px;height:20px}.pay-icon-payssion-pay{width:36px;height:20px}.pay-popup{position:fixed;z-index:1001}.pay-popup-body{position:fixed;display:flex;flex-direction:column;background-color:#fff;z-index:1010;box-sizing:border-box}.pay-popup-body.pay-popup-body-position-bottom{width:100%;left:0;bottom:0}.pay-popup-body.pay-popup-body-position-top{width:100%;left:0;top:0}.pay-popup-body.pay-popup-body-position-left{height:100%;width:80vw;left:0;top:0}.pay-popup-body.pay-popup-body-position-right{height:100%;width:80vw;right:0;top:0}.pay-popup-body.pay-popup-body-round.pay-popup-body-position-bottom{border-radius:16px 16px 0 0}.pay-popup-body.pay-popup-body-round.pay-popup-body-position-top{border-radius:0 0 16px 16px}.pay-popup-body.pay-popup-body-round.pay-popup-body-position-left{border-radius:0 16px 16px 0}.pay-popup-body.pay-popup-body-round.pay-popup-body-position-right{border-radius:16px 0 0 16px}.pay-popup-close-icon{position:absolute;z-index:1;cursor:pointer;padding:4px;font-size:18px;line-height:1;color:#999}.pay-popup-body.pay-popup-body-position-bottom .pay-popup-close-icon,.pay-popup-body.pay-popup-body-position-left .pay-popup-close-icon{top:8px;right:8px}.pay-popup-body.pay-popup-body-position-top .pay-popup-close-icon{bottom:8px;right:8px}.pay-popup-body.pay-popup-body-position-right .pay-popup-close-icon{top:8px;left:8px}.pay-popup-content{flex:1;overflow-y:auto;-webkit-overflow-scrolling:touch}.pay-popup-body.pay-popup-body-with-close.pay-popup-body-position-bottom .pay-popup-content,.pay-popup-body.pay-popup-body-with-close.pay-popup-body-position-left .pay-popup-content{padding-top:40px}.pay-popup-body.pay-popup-body-with-close.pay-popup-body-position-right .pay-popup-content{padding-top:40px}.pay-popup-body.pay-popup-body-with-close.pay-popup-body-position-top .pay-popup-content{padding-bottom:40px}
|
|
@@ -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 AlipayModal from './alipay-modal';
|
|
@@ -18,6 +19,7 @@ var AlipayButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
18
19
|
children = _props$children === void 0 ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(IconAlipay, null), "\u652F\u4ED8\u5B9D\u652F\u4ED8") : _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 alipayButtonRef = useRef(null);
|
|
@@ -34,13 +36,21 @@ var AlipayButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
34
36
|
},
|
|
35
37
|
closeModal: function closeModal() {
|
|
36
38
|
var _alipayModalRef$curre2;
|
|
39
|
+
if (executionOptions) managed.cancel();
|
|
37
40
|
(_alipayModalRef$curre2 = alipayModalRef.current) === null || _alipayModalRef$curre2 === void 0 || _alipayModalRef$curre2.close();
|
|
38
41
|
},
|
|
39
42
|
current: alipayButtonRef.current
|
|
40
43
|
};
|
|
41
44
|
});
|
|
45
|
+
var managed = useManagedOrder(createOrder, function (target) {
|
|
46
|
+
var _alipayModalRef$curre3;
|
|
47
|
+
(_alipayModalRef$curre3 = alipayModalRef.current) === null || _alipayModalRef$curre3 === void 0 || _alipayModalRef$curre3.open(target);
|
|
48
|
+
}, executionOptions, function (target) {
|
|
49
|
+
return typeof target.formHtml === 'string' && Boolean(target.formHtml.trim());
|
|
50
|
+
});
|
|
51
|
+
var managedRun = managed.run;
|
|
42
52
|
var handlePayCreateOrder = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
43
|
-
var options, _alipayModalRef$
|
|
53
|
+
var options, _alipayModalRef$curre4;
|
|
44
54
|
return _regenerator().w(function (_context) {
|
|
45
55
|
while (1) switch (_context.n) {
|
|
46
56
|
case 0:
|
|
@@ -53,7 +63,7 @@ var AlipayButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
53
63
|
case 1:
|
|
54
64
|
options = _context.v;
|
|
55
65
|
if (options) {
|
|
56
|
-
alipayModalRef === null || alipayModalRef === void 0 || (_alipayModalRef$
|
|
66
|
+
alipayModalRef === null || alipayModalRef === void 0 || (_alipayModalRef$curre4 = alipayModalRef.current) === null || _alipayModalRef$curre4 === void 0 || _alipayModalRef$curre4.open(options);
|
|
57
67
|
}
|
|
58
68
|
case 2:
|
|
59
69
|
return _context.a(2);
|
|
@@ -63,18 +73,27 @@ var AlipayButton = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
63
73
|
var handleClick = useCallback(function (e) {
|
|
64
74
|
var _modalProps$alipayPro;
|
|
65
75
|
if (createOrder) {
|
|
76
|
+
if (executionOptions) {
|
|
77
|
+
onClick === null || onClick === void 0 || onClick(e);
|
|
78
|
+
if (e.defaultPrevented) return;
|
|
79
|
+
return managedRun().then(function () {
|
|
80
|
+
return undefined;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
66
83
|
handlePayCreateOrder();
|
|
67
84
|
} else if (modalProps !== null && modalProps !== void 0 && (_modalProps$alipayPro = modalProps.alipayProps) !== null && _modalProps$alipayPro !== void 0 && _modalProps$alipayPro.formHtml) {
|
|
68
|
-
var _alipayModalRef$
|
|
69
|
-
alipayModalRef === null || alipayModalRef === void 0 || (_alipayModalRef$
|
|
85
|
+
var _alipayModalRef$curre5;
|
|
86
|
+
alipayModalRef === null || alipayModalRef === void 0 || (_alipayModalRef$curre5 = alipayModalRef.current) === null || _alipayModalRef$curre5 === void 0 || _alipayModalRef$curre5.open();
|
|
70
87
|
}
|
|
71
88
|
onClick === null || onClick === void 0 || onClick(e);
|
|
72
|
-
}, [onClick, createOrder, handlePayCreateOrder, modalProps]);
|
|
89
|
+
}, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, modalProps]);
|
|
73
90
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({
|
|
74
91
|
ref: alipayButtonRef,
|
|
75
92
|
className: cs(getPrefixCls('alipay-btn'), className),
|
|
76
93
|
onClick: handleClick
|
|
77
|
-
}, others
|
|
94
|
+
}, others, {
|
|
95
|
+
loading: executionOptions ? managed.loading || others.loading : others.loading
|
|
96
|
+
}), children), /*#__PURE__*/React.createElement(AlipayModal, _extends({
|
|
78
97
|
ref: alipayModalRef
|
|
79
98
|
}, modalProps)));
|
|
80
99
|
});
|
package/dist/es/Alipay/alipay.js
CHANGED
|
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
10
10
|
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; }
|
|
11
11
|
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; } }
|
|
12
12
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
13
|
-
import React, { memo, useState } from 'react';
|
|
13
|
+
import React, { memo, useState, useEffect, useRef } from 'react';
|
|
14
14
|
import FullScreenLoading from '../FullScreenLoading';
|
|
15
15
|
import { getPrefixCls } from '../utils/getPrefixCls';
|
|
16
16
|
import cs from '../utils/classNames';
|
|
@@ -26,36 +26,63 @@ var AlipayQrIframe = function AlipayQrIframe(_ref) {
|
|
|
26
26
|
_ref$iframeClassName = _ref.iframeClassName,
|
|
27
27
|
iframeClassName = _ref$iframeClassName === void 0 ? '' : _ref$iframeClassName,
|
|
28
28
|
_ref$iframeStyle = _ref.iframeStyle,
|
|
29
|
-
iframeStyle = _ref$iframeStyle === void 0 ? {} : _ref$iframeStyle
|
|
29
|
+
iframeStyle = _ref$iframeStyle === void 0 ? {} : _ref$iframeStyle,
|
|
30
|
+
_ref$classNames = _ref.classNames,
|
|
31
|
+
classNames = _ref$classNames === void 0 ? {} : _ref$classNames,
|
|
32
|
+
_ref$styles = _ref.styles,
|
|
33
|
+
styles = _ref$styles === void 0 ? {} : _ref$styles,
|
|
34
|
+
loadingContent = _ref.loadingContent,
|
|
35
|
+
onFrameLoad = _ref.onFrameLoad,
|
|
36
|
+
onFrameError = _ref.onFrameError;
|
|
30
37
|
var _useState = useState(true),
|
|
31
38
|
_useState2 = _slicedToArray(_useState, 2),
|
|
32
39
|
loading = _useState2[0],
|
|
33
40
|
setLoading = _useState2[1];
|
|
41
|
+
var iframeRef = useRef(null);
|
|
42
|
+
var customLoading = loadingContent !== undefined;
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
if (customLoading) setLoading(true);
|
|
45
|
+
}, [formHtml, customLoading]);
|
|
46
|
+
useEffect(function () {
|
|
47
|
+
var node = iframeRef.current;
|
|
48
|
+
if (!node || !onFrameError) return;
|
|
49
|
+
var failed = function failed() {
|
|
50
|
+
setLoading(false);
|
|
51
|
+
onFrameError();
|
|
52
|
+
};
|
|
53
|
+
node.addEventListener('error', failed);
|
|
54
|
+
return function () {
|
|
55
|
+
return node.removeEventListener('error', failed);
|
|
56
|
+
};
|
|
57
|
+
}, [onFrameError]);
|
|
34
58
|
return /*#__PURE__*/React.createElement(FullScreenLoading, {
|
|
35
|
-
loading: loading,
|
|
59
|
+
loading: loading && loadingContent === undefined,
|
|
36
60
|
type: 'spin-dots',
|
|
37
61
|
text: null,
|
|
38
62
|
fullscreen: false
|
|
39
63
|
}, /*#__PURE__*/React.createElement("div", {
|
|
40
|
-
className: cs(classPrefix, wrapperClassName),
|
|
41
|
-
style: _objectSpread({
|
|
64
|
+
className: cs(classPrefix, wrapperClassName, classNames.root),
|
|
65
|
+
style: _objectSpread(_objectSpread({
|
|
42
66
|
position: 'relative'
|
|
43
|
-
}, wrapperStyle)
|
|
44
|
-
}, /*#__PURE__*/React.createElement("iframe", {
|
|
67
|
+
}, wrapperStyle), styles.root)
|
|
68
|
+
}, loading && loadingContent !== undefined ? loadingContent : null, /*#__PURE__*/React.createElement("iframe", {
|
|
69
|
+
ref: iframeRef,
|
|
45
70
|
srcDoc: formHtml,
|
|
46
|
-
className: cs("".concat(classPrefix, "__iframe"), iframeClassName),
|
|
47
|
-
style: _objectSpread({
|
|
71
|
+
className: cs("".concat(classPrefix, "__iframe"), iframeClassName, classNames.iframe),
|
|
72
|
+
style: _objectSpread(_objectSpread({
|
|
48
73
|
width: 210,
|
|
49
74
|
height: 210,
|
|
50
75
|
border: 'none'
|
|
51
|
-
}, iframeStyle),
|
|
76
|
+
}, iframeStyle), styles.iframe),
|
|
52
77
|
title: "alipay-qrcode",
|
|
53
78
|
scrolling: "no",
|
|
54
79
|
onLoad: function onLoad() {
|
|
55
|
-
|
|
80
|
+
setLoading(false);
|
|
81
|
+
onFrameLoad === null || onFrameLoad === void 0 || onFrameLoad();
|
|
56
82
|
}
|
|
57
83
|
}), !!tipText && /*#__PURE__*/React.createElement("span", {
|
|
58
|
-
className: "".concat(classPrefix, "__tip")
|
|
84
|
+
className: cs("".concat(classPrefix, "__tip"), classNames.tip),
|
|
85
|
+
style: styles.tip
|
|
59
86
|
}, tipText)));
|
|
60
87
|
};
|
|
61
88
|
export default /*#__PURE__*/memo(AlipayQrIframe);
|
|
@@ -1,7 +1,26 @@
|
|
|
1
|
+
import type { PaymentAppearance, PaymentExecutionOptions } 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
|
-
export interface AlipayProps {
|
|
5
|
+
export interface AlipayProps extends PaymentAppearance<'root' | 'iframe' | 'tip'> {
|
|
6
|
+
/**
|
|
7
|
+
* @zh 自定义加载内容。
|
|
8
|
+
* @en Custom loading content.
|
|
9
|
+
* @since 1.2.0
|
|
10
|
+
*/
|
|
11
|
+
loadingContent?: React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* @zh iframe 已加载,不代表已支付。
|
|
14
|
+
* @en Iframe loaded, not payment success.
|
|
15
|
+
* @since 1.2.0
|
|
16
|
+
*/
|
|
17
|
+
onFrameLoad?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* @zh 浏览器能观测到的 iframe 错误。
|
|
20
|
+
* @en Browser-observable iframe errors.
|
|
21
|
+
* @since 1.2.0
|
|
22
|
+
*/
|
|
23
|
+
onFrameError?: () => void;
|
|
5
24
|
/**
|
|
6
25
|
* @zh 支付宝支付 html 字符串,必须包含自动提交脚本
|
|
7
26
|
* @en Alipay payment html string, must contain auto submit script
|
|
@@ -41,6 +60,12 @@ export interface AlipayModalProps extends PayModalProps {
|
|
|
41
60
|
alipayProps?: AlipayProps;
|
|
42
61
|
}
|
|
43
62
|
export interface AlipayButtonProps extends ButtonProps {
|
|
63
|
+
/**
|
|
64
|
+
* @zh 显式启用受管理的 createOrder 流程;未传保持旧行为。
|
|
65
|
+
* @en Opt-in managed createOrder execution; omitted preserves legacy behavior.
|
|
66
|
+
* @since 1.2.0
|
|
67
|
+
*/
|
|
68
|
+
executionOptions?: PaymentExecutionOptions;
|
|
44
69
|
/**
|
|
45
70
|
* @zh 创建订单函数,返回 Paypal 所需参数
|
|
46
71
|
* @en Function to create order, returns Paypal required params
|