pay-sdk-react 1.1.5 → 1.1.7

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 (68) hide show
  1. package/dist/css/index.css +3 -1
  2. package/dist/css/index.min.css +1 -1
  3. package/dist/es/Airwallex/airwallex-button.d.ts +2 -2
  4. package/dist/es/Airwallex/airwallex-button.js +40 -11
  5. package/dist/es/Airwallex/interface.d.ts +32 -1
  6. package/dist/es/Airwallex/style/index.css +3 -1
  7. package/dist/es/Airwallex/style/index.min.css +1 -1
  8. package/dist/es/Alipay/alipay-button.d.ts +2 -2
  9. package/dist/es/Alipay/alipay-button.js +20 -8
  10. package/dist/es/Alipay/interface.d.ts +13 -2
  11. package/dist/es/MAlipay/style/index.css +3 -1
  12. package/dist/es/MAlipay/style/index.min.css +1 -1
  13. package/dist/es/MWeChat/style/index.css +3 -1
  14. package/dist/es/MWeChat/style/index.min.css +1 -1
  15. package/dist/es/PayButton/index.d.ts +2 -2
  16. package/dist/es/PayButton/index.js +10 -8
  17. package/dist/es/PayButton/interface.d.ts +5 -19
  18. package/dist/es/PayButton/interface.js +1 -93
  19. package/dist/es/PayMask/interface.d.ts +6 -0
  20. package/dist/es/PayMask/pay-mask.js +5 -2
  21. package/dist/es/Paypal/interface.d.ts +23 -1
  22. package/dist/es/Paypal/paypal-button.d.ts +2 -2
  23. package/dist/es/Paypal/paypal-button.js +31 -7
  24. package/dist/es/Payssion/interface.d.ts +12 -1
  25. package/dist/es/Payssion/payssion-button.d.ts +2 -2
  26. package/dist/es/Payssion/payssion-button.js +17 -4
  27. package/dist/es/Stripe/interface.d.ts +22 -1
  28. package/dist/es/Stripe/stripe-button.d.ts +2 -2
  29. package/dist/es/Stripe/stripe-button.js +31 -11
  30. package/dist/es/Stripe/style/index.css +3 -1
  31. package/dist/es/Stripe/style/index.min.css +1 -1
  32. package/dist/es/Wechat/interface.d.ts +13 -2
  33. package/dist/es/Wechat/wechat-button.d.ts +2 -2
  34. package/dist/es/Wechat/wechat-button.js +20 -8
  35. package/dist/es/Wechat/wechat.js +1 -1
  36. package/dist/es/confirm-modal/style/index.css +3 -1
  37. package/dist/es/confirm-modal/style/index.min.css +1 -1
  38. package/dist/es/hooks/usePayWindowOpen.d.ts +6 -0
  39. package/dist/es/hooks/usePayWindowOpen.js +9 -4
  40. package/dist/es/index.d.ts +1 -1
  41. package/dist/es/pay-modal/style/index.css +3 -1
  42. package/dist/es/pay-modal/style/index.min.css +1 -1
  43. package/dist/lib/Airwallex/airwallex-button.js +41 -12
  44. package/dist/lib/Airwallex/style/index.css +3 -1
  45. package/dist/lib/Airwallex/style/index.min.css +1 -1
  46. package/dist/lib/Alipay/alipay-button.js +20 -8
  47. package/dist/lib/MAlipay/style/index.css +3 -1
  48. package/dist/lib/MAlipay/style/index.min.css +1 -1
  49. package/dist/lib/MWeChat/style/index.css +3 -1
  50. package/dist/lib/MWeChat/style/index.min.css +1 -1
  51. package/dist/lib/PayButton/index.js +10 -8
  52. package/dist/lib/PayButton/interface.js +3 -1
  53. package/dist/lib/PayMask/pay-mask.js +2 -0
  54. package/dist/lib/Paypal/paypal-button.js +28 -5
  55. package/dist/lib/Payssion/payssion-button.js +17 -4
  56. package/dist/lib/Stripe/stripe-button.js +32 -12
  57. package/dist/lib/Stripe/style/index.css +3 -1
  58. package/dist/lib/Stripe/style/index.min.css +1 -1
  59. package/dist/lib/Wechat/wechat-button.js +20 -8
  60. package/dist/lib/Wechat/wechat.js +1 -1
  61. package/dist/lib/confirm-modal/style/index.css +3 -1
  62. package/dist/lib/confirm-modal/style/index.min.css +1 -1
  63. package/dist/lib/hooks/usePayWindowOpen.js +8 -4
  64. package/dist/lib/pay-modal/style/index.css +3 -1
  65. package/dist/lib/pay-modal/style/index.min.css +1 -1
  66. package/dist/umd/pay-sdk-react.umd.js +131 -28
  67. package/dist/umd/pay-sdk-react.umd.js.map +1 -1
  68. package/package.json +1 -1
