pay-sdk-react 1.1.14 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +241 -78
  2. package/README.zh-CN.md +243 -79
  3. package/dist/css/index.css +11 -0
  4. package/dist/css/index.min.css +1 -1
  5. package/dist/es/Airwallex/airwallex-button.js +48 -16
  6. package/dist/es/Airwallex/airwallex-checkout-button.d.ts +4 -0
  7. package/dist/es/Airwallex/airwallex-checkout-button.js +73 -0
  8. package/dist/es/Airwallex/airwallex-managed.d.ts +4 -0
  9. package/dist/es/Airwallex/airwallex-managed.js +87 -0
  10. package/dist/es/Airwallex/airwallex-modal.js +7 -3
  11. package/dist/es/Airwallex/airwallex-popup.js +7 -3
  12. package/dist/es/Airwallex/airwallex.d.ts +1 -3
  13. package/dist/es/Airwallex/airwallex.js +10 -1
  14. package/dist/es/Airwallex/hooks/useAirwallexCheckout.d.ts +7 -0
  15. package/dist/es/Airwallex/hooks/useAirwallexCheckout.js +155 -0
  16. package/dist/es/Airwallex/index.d.ts +4 -0
  17. package/dist/es/Airwallex/index.js +5 -1
  18. package/dist/es/Airwallex/interface.d.ts +146 -0
  19. package/dist/es/Alipay/alipay-button.js +26 -7
  20. package/dist/es/Alipay/alipay.js +39 -12
  21. package/dist/es/Alipay/interface.d.ts +26 -1
  22. package/dist/es/Paypal/index.d.ts +2 -0
  23. package/dist/es/Paypal/index.js +3 -1
  24. package/dist/es/Paypal/interface.d.ts +40 -0
  25. package/dist/es/Paypal/paypal-button.js +24 -3
  26. package/dist/es/Paypal/paypal-smart-button.d.ts +4 -0
  27. package/dist/es/Paypal/paypal-smart-button.js +48 -0
  28. package/dist/es/Payssion/interface.d.ts +7 -0
  29. package/dist/es/Payssion/payssion-button.js +25 -4
  30. package/dist/es/Pix/interface.d.ts +67 -0
  31. package/dist/es/Pix/pix-button.js +26 -7
  32. package/dist/es/Pix/pix-enhanced.d.ts +4 -0
  33. package/dist/es/Pix/pix-enhanced.js +182 -0
  34. package/dist/es/Pix/pix.d.ts +1 -1
  35. package/dist/es/Pix/pix.js +6 -1
  36. package/dist/es/Pix/style/index.css +11 -0
  37. package/dist/es/Pix/style/index.min.css +1 -1
  38. package/dist/es/Stripe/hooks/useStripeCheckout.d.ts +7 -0
  39. package/dist/es/Stripe/hooks/useStripeCheckout.js +86 -0
  40. package/dist/es/Stripe/index.d.ts +4 -0
  41. package/dist/es/Stripe/index.js +5 -1
  42. package/dist/es/Stripe/interface.d.ts +120 -0
  43. package/dist/es/Stripe/stripe-button.js +32 -10
  44. package/dist/es/Stripe/stripe-checkout-button.d.ts +4 -0
  45. package/dist/es/Stripe/stripe-checkout-button.js +70 -0
  46. package/dist/es/Stripe/stripe-modal.js +19 -2
  47. package/dist/es/Stripe/stripe-popup.js +13 -2
  48. package/dist/es/Stripe/stripe.js +38 -4
  49. package/dist/es/Wechat/interface.d.ts +13 -0
  50. package/dist/es/Wechat/wechat-button.js +26 -7
  51. package/dist/es/Wechat/wechat-content.d.ts +4 -0
  52. package/dist/es/Wechat/wechat-content.js +61 -0
  53. package/dist/es/Wechat/wechat.d.ts +1 -1
  54. package/dist/es/Wechat/wechat.js +5 -1
  55. package/dist/es/hooks/useLatestCallback.d.ts +1 -0
  56. package/dist/es/hooks/useLatestCallback.js +8 -0
  57. package/dist/es/hooks/useManagedOrder.d.ts +8 -0
  58. package/dist/es/hooks/useManagedOrder.js +67 -0
  59. package/dist/es/hooks/usePaymentExecution.d.ts +13 -0
  60. package/dist/es/hooks/usePaymentExecution.js +176 -0
  61. package/dist/es/hooks/usePaymentQr.d.ts +6 -0
  62. package/dist/es/hooks/usePaymentQr.js +52 -0
  63. package/dist/es/hooks/usePaymentRedirect.d.ts +5 -0
  64. package/dist/es/hooks/usePaymentRedirect.js +83 -0
  65. package/dist/es/index.d.ts +33 -6
  66. package/dist/es/index.js +19 -1
  67. package/dist/es/pay-modal/interface.d.ts +22 -2
  68. package/dist/es/pay-modal/pay-modal.js +36 -16
  69. package/dist/es/shared/entitys/payment.d.ts +227 -0
  70. package/dist/es/shared/entitys/payment.js +75 -0
  71. package/dist/es/shared/enums/index.d.ts +1 -88
  72. package/dist/es/shared/enums/index.js +1 -91
  73. package/dist/es/shared/enums/payment.d.ts +162 -0
  74. package/dist/es/shared/enums/payment.js +168 -0
  75. package/dist/es/shared/index.d.ts +2 -0
  76. package/dist/es/shared/index.js +2 -1
  77. package/dist/lib/Airwallex/airwallex-button.js +31 -10
  78. package/dist/lib/Airwallex/airwallex-checkout-button.js +52 -0
  79. package/dist/lib/Airwallex/airwallex-managed.js +86 -0
  80. package/dist/lib/Airwallex/airwallex-modal.js +4 -2
  81. package/dist/lib/Airwallex/airwallex-popup.js +4 -2
  82. package/dist/lib/Airwallex/airwallex.js +9 -1
  83. package/dist/lib/Airwallex/hooks/useAirwallexCheckout.js +83 -0
  84. package/dist/lib/Airwallex/index.js +18 -1
  85. package/dist/lib/Alipay/alipay-button.js +21 -6
  86. package/dist/lib/Alipay/alipay.js +36 -9
  87. package/dist/lib/Paypal/index.js +17 -1
  88. package/dist/lib/Paypal/paypal-button.js +19 -2
  89. package/dist/lib/Paypal/paypal-smart-button.js +45 -0
  90. package/dist/lib/Payssion/payssion-button.js +20 -3
  91. package/dist/lib/Pix/pix-button.js +21 -6
  92. package/dist/lib/Pix/pix-enhanced.js +143 -0
  93. package/dist/lib/Pix/pix.js +6 -1
  94. package/dist/lib/Pix/style/index.css +11 -0
  95. package/dist/lib/Pix/style/index.min.css +1 -1
  96. package/dist/lib/Stripe/hooks/useStripeCheckout.js +41 -0
  97. package/dist/lib/Stripe/index.js +18 -1
  98. package/dist/lib/Stripe/stripe-button.js +28 -10
  99. package/dist/lib/Stripe/stripe-checkout-button.js +50 -0
  100. package/dist/lib/Stripe/stripe-modal.js +12 -1
  101. package/dist/lib/Stripe/stripe-popup.js +12 -1
  102. package/dist/lib/Stripe/stripe.js +30 -1
  103. package/dist/lib/Wechat/wechat-button.js +21 -6
  104. package/dist/lib/Wechat/wechat-content.js +65 -0
  105. package/dist/lib/Wechat/wechat.js +3 -1
  106. package/dist/lib/hooks/useLatestCallback.js +13 -0
  107. package/dist/lib/hooks/useManagedOrder.js +29 -0
  108. package/dist/lib/hooks/usePaymentExecution.js +113 -0
  109. package/dist/lib/hooks/usePaymentQr.js +51 -0
  110. package/dist/lib/hooks/usePaymentRedirect.js +87 -0
  111. package/dist/lib/index.js +57 -1
  112. package/dist/lib/pay-modal/pay-modal.js +33 -16
  113. package/dist/lib/shared/entitys/payment.js +61 -0
  114. package/dist/lib/shared/enums/index.js +11 -91
  115. package/dist/lib/shared/enums/payment.js +172 -0
  116. package/dist/lib/shared/index.js +12 -1
  117. package/dist/umd/pay-sdk-react.umd.js +6488 -7731
  118. package/dist/umd/pay-sdk-react.umd.js.map +1 -1
  119. package/package.json +17 -3
