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,168 @@
|
|
|
1
|
+
export var PaymentMethod = /*#__PURE__*/function (PaymentMethod) {
|
|
2
|
+
/**
|
|
3
|
+
* @zh 微信(pc)
|
|
4
|
+
* @en Wechat(pc)
|
|
5
|
+
*/
|
|
6
|
+
PaymentMethod["WechatPc"] = "wechat-pc";
|
|
7
|
+
/**
|
|
8
|
+
* @zh 支付宝(pc)
|
|
9
|
+
* @en Alipay(pc)
|
|
10
|
+
*/
|
|
11
|
+
PaymentMethod["AlipayPc"] = "alipay-pc";
|
|
12
|
+
/**
|
|
13
|
+
* @zh paypal(pc)
|
|
14
|
+
* @en Paypal(pc)
|
|
15
|
+
*/
|
|
16
|
+
PaymentMethod["PaypalPc"] = "paypal-pc";
|
|
17
|
+
/**
|
|
18
|
+
* @zh stripe(pc)
|
|
19
|
+
* @en Stripe(pc)
|
|
20
|
+
*/
|
|
21
|
+
PaymentMethod["StripePc"] = "stripe-pc";
|
|
22
|
+
/**
|
|
23
|
+
* @zh 微信(H5)
|
|
24
|
+
* @en Wechat(H5)
|
|
25
|
+
*/
|
|
26
|
+
PaymentMethod["WechatH5"] = "wechat-h5";
|
|
27
|
+
/**
|
|
28
|
+
* @zh 支付宝(H5)
|
|
29
|
+
* @en Alipay(H5)
|
|
30
|
+
*/
|
|
31
|
+
PaymentMethod["AlipayH5"] = "alipay-h5";
|
|
32
|
+
/**
|
|
33
|
+
* @zh paypal(H5)
|
|
34
|
+
* @en Paypal(H5)
|
|
35
|
+
*/
|
|
36
|
+
PaymentMethod["PaypalH5"] = "paypal-h5";
|
|
37
|
+
/**
|
|
38
|
+
* @zh 微信内部(H5)
|
|
39
|
+
* @en Wechat inside(H5)
|
|
40
|
+
*/
|
|
41
|
+
PaymentMethod["WechatInsideH5"] = "wechat-inside-h5";
|
|
42
|
+
/**
|
|
43
|
+
* @zh stripe(H5)
|
|
44
|
+
* @en Stripe(H5)
|
|
45
|
+
*/
|
|
46
|
+
PaymentMethod["StripeH5"] = "stripe-h5";
|
|
47
|
+
/**
|
|
48
|
+
* @zh payssion支付
|
|
49
|
+
* @en Payssion
|
|
50
|
+
*/
|
|
51
|
+
PaymentMethod["Payssion"] = "payssion";
|
|
52
|
+
/**
|
|
53
|
+
* @zh 空中云汇
|
|
54
|
+
* @en Airwallex
|
|
55
|
+
*/
|
|
56
|
+
PaymentMethod["Airwallex"] = "airwallex";
|
|
57
|
+
/**
|
|
58
|
+
* @zh PIX(pc)
|
|
59
|
+
* @en PIX(pc)
|
|
60
|
+
*/
|
|
61
|
+
PaymentMethod["PixPc"] = "pix-pc";
|
|
62
|
+
/**
|
|
63
|
+
* @zh PIX(H5)
|
|
64
|
+
* @en PIX(H5)
|
|
65
|
+
*/
|
|
66
|
+
PaymentMethod["PixH5"] = "pix-h5";
|
|
67
|
+
return PaymentMethod;
|
|
68
|
+
}({});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @zh 支付页面打开模式枚举
|
|
72
|
+
* @en Payment page opening mode enum
|
|
73
|
+
*/
|
|
74
|
+
export var OpenPayUrlMode = /*#__PURE__*/function (OpenPayUrlMode) {
|
|
75
|
+
/**
|
|
76
|
+
* @zh 新页面或弹窗模式 - 使用 window.open() 打开新页面或弹窗,支持智能设备检测
|
|
77
|
+
* @en New page or popup mode - Use window.open() to open new page or popup, supports smart device detection
|
|
78
|
+
*/
|
|
79
|
+
OpenPayUrlMode["Window"] = "window";
|
|
80
|
+
/**
|
|
81
|
+
* @zh 新页面模式 - 使用 window.location.href 跳转到新页面
|
|
82
|
+
* @en New page mode - Use window.location.href to navigate to new page
|
|
83
|
+
*/
|
|
84
|
+
OpenPayUrlMode["Href"] = "href";
|
|
85
|
+
/**
|
|
86
|
+
* @zh 替换页面模式 - 使用 window.location.replace 替换当前页面
|
|
87
|
+
* @en Replace page mode - Use window.location.replace to replace current page
|
|
88
|
+
*/
|
|
89
|
+
OpenPayUrlMode["Replace"] = "replace";
|
|
90
|
+
return OpenPayUrlMode;
|
|
91
|
+
}({});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @zh 前端执行状态,不代表订单状态。
|
|
95
|
+
* @en Frontend execution, not order status.
|
|
96
|
+
* @since 1.2.0
|
|
97
|
+
*/
|
|
98
|
+
export var PaymentExecutionStatus = /*#__PURE__*/function (PaymentExecutionStatus) {
|
|
99
|
+
/**
|
|
100
|
+
* @zh 尚未执行。
|
|
101
|
+
* @en Not executed.
|
|
102
|
+
* @since 1.2.0
|
|
103
|
+
*/
|
|
104
|
+
PaymentExecutionStatus["Idle"] = "idle";
|
|
105
|
+
/**
|
|
106
|
+
* @zh 当前前端执行处理中。
|
|
107
|
+
* @en Frontend execution is pending.
|
|
108
|
+
* @since 1.2.0
|
|
109
|
+
*/
|
|
110
|
+
PaymentExecutionStatus["Pending"] = "pending";
|
|
111
|
+
/**
|
|
112
|
+
* @zh 当前执行阶段完成,不代表支付成功。
|
|
113
|
+
* @en Execution stage completed, not payment success.
|
|
114
|
+
* @since 1.2.0
|
|
115
|
+
*/
|
|
116
|
+
PaymentExecutionStatus["Completed"] = "completed";
|
|
117
|
+
/**
|
|
118
|
+
* @zh 当前前端执行已取消。
|
|
119
|
+
* @en Frontend execution cancelled.
|
|
120
|
+
* @since 1.2.0
|
|
121
|
+
*/
|
|
122
|
+
PaymentExecutionStatus["Cancelled"] = "cancelled";
|
|
123
|
+
/**
|
|
124
|
+
* @zh 当前前端执行失败。
|
|
125
|
+
* @en Frontend execution failed.
|
|
126
|
+
* @since 1.2.0
|
|
127
|
+
*/
|
|
128
|
+
PaymentExecutionStatus["Failed"] = "failed";
|
|
129
|
+
return PaymentExecutionStatus;
|
|
130
|
+
}({});
|
|
131
|
+
/**
|
|
132
|
+
* @zh 执行错误分类。
|
|
133
|
+
* @en Execution error codes.
|
|
134
|
+
* @since 1.2.0
|
|
135
|
+
*/
|
|
136
|
+
export var PaymentErrorCode = /*#__PURE__*/function (PaymentErrorCode) {
|
|
137
|
+
/**
|
|
138
|
+
* @zh 目标或凭证无效。
|
|
139
|
+
* @en Invalid target or credentials.
|
|
140
|
+
* @since 1.2.0
|
|
141
|
+
*/
|
|
142
|
+
PaymentErrorCode["InvalidParameters"] = "invalid_parameters";
|
|
143
|
+
/**
|
|
144
|
+
* @zh 执行时缺少浏览器环境。
|
|
145
|
+
* @en Browser environment unavailable for execution.
|
|
146
|
+
* @since 1.2.0
|
|
147
|
+
*/
|
|
148
|
+
PaymentErrorCode["BrowserUnavailable"] = "browser_unavailable";
|
|
149
|
+
/**
|
|
150
|
+
* @zh 支付窗口被浏览器拦截。
|
|
151
|
+
* @en Payment window blocked by the browser.
|
|
152
|
+
* @since 1.2.0
|
|
153
|
+
*/
|
|
154
|
+
PaymentErrorCode["WindowBlocked"] = "window_blocked";
|
|
155
|
+
/**
|
|
156
|
+
* @zh 官方 SDK 初始化失败。
|
|
157
|
+
* @en Official SDK initialization failed.
|
|
158
|
+
* @since 1.2.0
|
|
159
|
+
*/
|
|
160
|
+
PaymentErrorCode["InitializationFailed"] = "initialization_failed";
|
|
161
|
+
/**
|
|
162
|
+
* @zh 其他前端执行失败。
|
|
163
|
+
* @en Other frontend execution failure.
|
|
164
|
+
* @since 1.2.0
|
|
165
|
+
*/
|
|
166
|
+
PaymentErrorCode["ExecutionFailed"] = "execution_failed";
|
|
167
|
+
return PaymentErrorCode;
|
|
168
|
+
}({});
|
|
@@ -1 +1,3 @@
|
|
|
1
1
|
export * from './enums';
|
|
2
|
+
export { PaymentExecutionError } from './entitys/payment';
|
|
3
|
+
export type { CheckoutSource, PaymentAppearance, PaymentExecutionOptions, PaymentExecutionResult, PaymentExecutionReturn, PaymentQrAppearance, PaymentRedirectOptions, } from './entitys/payment';
|
package/dist/es/shared/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './enums';
|
|
1
|
+
export * from './enums';
|
|
2
|
+
export { PaymentExecutionError } from './entitys/payment';
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _useManagedOrder = require("../hooks/useManagedOrder");
|
|
7
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
9
|
var _airwallexPopup = _interopRequireDefault(require("./airwallex-popup"));
|
|
9
10
|
var _airwallexModal = _interopRequireDefault(require("./airwallex-modal"));
|
|
@@ -18,6 +19,7 @@ const AirwallexButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
18
19
|
children = 'Airwallex',
|
|
19
20
|
onClick,
|
|
20
21
|
createOrder,
|
|
22
|
+
executionOptions,
|
|
21
23
|
...others
|
|
22
24
|
} = props;
|
|
23
25
|
const airwallexButtonRef = (0, _react.useRef)(null);
|
|
@@ -36,6 +38,7 @@ const AirwallexButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
36
38
|
},
|
|
37
39
|
closeModal: () => {
|
|
38
40
|
var _airwallexModalRef$cu2;
|
|
41
|
+
if (executionOptions) managed.cancel();
|
|
39
42
|
(_airwallexModalRef$cu2 = airwallexModalRef.current) === null || _airwallexModalRef$cu2 === void 0 || _airwallexModalRef$cu2.close();
|
|
40
43
|
},
|
|
41
44
|
openPopup: options => {
|
|
@@ -44,6 +47,7 @@ const AirwallexButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
44
47
|
},
|
|
45
48
|
closePopup: () => {
|
|
46
49
|
var _airwallexPopupRef$cu2;
|
|
50
|
+
if (executionOptions) managed.cancel();
|
|
47
51
|
(_airwallexPopupRef$cu2 = airwallexPopupRef.current) === null || _airwallexPopupRef$cu2 === void 0 || _airwallexPopupRef$cu2.close();
|
|
48
52
|
},
|
|
49
53
|
openPayment: options => {
|
|
@@ -53,10 +57,21 @@ const AirwallexButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
53
57
|
}
|
|
54
58
|
},
|
|
55
59
|
closePayment: () => {
|
|
60
|
+
if (executionOptions) managed.cancel();
|
|
56
61
|
setShowMask(false);
|
|
57
62
|
},
|
|
58
63
|
current: airwallexButtonRef.current
|
|
59
64
|
}));
|
|
65
|
+
const managed = (0, _useManagedOrder.useManagedOrder)(createOrder ? async () => createOrder() : undefined, target => {
|
|
66
|
+
if (props.payMode === 'embedded') {
|
|
67
|
+
var _airwallexModalRef$cu3, _airwallexPopupRef$cu3;
|
|
68
|
+
if (props.displayType === 'modal') (_airwallexModalRef$cu3 = airwallexModalRef.current) === null || _airwallexModalRef$cu3 === void 0 || _airwallexModalRef$cu3.open(target);else (_airwallexPopupRef$cu3 = airwallexPopupRef.current) === null || _airwallexPopupRef$cu3 === void 0 || _airwallexPopupRef$cu3.open(target);
|
|
69
|
+
} else {
|
|
70
|
+
setAirwallexUrl(target.airwallexUrl);
|
|
71
|
+
setShowMask(true);
|
|
72
|
+
}
|
|
73
|
+
}, executionOptions, target => props.payMode === 'embedded' ? Boolean(target.type && target.options) : typeof target.airwallexUrl === 'string' && Boolean(target.airwallexUrl.trim()));
|
|
74
|
+
const managedRun = managed.run;
|
|
60
75
|
const handlePayCreateOrder = (0, _react.useCallback)(async () => {
|
|
61
76
|
if (createOrder) {
|
|
62
77
|
// 1. 业务侧创建订单,获取参数
|
|
@@ -64,11 +79,11 @@ const AirwallexButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
64
79
|
if (options) {
|
|
65
80
|
if ((props === null || props === void 0 ? void 0 : props.payMode) === 'embedded') {
|
|
66
81
|
if ((props === null || props === void 0 ? void 0 : props.displayType) === 'modal') {
|
|
67
|
-
var _airwallexModalRef$
|
|
68
|
-
airwallexModalRef === null || airwallexModalRef === void 0 || (_airwallexModalRef$
|
|
82
|
+
var _airwallexModalRef$cu4;
|
|
83
|
+
airwallexModalRef === null || airwallexModalRef === void 0 || (_airwallexModalRef$cu4 = airwallexModalRef.current) === null || _airwallexModalRef$cu4 === void 0 || _airwallexModalRef$cu4.open(options);
|
|
69
84
|
} else {
|
|
70
|
-
var _airwallexPopupRef$
|
|
71
|
-
(_airwallexPopupRef$
|
|
85
|
+
var _airwallexPopupRef$cu4;
|
|
86
|
+
(_airwallexPopupRef$cu4 = airwallexPopupRef.current) === null || _airwallexPopupRef$cu4 === void 0 || _airwallexPopupRef$cu4.open(options);
|
|
72
87
|
}
|
|
73
88
|
} else {
|
|
74
89
|
setShowMask(true);
|
|
@@ -80,6 +95,10 @@ const AirwallexButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
80
95
|
const handleClick = (0, _react.useCallback)(e => {
|
|
81
96
|
onClick === null || onClick === void 0 || onClick(e);
|
|
82
97
|
if (createOrder) {
|
|
98
|
+
if (executionOptions) {
|
|
99
|
+
if (e.defaultPrevented) return;
|
|
100
|
+
return managedRun().then(() => undefined);
|
|
101
|
+
}
|
|
83
102
|
handlePayCreateOrder();
|
|
84
103
|
return;
|
|
85
104
|
}
|
|
@@ -87,14 +106,14 @@ const AirwallexButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
87
106
|
if ((props === null || props === void 0 ? void 0 : props.displayType) === 'modal') {
|
|
88
107
|
var _props$modalProps;
|
|
89
108
|
if (props !== null && props !== void 0 && (_props$modalProps = props.modalProps) !== null && _props$modalProps !== void 0 && (_props$modalProps = _props$modalProps.airwallexProps) !== null && _props$modalProps !== void 0 && _props$modalProps.initOptions) {
|
|
90
|
-
var _airwallexModalRef$
|
|
91
|
-
airwallexModalRef === null || airwallexModalRef === void 0 || (_airwallexModalRef$
|
|
109
|
+
var _airwallexModalRef$cu5;
|
|
110
|
+
airwallexModalRef === null || airwallexModalRef === void 0 || (_airwallexModalRef$cu5 = airwallexModalRef.current) === null || _airwallexModalRef$cu5 === void 0 || _airwallexModalRef$cu5.open();
|
|
92
111
|
}
|
|
93
112
|
} else {
|
|
94
113
|
var _props$popupProps;
|
|
95
114
|
if (props !== null && props !== void 0 && (_props$popupProps = props.popupProps) !== null && _props$popupProps !== void 0 && (_props$popupProps = _props$popupProps.airwallexProps) !== null && _props$popupProps !== void 0 && _props$popupProps.initOptions) {
|
|
96
|
-
var _airwallexPopupRef$
|
|
97
|
-
airwallexPopupRef === null || airwallexPopupRef === void 0 || (_airwallexPopupRef$
|
|
115
|
+
var _airwallexPopupRef$cu5;
|
|
116
|
+
airwallexPopupRef === null || airwallexPopupRef === void 0 || (_airwallexPopupRef$cu5 = airwallexPopupRef.current) === null || _airwallexPopupRef$cu5 === void 0 || _airwallexPopupRef$cu5.open();
|
|
98
117
|
}
|
|
99
118
|
}
|
|
100
119
|
return;
|
|
@@ -103,11 +122,13 @@ const AirwallexButton = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
103
122
|
setShowMask(true);
|
|
104
123
|
setAirwallexUrl(props === null || props === void 0 ? void 0 : props.airwallexUrl);
|
|
105
124
|
}
|
|
106
|
-
}, [onClick, createOrder, handlePayCreateOrder, props]);
|
|
125
|
+
}, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, props]);
|
|
107
126
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Button.default, _extends({
|
|
108
127
|
ref: airwallexButtonRef,
|
|
109
128
|
onClick: handleClick
|
|
110
|
-
}, (0, _omit.default)(others, ['payMode', 'displayType', 'createOrder', 'airwallexUrl', 'maskProps', 'popupProps', 'modalProps'])
|
|
129
|
+
}, (0, _omit.default)(others, ['payMode', 'displayType', 'createOrder', 'airwallexUrl', 'maskProps', 'popupProps', 'modalProps']), {
|
|
130
|
+
loading: executionOptions ? managed.loading || others.loading : others.loading
|
|
131
|
+
}), children), (props === null || props === void 0 ? void 0 : props.payMode) === 'embedded' && (props === null || props === void 0 ? void 0 : props.displayType) === 'popup' && /*#__PURE__*/_react.default.createElement(_airwallexPopup.default, _extends({
|
|
111
132
|
ref: airwallexPopupRef
|
|
112
133
|
}, props === null || props === void 0 ? void 0 : props.popupProps)), (props === null || props === void 0 ? void 0 : props.payMode) === 'embedded' && (props === null || props === void 0 ? void 0 : props.displayType) === 'modal' && /*#__PURE__*/_react.default.createElement(_airwallexModal.default, _extends({
|
|
113
134
|
ref: airwallexModalRef
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _Button = _interopRequireDefault(require("../Button"));
|
|
10
|
+
var _useAirwallexCheckout = require("./hooks/useAirwallexCheckout");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
13
|
+
/**
|
|
14
|
+
* @zh Airwallex 托管支付按钮,复用 useAirwallexCheckout。
|
|
15
|
+
* @en Hosted Airwallex button sharing useAirwallexCheckout.
|
|
16
|
+
* @since 1.2.0
|
|
17
|
+
*/
|
|
18
|
+
const AirwallexCheckoutButton = props => {
|
|
19
|
+
const {
|
|
20
|
+
target,
|
|
21
|
+
createOrder,
|
|
22
|
+
redirectOptions,
|
|
23
|
+
initOptions,
|
|
24
|
+
beforePay,
|
|
25
|
+
onLoadingChange,
|
|
26
|
+
onPaymentError,
|
|
27
|
+
onCancel,
|
|
28
|
+
children = 'Airwallex',
|
|
29
|
+
onClick,
|
|
30
|
+
loading,
|
|
31
|
+
...buttonProps
|
|
32
|
+
} = props;
|
|
33
|
+
const checkout = (0, _useAirwallexCheckout.useAirwallexCheckout)({
|
|
34
|
+
redirectOptions,
|
|
35
|
+
initOptions,
|
|
36
|
+
beforePay,
|
|
37
|
+
onLoadingChange,
|
|
38
|
+
onPaymentError,
|
|
39
|
+
onCancel
|
|
40
|
+
});
|
|
41
|
+
return /*#__PURE__*/_react.default.createElement(_Button.default, _extends({}, buttonProps, {
|
|
42
|
+
loading: checkout.loading || loading,
|
|
43
|
+
onClick: async event => {
|
|
44
|
+
event.persist();
|
|
45
|
+
await (onClick === null || onClick === void 0 ? void 0 : onClick(event));
|
|
46
|
+
if (!event.defaultPrevented) await checkout.openCheckout(createOrder ?? target ?? {
|
|
47
|
+
url: ''
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}), children);
|
|
51
|
+
};
|
|
52
|
+
var _default = exports.default = /*#__PURE__*/_react.default.memo(AirwallexCheckoutButton);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _airwallexPaymentElements = require("airwallex-payment-elements");
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
|
+
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); }
|
|
12
|
+
const AirwallexManaged = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
13
|
+
const {
|
|
14
|
+
type,
|
|
15
|
+
options,
|
|
16
|
+
initOptions,
|
|
17
|
+
instanceOptions,
|
|
18
|
+
onReady,
|
|
19
|
+
onSuccess,
|
|
20
|
+
onError,
|
|
21
|
+
style,
|
|
22
|
+
...others
|
|
23
|
+
} = props;
|
|
24
|
+
const container = (0, _react.useRef)(null);
|
|
25
|
+
const latest = (0, _react.useRef)(props);
|
|
26
|
+
latest.current = props;
|
|
27
|
+
const configuration = JSON.stringify([type, options, initOptions]);
|
|
28
|
+
(0, _react.useImperativeHandle)(ref, () => container.current);
|
|
29
|
+
(0, _react.useEffect)(() => {
|
|
30
|
+
let active = true;
|
|
31
|
+
let element = null;
|
|
32
|
+
const node = container.current;
|
|
33
|
+
if (!node) return;
|
|
34
|
+
const ready = event => {
|
|
35
|
+
var _latest$current$onRea, _latest$current;
|
|
36
|
+
return (_latest$current$onRea = (_latest$current = latest.current).onReady) === null || _latest$current$onRea === void 0 ? void 0 : _latest$current$onRea.call(_latest$current, event);
|
|
37
|
+
};
|
|
38
|
+
const success = event => {
|
|
39
|
+
var _latest$current$onSuc, _latest$current2;
|
|
40
|
+
return (_latest$current$onSuc = (_latest$current2 = latest.current).onSuccess) === null || _latest$current$onSuc === void 0 ? void 0 : _latest$current$onSuc.call(_latest$current2, event);
|
|
41
|
+
};
|
|
42
|
+
const error = event => {
|
|
43
|
+
var _latest$current$onErr, _latest$current3;
|
|
44
|
+
return (_latest$current$onErr = (_latest$current3 = latest.current).onError) === null || _latest$current$onErr === void 0 ? void 0 : _latest$current$onErr.call(_latest$current3, event);
|
|
45
|
+
};
|
|
46
|
+
node.addEventListener('onReady', ready);
|
|
47
|
+
node.addEventListener('onSuccess', success);
|
|
48
|
+
node.addEventListener('onError', error);
|
|
49
|
+
const snapshot = latest.current;
|
|
50
|
+
(0, _airwallexPaymentElements.loadAirwallex)({
|
|
51
|
+
env: 'demo',
|
|
52
|
+
...snapshot.initOptions
|
|
53
|
+
}).then(sdk => {
|
|
54
|
+
if (!active || !sdk) return;
|
|
55
|
+
const created = sdk.createElement(snapshot.type, snapshot.options);
|
|
56
|
+
if (!created) throw new Error('Payment element unavailable.');
|
|
57
|
+
element = created;
|
|
58
|
+
created.mount(node);
|
|
59
|
+
}).catch(() => {
|
|
60
|
+
var _latest$current$onErr2, _latest$current4;
|
|
61
|
+
if (active) (_latest$current$onErr2 = (_latest$current4 = latest.current).onError) === null || _latest$current$onErr2 === void 0 || _latest$current$onErr2.call(_latest$current4, new Error('Unable to initialize Airwallex element.'));
|
|
62
|
+
});
|
|
63
|
+
return () => {
|
|
64
|
+
var _element;
|
|
65
|
+
active = false;
|
|
66
|
+
node.removeEventListener('onReady', ready);
|
|
67
|
+
node.removeEventListener('onSuccess', success);
|
|
68
|
+
node.removeEventListener('onError', error);
|
|
69
|
+
(_element = element) === null || _element === void 0 || _element.unmount();
|
|
70
|
+
};
|
|
71
|
+
}, [configuration]);
|
|
72
|
+
// callbacks are read through latest; keep them out of the DOM.
|
|
73
|
+
void onReady;
|
|
74
|
+
void onSuccess;
|
|
75
|
+
void onError;
|
|
76
|
+
return /*#__PURE__*/_react.default.createElement("div", _extends({}, others, {
|
|
77
|
+
ref: container,
|
|
78
|
+
id: instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.containerId,
|
|
79
|
+
style: {
|
|
80
|
+
width: '100%',
|
|
81
|
+
...style
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
});
|
|
85
|
+
AirwallexManaged.displayName = 'AirwallexManaged';
|
|
86
|
+
var _default = exports.default = AirwallexManaged;
|
|
@@ -16,6 +16,8 @@ const AirwallexModal = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
16
16
|
airwallexProps: propsAirwallexProps,
|
|
17
17
|
visible,
|
|
18
18
|
onClose,
|
|
19
|
+
closeOnSuccess = true,
|
|
20
|
+
closeOnError = true,
|
|
19
21
|
footer = null,
|
|
20
22
|
...rest
|
|
21
23
|
} = props;
|
|
@@ -50,14 +52,14 @@ const AirwallexModal = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
50
52
|
}, rest), _airwallexProps && /*#__PURE__*/_react.default.createElement(_airwallex.default, _extends({
|
|
51
53
|
onSuccess: event => {
|
|
52
54
|
var _airwallexProps$onSuc;
|
|
53
|
-
if (!isControlled) {
|
|
55
|
+
if (closeOnSuccess && !isControlled) {
|
|
54
56
|
setUncontrolledVisible(false);
|
|
55
57
|
}
|
|
56
58
|
_airwallexProps === null || _airwallexProps === void 0 || (_airwallexProps$onSuc = _airwallexProps.onSuccess) === null || _airwallexProps$onSuc === void 0 || _airwallexProps$onSuc.call(_airwallexProps, event);
|
|
57
59
|
},
|
|
58
60
|
onError: event => {
|
|
59
61
|
var _airwallexProps$onErr;
|
|
60
|
-
if (!isControlled) {
|
|
62
|
+
if (closeOnError && !isControlled) {
|
|
61
63
|
setUncontrolledVisible(false);
|
|
62
64
|
}
|
|
63
65
|
_airwallexProps === null || _airwallexProps === void 0 || (_airwallexProps$onErr = _airwallexProps.onError) === null || _airwallexProps$onErr === void 0 || _airwallexProps$onErr.call(_airwallexProps, event);
|
|
@@ -15,6 +15,8 @@ const AirwallexPopup = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
15
15
|
const {
|
|
16
16
|
visible: controlledVisible,
|
|
17
17
|
onClose,
|
|
18
|
+
closeOnSuccess = true,
|
|
19
|
+
closeOnError = true,
|
|
18
20
|
closeOnMaskClick = true,
|
|
19
21
|
bodyStyle,
|
|
20
22
|
airwallexProps: propsAirwallexProps,
|
|
@@ -57,14 +59,14 @@ const AirwallexPopup = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
|
57
59
|
}, others), _airwallexProps && /*#__PURE__*/_react.default.createElement(_airwallex.default, _extends({
|
|
58
60
|
onSuccess: event => {
|
|
59
61
|
var _airwallexProps$onSuc;
|
|
60
|
-
if (!isControlled) {
|
|
62
|
+
if (closeOnSuccess && !isControlled) {
|
|
61
63
|
setUncontrolledVisible(false);
|
|
62
64
|
}
|
|
63
65
|
_airwallexProps === null || _airwallexProps === void 0 || (_airwallexProps$onSuc = _airwallexProps.onSuccess) === null || _airwallexProps$onSuc === void 0 || _airwallexProps$onSuc.call(_airwallexProps, event);
|
|
64
66
|
},
|
|
65
67
|
onError: event => {
|
|
66
68
|
var _airwallexProps$onErr;
|
|
67
|
-
if (!isControlled) {
|
|
69
|
+
if (closeOnError && !isControlled) {
|
|
68
70
|
setUncontrolledVisible(false);
|
|
69
71
|
}
|
|
70
72
|
_airwallexProps === null || _airwallexProps === void 0 || (_airwallexProps$onErr = _airwallexProps.onError) === null || _airwallexProps$onErr === void 0 || _airwallexProps$onErr.call(_airwallexProps, event);
|
|
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _airwallexManaged = _interopRequireDefault(require("./airwallex-managed"));
|
|
8
9
|
var _airwallexPaymentElements = require("airwallex-payment-elements");
|
|
9
10
|
var _dom = require("../utils/dom");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
12
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
13
|
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); }
|
|
12
14
|
const Airwallex = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
@@ -69,4 +71,10 @@ const Airwallex = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
|
69
71
|
}, others));
|
|
70
72
|
});
|
|
71
73
|
Airwallex.displayName = 'Airwallex';
|
|
72
|
-
|
|
74
|
+
const AirwallexEntry = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => props.instanceOptions ? /*#__PURE__*/_react.default.createElement(_airwallexManaged.default, _extends({}, props, {
|
|
75
|
+
ref: ref
|
|
76
|
+
})) : /*#__PURE__*/_react.default.createElement(Airwallex, _extends({}, props, {
|
|
77
|
+
ref: ref
|
|
78
|
+
})));
|
|
79
|
+
AirwallexEntry.displayName = 'AirwallexEntry';
|
|
80
|
+
var _default = exports.default = /*#__PURE__*/_react.default.memo(AirwallexEntry);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useAirwallexCheckout = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _usePaymentExecution = require("../../hooks/usePaymentExecution");
|
|
10
|
+
var _usePaymentRedirect = require("../../hooks/usePaymentRedirect");
|
|
11
|
+
var _useLatestCallback = require("../../hooks/useLatestCallback");
|
|
12
|
+
var _enums = require("../../shared/enums");
|
|
13
|
+
var _payment = require("../../shared/entitys/payment");
|
|
14
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
|
+
/**
|
|
16
|
+
* @zh URL 跳转或官方托管 Checkout;不在挂载时执行。
|
|
17
|
+
* @en URL or official hosted checkout; no mount-time execution.
|
|
18
|
+
* @since 1.2.0
|
|
19
|
+
*/
|
|
20
|
+
const useAirwallexCheckout = (options = {}) => {
|
|
21
|
+
const latest = (0, _react.useRef)(options);
|
|
22
|
+
latest.current = options;
|
|
23
|
+
const initialized = (0, _react.useRef)();
|
|
24
|
+
const execution = (0, _usePaymentExecution.usePaymentExecution)(options);
|
|
25
|
+
const redirect = (0, _usePaymentRedirect.usePaymentRedirect)(options.redirectOptions);
|
|
26
|
+
const openCheckout = (0, _useLatestCallback.useLatestCallback)(source => execution.run(async context => {
|
|
27
|
+
var _latest$current$redir;
|
|
28
|
+
const target = typeof source === 'function' ? await source(context.signal) : source;
|
|
29
|
+
if (!context.isCurrent()) return;
|
|
30
|
+
if (target === null) {
|
|
31
|
+
execution.cancel();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (target && typeof target.url === 'string') {
|
|
35
|
+
redirect.open(target.url);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const params = target === null || target === void 0 ? void 0 : target.checkout;
|
|
39
|
+
if (!(params !== null && params !== void 0 && params.client_secret) || !params.currency || (params.mode === 'recurring' ? !params.customer_id : !params.intent_id)) {
|
|
40
|
+
throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InvalidParameters, 'Required hosted checkout parameters are missing.');
|
|
41
|
+
}
|
|
42
|
+
const mode = (_latest$current$redir = latest.current.redirectOptions) === null || _latest$current$redir === void 0 ? void 0 : _latest$current$redir.openMode;
|
|
43
|
+
if (mode && mode !== _enums.OpenPayUrlMode.Href) throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InvalidParameters, 'Official hosted checkout navigates the current page.');
|
|
44
|
+
if (typeof window === 'undefined') throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.BrowserUnavailable, 'A browser is required.');
|
|
45
|
+
const initOptions = {
|
|
46
|
+
...latest.current.initOptions,
|
|
47
|
+
enabledElements: ['payments']
|
|
48
|
+
};
|
|
49
|
+
const key = JSON.stringify(initOptions);
|
|
50
|
+
if (!initialized.current || initialized.current.key !== key) {
|
|
51
|
+
const value = Promise.resolve().then(() => _interopRequireWildcard(require('@airwallex/components-sdk'))).then(({
|
|
52
|
+
init
|
|
53
|
+
}) => init(initOptions));
|
|
54
|
+
initialized.current = {
|
|
55
|
+
key,
|
|
56
|
+
value
|
|
57
|
+
};
|
|
58
|
+
value.catch(() => {
|
|
59
|
+
var _initialized$current;
|
|
60
|
+
if (((_initialized$current = initialized.current) === null || _initialized$current === void 0 ? void 0 : _initialized$current.value) === value) initialized.current = undefined;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
let instance;
|
|
64
|
+
try {
|
|
65
|
+
instance = await initialized.current.value;
|
|
66
|
+
} catch {
|
|
67
|
+
throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InitializationFailed, 'Unable to initialize Airwallex.');
|
|
68
|
+
}
|
|
69
|
+
if (!context.isCurrent()) return;
|
|
70
|
+
if (!instance.payments) throw new _payment.PaymentExecutionError(_enums.PaymentErrorCode.InitializationFailed, 'Airwallex payments are unavailable.');
|
|
71
|
+
await instance.payments.redirectToCheckout(params);
|
|
72
|
+
}));
|
|
73
|
+
const closeCheckout = (0, _useLatestCallback.useLatestCallback)(() => {
|
|
74
|
+
execution.cancel();
|
|
75
|
+
redirect.close();
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
...execution,
|
|
79
|
+
openCheckout,
|
|
80
|
+
closeCheckout
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
exports.useAirwallexCheckout = useAirwallexCheckout;
|
|
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
+
AirwallexCheckoutButton: true,
|
|
7
8
|
AirwallexPopup: true,
|
|
8
9
|
AirwallexButton: true,
|
|
9
|
-
AirwallexModal: true
|
|
10
|
+
AirwallexModal: true,
|
|
11
|
+
useAirwallexCheckout: true
|
|
10
12
|
};
|
|
11
13
|
Object.defineProperty(exports, "AirwallexButton", {
|
|
12
14
|
enumerable: true,
|
|
@@ -14,6 +16,12 @@ Object.defineProperty(exports, "AirwallexButton", {
|
|
|
14
16
|
return _airwallexButton.default;
|
|
15
17
|
}
|
|
16
18
|
});
|
|
19
|
+
Object.defineProperty(exports, "AirwallexCheckoutButton", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _airwallexCheckoutButton.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
17
25
|
Object.defineProperty(exports, "AirwallexModal", {
|
|
18
26
|
enumerable: true,
|
|
19
27
|
get: function () {
|
|
@@ -27,6 +35,13 @@ Object.defineProperty(exports, "AirwallexPopup", {
|
|
|
27
35
|
}
|
|
28
36
|
});
|
|
29
37
|
exports.default = void 0;
|
|
38
|
+
Object.defineProperty(exports, "useAirwallexCheckout", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _useAirwallexCheckout.useAirwallexCheckout;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
var _airwallexCheckoutButton = _interopRequireDefault(require("./airwallex-checkout-button"));
|
|
30
45
|
var _airwallex = _interopRequireDefault(require("./airwallex"));
|
|
31
46
|
var _airwallexPopup = _interopRequireDefault(require("./airwallex-popup"));
|
|
32
47
|
var _airwallexButton = _interopRequireDefault(require("./airwallex-button"));
|
|
@@ -43,8 +58,10 @@ Object.keys(_interface).forEach(function (key) {
|
|
|
43
58
|
}
|
|
44
59
|
});
|
|
45
60
|
});
|
|
61
|
+
var _useAirwallexCheckout = require("./hooks/useAirwallexCheckout");
|
|
46
62
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
47
63
|
const AirwallexComponent = Object.assign({}, _airwallex.default, {
|
|
64
|
+
CheckoutButton: _airwallexCheckoutButton.default,
|
|
48
65
|
Button: _airwallexButton.default,
|
|
49
66
|
Popup: _airwallexPopup.default,
|
|
50
67
|
Modal: _airwallexModal.default
|
|
@@ -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 {
|