This commit is contained in:
Daniil Chemerkin 2024-06-16 22:51:39 +00:00
parent bb8d8073e3
commit ab9250f5c3
5 changed files with 63 additions and 37 deletions

View File

@ -17,6 +17,7 @@ interface ICheckoutFormProps {
subscriptionReceiptId?: string; subscriptionReceiptId?: string;
returnUrl?: string; returnUrl?: string;
confirmType?: "payment" | "setup"; confirmType?: "payment" | "setup";
isHide?: boolean;
} }
export default function CheckoutForm({ export default function CheckoutForm({
@ -24,6 +25,7 @@ export default function CheckoutForm({
subscriptionReceiptId, subscriptionReceiptId,
returnUrl, returnUrl,
confirmType = "payment", confirmType = "payment",
isHide = false,
}: ICheckoutFormProps) { }: ICheckoutFormProps) {
const stripe = useStripe(); const stripe = useStripe();
const elements = useElements(); const elements = useElements();
@ -70,13 +72,19 @@ export default function CheckoutForm({
return ( return (
<form <form
className="payment-form-stripe" className={`payment-form-stripe ${isHide ? styles.hide : ""}`}
id="payment-form" id="payment-form"
onSubmit={handleSubmit} onSubmit={handleSubmit}
> >
{children ? children : null} {children ? children : null}
<PaymentElement <PaymentElement
options={{ terms: { card: "never" } }} options={{
terms: { card: "never" },
wallets: {
googlePay: "never",
applePay: "never",
},
}}
onReady={() => setFormReady(true)} onReady={() => setFormReady(true)}
/> />
<MainButton <MainButton

View File

@ -9,6 +9,11 @@
gap: 16px; gap: 16px;
} }
.hide {
height: 0;
visibility: hidden;
}
.payment-loader { .payment-loader {
display: flex; display: flex;
justify-content: center; justify-content: center;

View File

@ -94,7 +94,10 @@ function ExpressCheckoutStripe({
<div className={`${styles.container} ${isHideForm ? styles.hide : ""}`}> <div className={`${styles.container} ${isHideForm ? styles.hide : ""}`}>
<ExpressCheckoutElement <ExpressCheckoutElement
onReady={onReady} onReady={onReady}
onLoadError={() => onChangeLoading && onChangeLoading(false)} onLoadError={(e) => {
console.log("Error: ", e);
onChangeLoading && onChangeLoading(false);
}}
onConfirm={onConfirm} onConfirm={onConfirm}
options={{ options={{
layout: { layout: {
@ -102,6 +105,10 @@ function ExpressCheckoutStripe({
overflow: "never", overflow: "never",
}, },
paymentMethodOrder: ["apple_pay", "google_pay", "amazon_pay", "link"], paymentMethodOrder: ["apple_pay", "google_pay", "amazon_pay", "link"],
wallets: {
googlePay: "always",
applePay: "always",
},
}} }}
/> />
{errorMessage && <p className={styles.error}>{errorMessage}</p>} {errorMessage && <p className={styles.error}>{errorMessage}</p>}

View File

@ -160,6 +160,7 @@ function PaymentModal({
)} )}
<div className={styles["payment-method-container"]}> <div className={styles["payment-method-container"]}>
{stripePromise && clientSecret && ( {stripePromise && clientSecret && (
<>
<Elements stripe={stripePromise} options={{ clientSecret }}> <Elements stripe={stripePromise} options={{ clientSecret }}>
<ExpressCheckoutStripe <ExpressCheckoutStripe
clientSecret={clientSecret} clientSecret={clientSecret}
@ -174,14 +175,16 @@ function PaymentModal({
setIsLoadingExpressCheckout(isLoading) setIsLoadingExpressCheckout(isLoading)
} }
/> />
{selectedPaymentMethod === EPaymentMethod.CREDIT_CARD && ( </Elements>
<Elements stripe={stripePromise} options={{ clientSecret }}>
<CheckoutForm <CheckoutForm
confirmType={paymentType} confirmType={paymentType}
subscriptionReceiptId={paymentIntentId} subscriptionReceiptId={paymentIntentId}
returnUrl={returnUrl} returnUrl={returnUrl}
isHide={selectedPaymentMethod !== EPaymentMethod.CREDIT_CARD}
/> />
)}
</Elements> </Elements>
</>
)} )}
</div> </div>
<SecurityPayments /> <SecurityPayments />

View File

@ -165,6 +165,7 @@ function PaymentModal({
)} )}
<div className={styles["payment-method-container"]}> <div className={styles["payment-method-container"]}>
{stripePromise && clientSecret && ( {stripePromise && clientSecret && (
<>
<Elements stripe={stripePromise} options={{ clientSecret }}> <Elements stripe={stripePromise} options={{ clientSecret }}>
<ExpressCheckoutStripe <ExpressCheckoutStripe
clientSecret={clientSecret} clientSecret={clientSecret}
@ -179,14 +180,16 @@ function PaymentModal({
setIsLoadingExpressCheckout(isLoading) setIsLoadingExpressCheckout(isLoading)
} }
/> />
{selectedPaymentMethod === EPaymentMethod.CREDIT_CARD && ( </Elements>
<Elements stripe={stripePromise} options={{ clientSecret }}>
<CheckoutForm <CheckoutForm
confirmType={paymentType} confirmType={paymentType}
subscriptionReceiptId={paymentIntentId} subscriptionReceiptId={paymentIntentId}
returnUrl={returnUrl} returnUrl={returnUrl}
isHide={selectedPaymentMethod !== EPaymentMethod.CREDIT_CARD}
/> />
)}
</Elements> </Elements>
</>
)} )}
</div> </div>
<SecurityPayments /> <SecurityPayments />