@shopgate/engage
Version:
Shopgate's ENGAGE library.
60 lines (57 loc) • 1.46 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import { i18n } from "../../../core/helpers/i18n";
import { useCheckoutContext } from "../../hooks/common";
import { prepareStripeRequestCheckout } from "./StripeProvider";
import { getSdk } from "./sdk";
/**
* Paypal Pay button
* @returns {JSX}
*/
import { jsx as _jsx } from "react/jsx-runtime";
const StripePayButton = ({
children,
disabled,
onSubmit,
onValidate
}) => {
const {
order,
paymentData,
setLocked
} = useCheckoutContext();
const {
stripeRequest,
stripeRequestType
} = paymentData?.meta || {};
if (!stripeRequestType || !stripeRequestType?.applePay) {
return children;
}
/* eslint-disable react/button-has-type */
return /*#__PURE__*/_jsx("button", {
disabled: disabled,
lang: i18n.getLang(),
onClick: () => {
// Make sure button can't be triggered when loading
if (!onValidate() || disabled) {
return;
}
// Trigger stripe on client.
setLocked(true);
prepareStripeRequestCheckout(getSdk(), stripeRequest, order).then(event => {
stripeRequest.preparedEvent = event;
onSubmit();
}).catch(() => {
setLocked(false);
});
},
style: {
WebkitAppearance: '-apple-pay-button',
ApplePayButtonType: 'buy',
height: 40
},
children: ' '
});
/* eslint-enable react/button-has-type */
};
export default StripePayButton;