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,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 WechatModal from './wechat-modal';
@@ -18,6 +19,7 @@ var WechatButton = /*#__PURE__*/forwardRef(function (props, ref) {
18
19
  children = _props$children === void 0 ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(IconWechatPay, null), "\u5FAE\u4FE1\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 wechatButtonRef = useRef(null);
@@ -34,13 +36,21 @@ var WechatButton = /*#__PURE__*/forwardRef(function (props, ref) {
34
36
  },
35
37
  closeModal: function closeModal() {
36
38
  var _wechatModalRef$curre2;
39
+ if (executionOptions) managed.cancel();
37
40
  (_wechatModalRef$curre2 = wechatModalRef.current) === null || _wechatModalRef$curre2 === void 0 || _wechatModalRef$curre2.close();
38
41
  },
39
42
  current: wechatButtonRef.current
40
43
  };
41
44
  });
45
+ var managed = useManagedOrder(createOrder, function (target) {
46
+ var _wechatModalRef$curre3;
47
+ (_wechatModalRef$curre3 = wechatModalRef.current) === null || _wechatModalRef$curre3 === void 0 || _wechatModalRef$curre3.open(target);
48
+ }, executionOptions, function (target) {
49
+ return typeof target.wechatUrl === 'string' && Boolean(target.wechatUrl.trim());
50
+ });
51
+ var managedRun = managed.run;
42
52
  var handlePayCreateOrder = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