@@ -5271,10 +5271,11 @@
5271
5271
  const defaultProps$4 = {
5272
5272
  payUrl: '',
5273
5273
  openMode: exports.OpenPayUrlMode.Window,
5274
+ closeWindowOnUnmount: true,
5274
5275
  };
5275
5276
  function usePayWindowOpen(p) {
5276
5277
  const props = mergeProps(defaultProps$4, p);
5277
- const { payUrl, onClose, onSuccess, autoOpen = true } = props;
5278
+ const { payUrl, onClose, onSuccess, autoOpen = true, closeWindowOnUnmount = true, } = props;
5278
5279
  const payWindowRef = React.useRef(null);
5279
5280
  const pollTimerRef = React.useRef(null);
5280
5281
  const [isWindowMonitoring, setWindowMonitoring] = React.useState(false);
@@ -5362,7 +5363,9 @@
5362
5363
  return () => {
5363
5364
  clearInterval(pollTimerRef.current);
5364
5365
  window.removeEventListener('message', handleMessage);
5365
- payWindowRef.current?.close();
5366
+ if (closeWindowOnUnmount) {
5367
+ payWindowRef.current?.close();
5368
+ }
5366
5369
  };
5367
5370
  }, [isWindowMonitoring, props, onClose, onSuccess]);
5368
5371
  return {
@@ -5382,7 +5385,7 @@
5382
5385
  };
5383
5386
  const PayMask = (p) => {
5384
5387
  const props = mergeProps(defaultProps$3, p);
5385
- const { visible, payUrl, onClose, onMaskClick, onContinue, openMode, autoOpenWindow, forceNewWindow, className, destroyOnClose = true, ...rest } = props;
5388
+ const { visible, payUrl, onClose, onMaskClick, onContinue, openMode, autoOpenWindow, forceNewWindow, className, destroyOnClose = true, closeWindowOnUnmount = true, ...rest } = props;
5386
5389
  const [isWindowMonitoring, setIsWindowMonitoring] = React.useState(false);
5387
5390
  const { openWindow, closeWindow } = usePayWindowOpen({
5388
5391
  payUrl: payUrl || '',
@@ -5392,6 +5395,7 @@
5392
5395
  },
5393
5396
  autoOpen: autoOpenWindow,
5394
5397
  openMode,
5398
+ closeWindowOnUnmount,
5395
5399
  ...(openMode === exports.OpenPayUrlMode.Window && { forceNewWindow }),
5396
5400
  });
5397
5401
  React.useEffect(() => {
@@ -5520,12 +5524,32 @@
5520
5524
  Button.displayName = 'Button';
5521
5525
 
5522
5526
  const PaypalButton = React.forwardRef((props, ref) => {
5523
- const { className, children = (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(IconPaypalText, {}), " Buy Now"] })), onClick, paypalUrl: propsPaypalUrl, createOrder, maskProps, ...others } = props;
5527
+ const { className, children = (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(IconPaypalText, {}), " Buy Now"] })), onClick, paypalUrl: propsPaypalUrl, createOrder, maskProps, isPayment, closeWindowOnUnmount = true, ...others } = props;
5524
5528
  const { onClose: onMaskClose, ...restMaskProps } = maskProps || {};
5525
- const paypalButtonRef = React.useRef({ nativeElement: null });
5529
+ const paypalButtonRef = React.useRef(null);
5526
5530
  const [showMask, setShowMask] = React.useState(false);
5527
5531
  const [paypalUrl, setPaypalUrl] = React.useState();
