Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | 1x 109x 109x 109x 109x 109x 1x 1x 1x 1x 109x 109x 1x 109x 109x 109x | import { styled, useAppTheme } from "@theme/v2/Provider";
import { CircularProgress, Link, Stack } from "@mui/material";
import SummaryCard from "@pages/MerchantCheckout/CheckoutPending/components/SummaryCard";
import Payment from "componentsV2/Payment/Payment";
import { FormProvider, useForm } from "react-hook-form";
import { convertHexToRGB } from "@utils/theme";
import GiveButton from "@shared/Button/GiveButton";
import NiceModal from "@ebay/nice-modal-react";
import { TERMS_OF_SERVICE_REBRAND_MODAL } from "modals/modal_names";
import GiveText from "@shared/Text/GiveText";
import CheckoutFooter from "@sections/PayBuilder/Checkout/components/CheckoutFooter";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { yupResolver } from "@hookform/resolvers/yup";
import { formSchema } from "@pages/MerchantCheckout/CheckoutPending/schema";
import { TypeFormInputs } from "@pages/MerchantCheckout/types";
import usePayNow from "@pages/MerchantCheckout/hooks/usePayNow";
import useGetCheckoutInfo from "@pages/MerchantCheckout/hooks/useGetCheckoutInfo";
import { PaymentErrorBoundary } from "@components/ErrorBoundary";
interface ICheckoutPending {
onPaymentSuccess: (v: any) => void;
}
const CheckoutPending = ({ onPaymentSuccess }: ICheckoutPending) => {
const theme = useAppTheme();
const { isMobileView } = useCustomThemeV2();
const { externalUrl: paymentFor, amount: total } = useGetCheckoutInfo();
const methods = useForm<TypeFormInputs>({
resolver: yupResolver(formSchema),
mode: "onSubmit",
});
const onPaymentFailed = () => {
methods.setError("payment.cvv", {
type: "custom",
message: "",
});
methods.setError("payment.expirationDate", {
type: "custom",
message: "",
});
methods.setError("payment.nameOnCard", {
type: "custom",
message: "",
});
methods.setError("payment.cardNumber", {
type: "custom",
message: "Your card was declined. Try again or use different card.",
});
};
const { handlePayNow: onPay, isProcessing } = usePayNow(
onPaymentSuccess,
onPaymentFailed,
);
return (
<PaymentErrorBoundary
isCritical
errorContext={{
isCheckoutPending: true,
paymentFor,
total,
}}
onReset={() => {
methods.reset();
}}
>
<FormProvider {...methods}>
<StyledContainer>
<SummaryCard paymentFor={paymentFor} total={total} />
<Payment
isMobileView={isMobileView}
isDisabledFields={isProcessing}
showTooltip={false}
styles={{
rootContainerSx: {
background: convertHexToRGB(
theme.palette.primitive?.blue["50"] || "",
0.08,
),
borderColor: theme.palette.primitive?.blue["50"],
height: "fit-content",
},
paymentSectionStyles: {
background: theme.palette.surface?.secondary,
},
}}
/>
<GiveButton
{...(isProcessing
? { sx: { backgroundColor: "#998A6B", opacity: 0.5 } }
: {})}
size="large"
label={<PayNowButtonContent isProcessing={isProcessing} />}
disabled={isProcessing}
onClick={methods.handleSubmit(onPay)}
data-testid="merchant-checkout-pay-now-btn"
/>
<GiveText
variant="bodyS"
color="primary"
sx={{
textAlign: "center",
}}
>
By clicking 'Pay Now,' I accept GivePayments'{" "}
<Link
color="inherit"
onClick={() => NiceModal.show(TERMS_OF_SERVICE_REBRAND_MODAL)}
sx={{ cursor: "pointer" }}
>
Terms & Conditions
</Link>
</GiveText>
<CheckoutFooter isDesktopView={!isMobileView} />
</StyledContainer>
</FormProvider>
</PaymentErrorBoundary>
);
};
const PayNowButtonContent = ({ isProcessing }: { isProcessing: boolean }) => {
const theme = useAppTheme();
return (
<Stack direction="row" alignItems="center" gap={1.5}>
<GiveText variant="bodyL" sx={{ color: theme.palette.primitive?.neutral?.["0"] }}>
{isProcessing ? "Processing" : "Pay Now"}
</GiveText>
{isProcessing && (
<CircularProgress
size={14}
sx={{ color: theme.palette.primitive?.neutral?.["0"] }}
/>
)}
</Stack>
);
};
const StyledContainer = styled(Stack)(({ theme }) => ({
gap: theme.spacing(2),
width: "100%",
height: "100%",
}));
export default CheckoutPending;
|