AW-104-express-checkout-edits
This commit is contained in:
parent
2fb3606989
commit
90ad1b8a16
@ -10,6 +10,7 @@ import {
|
|||||||
AvailablePaymentMethods,
|
AvailablePaymentMethods,
|
||||||
StripeExpressCheckoutElementReadyEvent,
|
StripeExpressCheckoutElementReadyEvent,
|
||||||
} from "@stripe/stripe-js";
|
} from "@stripe/stripe-js";
|
||||||
|
import { checkExpressCheckoutStripeFormAvailable } from "@/data/paymentMethods";
|
||||||
|
|
||||||
interface IExpressCheckoutStripeProps {
|
interface IExpressCheckoutStripeProps {
|
||||||
clientSecret: string;
|
clientSecret: string;
|
||||||
@ -22,20 +23,6 @@ interface IExpressCheckoutStripeProps {
|
|||||||
onChangeLoading?: (isLoading: boolean) => void;
|
onChangeLoading?: (isLoading: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkFormAvailable = (
|
|
||||||
availablePaymentMethods: undefined | AvailablePaymentMethods
|
|
||||||
) => {
|
|
||||||
if (!availablePaymentMethods) return false;
|
|
||||||
let result = false;
|
|
||||||
for (const key in availablePaymentMethods) {
|
|
||||||
if (availablePaymentMethods[key as keyof AvailablePaymentMethods]) {
|
|
||||||
result = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
function ExpressCheckoutStripe({
|
function ExpressCheckoutStripe({
|
||||||
clientSecret,
|
clientSecret,
|
||||||
returnUrl = "https://${window.location.host}/payment/result/",
|
returnUrl = "https://${window.location.host}/payment/result/",
|
||||||
@ -95,7 +82,9 @@ function ExpressCheckoutStripe({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onReady = (event: StripeExpressCheckoutElementReadyEvent) => {
|
const onReady = (event: StripeExpressCheckoutElementReadyEvent) => {
|
||||||
const _isAvailable = checkFormAvailable(event.availablePaymentMethods);
|
const _isAvailable = checkExpressCheckoutStripeFormAvailable(
|
||||||
|
event.availablePaymentMethods
|
||||||
|
);
|
||||||
setIsAvailable(_isAvailable);
|
setIsAvailable(_isAvailable);
|
||||||
onAvailable && onAvailable(_isAvailable, event.availablePaymentMethods);
|
onAvailable && onAvailable(_isAvailable, event.availablePaymentMethods);
|
||||||
onChangeLoading && onChangeLoading(false);
|
onChangeLoading && onChangeLoading(false);
|
||||||
@ -107,6 +96,13 @@ function ExpressCheckoutStripe({
|
|||||||
onReady={onReady}
|
onReady={onReady}
|
||||||
onLoadError={() => onChangeLoading && onChangeLoading(false)}
|
onLoadError={() => onChangeLoading && onChangeLoading(false)}
|
||||||
onConfirm={onConfirm}
|
onConfirm={onConfirm}
|
||||||
|
options={{
|
||||||
|
layout: {
|
||||||
|
maxColumns: 1,
|
||||||
|
overflow: "never",
|
||||||
|
},
|
||||||
|
paymentMethodOrder: ["apple_pay", "google_pay", "amazon_pay", "link"],
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{errorMessage && <p className={styles.error}>{errorMessage}</p>}
|
{errorMessage && <p className={styles.error}>{errorMessage}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -185,7 +185,7 @@ function PaymentModal({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<SecurityPayments />
|
<SecurityPayments />
|
||||||
<p className={styles.address}>500 N RAINBOW BLVD LAS VEGAS, NV 89107</p>
|
<p className={styles.address}>1123 Rimer Dr Moraga, California 94556</p>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
.address {
|
.address {
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-method {
|
.payment-method {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import styles from "./styles.module.css"
|
|||||||
|
|
||||||
function PaymentAddress() {
|
function PaymentAddress() {
|
||||||
return (
|
return (
|
||||||
<p className={styles.address}>500 N RAINBOW BLVD LAS VEGAS, NV 89107</p>
|
<p className={styles.address}>1123 Rimer Dr Moraga, California 94556</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,4 +4,5 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 9px;
|
margin-top: 9px;
|
||||||
color: rgb(130, 130, 130);
|
color: rgb(130, 130, 130);
|
||||||
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,7 @@ function PaymentForm({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<SecurityPayments />
|
<SecurityPayments />
|
||||||
<p className={styles.address}>500 N RAINBOW BLVD LAS VEGAS, NV 89107</p>
|
<p className={styles.address}>1123 Rimer Dr Moraga, California 94556</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,4 +41,5 @@
|
|||||||
.address {
|
.address {
|
||||||
color: gray;
|
color: gray;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -190,7 +190,7 @@ function PaymentModal({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<SecurityPayments />
|
<SecurityPayments />
|
||||||
<p className={styles.address}>500 N RAINBOW BLVD LAS VEGAS, NV 89107</p>
|
<p className={styles.address}>1123 Rimer Dr Moraga, California 94556</p>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
.address {
|
.address {
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
|
text-transform: uppercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
.payment-method {
|
.payment-method {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { TCanMakePaymentResult } from "@/components/PaymentPage/methods/StripeButton";
|
import { TCanMakePaymentResult } from "@/components/PaymentPage/methods/StripeButton";
|
||||||
import CreditCard from "@/components/ui/PaymentMethodsButtons/CreditCard";
|
import CreditCard from "@/components/ui/PaymentMethodsButtons/CreditCard";
|
||||||
import PaymentButtons from "@/components/ui/PaymentMethodsButtons/PaymentButtons";
|
import PaymentButtons from "@/components/ui/PaymentMethodsButtons/PaymentButtons";
|
||||||
|
import { AvailablePaymentMethods } from "@stripe/stripe-js";
|
||||||
|
|
||||||
export enum EPaymentMethod {
|
export enum EPaymentMethod {
|
||||||
CREDIT_CARD = "card",
|
CREDIT_CARD = "card",
|
||||||
@ -23,6 +24,20 @@ export interface IPaymentMethod {
|
|||||||
// },
|
// },
|
||||||
// ];
|
// ];
|
||||||
|
|
||||||
|
export const checkExpressCheckoutStripeFormAvailable = (
|
||||||
|
availablePaymentMethods: undefined | AvailablePaymentMethods
|
||||||
|
) => {
|
||||||
|
if (!availablePaymentMethods) return false;
|
||||||
|
let result = false;
|
||||||
|
for (const key in availablePaymentMethods) {
|
||||||
|
if (availablePaymentMethods[key as keyof AvailablePaymentMethods]) {
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
export function paymentMethods(
|
export function paymentMethods(
|
||||||
availableMethods: TCanMakePaymentResult
|
availableMethods: TCanMakePaymentResult
|
||||||
): IPaymentMethod[] {
|
): IPaymentMethod[] {
|
||||||
@ -37,7 +52,12 @@ export function paymentMethods(
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!availableMethods) {
|
if (
|
||||||
|
!availableMethods ||
|
||||||
|
!checkExpressCheckoutStripeFormAvailable(
|
||||||
|
availableMethods as AvailablePaymentMethods
|
||||||
|
)
|
||||||
|
) {
|
||||||
methods = methods.filter(
|
methods = methods.filter(
|
||||||
(method) => method.id !== EPaymentMethod.PAYMENT_BUTTONS
|
(method) => method.id !== EPaymentMethod.PAYMENT_BUTTONS
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user