diff --git a/src/Common/Types/index.tsx b/src/Common/Types/index.tsx index 2fc854f1..8ce43220 100644 --- a/src/Common/Types/index.tsx +++ b/src/Common/Types/index.tsx @@ -254,8 +254,22 @@ export interface OnBehalfDonor { email: string; } +export enum PaymentGateways { + OFFLINE = "offline", + PAYPAL = "paypal", + STRIPE = "stripe", +} + export interface ShowPaymentMethodParams { - paymentMethod: "card" | "giropay" | "sofort" | "sepa_debit"; + gateway: PaymentGateways; + paymentMethod: + | "card" + | "giropay" + | "sofort" + | "sepa_debit" + | "offline" + | "paypal" + | "native_pay"; // native_pay includes apple_pay, google_pay; countries?: string[]; currencies?: string[]; authenticatedMethod?: boolean; diff --git a/src/Donations/Components/PaymentsForm.tsx b/src/Donations/Components/PaymentsForm.tsx index bd2cb7ec..eb1986be 100644 --- a/src/Donations/Components/PaymentsForm.tsx +++ b/src/Donations/Components/PaymentsForm.tsx @@ -28,6 +28,7 @@ import { useRouter } from "next/router"; import { CONTACT, PAYMENT } from "src/Utils/donationStepConstants"; import BankTransfer from "../PaymentMethods/BankTransfer"; import { + PaymentGateways, PaypalApproveData, PaypalErrorData, ShowPaymentMethodParams, @@ -219,6 +220,7 @@ function PaymentsForm(): ReactElement { const { theme } = React.useContext(ThemeContext); const showPaymentMethod = ({ + gateway, paymentMethod, countries, currencies, @@ -230,14 +232,30 @@ function PaymentsForm(): ReactElement { : true; const isAuthenticatedMethod = authenticatedMethod ? isAuthenticated : true; + const showPaypal = + gateway === PaymentGateways.PAYPAL + ? paypalCurrencies.includes(currency) + : true; + + const showNativePay = + gateway === PaymentGateways.STRIPE && paymentMethod === "native_pay" + ? Boolean(paymentSetup?.gateways?.stripe?.account && currency) && + (frequency !== "once" + ? paymentSetup?.recurrency.methods?.includes("card") || false + : true) + : true; + return ( isAvailableInCountry && isAvailableForCurrency && isAuthenticatedMethod && - paymentSetup?.gateways.stripe.methods?.includes(paymentMethod) && - (frequency !== "once" - ? paymentSetup?.recurrency.methods?.includes(paymentMethod) - : true) + showPaypal && + showNativePay && + (paymentSetup?.gateways.stripe.methods?.includes(paymentMethod) || + (paymentSetup?.gateways && + Object.keys(paymentSetup?.gateways).includes(gateway))) && // check for gateway is for paypal and offline paymentMethods + (frequency === "once" || + paymentSetup?.recurrency.methods?.includes(paymentMethod)) ); }; @@ -334,13 +352,18 @@ function PaymentsForm(): ReactElement { )}