pay-sdk-react 1.1.13 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +465 -84
- package/README.zh-CN.md +466 -85
- package/dist/css/index.css +86 -6
- package/dist/css/index.min.css +1 -1
- package/dist/es/Airwallex/airwallex-button.js +48 -16
- package/dist/es/Airwallex/airwallex-checkout-button.d.ts +4 -0
- package/dist/es/Airwallex/airwallex-checkout-button.js +73 -0
- package/dist/es/Airwallex/airwallex-managed.d.ts +4 -0
- package/dist/es/Airwallex/airwallex-managed.js +87 -0
- package/dist/es/Airwallex/airwallex-modal.js +7 -3
- package/dist/es/Airwallex/airwallex-popup.js +7 -3
- package/dist/es/Airwallex/airwallex.d.ts +1 -3
- package/dist/es/Airwallex/airwallex.js +10 -1
- package/dist/es/Airwallex/hooks/useAirwallexCheckout.d.ts +7 -0
- package/dist/es/Airwallex/hooks/useAirwallexCheckout.js +155 -0
- package/dist/es/Airwallex/index.d.ts +4 -0
- package/dist/es/Airwallex/index.js +5 -1
- package/dist/es/Airwallex/interface.d.ts +146 -0
- package/dist/es/Airwallex/style/index.css +2 -2
- package/dist/es/Airwallex/style/index.min.css +1 -1
- package/dist/es/Alipay/alipay-button.js +26 -7
- package/dist/es/Alipay/alipay.js +39 -12
- package/dist/es/Alipay/interface.d.ts +26 -1
- package/dist/es/Alipay/style/index.css +2 -2
- package/dist/es/Alipay/style/index.min.css +1 -1
- package/dist/es/MAlipay/style/index.css +2 -2
- package/dist/es/MAlipay/style/index.min.css +1 -1
- package/dist/es/MPix/index.d.ts +2 -0
- package/dist/es/MPix/index.js +2 -0
- package/dist/es/MPix/interface.d.ts +44 -0
- package/dist/es/MPix/interface.js +1 -0
- package/dist/es/MPix/m-pix-button.d.ts +6 -0
- package/dist/es/MPix/m-pix-button.js +159 -0
- package/dist/es/MPix/style/index.css +256 -0
- package/dist/es/MPix/style/index.d.ts +1 -0
- package/dist/es/MPix/style/index.js +1 -0
- package/dist/es/MPix/style/index.min.css +1 -0
- package/dist/es/MWeChat/style/index.css +2 -2
- package/dist/es/MWeChat/style/index.min.css +1 -1
- package/dist/es/PayButton/index.js +12 -0
- package/dist/es/PayButton/interface.d.ts +28 -2
- package/dist/es/Paypal/index.d.ts +2 -0
- package/dist/es/Paypal/index.js +3 -1
- package/dist/es/Paypal/interface.d.ts +40 -0
- package/dist/es/Paypal/paypal-button.js +24 -3
- package/dist/es/Paypal/paypal-smart-button.d.ts +4 -0
- package/dist/es/Paypal/paypal-smart-button.js +48 -0
- package/dist/es/Payssion/interface.d.ts +7 -0
- package/dist/es/Payssion/payssion-button.js +25 -4
- package/dist/es/Pix/index.d.ts +11 -0
- package/dist/es/Pix/index.js +10 -0
- package/dist/es/Pix/interface.d.ts +147 -0
- package/dist/es/Pix/interface.js +1 -0
- package/dist/es/Pix/pix-button.d.ts +6 -0
- package/dist/es/Pix/pix-button.js +99 -0
- package/dist/es/Pix/pix-enhanced.d.ts +4 -0
- package/dist/es/Pix/pix-enhanced.js +182 -0
- package/dist/es/Pix/pix-modal.d.ts +6 -0
- package/dist/es/Pix/pix-modal.js +57 -0
- package/dist/es/Pix/pix.d.ts +4 -0
- package/dist/es/Pix/pix.js +125 -0
- package/dist/es/Pix/style/index.css +80 -0
- package/dist/es/Pix/style/index.d.ts +1 -0
- package/dist/es/Pix/style/index.js +1 -0
- package/dist/es/Pix/style/index.min.css +1 -0
- package/dist/es/Stripe/hooks/useStripeCheckout.d.ts +7 -0
- package/dist/es/Stripe/hooks/useStripeCheckout.js +86 -0
- package/dist/es/Stripe/index.d.ts +4 -0
- package/dist/es/Stripe/index.js +5 -1
- package/dist/es/Stripe/interface.d.ts +120 -0
- package/dist/es/Stripe/stripe-button.js +32 -10
- package/dist/es/Stripe/stripe-checkout-button.d.ts +4 -0
- package/dist/es/Stripe/stripe-checkout-button.js +70 -0
- package/dist/es/Stripe/stripe-modal.js +19 -2
- package/dist/es/Stripe/stripe-popup.js +13 -2
- package/dist/es/Stripe/stripe.js +38 -4
- package/dist/es/Stripe/style/index.css +2 -2
- package/dist/es/Stripe/style/index.min.css +1 -1
- package/dist/es/Wechat/interface.d.ts +13 -0
- package/dist/es/Wechat/style/index.css +2 -2
- package/dist/es/Wechat/style/index.min.css +1 -1
- package/dist/es/Wechat/wechat-button.js +26 -7
- package/dist/es/Wechat/wechat-content.d.ts +4 -0
- package/dist/es/Wechat/wechat-content.js +61 -0
- package/dist/es/Wechat/wechat.d.ts +1 -1
- package/dist/es/Wechat/wechat.js +5 -1
- package/dist/es/confirm-modal/style/index.css +2 -2
- package/dist/es/confirm-modal/style/index.min.css +1 -1
- package/dist/es/hooks/useLatestCallback.d.ts +1 -0
- package/dist/es/hooks/useLatestCallback.js +8 -0
- package/dist/es/hooks/useManagedOrder.d.ts +8 -0
- package/dist/es/hooks/useManagedOrder.js +67 -0
- package/dist/es/hooks/usePaymentExecution.d.ts +13 -0
- package/dist/es/hooks/usePaymentExecution.js +176 -0
- package/dist/es/hooks/usePaymentQr.d.ts +6 -0
- package/dist/es/hooks/usePaymentQr.js +52 -0
- package/dist/es/hooks/usePaymentRedirect.d.ts +5 -0
- package/dist/es/hooks/usePaymentRedirect.js +83 -0
- package/dist/es/icons/IconCheck/index.d.ts +4 -0
- package/dist/es/icons/IconCheck/index.js +22 -0
- package/dist/es/icons/IconCopy/index.d.ts +4 -0
- package/dist/es/icons/IconCopy/index.js +27 -0
- package/dist/es/icons/IconPix/index.d.ts +4 -0
- package/dist/es/icons/IconPix/index.js +33 -0
- package/dist/es/icons/index.d.ts +3 -0
- package/dist/es/icons/index.js +4 -1
- package/dist/es/index.d.ts +50 -6
- package/dist/es/index.js +28 -1
- package/dist/es/pay-modal/interface.d.ts +22 -2
- package/dist/es/pay-modal/pay-modal.js +36 -16
- package/dist/es/pay-modal/style/index.css +2 -2
- package/dist/es/pay-modal/style/index.min.css +1 -1
- package/dist/es/shared/entitys/payment.d.ts +227 -0
- package/dist/es/shared/entitys/payment.js +75 -0
- package/dist/es/shared/enums/index.d.ts +1 -78
- package/dist/es/shared/enums/index.js +1 -81
- package/dist/es/shared/enums/payment.d.ts +162 -0
- package/dist/es/shared/enums/payment.js +168 -0
- package/dist/es/shared/index.d.ts +2 -0
- package/dist/es/shared/index.js +2 -1
- package/dist/lib/Airwallex/airwallex-button.js +31 -10
- package/dist/lib/Airwallex/airwallex-checkout-button.js +52 -0
- package/dist/lib/Airwallex/airwallex-managed.js +86 -0
- package/dist/lib/Airwallex/airwallex-modal.js +4 -2
- package/dist/lib/Airwallex/airwallex-popup.js +4 -2
- package/dist/lib/Airwallex/airwallex.js +9 -1
- package/dist/lib/Airwallex/hooks/useAirwallexCheckout.js +83 -0
- package/dist/lib/Airwallex/index.js +18 -1
- package/dist/lib/Airwallex/style/index.css +2 -2
- package/dist/lib/Airwallex/style/index.min.css +1 -1
- package/dist/lib/Alipay/alipay-button.js +21 -6
- package/dist/lib/Alipay/alipay.js +36 -9
- package/dist/lib/Alipay/style/index.css +2 -2
- package/dist/lib/Alipay/style/index.min.css +1 -1
- package/dist/lib/MAlipay/style/index.css +2 -2
- package/dist/lib/MAlipay/style/index.min.css +1 -1
- package/dist/lib/MPix/index.js +28 -0
- package/dist/lib/MPix/interface.js +5 -0
- package/dist/lib/MPix/m-pix-button.js +127 -0
- package/dist/lib/MPix/style/index.css +256 -0
- package/dist/lib/MPix/style/index.js +3 -0
- package/dist/lib/MPix/style/index.min.css +1 -0
- package/dist/lib/MWeChat/style/index.css +2 -2
- package/dist/lib/MWeChat/style/index.min.css +1 -1
- package/dist/lib/PayButton/index.js +12 -0
- package/dist/lib/Paypal/index.js +17 -1
- package/dist/lib/Paypal/paypal-button.js +19 -2
- package/dist/lib/Paypal/paypal-smart-button.js +45 -0
- package/dist/lib/Payssion/payssion-button.js +20 -3
- package/dist/lib/Pix/index.js +43 -0
- package/dist/lib/Pix/interface.js +5 -0
- package/dist/lib/Pix/pix-button.js +83 -0
- package/dist/lib/Pix/pix-enhanced.js +143 -0
- package/dist/lib/Pix/pix-modal.js +50 -0
- package/dist/lib/Pix/pix.js +97 -0
- package/dist/lib/Pix/style/index.css +80 -0
- package/dist/lib/Pix/style/index.js +3 -0
- package/dist/lib/Pix/style/index.min.css +1 -0
- package/dist/lib/Stripe/hooks/useStripeCheckout.js +41 -0
- package/dist/lib/Stripe/index.js +18 -1
- package/dist/lib/Stripe/stripe-button.js +28 -10
- package/dist/lib/Stripe/stripe-checkout-button.js +50 -0
- package/dist/lib/Stripe/stripe-modal.js +12 -1
- package/dist/lib/Stripe/stripe-popup.js +12 -1
- package/dist/lib/Stripe/stripe.js +30 -1
- package/dist/lib/Stripe/style/index.css +2 -2
- package/dist/lib/Stripe/style/index.min.css +1 -1
- package/dist/lib/Wechat/style/index.css +2 -2
- package/dist/lib/Wechat/style/index.min.css +1 -1
- package/dist/lib/Wechat/wechat-button.js +21 -6
- package/dist/lib/Wechat/wechat-content.js +65 -0
- package/dist/lib/Wechat/wechat.js +3 -1
- package/dist/lib/confirm-modal/style/index.css +2 -2
- package/dist/lib/confirm-modal/style/index.min.css +1 -1
- package/dist/lib/hooks/useLatestCallback.js +13 -0
- package/dist/lib/hooks/useManagedOrder.js +29 -0
- package/dist/lib/hooks/usePaymentExecution.js +113 -0
- package/dist/lib/hooks/usePaymentQr.js +51 -0
- package/dist/lib/hooks/usePaymentRedirect.js +87 -0
- package/dist/lib/icons/IconCheck/index.js +27 -0
- package/dist/lib/icons/IconCopy/index.js +32 -0
- package/dist/lib/icons/IconPix/index.js +38 -0
- package/dist/lib/icons/index.js +25 -1
- package/dist/lib/index.js +86 -1
- package/dist/lib/pay-modal/pay-modal.js +33 -16
- package/dist/lib/pay-modal/style/index.css +2 -2
- package/dist/lib/pay-modal/style/index.min.css +1 -1
- package/dist/lib/shared/entitys/payment.js +61 -0
- package/dist/lib/shared/enums/index.js +11 -81
- package/dist/lib/shared/enums/payment.js +172 -0
- package/dist/lib/shared/index.js +12 -1
- package/dist/umd/pay-sdk-react.umd.js +10455 -11463
- package/dist/umd/pay-sdk-react.umd.js.map +1 -1
- package/package.json +44 -25
|
@@ -0,0 +1,182 @@
|
|
|
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
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
12
|
+
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."); }
|
|
13
|
+
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; } }
|
|
14
|
+
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; }
|
|
15
|
+
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; } }
|
|
16
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
17
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
18
|
+
import { usePaymentQr } from '../hooks/usePaymentQr';
|
|
19
|
+
import cs from '../utils/classNames';
|
|
20
|
+
import { getPrefixCls } from '../utils/getPrefixCls';
|
|
21
|
+
import { IconCheck, IconCopy } from '../icons';
|
|
22
|
+
var prefix = getPrefixCls('pix-qrcode');
|
|
23
|
+
var PixEnhanced = function PixEnhanced(_ref) {
|
|
24
|
+
var _qrProps$loadingConte, _qrProps$errorContent;
|
|
25
|
+
var pixCode = _ref.pixCode,
|
|
26
|
+
_ref$tipText = _ref.tipText,
|
|
27
|
+
tipText = _ref$tipText === void 0 ? '请使用银行App扫码支付' : _ref$tipText,
|
|
28
|
+
_ref$showCopyButton = _ref.showCopyButton,
|
|
29
|
+
showCopyButton = _ref$showCopyButton === void 0 ? true : _ref$showCopyButton,
|
|
30
|
+
className = _ref.className,
|
|
31
|
+
style = _ref.style,
|
|
32
|
+
_ref$qrProps = _ref.qrProps,
|
|
33
|
+
qrProps = _ref$qrProps === void 0 ? {} : _ref$qrProps,
|
|
34
|
+
_ref$showCode = _ref.showCode,
|
|
35
|
+
showCode = _ref$showCode === void 0 ? false : _ref$showCode,
|
|
36
|
+
copyText = _ref.copyText,
|
|
37
|
+
copiedText = _ref.copiedText,
|
|
38
|
+
confirmText = _ref.confirmText,
|
|
39
|
+
onConfirm = _ref.onConfirm,
|
|
40
|
+
onCopy = _ref.onCopy,
|
|
41
|
+
onCopyError = _ref.onCopyError,
|
|
42
|
+
_ref$actionClassNames = _ref.actionClassNames,
|
|
43
|
+
actionClassNames = _ref$actionClassNames === void 0 ? {} : _ref$actionClassNames,
|
|
44
|
+
_ref$actionStyles = _ref.actionStyles,
|
|
45
|
+
actionStyles = _ref$actionStyles === void 0 ? {} : _ref$actionStyles;
|
|
46
|
+
var _usePaymentQr = usePaymentQr(pixCode, false, qrProps),
|
|
47
|
+
imageUrl = _usePaymentQr.imageUrl,
|
|
48
|
+
loading = _usePaymentQr.loading,
|
|
49
|
+
failed = _usePaymentQr.failed;
|
|
50
|
+
var _useState = useState(false),
|
|
51
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
52
|
+
copied = _useState2[0],
|
|
53
|
+
setCopied = _useState2[1];
|
|
54
|
+
var timer = useRef();
|
|
55
|
+
var mounted = useRef(false);
|
|
56
|
+
useEffect(function () {
|
|
57
|
+
mounted.current = true;
|
|
58
|
+
return function () {
|
|
59
|
+
mounted.current = false;
|
|
60
|
+
if (timer.current) clearTimeout(timer.current);
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
var copy = /*#__PURE__*/function () {
|
|
64
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
65
|
+
var succeeded, _navigator$clipboard, textarea, _t;
|
|
66
|
+
return _regenerator().w(function (_context) {
|
|
67
|
+
while (1) switch (_context.n) {
|
|
68
|
+
case 0:
|
|
69
|
+
succeeded = false;
|
|
70
|
+
_context.p = 1;
|
|
71
|
+
if (!((_navigator$clipboard = navigator.clipboard) !== null && _navigator$clipboard !== void 0 && _navigator$clipboard.writeText)) {
|
|
72
|
+
_context.n = 3;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
_context.n = 2;
|
|
76
|
+
return navigator.clipboard.writeText(pixCode);
|
|
77
|
+
case 2:
|
|
78
|
+
succeeded = true;
|
|
79
|
+
case 3:
|
|
80
|
+
_context.n = 5;
|
|
81
|
+
break;
|
|
82
|
+
case 4:
|
|
83
|
+
_context.p = 4;
|
|
84
|
+
_t = _context.v;
|
|
85
|
+
case 5:
|
|
86
|
+
if (!succeeded) {
|
|
87
|
+
textarea = document.createElement('textarea');
|
|
88
|
+
textarea.value = pixCode;
|
|
89
|
+
textarea.style.position = 'fixed';
|
|
90
|
+
textarea.style.opacity = '0';
|
|
91
|
+
document.body.appendChild(textarea);
|
|
92
|
+
try {
|
|
93
|
+
textarea.select();
|
|
94
|
+
succeeded = document.execCommand('copy');
|
|
95
|
+
} catch (_unused2) {
|
|
96
|
+
succeeded = false;
|
|
97
|
+
} finally {
|
|
98
|
+
textarea.remove();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (mounted.current) {
|
|
102
|
+
_context.n = 6;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return _context.a(2);
|
|
106
|
+
case 6:
|
|
107
|
+
if (succeeded) {
|
|
108
|
+
_context.n = 7;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
onCopyError === null || onCopyError === void 0 || onCopyError();
|
|
112
|
+
return _context.a(2);
|
|
113
|
+
case 7:
|
|
114
|
+
setCopied(true);
|
|
115
|
+
if (timer.current) clearTimeout(timer.current);
|
|
116
|
+
timer.current = setTimeout(function () {
|
|
117
|
+
return setCopied(false);
|
|
118
|
+
}, 2000);
|
|
119
|
+
onCopy === null || onCopy === void 0 || onCopy();
|
|
120
|
+
case 8:
|
|
121
|
+
return _context.a(2);
|
|
122
|
+
}
|
|
123
|
+
}, _callee, null, [[1, 4]]);
|
|
124
|
+
}));
|
|
125
|
+
return function copy() {
|
|
126
|
+
return _ref2.apply(this, arguments);
|
|
127
|
+
};
|
|
128
|
+
}();
|
|
129
|
+
if (loading) return /*#__PURE__*/React.createElement(React.Fragment, null, (_qrProps$loadingConte = qrProps.loadingContent) !== null && _qrProps$loadingConte !== void 0 ? _qrProps$loadingConte : null);
|
|
130
|
+
if (failed) return /*#__PURE__*/React.createElement(React.Fragment, null, (_qrProps$errorContent = qrProps.errorContent) !== null && _qrProps$errorContent !== void 0 ? _qrProps$errorContent : null);
|
|
131
|
+
var _qrProps$classNames = qrProps.classNames,
|
|
132
|
+
names = _qrProps$classNames === void 0 ? {} : _qrProps$classNames,
|
|
133
|
+
_qrProps$styles = qrProps.styles,
|
|
134
|
+
styles = _qrProps$styles === void 0 ? {} : _qrProps$styles;
|
|
135
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
136
|
+
className: cs(prefix, className, names.root),
|
|
137
|
+
style: _objectSpread(_objectSpread({}, style), styles.root)
|
|
138
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
139
|
+
className: cs("".concat(prefix, "__container"), names.container),
|
|
140
|
+
style: _objectSpread({
|
|
141
|
+
position: 'relative',
|
|
142
|
+
width: qrProps.size,
|
|
143
|
+
height: qrProps.size
|
|
144
|
+
}, styles.container)
|
|
145
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
146
|
+
className: cs("".concat(prefix, "__image"), names.image),
|
|
147
|
+
style: styles.image,
|
|
148
|
+
src: imageUrl,
|
|
149
|
+
alt: "PIX\u652F\u4ED8\u4E8C\u7EF4\u7801"
|
|
150
|
+
}), qrProps.overlay !== undefined ? /*#__PURE__*/React.createElement("div", {
|
|
151
|
+
className: names.overlay,
|
|
152
|
+
style: _objectSpread({
|
|
153
|
+
position: 'absolute',
|
|
154
|
+
left: '50%',
|
|
155
|
+
top: '50%',
|
|
156
|
+
transform: 'translate(-50%, -50%)'
|
|
157
|
+
}, styles.overlay)
|
|
158
|
+
}, qrProps.overlay) : null), showCode ? /*#__PURE__*/React.createElement("code", {
|
|
159
|
+
className: cs("".concat(prefix, "__code"), actionClassNames.code),
|
|
160
|
+
style: actionStyles.code
|
|
161
|
+
}, pixCode) : null, tipText ? /*#__PURE__*/React.createElement("span", {
|
|
162
|
+
className: cs("".concat(prefix, "__tip"), names.tip),
|
|
163
|
+
style: styles.tip
|
|
164
|
+
}, tipText) : null, showCopyButton ? /*#__PURE__*/React.createElement("div", {
|
|
165
|
+
className: "".concat(prefix, "__code-section")
|
|
166
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
167
|
+
type: "button",
|
|
168
|
+
className: cs("".concat(prefix, "__copy-btn"), _defineProperty({}, "".concat(prefix, "__copy-btn--copied"), copied), actionClassNames.copy),
|
|
169
|
+
style: actionStyles.copy,
|
|
170
|
+
onClick: copy
|
|
171
|
+
}, copied ? /*#__PURE__*/React.createElement(IconCheck, {
|
|
172
|
+
className: "".concat(prefix, "__copy-icon")
|
|
173
|
+
}) : /*#__PURE__*/React.createElement(IconCopy, {
|
|
174
|
+
className: "".concat(prefix, "__copy-icon")
|
|
175
|
+
}), /*#__PURE__*/React.createElement("span", null, copied ? copiedText !== null && copiedText !== void 0 ? copiedText : '已复制' : copyText !== null && copyText !== void 0 ? copyText : '复制 PIX Code'))) : null, confirmText !== undefined ? /*#__PURE__*/React.createElement("button", {
|
|
176
|
+
type: "button",
|
|
177
|
+
className: cs("".concat(prefix, "__confirm-btn"), actionClassNames.confirm),
|
|
178
|
+
style: actionStyles.confirm,
|
|
179
|
+
onClick: onConfirm
|
|
180
|
+
}, confirmText) : null);
|
|
181
|
+
};
|
|
182
|
+
export default /*#__PURE__*/React.memo(PixEnhanced);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PixModalProps, PixModalRef } from './interface';
|
|
3
|
+
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<PixModalProps & {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
} & React.RefAttributes<PixModalRef>>>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var _excluded = ["pixProps", "visible", "onClose"];
|
|
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
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
4
|
+
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."); }
|
|
5
|
+
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; } }
|
|
6
|
+
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; }
|
|
7
|
+
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; } }
|
|
8
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
import React, { memo, useImperativeHandle, useRef, useState } from 'react';
|
|
12
|
+
import PayModal from '../pay-modal';
|
|
13
|
+
import PixQrCode from './pix';
|
|
14
|
+
var PixModal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
15
|
+
var propsPixProps = props.pixProps,
|
|
16
|
+
visible = props.visible,
|
|
17
|
+
_onClose = props.onClose,
|
|
18
|
+
others = _objectWithoutProperties(props, _excluded);
|
|
19
|
+
var pixRef = useRef(null);
|
|
20
|
+
var _useState = useState(false),
|
|
21
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
+
uncontrolledVisible = _useState2[0],
|
|
23
|
+
setUncontrolledVisible = _useState2[1];
|
|
24
|
+
var _useState3 = useState(),
|
|
25
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
26
|
+
pixProps = _useState4[0],
|
|
27
|
+
setPixProps = _useState4[1];
|
|
28
|
+
var isControlled = visible !== undefined;
|
|
29
|
+
var _visible = isControlled ? visible : uncontrolledVisible;
|
|
30
|
+
useImperativeHandle(ref, function () {
|
|
31
|
+
return {
|
|
32
|
+
open: function open(value) {
|
|
33
|
+
if (value) {
|
|
34
|
+
setPixProps(value);
|
|
35
|
+
}
|
|
36
|
+
setUncontrolledVisible(true);
|
|
37
|
+
},
|
|
38
|
+
close: function close() {
|
|
39
|
+
setUncontrolledVisible(false);
|
|
40
|
+
_onClose === null || _onClose === void 0 || _onClose();
|
|
41
|
+
},
|
|
42
|
+
current: pixRef.current
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
var _pixProps = propsPixProps !== null && propsPixProps !== void 0 ? propsPixProps : pixProps;
|
|
46
|
+
return /*#__PURE__*/React.createElement(PayModal, _extends({
|
|
47
|
+
visible: _visible,
|
|
48
|
+
onClose: function onClose() {
|
|
49
|
+
if (!isControlled) {
|
|
50
|
+
setUncontrolledVisible(false);
|
|
51
|
+
}
|
|
52
|
+
_onClose === null || _onClose === void 0 || _onClose();
|
|
53
|
+
}
|
|
54
|
+
}, others), (_pixProps === null || _pixProps === void 0 ? void 0 : _pixProps.pixCode) && /*#__PURE__*/React.createElement(PixQrCode, _pixProps));
|
|
55
|
+
});
|
|
56
|
+
PixModal.displayName = 'PixModal';
|
|
57
|
+
export default /*#__PURE__*/memo(PixModal);
|
|
@@ -0,0 +1,125 @@
|
|
|
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 _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; }
|
|
3
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
4
|
+
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); }
|
|
5
|
+
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 }; })(); }
|
|
6
|
+
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); }
|
|
7
|
+
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); }
|
|
8
|
+
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); }); }; }
|
|
9
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
10
|
+
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."); }
|
|
11
|
+
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; } }
|
|
12
|
+
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; }
|
|
13
|
+
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; } }
|
|
14
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
15
|
+
import React, { memo, useCallback, useEffect, useRef, useState } from 'react';
|
|
16
|
+
import cs from '../utils/classNames';
|
|
17
|
+
import PixEnhanced from './pix-enhanced';
|
|
18
|
+
import makeQrcode from '../utils/qrcode';
|
|
19
|
+
import { IconCopy, IconCheck } from '../icons';
|
|
20
|
+
import { getPrefixCls } from '../utils/getPrefixCls';
|
|
21
|
+
var classPrefix = getPrefixCls('pix-qrcode');
|
|
22
|
+
var PixQrCode = function PixQrCode(_ref) {
|
|
23
|
+
var pixCode = _ref.pixCode,
|
|
24
|
+
_ref$tipText = _ref.tipText,
|
|
25
|
+
tipText = _ref$tipText === void 0 ? '请使用银行App扫码支付' : _ref$tipText,
|
|
26
|
+
_ref$showCopyButton = _ref.showCopyButton,
|
|
27
|
+
showCopyButton = _ref$showCopyButton === void 0 ? true : _ref$showCopyButton,
|
|
28
|
+
className = _ref.className,
|
|
29
|
+
style = _ref.style;
|
|
30
|
+
var _useState = useState(''),
|
|
31
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
32
|
+
imageUrl = _useState2[0],
|
|
33
|
+
setImageUrl = _useState2[1];
|
|
34
|
+
var _useState3 = useState(false),
|
|
35
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
36
|
+
copied = _useState4[0],
|
|
37
|
+
setCopied = _useState4[1];
|
|
38
|
+
var timerRef = useRef();
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
if (pixCode) {
|
|
41
|
+
makeQrcode(pixCode).then(function (url) {
|
|
42
|
+
setImageUrl(url);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}, [pixCode]);
|
|
46
|
+
useEffect(function () {
|
|
47
|
+
return function () {
|
|
48
|
+
if (timerRef.current) {
|
|
49
|
+
clearTimeout(timerRef.current);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
var handleCopy = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
54
|
+
var textarea, _t;
|
|
55
|
+
return _regenerator().w(function (_context) {
|
|
56
|
+
while (1) switch (_context.n) {
|
|
57
|
+
case 0:
|
|
58
|
+
_context.p = 0;
|
|
59
|
+
_context.n = 1;
|
|
60
|
+
return navigator.clipboard.writeText(pixCode);
|
|
61
|
+
case 1:
|
|
62
|
+
setCopied(true);
|
|
63
|
+
if (timerRef.current) {
|
|
64
|
+
clearTimeout(timerRef.current);
|
|
65
|
+
}
|
|
66
|
+
timerRef.current = setTimeout(function () {
|
|
67
|
+
return setCopied(false);
|
|
68
|
+
}, 2000);
|
|
69
|
+
_context.n = 3;
|
|
70
|
+
break;
|
|
71
|
+
case 2:
|
|
72
|
+
_context.p = 2;
|
|
73
|
+
_t = _context.v;
|
|
74
|
+
// Fallback: use textarea for older browsers
|
|
75
|
+
textarea = document.createElement('textarea');
|
|
76
|
+
textarea.value = pixCode;
|
|
77
|
+
textarea.style.position = 'fixed';
|
|
78
|
+
textarea.style.opacity = '0';
|
|
79
|
+
document.body.appendChild(textarea);
|
|
80
|
+
textarea.select();
|
|
81
|
+
document.execCommand('copy');
|
|
82
|
+
document.body.removeChild(textarea);
|
|
83
|
+
setCopied(true);
|
|
84
|
+
if (timerRef.current) {
|
|
85
|
+
clearTimeout(timerRef.current);
|
|
86
|
+
}
|
|
87
|
+
timerRef.current = setTimeout(function () {
|
|
88
|
+
return setCopied(false);
|
|
89
|
+
}, 2000);
|
|
90
|
+
case 3:
|
|
91
|
+
return _context.a(2);
|
|
92
|
+
}
|
|
93
|
+
}, _callee, null, [[0, 2]]);
|
|
94
|
+
})), [pixCode]);
|
|
95
|
+
if (!imageUrl) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
99
|
+
className: cs(classPrefix, className),
|
|
100
|
+
style: style
|
|
101
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
102
|
+
className: "".concat(classPrefix, "__container")
|
|
103
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
104
|
+
className: "".concat(classPrefix, "__image"),
|
|
105
|
+
src: imageUrl,
|
|
106
|
+
alt: 'PIX支付二维码'
|
|
107
|
+
})), tipText && /*#__PURE__*/React.createElement("span", {
|
|
108
|
+
className: "".concat(classPrefix, "__tip")
|
|
109
|
+
}, tipText), showCopyButton && /*#__PURE__*/React.createElement("div", {
|
|
110
|
+
className: "".concat(classPrefix, "__code-section")
|
|
111
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
112
|
+
type: "button",
|
|
113
|
+
className: cs("".concat(classPrefix, "__copy-btn"), _defineProperty({}, "".concat(classPrefix, "__copy-btn--copied"), copied)),
|
|
114
|
+
onClick: handleCopy
|
|
115
|
+
}, copied ? /*#__PURE__*/React.createElement(IconCheck, {
|
|
116
|
+
className: "".concat(classPrefix, "__copy-icon")
|
|
117
|
+
}) : /*#__PURE__*/React.createElement(IconCopy, {
|
|
118
|
+
className: "".concat(classPrefix, "__copy-icon")
|
|
119
|
+
}), /*#__PURE__*/React.createElement("span", null, copied ? '已复制' : '复制 PIX Code'))));
|
|
120
|
+
};
|
|
121
|
+
var PixEntry = function PixEntry(props) {
|
|
122
|
+
var enhanced = props.qrProps !== undefined || props.showCode !== undefined || props.copyText !== undefined || props.copiedText !== undefined || props.confirmText !== undefined || props.onConfirm !== undefined || props.onCopy !== undefined || props.onCopyError !== undefined || props.actionClassNames !== undefined || props.actionStyles !== undefined;
|
|
123
|
+
return enhanced ? /*#__PURE__*/React.createElement(PixEnhanced, props) : /*#__PURE__*/React.createElement(PixQrCode, props);
|
|
124
|
+
};
|
|
125
|
+
export default /*#__PURE__*/memo(PixEntry);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
.pay-pix-qrcode {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
align-items: center;
|
|
5
|
+
}
|
|
6
|
+
.pay-pix-qrcode__container {
|
|
7
|
+
background-color: #fff;
|
|
8
|
+
border-radius: 8px;
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
align-items: center;
|
|
12
|
+
width: 180px;
|
|
13
|
+
height: 180px;
|
|
14
|
+
}
|
|
15
|
+
.pay-pix-qrcode__image {
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 100%;
|
|
18
|
+
object-fit: cover;
|
|
19
|
+
}
|
|
20
|
+
.pay-pix-qrcode__tip {
|
|
21
|
+
text-align: center;
|
|
22
|
+
color: #333;
|
|
23
|
+
font-size: 14px;
|
|
24
|
+
line-height: 20px;
|
|
25
|
+
margin-top: 12px;
|
|
26
|
+
}
|
|
27
|
+
.pay-pix-qrcode__code-section {
|
|
28
|
+
width: 100%;
|
|
29
|
+
max-width: 320px;
|
|
30
|
+
margin-top: 16px;
|
|
31
|
+
}
|
|
32
|
+
.pay-pix-qrcode__copy-btn {
|
|
33
|
+
width: 100%;
|
|
34
|
+
padding: 10px 16px;
|
|
35
|
+
border: 1px solid #32bcad;
|
|
36
|
+
background-color: #fff;
|
|
37
|
+
color: #32bcad;
|
|
38
|
+
border-radius: 8px;
|
|
39
|
+
font-size: 13px;
|
|
40
|
+
font-weight: 600;
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
transition: all 0.2s ease;
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
gap: 6px;
|
|
47
|
+
}
|
|
48
|
+
.pay-pix-qrcode__copy-btn:hover {
|
|
49
|
+
background-color: rgba(50, 188, 173, 0.06);
|
|
50
|
+
}
|
|
51
|
+
.pay-pix-qrcode__copy-btn:active {
|
|
52
|
+
background-color: rgba(50, 188, 173, 0.12);
|
|
53
|
+
}
|
|
54
|
+
.pay-pix-qrcode__copy-btn--copied {
|
|
55
|
+
color: #2ecc71;
|
|
56
|
+
border-color: #2ecc71;
|
|
57
|
+
background-color: rgba(46, 204, 113, 0.04);
|
|
58
|
+
}
|
|
59
|
+
.pay-pix-qrcode__copy-btn--copied:hover {
|
|
60
|
+
background-color: rgba(46, 204, 113, 0.08);
|
|
61
|
+
}
|
|
62
|
+
.pay-pix-qrcode__copy-btn--copied:active {
|
|
63
|
+
background-color: rgba(46, 204, 113, 0.14);
|
|
64
|
+
}
|
|
65
|
+
.pay-pix-qrcode__copy-icon {
|
|
66
|
+
width: 16px;
|
|
67
|
+
height: 16px;
|
|
68
|
+
flex-shrink: 0;
|
|
69
|
+
}
|
|
70
|
+
.pay-pix-qrcode__code {
|
|
71
|
+
display: block;
|
|
72
|
+
max-width: 100%;
|
|
73
|
+
overflow-wrap: anywhere;
|
|
74
|
+
padding: 8px;
|
|
75
|
+
}
|
|
76
|
+
.pay-pix-qrcode__confirm-btn {
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
margin-top: 12px;
|
|
79
|
+
padding: 8px 16px;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './index.css';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './index.css';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.pay-pix-qrcode{display:flex;flex-direction:column;align-items:center}.pay-pix-qrcode__container{background-color:#fff;border-radius:8px;display:flex;justify-content:center;align-items:center;width:180px;height:180px}.pay-pix-qrcode__image{width:100%;height:100%;object-fit:cover}.pay-pix-qrcode__tip{text-align:center;color:#333;font-size:14px;line-height:20px;margin-top:12px}.pay-pix-qrcode__code-section{width:100%;max-width:320px;margin-top:16px}.pay-pix-qrcode__copy-btn{width:100%;padding:10px 16px;border:1px solid #32bcad;background-color:#fff;color:#32bcad;border-radius:8px;font-size:13px;font-weight:600;cursor:pointer;transition:.2s;display:flex;align-items:center;justify-content:center;gap:6px}.pay-pix-qrcode__copy-btn:hover{background-color:rgba(50,188,173,.06)}.pay-pix-qrcode__copy-btn:active{background-color:rgba(50,188,173,.12)}.pay-pix-qrcode__copy-btn--copied{color:#2ecc71;border-color:#2ecc71;background-color:rgba(46,204,113,.04)}.pay-pix-qrcode__copy-btn--copied:hover{background-color:rgba(46,204,113,.08)}.pay-pix-qrcode__copy-btn--copied:active{background-color:rgba(46,204,113,.14)}.pay-pix-qrcode__copy-icon{width:16px;height:16px;flex-shrink:0}.pay-pix-qrcode__code{display:block;max-width:100%;overflow-wrap:anywhere;padding:8px}.pay-pix-qrcode__confirm-btn{cursor:pointer;margin-top:12px;padding:8px 16px}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UseStripeCheckoutOptions, UseStripeCheckoutReturn } from '../interface';
|
|
2
|
+
/**
|
|
3
|
+
* @zh 打开 Stripe 托管支付页面,不自动下单。
|
|
4
|
+
* @en Open hosted Stripe checkout; no automatic order creation.
|
|
5
|
+
* @since 1.2.0
|
|
6
|
+
*/
|
|
7
|
+
export declare const useStripeCheckout: (options?: UseStripeCheckoutOptions) => UseStripeCheckoutReturn;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function 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; }
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
8
|
+
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); }
|
|
9
|
+
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 }; })(); }
|
|
10
|
+
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); }
|
|
11
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
12
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
13
|
+
import { usePaymentExecution } from '../../hooks/usePaymentExecution';
|
|
14
|
+
import { usePaymentRedirect } from '../../hooks/usePaymentRedirect';
|
|
15
|
+
import { useLatestCallback } from '../../hooks/useLatestCallback';
|
|
16
|
+
import { PaymentErrorCode } from '../../shared/enums';
|
|
17
|
+
import { PaymentExecutionError } from '../../shared/entitys/payment';
|
|
18
|
+
/**
|
|
19
|
+
* @zh 打开 Stripe 托管支付页面,不自动下单。
|
|
20
|
+
* @en Open hosted Stripe checkout; no automatic order creation.
|
|
21
|
+
* @since 1.2.0
|
|
22
|
+
*/
|
|
23
|
+
export var useStripeCheckout = function useStripeCheckout() {
|
|
24
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25
|
+
var execution = usePaymentExecution(options);
|
|
26
|
+
var redirect = usePaymentRedirect(options.redirectOptions);
|
|
27
|
+
var openCheckout = useLatestCallback(function (source) {
|
|
28
|
+
return execution.run(/*#__PURE__*/function () {
|
|
29
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(context) {
|
|
30
|
+
var target, _t;
|
|
31
|
+
return _regenerator().w(function (_context) {
|
|
32
|
+
while (1) switch (_context.n) {
|
|
33
|
+
case 0:
|
|
34
|
+
if (!(typeof source === 'function')) {
|
|
35
|
+
_context.n = 2;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
_context.n = 1;
|
|
39
|
+
return source(context.signal);
|
|
40
|
+
case 1:
|
|
41
|
+
_t = _context.v;
|
|
42
|
+
_context.n = 3;
|
|
43
|
+
break;
|
|
44
|
+
case 2:
|
|
45
|
+
_t = source;
|
|
46
|
+
case 3:
|
|
47
|
+
target = _t;
|
|
48
|
+
if (context.isCurrent()) {
|
|
49
|
+
_context.n = 4;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
return _context.a(2);
|
|
53
|
+
case 4:
|
|
54
|
+
if (!(target === null)) {
|
|
55
|
+
_context.n = 5;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
execution.cancel();
|
|
59
|
+
return _context.a(2);
|
|
60
|
+
case 5:
|
|
61
|
+
if (!(!target || typeof target.url !== 'string')) {
|
|
62
|
+
_context.n = 6;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
throw new PaymentExecutionError(PaymentErrorCode.InvalidParameters, 'A payment URL is required.');
|
|
66
|
+
case 6:
|
|
67
|
+
redirect.open(target.url);
|
|
68
|
+
case 7:
|
|
69
|
+
return _context.a(2);
|
|
70
|
+
}
|
|
71
|
+
}, _callee);
|
|
72
|
+
}));
|
|
73
|
+
return function (_x) {
|
|
74
|
+
return _ref.apply(this, arguments);
|
|
75
|
+
};
|
|
76
|
+
}());
|
|
77
|
+
});
|
|
78
|
+
var closeCheckout = useLatestCallback(function () {
|
|
79
|
+
execution.cancel();
|
|
80
|
+
redirect.close();
|
|
81
|
+
});
|
|
82
|
+
return _objectSpread(_objectSpread({}, execution), {}, {
|
|
83
|
+
openCheckout: openCheckout,
|
|
84
|
+
closeCheckout: closeCheckout
|
|
85
|
+
});
|
|
86
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import StripeCheckoutButton from './stripe-checkout-button';
|
|
1
2
|
import Stripe from './stripe';
|
|
2
3
|
import StripePopup from './stripe-popup';
|
|
3
4
|
import StripeButton from './stripe-button';
|
|
4
5
|
import StripeModal from './stripe-modal';
|
|
5
6
|
export * from './interface';
|
|
6
7
|
type StripeComponentType = typeof Stripe & {
|
|
8
|
+
CheckoutButton: typeof StripeCheckoutButton;
|
|
7
9
|
Button: typeof StripeButton;
|
|
8
10
|
Popup: typeof StripePopup;
|
|
9
11
|
Modal: typeof StripeModal;
|
|
@@ -11,3 +13,5 @@ type StripeComponentType = typeof Stripe & {
|
|
|
11
13
|
declare const StripeComponent: StripeComponentType;
|
|
12
14
|
export default StripeComponent;
|
|
13
15
|
export { StripeButton, StripePopup, StripeModal };
|
|
16
|
+
export { StripeCheckoutButton };
|
|
17
|
+
export { useStripeCheckout } from './hooks/useStripeCheckout';
|
package/dist/es/Stripe/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import StripeCheckoutButton from './stripe-checkout-button';
|
|
1
2
|
import Stripe from './stripe';
|
|
2
3
|
import StripePopup from './stripe-popup';
|
|
3
4
|
import StripeButton from './stripe-button';
|
|
4
5
|
import StripeModal from './stripe-modal';
|
|
5
6
|
export * from './interface';
|
|
6
7
|
var StripeComponent = Object.assign({}, Stripe, {
|
|
8
|
+
CheckoutButton: StripeCheckoutButton,
|
|
7
9
|
Button: StripeButton,
|
|
8
10
|
Popup: StripePopup,
|
|
9
11
|
Modal: StripeModal
|
|
10
12
|
});
|
|
11
13
|
export default StripeComponent;
|
|
12
|
-
export { StripeButton, StripePopup, StripeModal };
|
|
14
|
+
export { StripeButton, StripePopup, StripeModal };
|
|
15
|
+
export { StripeCheckoutButton };
|
|
16
|
+
export { useStripeCheckout } from './hooks/useStripeCheckout';
|