@@ -1,91 +1 @@
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
- }({});
1
+ export * from './payment';
@@ -0,0 +1,162 @@
1
+ export declare enum PaymentMethod {
2
+ /**
3
+ * @zh 微信(pc)
4
+ * @en Wechat(pc)
5
+ */
6
+ WechatPc = "wechat-pc",
7
+ /**
8
+ * @zh 支付宝(pc)
9
+ * @en Alipay(pc)
10
+ */
11
+ AlipayPc = "alipay-pc",
12
+ /**
13
+ * @zh paypal(pc)
14
+ * @en Paypal(pc)
15
+ */
16
+ PaypalPc = "paypal-pc",
17
+ /**
18
+ * @zh stripe(pc)
19
+ * @en Stripe(pc)
20
+ */
21
+ StripePc = "stripe-pc",
22
+ /**
23
+ * @zh 微信(H5)
24
+ * @en Wechat(H5)
25
+ */
26
+ WechatH5 = "wechat-h5",
27
+ /**
28
+ * @zh 支付宝(H5)
29
+ * @en Alipay(H5)
30
+ */
31
+ AlipayH5 = "alipay-h5",
32
+ /**
33
+ * @zh paypal(H5)
34
+ * @en Paypal(H5)
35
+ */
36
+ PaypalH5 = "paypal-h5",
37
+ /**
38
+ * @zh 微信内部(H5)
39
+ * @en Wechat inside(H5)
40
+ */
41
+ WechatInsideH5 = "wechat-inside-h5",
42
+ /**
43
+ * @zh stripe(H5)
44
+ * @en Stripe(H5)
45
+ */
46
+ StripeH5 = "stripe-h5",
47
+ /**
48
+ * @zh payssion支付
49
+ * @en Payssion
50
+ */
51
+ Payssion = "payssion",
52
+ /**
53
+ * @zh 空中云汇
54
+ * @en Airwallex
55
+ */
56
+ Airwallex = "airwallex",
57
+ /**
58
+ * @zh PIX(pc)
59
+ * @en PIX(pc)
60
+ */
61
+ PixPc = "pix-pc",
62
+ /**
63
+ * @zh PIX(H5)
64
+ * @en PIX(H5)
65
+ */
66
+ PixH5 = "pix-h5"
67
+ }
68
+ /**
69
+ * @zh 支付页面打开模式枚举
70
+ * @en Payment page opening mode enum
71
+ */
72
+ export declare enum OpenPayUrlMode {
73
+ /**
74
+ * @zh 新页面或弹窗模式 - 使用 window.open() 打开新页面或弹窗,支持智能设备检测
75
+ * @en New page or popup mode - Use window.open() to open new page or popup, supports smart device detection
76
+ */
77
+ Window = "window",
78
+ /**
79
+ * @zh 新页面模式 - 使用 window.location.href 跳转到新页面
80
+ * @en New page mode - Use window.location.href to navigate to new page
81
+ */
82
+ Href = "href",
83
+ /**
84
+ * @zh 替换页面模式 - 使用 window.location.replace 替换当前页面
85
+ * @en Replace page mode - Use window.location.replace to replace current page
86
+ */
87
+ Replace = "replace"
88
+ }
89
+ /**
90
+ * @zh 前端执行状态,不代表订单状态。
91
+ * @en Frontend execution, not order status.
92
+ * @since 1.2.0
93
+ */
94
+ export declare enum PaymentExecutionStatus {
95
+ /**
96
+ * @zh 尚未执行。
97
+ * @en Not executed.
98
+ * @since 1.2.0
99
+ */
100
+ Idle = "idle",
101
+ /**
102
+ * @zh 当前前端执行处理中。
103
+ * @en Frontend execution is pending.
104
+ * @since 1.2.0
105
+ */
106
+ Pending = "pending",
107
+ /**
108
+ * @zh 当前执行阶段完成,不代表支付成功。
109
+ * @en Execution stage completed, not payment success.
110
+ * @since 1.2.0
111
+ */
112
+ Completed = "completed",
113
+ /**
114
+ * @zh 当前前端执行已取消。
115
+ * @en Frontend execution cancelled.
116
+ * @since 1.2.0
117
+ */
118
+ Cancelled = "cancelled",
119
+ /**
120
+ * @zh 当前前端执行失败。
121
+ * @en Frontend execution failed.
122
+ * @since 1.2.0
123
+ */
124
+ Failed = "failed"
125
+ }
126
+ /**
127
+ * @zh 执行错误分类。
128
+ * @en Execution error codes.
129
+ * @since 1.2.0
130
+ */
131
+ export declare enum PaymentErrorCode {
132
+ /**
133
+ * @zh 目标或凭证无效。
134
+ * @en Invalid target or credentials.
135
+ * @since 1.2.0
136
+ */
137
+ InvalidParameters = "invalid_parameters",
138
+ /**
139
+ * @zh 执行时缺少浏览器环境。
140
+ * @en Browser environment unavailable for execution.
141
+ * @since 1.2.0
142
+ */
143
+ BrowserUnavailable = "browser_unavailable",
144
+ /**
145
+ * @zh 支付窗口被浏览器拦截。
146
+ * @en Payment window blocked by the browser.
147
+ * @since 1.2.0
148
+ */
149
+ WindowBlocked = "window_blocked",
150
+ /**
151
+ * @zh 官方 SDK 初始化失败。
152
+ * @en Official SDK initialization failed.
153
+ * @since 1.2.0
154
+ */
155
+ InitializationFailed = "initialization_failed",
156
+ /**
157
+ * @zh 其他前端执行失败。
158
+ * @en Other frontend execution failure.
159
+ * @since 1.2.0
160
+ */
161
+ ExecutionFailed = "execution_failed"
162
+ }
@@ -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';
@@ -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$cu3;
68
- airwallexModalRef === null || airwallexModalRef === void 0 || (_airwallexModalRef$cu3 = airwallexModalRef.current) === null || _airwallexModalRef$cu3 === void 0 || _airwallexModalRef$cu3.open(options);
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$cu3;
71
- (_airwallexPopupRef$cu3 = airwallexPopupRef.current) === null || _airwallexPopupRef$cu3 === void 0 || _airwallexPopupRef$cu3.open(options);
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$cu4;
91
- airwallexModalRef === null || airwallexModalRef === void 0 || (_airwallexModalRef$cu4 = airwallexModalRef.current) === null || _airwallexModalRef$cu4 === void 0 || _airwallexModalRef$cu4.open();
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$cu4;
97
- airwallexPopupRef === null || airwallexPopupRef === void 0 || (_airwallexPopupRef$cu4 = airwallexPopupRef.current) === null || _airwallexPopupRef$cu4 === void 0 || _airwallexPopupRef$cu4.open();
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'])), 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({
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;