5528
- React.useImperativeHandle(ref, () => paypalButtonRef.current);
5532
+ // 监听 isPayment 状态变化,当支付完成时隐藏蒙层
5533
+ React.useEffect(() => {
5534
+ if (createOrder && isPayment) {
5535
+ setShowMask(false);
5536
+ }
5537
+ }, [createOrder, isPayment]);
5538
+ React.useImperativeHandle(ref, () => ({
5539
+ get nativeElement() {
5540
+ return paypalButtonRef.current?.nativeElement || null;
5541
+ },
5542
+ openPayment: (options) => {
5543
+ if (options) {
5544
+ setPaypalUrl(options.paypalUrl);
5545
+ }
5546
+ setShowMask(true);
5547
+ },
5548
+ closePayment: () => {
5549
+ setShowMask(false);
5550
+ },
5551
+ current: paypalButtonRef.current,
5552
+ }));
5529
5553
  const handlePayCreateOrder = React.useCallback(async () => {
5530
5554
  if (createOrder) {
5531
5555
  // 1. 业务侧创建订单,获取参数
@@ -5555,7 +5579,7 @@
5555
5579
  return (jsxRuntimeExports.jsxs(React.Fragment, { children: [jsxRuntimeExports.jsx(Button, { ref: paypalButtonRef, className: cs(getPrefixCls('paypal-btn'), className), onClick: handleClick, ...others, children: children }), showMask && paypalUrl && (jsxRuntimeExports.jsx(PayMask, { visible: showMask, onClose: () => {
5556
5580
  setShowMask(false);
5557
5581
  onMaskClose?.();
5558
- }, payUrl: paypalUrl, title: jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(IconPaypalWhite, {}), "PayPal"] }), ...restMaskProps }))] }));
5582
+ }, payUrl: paypalUrl, title: jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(IconPaypalWhite, {}), "PayPal"] }), closeWindowOnUnmount: closeWindowOnUnmount, ...restMaskProps }))] }));
5559
5583
  });
5560
5584
  PaypalButton.displayName = 'PaypalButton';
5561
5585
  var PaypalButton$1 = React.memo(PaypalButton);
@@ -9387,10 +9411,27 @@
9387
9411
 
