Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable native payments #447

Merged
merged 9 commits into from
Jan 15, 2024
5 changes: 4 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ SENTRY_AUTH_TOKEN=
SOURCE_VERSION=
RECURRENCY=true

TRACKING_KEY=
TRACKING_KEY=

ENABLE_APPLE_PAY=
ENABLE_GOOGLE_PAY=
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ const nextConfig = {
ESRI_CLIENT_SECRET: process.env.ESRI_CLIENT_SECRET,
RECURRENCY: process.env.RECURRENCY,
TRACKING_KEY: process.env.TRACKING_KEY,
ENABLE_GOOGLE_PAY: process.env.ENABLE_GOOGLE_PAY,
ENABLE_APPLE_PAY: process.env.ENABLE_APPLE_PAY,
DISABLE_VERCEL_REDIRECT: process.env.DISABLE_VERCEL_REDIRECT,
},
trailingSlash: false,
reactStrictMode: true,
Expand Down
5 changes: 4 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ function MyApp({
process.env.VERCEL_URL &&
typeof window !== "undefined"
) {
if (process.env.VERCEL_URL !== window.location.hostname) {
if (
process.env.VERCEL_URL !== window.location.hostname &&
process.env.DISABLE_VERCEL_REDIRECT !== "true"
) {
router.replace(`https://${process.env.VERCEL_URL}`);
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/Donations/Components/DonationsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function DonationsForm(): ReactElement {
//Only used for native pay. Is this still applicable, or should this be removed?
const onPaymentFunction = async (
paymentMethod: PaymentMethod,
paymentRequest: PaymentRequest,
paymentRequest: PaymentRequest
) => {
// eslint-disable-next-line no-underscore-dangle
setPaymentType(paymentRequest._activeBackingLibraryName); //TODOO - is _activeBackingLibraryName a private variable?
Expand Down Expand Up @@ -223,7 +223,7 @@ function DonationsForm(): ReactElement {
amount: getFormatedCurrency(
i18n.language,
currency,
paymentSetup.unitCost * quantity,
paymentSetup.unitCost * quantity
),
});
break;
Expand All @@ -233,7 +233,7 @@ function DonationsForm(): ReactElement {
amount: getFormatedCurrency(
i18n.language,
currency,
paymentSetup.unitCost * quantity,
paymentSetup.unitCost * quantity
),
});
break;
Expand Down Expand Up @@ -389,13 +389,11 @@ function DonationsForm(): ReactElement {
paymentSetup?.gateways?.stripe?.account &&
currency ? (
<NativePay
isApplePayEnabled={false}
isGooglePayEnabled={false}
country={country}
currency={currency}
amount={formatAmountForStripe(
paymentSetup?.unitCost * quantity,
currency.toLowerCase(),
currency.toLowerCase()
)}
onPaymentFunction={onPaymentFunction}
paymentSetup={paymentSetup}
Expand All @@ -405,7 +403,7 @@ function DonationsForm(): ReactElement {
query: { ...router.query, step: CONTACT },
},
undefined,
{ shallow: true },
{ shallow: true }
);
setRetainQuantityValue(true);
}}
Expand Down
2 changes: 0 additions & 2 deletions src/Donations/PaymentMethods/PaymentMethodTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ export default function PaymentMethodTabs({
{/*9 May 2023 - Apple Pay / Google Pay is disabled currently as it is not working correctly*/}
{showNativePay && (
<NativePay
isApplePayEnabled={false}
isGooglePayEnabled={false}
country={country}
currency={currency}
amount={formatAmountForStripe(
Expand Down
28 changes: 10 additions & 18 deletions src/Donations/PaymentMethods/PaymentRequestCustomButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,32 @@
paymentLabel: string;
frequency: string | null;
paymentSetup: PaymentOptions;
isApplePayEnabled: boolean;
isGooglePayEnabled: boolean;
}

export const PaymentRequestCustomButton = ({
country,
currency,
amount,
onPaymentFunction,
continueNext,
isPaymentPage,
paymentLabel,
frequency,
paymentSetup,
isApplePayEnabled,
isGooglePayEnabled,
}: PaymentButtonProps): ReactElement | null => {
const isApplePayEnabled = process.env.ENABLE_APPLE_PAY === "true" || false;
const isGooglePayEnabled = process.env.ENABLE_GOOGLE_PAY === "true" || false;
const { t, ready } = useTranslation(["common"]);
const { paymentRequest, setPaymentRequest } = useContext(QueryParamContext);

const stripe = useStripe();
const [canMakePayment, setCanMakePayment] = useState(false);

Check notice on line 51 in src/Donations/PaymentMethods/PaymentRequestCustomButton.tsx

View check run for this annotation

codefactor.io / CodeFactor

src/Donations/PaymentMethods/PaymentRequestCustomButton.tsx#L34-L51

Complex Method
const [paymentLoading, setPaymentLoading] = useState(false);

useEffect(() => {
setPaymentRequest(null);
}, []);

useEffect(() => {
if (
stripe &&
Expand Down Expand Up @@ -108,6 +110,7 @@
useEffect(() => {
if (paymentRequest && !paymentLoading) {
setPaymentLoading(true);
paymentRequest.off("paymentmethod");
paymentRequest.on(
"paymentmethod",
({ complete, paymentMethod }: PaymentRequestPaymentMethodEvent) => {
Expand All @@ -119,14 +122,9 @@
}
return () => {
if (paymentRequest && !paymentLoading) {
paymentRequest.off(
"paymentmethod",
({ complete, paymentMethod }: PaymentRequestPaymentMethodEvent) => {
onPaymentFunction(paymentMethod, paymentRequest);
complete("success");
setPaymentLoading(false);
}
);
paymentRequest.off("paymentmethod", () => {
setPaymentLoading(false);
});
}
};
}, [paymentRequest, onPaymentFunction]);
Expand Down Expand Up @@ -215,8 +213,6 @@
/* 9 May 2023 - Apple Pay / Google Pay is disabled currently as it is not working correctly*/

interface NativePayProps {
isApplePayEnabled: boolean;
isGooglePayEnabled: boolean;
country: string;
currency: string;
amount: number;
Expand All @@ -231,8 +227,6 @@
frequency: string | null;
}
export const NativePay = ({
isApplePayEnabled = false,
isGooglePayEnabled = false,
country,
currency,
amount,
Expand Down Expand Up @@ -279,8 +273,6 @@
paymentLabel={paymentLabel}
frequency={frequency}
paymentSetup={paymentSetup}
isApplePayEnabled={isApplePayEnabled}
isGooglePayEnabled={isGooglePayEnabled}
/>
</Elements>
);
Expand Down
Loading