pay-sdk-react
Version:
A cross-platform payment SDK for React, supporting Alipay, WeChat Pay, PayPal, Stripe, Payssion, and Airwallex, compatible with H5, PC, and App environments.
38 lines • 1.65 kB
JavaScript
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
var _excluded = ["stripeKey", "clientSecret", "className"];
import React, { memo, useImperativeHandle, useMemo, useRef } from 'react';
import { EmbeddedCheckout, EmbeddedCheckoutProvider } from '@stripe/react-stripe-js';
import { loadStripe } from '@stripe/stripe-js';
import cs from '../utils/classNames';
import { getPrefixCls } from '../utils/getPrefixCls';
var Stripe = /*#__PURE__*/React.forwardRef(function (props, ref) {
var stripeKey = props.stripeKey,
clientSecret = props.clientSecret,
_props$className = props.className,
className = _props$className === void 0 ? '' : _props$className,
others = _objectWithoutProperties(props, _excluded);
var stripeRef = useRef(null);
useImperativeHandle(ref, function () {
return stripeRef.current;
});
var stripePromise = useMemo(function () {
if (!stripeKey) {
return null;
}
return loadStripe === null || loadStripe === void 0 ? void 0 : loadStripe(stripeKey);
}, [stripeKey]);
var classNames = cs(getPrefixCls('pay-stripe'), className);
return /*#__PURE__*/React.createElement("div", _extends({
ref: stripeRef
}, others, {
className: classNames
}), clientSecret && stripePromise && /*#__PURE__*/React.createElement(EmbeddedCheckoutProvider, {
stripe: stripePromise,
options: {
clientSecret: clientSecret
}
}, /*#__PURE__*/React.createElement(EmbeddedCheckout, null)));
});
Stripe.displayName = 'Stripe';
export default /*#__PURE__*/memo(Stripe);