43
- var _wechatModalRef$curre3, options;
53
+ var _wechatModalRef$curre4, options;
44
54
  return _regenerator().w(function (_context) {
45
55
  while (1) switch (_context.n) {
46
56
  case 0:
@@ -52,7 +62,7 @@ var WechatButton = /*#__PURE__*/forwardRef(function (props, ref) {
52
62
  return createOrder();
53
63
  case 1:
54
64
  options = _context.v;
55
- (_wechatModalRef$curre3 = wechatModalRef.current) === null || _wechatModalRef$curre3 === void 0 || _wechatModalRef$curre3.open(options);
65
+ (_wechatModalRef$curre4 = wechatModalRef.current) === null || _wechatModalRef$curre4 === void 0 || _wechatModalRef$curre4.open(options);
56
66
  case 2:
57
67
  return _context.a(2);
58
68
  }
@@ -61,18 +71,27 @@ var WechatButton = /*#__PURE__*/forwardRef(function (props, ref) {
61
71
  var handleClick = useCallback(function (e) {
62
72
  var _modalProps$wechatPro;
63
73
  if (createOrder) {
74
+ if (executionOptions) {
75
+ onClick === null || onClick === void 0 || onClick(e);
76
+ if (e.defaultPrevented) return;
77
+ return managedRun().then(function () {
78
+ return undefined;
79
+ });
80
+ }
64
81
  handlePayCreateOrder();
65
82
  } else if (modalProps !== null && modalProps !== void 0 && (_modalProps$wechatPro = modalProps.wechatProps) !== null && _modalProps$wechatPro !== void 0 && _modalProps$wechatPro.wechatUrl) {
66
- var _wechatModalRef$curre4;
67
- wechatModalRef === null || wechatModalRef === void 0 || (_wechatModalRef$curre4 = wechatModalRef.current) === null || _wechatModalRef$curre4 === void 0 || _wechatModalRef$curre4.open();
83
+ var _wechatModalRef$curre5;
84
+ wechatModalRef === null || wechatModalRef === void 0 || (_wechatModalRef$curre5 = wechatModalRef.current) === null || _wechatModalRef$curre5 === void 0 || _wechatModalRef$curre5.open();
68
85
  }
69
86
  onClick === null || onClick === void 0 || onClick(e);
70
- }, [onClick, createOrder, handlePayCreateOrder, modalProps]);
87
+ }, [executionOptions, managedRun, onClick, createOrder, handlePayCreateOrder, modalProps]);
71
88
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({
72
89
  ref: wechatButtonRef,
73
90
  className: cs(getPrefixCls('wechat-btn'), className),
74
91
  onClick: handleClick
75
- }, others), children), /*#__PURE__*/React.createElement(WechatModal, _extends({
92
+ }, others, {
93
+ loading: executionOptions ? managed.loading || others.loading : others.loading
94
+ }), children), /*#__PURE__*/React.createElement(WechatModal, _extends({
76
95
  ref: wechatModalRef
77
96
  }, modalProps)));
78
97
  });
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { WechatProps } from './interface';
3
+ declare const _default: React.MemoExoticComponent<({ wechatUrl, wechatType, tipText, className, style, qrProps, }: WechatProps) => import("react/jsx-runtime").JSX.Element>;
4
+ export default _default;
@@ -0,0 +1,61 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import React from 'react';
8
+ import { usePaymentQr } from '../hooks/usePaymentQr';
9
+ import cs from '../utils/classNames';
10
+ import { getPrefixCls } from '../utils/getPrefixCls';
11
+ var WechatContent = function WechatContent(_ref) {
12
+ var _qrProps$loadingConte, _qrProps$errorContent;
13
+ var wechatUrl = _ref.wechatUrl,
14
+ _ref$wechatType = _ref.wechatType,
15
+ wechatType = _ref$wechatType === void 0 ? 'qrcode' : _ref$wechatType,
16
+ _ref$tipText = _ref.tipText,
17
+ tipText = _ref$tipText === void 0 ? '请使用微信APP扫码支付' : _ref$tipText,
18
+ className = _ref.className,
19
+ style = _ref.style,
20
+ _ref$qrProps = _ref.qrProps,
21
+ qrProps = _ref$qrProps === void 0 ? {} : _ref$qrProps;
22
+ var _usePaymentQr = usePaymentQr(wechatUrl, wechatType === 'image', qrProps),
23
+ imageUrl = _usePaymentQr.imageUrl,
24
+ loading = _usePaymentQr.loading,
25
+ failed = _usePaymentQr.failed;
26
+ if (loading) return /*#__PURE__*/React.createElement(React.Fragment, null, (_qrProps$loadingConte = qrProps.loadingContent) !== null && _qrProps$loadingConte !== void 0 ? _qrProps$loadingConte : null);
27
+ if (failed) return /*#__PURE__*/React.createElement(React.Fragment, null, (_qrProps$errorContent = qrProps.errorContent) !== null && _qrProps$errorContent !== void 0 ? _qrProps$errorContent : null);
28
+ var prefix = getPrefixCls('wechat-qrcode');
29
+ var _qrProps$classNames = qrProps.classNames,
30
+ names = _qrProps$classNames === void 0 ? {} : _qrProps$classNames,
31
+ _qrProps$styles = qrProps.styles,
32
+ styles = _qrProps$styles === void 0 ? {} : _qrProps$styles;
33
+ return /*#__PURE__*/React.createElement("div", {
34
+ className: cs(prefix, className, names.root),
35
+ style: _objectSpread(_objectSpread({}, style), styles.root)
36
+ }, /*#__PURE__*/React.createElement("div", {
37
+ className: cs("".concat(prefix, "__container"), names.container),
38
+ style: _objectSpread({
39
+ position: 'relative',
40
+ width: qrProps.size,
41
+ height: qrProps.size
42
+ }, styles.container)
43
+ }, /*#__PURE__*/React.createElement("img", {
44
+ className: cs("".concat(prefix, "__image"), names.image),
45
+ style: styles.image,
46
+ src: imageUrl,
47
+ alt: "\u5FAE\u4FE1\u652F\u4ED8\u4E8C\u7EF4\u7801"
48
+ }), qrProps.overlay !== undefined ? /*#__PURE__*/React.createElement("div", {
49
+ className: names.overlay,
50
+ style: _objectSpread({
51
+ position: 'absolute',
52
+ left: '50%',
53
+ top: '50%',
54
+ transform: 'translate(-50%, -50%)'
55
+ }, styles.overlay)
56
+ }, qrProps.overlay) : null), tipText ? /*#__PURE__*/React.createElement("span", {
57
+ className: cs("".concat(prefix, "__tip"), names.tip),
58
+ style: styles.tip
59
+ }, tipText) : null);
60
+ };
61
+ export default /*#__PURE__*/React.memo(WechatContent);
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { WechatProps } from './interface';
3
- declare const _default: React.NamedExoticComponent<WechatProps>;
3
+ declare const _default: React.MemoExoticComponent<(props: WechatProps) => import("react/jsx-runtime").JSX.Element>;
4
4
  export default _default;
