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,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
+ }
@@ -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$curre3;
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$curre3 = alipayModalRef.current) === null || _alipayModalRef$curre3 === void 0 || _alipayModalRef$curre3.open(options);
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$curre4;
69
- alipayModalRef === null || alipayModalRef === void 0 || (_alipayModalRef$curre4 = alipayModalRef.current) === null || _alipayModalRef$curre4 === void 0 || _alipayModalRef$curre4.open();
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), children), /*#__PURE__*/React.createElement(AlipayModal, _extends({
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
  });
@@ -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
- return setLoading(false);
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
@@ -1,2 +1,4 @@
1
1
  export * from './interface';
2
2
  export { default as PaypalButton } from './paypal-button';
3
+ export { default as PaypalSmartButton } from './paypal-smart-button';
4
+ export { PayPalScriptProvider as PaypalProvider } from '@paypal/react-paypal-js';
@@ -1,2 +1,4 @@
1
1
  export * from './interface';
2
- export { default as PaypalButton } from './paypal-button';
2
+ export { default as PaypalButton } from './paypal-button';
3
+ export { default as PaypalSmartButton } from './paypal-smart-button';
4
+ export { PayPalScriptProvider as PaypalProvider } from '@paypal/react-paypal-js';
@@ -1,3 +1,6 @@
1
+ import type { PaymentExecutionOptions } from '../shared/entitys/payment';
2
+ import type { ComponentProps, ReactNode } from 'react';
3
+ import type { PayPalButtons, PayPalScriptProvider } from '@paypal/react-paypal-js';
1
4
  import { ButtonProps, ButtonRef } from '../Button';
2
5
  import { PayMaskProps } from '../PayMask';
3
6
  /**
@@ -7,6 +10,12 @@ import { PayMaskProps } from '../PayMask';
7
10
  * @en Props for Paypal component
8
11
  */
9
12
  export interface PaypalButtonProps extends ButtonProps {
13
+ /**
14
+ * @zh 显式启用受管理的 createOrder 流程;未传保持旧行为。
15
+ * @en Opt-in managed createOrder execution; omitted preserves legacy behavior.
16
+ * @since 1.2.0
17
+ */
18
+ executionOptions?: PaymentExecutionOptions;
10
19
  /**
11
20
  * @zh PaypalMask 组件的属性
12
21
  * @en Props for PaypalMask component
@@ -62,3 +71,34 @@ export interface PaypalSecretMap {
62
71
  * @en Function to create order, returns Paypal required params
63
72
  */
64
73
  export type CreateOrderPaypalFn = () => Promise<PaypalSecretMap>;
74
+ /**
75
+ * @zh 官方按钮事件透传,由业务确认订单。
76
+ * @en Official button callbacks; caller confirms orders.
77
+ * @since 1.2.0
78
+ */
79
+ export type PaypalSmartButtonProps = ComponentProps<typeof PayPalButtons> & {
80
+ /**
81
+ * @zh 配置时由组件提供 Provider;未配置时复用外层 Provider。
82
+ * @en Provide a local Provider or reuse an outer Provider.
83
+ * @since 1.2.0
84
+ */
85
+ scriptOptions?: ComponentProps<typeof PayPalScriptProvider>['options'];
86
+ /**
87
+ * @zh 官方脚本加载时的内容。
88
+ * @en Content while the official script loads.
89
+ * @since 1.2.0
90
+ */
91
+ loadingContent?: ReactNode;
92
+ /**
93
+ * @zh 官方脚本加载失败时的展示。
94
+ * @en Content on script loading failure.
95
+ * @since 1.2.0
96
+ */
97
+ errorContent?: ReactNode;
98
+ /**
99
+ * @zh 脚本加载失败,与按钮 onError 分开。
100
+ * @en Script loading failure, separate from button onError.
101
+ * @since 1.2.0
102
+ */
103
+ onScriptError?: () => void;
104
+ };
@@ -1,4 +1,4 @@
1
- var _excluded = ["className", "children", "onClick", "paypalUrl", "createOrder", "maskProps", "isPayment", "closeWindowOnUnmount"],
1
+ var _excluded = ["className", "children", "onClick", "paypalUrl", "createOrder", "executionOptions", "maskProps", "isPayment", "closeWindowOnUnmount"],
2
2
  _excluded2 = ["onClose"];
3
3
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
4
4
  function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
@@ -13,6 +13,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
13
13
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
14
14
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
15
15
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
16
+ import { useManagedOrder } from '../hooks/useManagedOrder';
16
17
  import React, { forwardRef, memo, useCallback, useImperativeHandle, useRef, useState, useEffect } from 'react';
17
18
  import { IconPaypalText, IconPaypalWhite } from '../icons';
18
19
  import cs from '../utils/classNames';
@@ -26,6 +27,7 @@ var PaypalButton = /*#__PURE__*/forwardRef(function (props, ref) {
26
27
  onClick = props.onClick,
27
28
  propsPaypalUrl = props.paypalUrl,
28
29
  createOrder = props.createOrder,
30
+ executionOptions = props.executionOptions,
29
31
  maskProps = props.maskProps,
30
32
  isPayment = props.isPayment,
31
33
  _props$closeWindowOnU = props.closeWindowOnUnmount,
@@ -61,11 +63,21 @@ var PaypalButton = /*#__PURE__*/forwardRef(function (props, ref) {
61
63
  }
62
64
  },
63
65
  closePayment: function closePayment() {
66
+ if (executionOptions) managed.cancel();
64
67
  setShowMask(false);
65
68
  },
66
69
  current: paypalButtonRef.current
67
70
  };
68
71
  });
72
+ var managed = useManagedOrder(createOrder, function (target) {
73
+ if (target.paypalUrl) {
74
+ setPaypalUrl(target.paypalUrl);
75
+ setShowMask(true);
76
+ }
77
+ }, executionOptions, function (target) {
78
+ return typeof target.paypalUrl === 'string' && Boolean(target.paypalUrl.trim());
79
+ });
80
+ var managedRun = managed.run;
69
81
  var handlePayCreateOrder = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
70
82
  var _yield$createOrder, _paypalUrl;
71
83
  return _regenerator().w(function (_context) {
@@ -98,17 +110,26 @@ var PaypalButton = /*#__PURE__*/forwardRef(function (props, ref) {
98
110
  }, [propsPaypalUrl]);
99
111
  var handleClick = useCallback(function (e) {
100
112
  if (createOrder) {
113
+ if (executionOptions) {
114
+ onClick === null || onClick === void 0 || onClick(e);
115
+ if (e.defaultPrevented) return;
116
+ return managedRun().then(function () {
117
+ return undefined;
118
+ });
119
+ }
101
120
  handlePayCreateOrder();
102
121
  } else {
103
122
  handleOpen();
104
123
  }
105
124
  onClick === null || onClick === void 0 || onClick(e);
106
- }, [onClick, createOrder, handlePayCreateOrder, handleOpen]);
125
+ }, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, handleOpen]);
107
126
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({
108
127
  ref: paypalButtonRef,
109
128
  className: cs(getPrefixCls('paypal-btn'), className),
110
129
  onClick: handleClick
111
- }, others), children), showMask && paypalUrl && /*#__PURE__*/React.createElement(PayMask, _extends({
130
+ }, others, {
131
+ loading: executionOptions ? managed.loading || others.loading : others.loading
132
+ }), children), showMask && paypalUrl && /*#__PURE__*/React.createElement(PayMask, _extends({
112
133
  visible: showMask,
113
134
  onClose: function onClose() {
114
135
  setShowMask(false);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { PaypalSmartButtonProps } from './interface';
3
+ declare const _default: React.MemoExoticComponent<({ scriptOptions, ...props }: PaypalSmartButtonProps) => import("react/jsx-runtime").JSX.Element>;
4
+ export default _default;
@@ -0,0 +1,48 @@
1
+ 'use client';
2
+
3
+ var _excluded = ["loadingContent", "errorContent", "onScriptError"],
4
+ _excluded2 = ["scriptOptions"];
5
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ 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; }
9
+ 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; } }
10
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
11
+ 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; }
12
+ 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; }
13
+ import React, { useEffect, useRef } from 'react';
14
+ import { PayPalButtons, PayPalScriptProvider, usePayPalScriptReducer } from '@paypal/react-paypal-js';
15
+ var SmartButtonContent = function SmartButtonContent(_ref) {
16
+ var loadingContent = _ref.loadingContent,
17
+ errorContent = _ref.errorContent,
18
+ onScriptError = _ref.onScriptError,
19
+ props = _objectWithoutProperties(_ref, _excluded);
20
+ var _usePayPalScriptReduc = usePayPalScriptReducer(),
21
+ _usePayPalScriptReduc2 = _slicedToArray(_usePayPalScriptReduc, 1),
22
+ _usePayPalScriptReduc3 = _usePayPalScriptReduc2[0],
23
+ isPending = _usePayPalScriptReduc3.isPending,
24
+ isRejected = _usePayPalScriptReduc3.isRejected;
25
+ var onError = useRef(onScriptError);
26
+ onError.current = onScriptError;
27
+ useEffect(function () {
28
+ var _onError$current;
29
+ if (isRejected) (_onError$current = onError.current) === null || _onError$current === void 0 || _onError$current.call(onError);
30
+ }, [isRejected]);
31
+ if (isRejected && errorContent !== undefined) return /*#__PURE__*/React.createElement(React.Fragment, null, errorContent);
32
+ if (isPending && loadingContent !== undefined) return /*#__PURE__*/React.createElement(React.Fragment, null, loadingContent);
33
+ return /*#__PURE__*/React.createElement(PayPalButtons, props);
34
+ };
35
+ /**
36
+ * @zh PayPal 官方按钮封装,业务负责确认订单。
37
+ * @en Official PayPal button wrapper; the caller verifies orders.
38
+ * @since 1.2.0
39
+ */
40
+ var PaypalSmartButton = function PaypalSmartButton(_ref2) {
41
+ var scriptOptions = _ref2.scriptOptions,
42
+ props = _objectWithoutProperties(_ref2, _excluded2);
43
+ if (scriptOptions) return /*#__PURE__*/React.createElement(PayPalScriptProvider, {
44
+ options: scriptOptions
45
+ }, /*#__PURE__*/React.createElement(SmartButtonContent, props));
46
+ return /*#__PURE__*/React.createElement(SmartButtonContent, props);
47
+ };
48
+ export default /*#__PURE__*/React.memo(PaypalSmartButton);
@@ -1,3 +1,4 @@
1
+ import type { PaymentExecutionOptions } from '../shared/entitys/payment';
1
2
  import { ButtonProps, ButtonRef } from '../Button';
2
3
  import { PayMaskProps } from '../PayMask';
3
4
  /**
@@ -7,6 +8,12 @@ import { PayMaskProps } from '../PayMask';
7
8
  * @en Props for Paypal component
8
9
  */
9
10
  export interface PayssionButtonProps extends ButtonProps {
11
+ /**
12
+ * @zh 显式启用受管理的 createOrder 流程;未传保持旧行为。
13
+ * @en Opt-in managed createOrder execution; omitted preserves legacy behavior.
14
+ * @since 1.2.0
15
+ */
16
+ executionOptions?: PaymentExecutionOptions;
10
17
  /**
11
18
  * @zh PayssionMask 组件的属性
12
19
  * @en Props for PayssionMask component