9388
9412
  const StripeButton = React.forwardRef((props, ref) => {
9389
9413
  const { children = 'Stripe', onClick, displayType = 'popup', stripePopupProps, stripeModalProps, createOrder, ...others } = props;
9390
- const stripeButtonRef = React.useRef({ nativeElement: null });
9414
+ const stripeButtonRef = React.useRef(null);
9391
9415
  const stripePopupRef = React.useRef(null);
9392
9416
  const stripeModalRef = React.useRef(null);
9393
- React.useImperativeHandle(ref, () => stripeButtonRef.current);
9417
+ React.useImperativeHandle(ref, () => ({
9418
+ get nativeElement() {
9419
+ return stripeButtonRef.current?.nativeElement || null;
9420
+ },
9421
+ openPopup: (options) => {
9422
+ stripePopupRef.current?.open(options);
9423
+ },
9424
+ closePopup: () => {
9425
+ stripePopupRef.current?.close();
9426
+ },
9427
+ openModal: (options) => {
9428
+ stripeModalRef.current?.open(options);
9429
+ },
9430
+ closeModal: () => {
9431
+ stripeModalRef.current?.close();
9432
+ },
9433
+ current: stripeButtonRef.current,
9434
+ }));
9394
9435
  const handlePayCreateOrder = React.useCallback(async () => {
9395
9436
  if (createOrder) {
9396
9437
  // 1. 业务侧创建订单,获取参数
@@ -9566,14 +9607,38 @@
9566
9607
 
9567
9608
  const AirwallexButton = React.forwardRef((props, ref) => {
9568
9609
  const { children = 'Airwallex', onClick, createOrder, ...others } = props;
9569
- const airwallexButtonRef = React.useRef({
9570
- nativeElement: null,
9571
- });
9610
+ const airwallexButtonRef = React.useRef(null);
9572
9611
  const airwallexPopupRef = React.useRef(null);
9573
9612
  const airwallexModalRef = React.useRef(null);
9574
9613
  const [showMask, setShowMask] = React.useState(false);
9575
9614
  const [airwallexUrl, setAirwallexUrl] = React.useState();
9576
- React.useImperativeHandle(ref, () => airwallexButtonRef.current);
9615
+ React.useImperativeHandle(ref, () => ({
9616
+ get nativeElement() {
9617
+ return airwallexButtonRef.current?.nativeElement || null;
9618
+ },
9619
+ openModal: (options) => {
9620
+ airwallexModalRef.current?.open(options);
9621
+ },
9622
+ closeModal: () => {
9623
+ airwallexModalRef.current?.close();
9624
+ },
9625
+ openPopup: (options) => {
9626
+ airwallexPopupRef.current?.open(options);
9627
+ },
9628
+ closePopup: () => {
9629
+ airwallexPopupRef.current?.close();
9630
+ },
9631
+ openPayment: (options) => {
9632
+ if (options) {
9633
+ setAirwallexUrl(options.airwallexUrl);
9634
+ }
9635
+ setShowMask(true);
9636
+ },
9637
+ closePayment: () => {
9638
+ setShowMask(false);
9639
+ },
9640
+ current: airwallexButtonRef.current,
9641
+ }));
9577
9642
  const handlePayCreateOrder = React.useCallback(async () => {
9578
9643
  if (createOrder) {
9579
9644
  // 1. 业务侧创建订单,获取参数
@@ -9638,10 +9703,24 @@
9638
9703
  const PayssionButton = React.forwardRef((props, ref) => {
9639
9704
  const { className, children = (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(IconPayssionPay, {}), "Payssion"] })), onClick, payssionUrl: propsPayssionUrl, createOrder, maskProps, ...others } = props;
9640
9705
  const { onClose, ...restMaskProps } = maskProps || {};
9641
- const payssionButtonRef = React.useRef({ nativeElement: null });
9706
+ const payssionButtonRef = React.useRef(null);
9642
9707
  const [showMask, setShowMask] = React.useState(false);
9643
9708
  const [payssionUrl, setPayssionUrl] = React.useState();
9644
- React.useImperativeHandle(ref, () => payssionButtonRef.current);
9709
+ React.useImperativeHandle(ref, () => ({
9710
+ get nativeElement() {
9711
+ return payssionButtonRef.current?.nativeElement || null;
9712
+ },
9713
+ openPayment: (options) => {
9714
+ if (options) {
9715
+ setPayssionUrl(options.payssionUrl);
9716
+ }
9717
+ setShowMask(true);
9718
+ },
9719
+ closePayment: () => {
9720
+ setShowMask(false);
9721
+ },
9722
+ current: payssionButtonRef.current,
9723
+ }));
9645
9724
  const handlePayCreateOrder = React.useCallback(async () => {
9646
9725
  if (createOrder) {
9647
9726
  // 1. 业务侧创建订单,获取参数
@@ -9997,9 +10076,20 @@
9997
10076
 
9998
10077
  const AlipayButton = React.forwardRef((props, ref) => {
9999
10078
  const { className, children = (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(IconAlipay, {}), "\u652F\u4ED8\u5B9D\u652F\u4ED8"] })), onClick, createOrder, modalProps, ...others } = props;
10000
- const alipayButtonRef = React.useRef({ nativeElement: null });
10079
+ const alipayButtonRef = React.useRef(null);
10001
10080
  const alipayModalRef = React.useRef(null);
10002
- React.useImperativeHandle(ref, () => alipayButtonRef.current);
10081
+ React.useImperativeHandle(ref, () => ({
10082
+ get nativeElement() {
10083
+ return alipayButtonRef.current?.nativeElement || null;
10084
+ },
10085
+ openModal: (options) => {
10086
+ alipayModalRef.current?.open(options);
10087
+ },
10088
+ closeModal: () => {
10089
+ alipayModalRef.current?.close();
10090
+ },
10091
+ current: alipayButtonRef.current,
10092
+ }));
10003
10093
  const handlePayCreateOrder = React.useCallback(async () => {
10004
10094
  if (createOrder) {
10005
10095
  const options = await createOrder();
@@ -16351,7 +16441,7 @@
16351
16441
  });
16352
16442
  };
16353
16443
 
16354
- const classPrefix = getPrefixCls('wechat');
16444
+ const classPrefix = getPrefixCls('wechat-qrcode');
16355
16445
  const WechatQrCode = ({ wechatType = 'qrcode', wechatUrl, tipText = '请使用微信APP扫码支付', className, style, }) => {
16356
16446
  const [imageUrl, setImageUrl] = React.useState('');
16357
16447
  React.useEffect(() => {
@@ -16404,9 +16494,20 @@
16404
16494
 
16405
16495
  const WechatButton = React.forwardRef((props, ref) => {
16406
16496
  const { className, children = (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(IconWechatPay, {}), "\u5FAE\u4FE1\u652F\u4ED8"] })), onClick, createOrder, modalProps, ...others } = props;
16407
- const wechatButtonRef = React.useRef({ nativeElement: null });
16497
+ const wechatButtonRef = React.useRef(null);
16408
16498
  const wechatModalRef = React.useRef(null);
16409
- React.useImperativeHandle(ref, () => wechatButtonRef.current);
16499
+ React.useImperativeHandle(ref, () => ({
16500
+ get nativeElement() {
16501
+ return wechatButtonRef.current?.nativeElement || null;
16502
+ },
16503
+ openModal: (options) => {
16504
+ wechatModalRef.current?.open(options);
16505
+ },
16506
+ closeModal: () => {
16507
+ wechatModalRef.current?.close();
16508
+ },
16509
+ current: wechatButtonRef.current,
16510
+ }));
16410
16511
  const handlePayCreateOrder = React.useCallback(async () => {
16411
16512
  if (createOrder) {
16412
16513
  const options = await createOrder();
@@ -16432,31 +16533,33 @@
16432
16533
  WechatComponent.Modal = WechatModal$1;
16433
16534
 
16434
16535
  const PayButton = React.forwardRef((props, ref) => {
16536
+ // 使用类型断言来确保 ref 类型正确
16537
+ const typedRef = ref;
16435
16538
  if (props.payMethod === exports.PaymentMethod.PaypalH5 ||
16436
16539
  props.payMethod === exports.PaymentMethod.PaypalPc) {
16437
- return jsxRuntimeExports.jsx(PaypalButton$1, { ref: ref, ...props });
16540
+ return (jsxRuntimeExports.jsx(PaypalButton$1, { ref: typedRef, ...props }));
16438
16541
  }
16439
16542
  if (props.payMethod === exports.PaymentMethod.StripeH5 ||
16440
16543
  props.payMethod === exports.PaymentMethod.StripePc) {
16441
- return jsxRuntimeExports.jsx(StripeComponent.Button, { ref: ref, ...props });
16544
+ return (jsxRuntimeExports.jsx(StripeComponent.Button, { ref: typedRef, ...props }));
16442
16545
  }
16443
16546
  if (props.payMethod === exports.PaymentMethod.Airwallex) {
16444
- return jsxRuntimeExports.jsx(AirwallexComponent.Button, { ref: ref, ...props });
16547
+ return (jsxRuntimeExports.jsx(AirwallexComponent.Button, { ref: typedRef, ...props }));
16445
16548
  }
16446
16549
  if (props.payMethod === exports.PaymentMethod.Payssion) {
16447
- return jsxRuntimeExports.jsx(PayssionButton$1, { ref: ref, ...props });
16550
+ return (jsxRuntimeExports.jsx(PayssionButton$1, { ref: typedRef, ...props }));
16448
16551
  }
16449
16552
  if (props.payMethod === exports.PaymentMethod.WechatH5) {
16450
- return jsxRuntimeExports.jsx(MWechatButton$1, { ref: ref, ...props });
16553
+ return (jsxRuntimeExports.jsx(MWechatButton$1, { ref: typedRef, ...props }));
16451
16554
  }
16452
16555
  if (props.payMethod === exports.PaymentMethod.AlipayH5) {
16453
- return jsxRuntimeExports.jsx(MAlipayComponent.Button, { ref: ref, ...props });
16556
+ return (jsxRuntimeExports.jsx(MAlipayComponent.Button, { ref: typedRef, ...props }));
16454
16557
  }
16455
16558
  if (props.payMethod === exports.PaymentMethod.AlipayPc) {
16456
- return jsxRuntimeExports.jsx(AlipayComponent.Button, { ref: ref, ...props });
16559
+ return (jsxRuntimeExports.jsx(AlipayComponent.Button, { ref: typedRef, ...props }));
16457
16560
  }
16458
16561
  if (props.payMethod === exports.PaymentMethod.WechatPc) {
16459
- return jsxRuntimeExports.jsx(WechatComponent.Button, { ref: ref, ...props });
16562
+ return (jsxRuntimeExports.jsx(WechatComponent.Button, { ref: typedRef, ...props }));
16460
16563
  }
16461
16564
  return null;
16462
16565
  });