@@ -6,6 +6,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
6
6
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
7
  import React, { memo, useEffect, useState } from 'react';
8
8
  import cs from '../utils/classNames';
9
+ import WechatContent from './wechat-content';
9
10
  import makeQrcode from '../utils/qrcode';
10
11
  import { getPrefixCls } from '../utils/getPrefixCls';
11
12
  var classPrefix = getPrefixCls('wechat-qrcode');
@@ -46,4 +47,7 @@ var WechatQrCode = function WechatQrCode(_ref) {
46
47
  className: "".concat(classPrefix, "__tip")
47
48
  }, tipText));
48
49
  };
49
- export default /*#__PURE__*/memo(WechatQrCode);
50
+ var WechatEntry = function WechatEntry(props) {
51
+ return props.qrProps ? /*#__PURE__*/React.createElement(WechatContent, props) : /*#__PURE__*/React.createElement(WechatQrCode, props);
52
+ };
53
+ export default /*#__PURE__*/memo(WechatEntry);
@@ -0,0 +1 @@
1
+ export declare const useLatestCallback: <Args extends unknown[], Result>(callback: (...args: Args) => Result) => (...args: Args) => Result;
@@ -0,0 +1,8 @@
1
+ import { useCallback, useRef } from 'react';
2
+ export var useLatestCallback = function useLatestCallback(callback) {
3
+ var latest = useRef(callback);
4
+ latest.current = callback;
5
+ return useCallback(function () {
6
+ return latest.current.apply(latest, arguments);
7
+ }, []);
8
+ };
@@ -0,0 +1,8 @@
1
+ import { PaymentExecutionError, type PaymentExecutionOptions } from '../shared/entitys/payment';
2
+ export declare const useManagedOrder: <T>(factory: (() => Promise<T>) | undefined, receive: (target: T) => void, options?: PaymentExecutionOptions, validate?: ((target: T) => boolean) | undefined) => {
3
+ run: () => Promise<import("../shared/entitys/payment").PaymentExecutionResult<void>>;
4
+ cancel: () => void;
5
+ status: import("../shared/enums").PaymentExecutionStatus;
6
+ error: PaymentExecutionError | null;
7
+ loading: boolean;
8
+ };
@@ -0,0 +1,67 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ 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 }; })(); }
8
+ 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); }
9
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
10
+ 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); }); }; }
11
+ import { usePaymentExecution } from './usePaymentExecution';
12
+ import { useLatestCallback } from './useLatestCallback';
13
+ import { PaymentErrorCode } from '../shared/enums';
14
+ import { PaymentExecutionError } from '../shared/entitys/payment';
15
+ export var useManagedOrder = function useManagedOrder(factory, receive, options, validate) {
16
+ var execution = usePaymentExecution(options);
17
+ var run = useLatestCallback(function () {
18
+ return execution.run(/*#__PURE__*/function () {
19
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context) {
20
+ var target;
21
+ return _regenerator().w(function (_context) {
22
+ while (1) switch (_context.n) {
23
+ case 0:
24
+ if (factory) {
25
+ _context.n = 1;
26
+ break;
27
+ }
28
+ throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'createOrder is required for managed order execution.');
29
+ case 1:
30
+ _context.n = 2;
31
+ return factory();
32
+ case 2:
33
+ target = _context.v;
34
+ if (context.isCurrent()) {
35
+ _context.n = 3;
36
+ break;
37
+ }
38
+ return _context.a(2);
39
+ case 3:
40
+ if (!(target == null)) {
41
+ _context.n = 4;
42
+ break;
43
+ }
44
+ execution.cancel();
45
+ return _context.a(2);
46
+ case 4:
47
+ if (!(validate && !validate(target))) {
48
+ _context.n = 5;
49
+ break;
50
+ }
51
+ throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'Invalid payment parameters returned by createOrder.');
52
+ case 5:
53
+ receive(target);
54
+ case 6:
55
+ return _context.a(2);
56
+ }
57
+ }, _callee);
58
+ }));
59
+ return function (_x) {
60
+ return _ref.apply(this, arguments);
61
+ };
62
+ }());
63
+ });
64
+ return _objectSpread(_objectSpread({}, execution), {}, {
65
+ run: run
66
+ });
67
+ };
@@ -0,0 +1,13 @@
1
+ import { PaymentExecutionStatus } from '../shared/enums';
2
+ import { PaymentExecutionError, type PaymentExecutionOptions, type PaymentExecutionResult } from '../shared/entitys/payment';
3
+ export interface ExecutionContext {
4
+ signal: AbortSignal;
5
+ isCurrent: () => boolean;
6
+ }
7
+ export declare const usePaymentExecution: (options?: PaymentExecutionOptions) => {
8
+ run: <T>(task: (context: ExecutionContext) => T | Promise<T>) => Promise<PaymentExecutionResult<T>>;
9
+ cancel: () => void;
10
+ status: PaymentExecutionStatus;
11
+ error: PaymentExecutionError | null;
12
+ loading: boolean;
13
+ };
@@ -0,0 +1,176 @@
1
+ 'use client';
2
+
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
+ 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); }
5
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
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
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
8
+ 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."); }
9
+ 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; } }
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
+ 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
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
13
+ import { useEffect, useRef, useState } from 'react';
14
+ import { PaymentErrorCode, PaymentExecutionStatus } from '../shared/enums';
15
+ import { PaymentExecutionError } from '../shared/entitys/payment';
16
+ import { useLatestCallback } from './useLatestCallback';
17
+ export var usePaymentExecution = function usePaymentExecution() {
18
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ var latest = useRef(options);
20
+ latest.current = options;
21
+ var mounted = useRef(false);
22
+ var sequence = useRef(0);
23
+ var pending = useRef(false);
24
+ var controller = useRef();
25
+ var _useState = useState(PaymentExecutionStatus.Idle),
26
+ _useState2 = _slicedToArray(_useState, 2),
27
+ status = _useState2[0],
28
+ setStatus = _useState2[1];
29
+ var _useState3 = useState(null),
30
+ _useState4 = _slicedToArray(_useState3, 2),
31
+ error = _useState4[0],
32
+ setError = _useState4[1];
33
+ var cancel = useLatestCallback(function () {
34
+ var _controller$current;
35
+ var wasPending = pending.current;
36
+ sequence.current += 1;
37
+ (_controller$current = controller.current) === null || _controller$current === void 0 || _controller$current.abort();
38
+ pending.current = false;
39
+ if (mounted.current && wasPending) {
40
+ var _latest$current$onLoa, _latest$current, _latest$current$onCan, _latest$current2;
41
+ setStatus(PaymentExecutionStatus.Cancelled);
42
+ (_latest$current$onLoa = (_latest$current = latest.current).onLoadingChange) === null || _latest$current$onLoa === void 0 || _latest$current$onLoa.call(_latest$current, false);
43
+ (_latest$current$onCan = (_latest$current2 = latest.current).onCancel) === null || _latest$current$onCan === void 0 || _latest$current$onCan.call(_latest$current2);
44
+ }
45
+ });
46
+ useEffect(function () {
47
+ mounted.current = true;
48
+ return function () {
49
+ var _controller$current2;
50
+ mounted.current = false;
51
+ sequence.current += 1;
52
+ (_controller$current2 = controller.current) === null || _controller$current2 === void 0 || _controller$current2.abort();
53
+ pending.current = false;
54
+ };
55
+ }, []);
56
+ var run = useLatestCallback(/*#__PURE__*/function () {
57
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(task) {
58
+ var id, request, isCurrent, result, _latest$current$onLoa2, _latest$current3, _latest$current$befor, _latest$current4, permitted, value, failure, _latest$current$onLoa3, _latest$current5, _latest$current$onPay, _latest$current6, _latest$current$onCan2, _latest$current7, _t;
59
+ return _regenerator().w(function (_context) {
60
+ while (1) switch (_context.n) {
61
+ case 0:
62
+ if (mounted.current) {
63
+ _context.n = 1;
64
+ break;
65
+ }
66
+ return _context.a(2, {
67
+ status: PaymentExecutionStatus.Cancelled
68
+ });
69
+ case 1:
70
+ if (!pending.current) {
71
+ _context.n = 2;
72
+ break;
73
+ }
74
+ return _context.a(2, {
75
+ status: PaymentExecutionStatus.Pending
76
+ });
77
+ case 2:
78
+ id = ++sequence.current;
79
+ request = new AbortController();
80
+ controller.current = request;
81
+ pending.current = true;
82
+ setError(null);
83
+ setStatus(PaymentExecutionStatus.Pending);
84
+ isCurrent = function isCurrent() {
85
+ return mounted.current && sequence.current === id && !request.signal.aborted;
86
+ };
87
+ _context.p = 3;
88
+ (_latest$current$onLoa2 = (_latest$current3 = latest.current).onLoadingChange) === null || _latest$current$onLoa2 === void 0 || _latest$current$onLoa2.call(_latest$current3, true);
89
+ _context.n = 4;
90
+ return (_latest$current$befor = (_latest$current4 = latest.current).beforePay) === null || _latest$current$befor === void 0 ? void 0 : _latest$current$befor.call(_latest$current4);
91
+ case 4:
92
+ permitted = _context.v;
93
+ if (isCurrent()) {
94
+ _context.n = 5;
95
+ break;
96
+ }
97
+ return _context.a(2, {
98
+ status: PaymentExecutionStatus.Cancelled
99
+ });
100
+ case 5:
101
+ if (!(permitted === false)) {
102
+ _context.n = 6;
103
+ break;
104
+ }
105
+ result = {
106
+ status: PaymentExecutionStatus.Cancelled
107
+ };
108
+ _context.n = 9;
109
+ break;
110
+ case 6:
111
+ _context.n = 7;
112
+ return task({
113
+ signal: request.signal,
114
+ isCurrent: isCurrent
115
+ });
116
+ case 7:
117
+ value = _context.v;
118
+ if (isCurrent()) {
119
+ _context.n = 8;
120
+ break;
121
+ }
122
+ return _context.a(2, {
123
+ status: PaymentExecutionStatus.Cancelled
124
+ });
125
+ case 8:
126
+ result = {
127
+ status: PaymentExecutionStatus.Completed,
128
+ value: value
129
+ };
130
+ case 9:
131
+ _context.n = 12;
132
+ break;
133
+ case 10:
134
+ _context.p = 10;
135
+ _t = _context.v;
136
+ if (isCurrent()) {
137
+ _context.n = 11;
138
+ break;
139
+ }
140
+ return _context.a(2, {
141
+ status: PaymentExecutionStatus.Cancelled
142
+ });
143
+ case 11:
144
+ failure = _t instanceof PaymentExecutionError ? _t : new PaymentExecutionError(PaymentErrorCode.ExecutionFailed, 'Payment execution failed.');
145
+ result = {
146
+ status: PaymentExecutionStatus.Failed,
147
+ error: failure
148
+ };
149
+ setError(failure);
150
+ case 12:
151
+ _context.p = 12;
152
+ if (isCurrent()) pending.current = false;
153
+ return _context.f(12);
154
+ case 13:
155
+ if (isCurrent()) {
156
+ setStatus(result.status);
157
+ (_latest$current$onLoa3 = (_latest$current5 = latest.current).onLoadingChange) === null || _latest$current$onLoa3 === void 0 || _latest$current$onLoa3.call(_latest$current5, false);
158
+ if (result.error) (_latest$current$onPay = (_latest$current6 = latest.current).onPaymentError) === null || _latest$current$onPay === void 0 || _latest$current$onPay.call(_latest$current6, result.error);
159
+ if (result.status === PaymentExecutionStatus.Cancelled) (_latest$current$onCan2 = (_latest$current7 = latest.current).onCancel) === null || _latest$current$onCan2 === void 0 || _latest$current$onCan2.call(_latest$current7);
160
+ }
161
+ return _context.a(2, result);
162
+ }
163
+ }, _callee, null, [[3, 10, 12, 13]]);
164
+ }));
165
+ return function (_x) {
166
+ return _ref.apply(this, arguments);
167
+ };
168
+ }());
169
+ return {
170
+ run: run,
171
+ cancel: cancel,
172
+ status: status,
173
+ error: error,
174
+ loading: status === PaymentExecutionStatus.Pending
175
+ };
176
+ };
@@ -0,0 +1,6 @@
1
+ import type { PaymentQrAppearance } from '../shared/entitys/payment';
2
+ export declare const usePaymentQr: (value: string, image: boolean, options: PaymentQrAppearance) => {
3
+ imageUrl: string;
4
+ loading: boolean;
5
+ failed: boolean;
6
+ };
@@ -0,0 +1,52 @@
1
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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; } }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
+ import { useEffect, useRef, useState } from 'react';
8
+ import makeQrcode from '../utils/qrcode';
9
+ export var usePaymentQr = function usePaymentQr(value, image, options) {
10
+ var callbacks = useRef(options);
11
+ callbacks.current = options;
12
+ var _useState = useState({
13
+ imageUrl: '',
14
+ loading: true,
15
+ failed: false
16
+ }),
17
+ _useState2 = _slicedToArray(_useState, 2),
18
+ state = _useState2[0],
19
+ setState = _useState2[1];
20
+ useEffect(function () {
21
+ var active = true;
22
+ setState({
23
+ imageUrl: '',
24
+ loading: true,
25
+ failed: false
26
+ });
27
+ var task = image ? Promise.resolve(value) : makeQrcode(value);
28
+ task.then(function (imageUrl) {
29
+ var _callbacks$current$on, _callbacks$current;
30
+ if (!active) return;
31
+ setState({
32
+ imageUrl: imageUrl,
33
+ loading: false,
34
+ failed: false
35
+ });
36
+ (_callbacks$current$on = (_callbacks$current = callbacks.current).onQrReady) === null || _callbacks$current$on === void 0 || _callbacks$current$on.call(_callbacks$current, imageUrl);
37
+ }).catch(function () {
38
+ var _callbacks$current$on2, _callbacks$current2;
39
+ if (!active) return;
40
+ setState({
41
+ imageUrl: '',
42
+ loading: false,
43
+ failed: true
44
+ });
45
+ (_callbacks$current$on2 = (_callbacks$current2 = callbacks.current).onQrError) === null || _callbacks$current$on2 === void 0 || _callbacks$current$on2.call(_callbacks$current2);
46
+ });
47
+ return function () {
48
+ active = false;
49
+ };
50
+ }, [value, image]);
51
+ return state;
52
+ };
@@ -0,0 +1,5 @@
1
+ import { type PaymentRedirectOptions } from '../shared/entitys/payment';
2
+ export declare const usePaymentRedirect: (options?: PaymentRedirectOptions) => {
3
+ open: (rawUrl: string) => void;
4
+ close: () => void;
5
+ };
@@ -0,0 +1,83 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useRef } from 'react';
4
+ import { OpenPayUrlMode, PaymentErrorCode } from '../shared/enums';
5
+ import { PaymentExecutionError } from '../shared/entitys/payment';
6
+ import { useLatestCallback } from './useLatestCallback';
7
+ var nextWindowId = 0;
8
+ export var usePaymentRedirect = function usePaymentRedirect() {
9
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10
+ var latest = useRef(options);
11
+ latest.current = options;
12
+ var owned = useRef(null);
13
+ var monitor = useRef();
14
+ var name = useRef();
15
+ var clearMonitor = function clearMonitor() {
16
+ if (monitor.current !== undefined) clearInterval(monitor.current);
17
+ monitor.current = undefined;
18
+ };
19
+ var close = useLatestCallback(function () {
20
+ var _owned$current;
21
+ clearMonitor();
22
+ (_owned$current = owned.current) === null || _owned$current === void 0 || _owned$current.close();
23
+ owned.current = null;
24
+ });
25
+ var open = useLatestCallback(function (rawUrl) {
26
+ var _latest$current$openM, _latest$current$onOpe, _latest$current2;
27
+ if (typeof window === 'undefined') throw new PaymentExecutionError(PaymentErrorCode.BrowserUnavailable, 'A browser is required.');
28
+ var url;
29
+ try {
30
+ url = new URL(rawUrl, window.location.href);
31
+ } catch (_unused) {
32
+ throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'Invalid payment URL.');
33
+ }
34
+ if (!(rawUrl !== null && rawUrl !== void 0 && rawUrl.trim()) || !['https:', 'http:'].includes(url.protocol)) {
35
+ throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'Payment URL must use HTTP or HTTPS.');
36
+ }
37
+ var mode = (_latest$current$openM = latest.current.openMode) !== null && _latest$current$openM !== void 0 ? _latest$current$openM : OpenPayUrlMode.Href;
38
+ if (mode === OpenPayUrlMode.Window) {
39
+ var _latest$current$windo;
40
+ close();
41
+ if (!name.current) name.current = "pay_sdk_".concat(++nextWindowId);
42
+ var child = window.open(url.href, (_latest$current$windo = latest.current.windowName) !== null && _latest$current$windo !== void 0 ? _latest$current$windo : name.current, latest.current.windowFeatures);
43
+ if (!child) throw new PaymentExecutionError(PaymentErrorCode.WindowBlocked, 'The payment window was blocked.');
44
+ owned.current = child;
45
+ monitor.current = setInterval(function () {
46
+ var _owned$current2;
47
+ if ((_owned$current2 = owned.current) !== null && _owned$current2 !== void 0 && _owned$current2.closed) {
48
+ var _latest$current$onWin, _latest$current;
49
+ clearMonitor();
50
+ owned.current = null;
51
+ (_latest$current$onWin = (_latest$current = latest.current).onWindowClose) === null || _latest$current$onWin === void 0 || _latest$current$onWin.call(_latest$current);
52
+ }
53
+ }, 500);
54
+ } else if (mode === OpenPayUrlMode.Replace) {
55
+ window.location.replace(url.href);
56
+ } else if (mode === OpenPayUrlMode.Href) {
57
+ window.location.assign(url.href);
58
+ } else {
59
+ throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'Unsupported opening mode.');
60
+ }
61
+ (_latest$current$onOpe = (_latest$current2 = latest.current).onOpen) === null || _latest$current$onOpe === void 0 || _latest$current$onOpe.call(_latest$current2, url.href);
62
+ });
63
+ useEffect(function () {
64
+ var onMessage = function onMessage(event) {
65
+ var _config$allowedMessag, _config$onMessage;
66
+ var config = latest.current;
67
+ if (!owned.current || event.source !== owned.current || !((_config$allowedMessag = config.allowedMessageOrigins) !== null && _config$allowedMessag !== void 0 && _config$allowedMessag.includes(event.origin)) || !config.messageValidator) return;
68
+ if (config.messageValidator(event)) (_config$onMessage = config.onMessage) === null || _config$onMessage === void 0 || _config$onMessage.call(config, event);
69
+ };
70
+ window.addEventListener('message', onMessage);
71
+ return function () {
72
+ var _owned$current3;
73
+ window.removeEventListener('message', onMessage);
74
+ clearMonitor();
75
+ if (latest.current.closeWindowOnUnmount !== false) (_owned$current3 = owned.current) === null || _owned$current3 === void 0 || _owned$current3.close();
76
+ owned.current = null;
77
+ };
78
+ }, []);
79
+ return {
80
+ open: open,
81
+ close: close
82
+ };
83
+ };