Skip to content

Commit

Permalink
Merge pull request #447 from Plant-for-the-Planet-org/feature/enable-…
Browse files Browse the repository at this point in the history
…native-payments

Enable native payments
  • Loading branch information
mariahosfeld authored Jan 15, 2024
2 parents 769295d + 6887189 commit 67b1d1b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
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
2 changes: 0 additions & 2 deletions src/Donations/Components/DonationsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ function DonationsForm(): ReactElement {
paymentSetup?.gateways?.stripe?.account &&
currency ? (
<NativePay
isApplePayEnabled={false}
isGooglePayEnabled={false}
country={country}
currency={currency}
amount={formatAmountForStripe(
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,8 +29,6 @@ interface PaymentButtonProps {
paymentLabel: string;
frequency: string | null;
paymentSetup: PaymentOptions;
isApplePayEnabled: boolean;
isGooglePayEnabled: boolean;
}

export const PaymentRequestCustomButton = ({
Expand All @@ -43,16 +41,20 @@ export const PaymentRequestCustomButton = ({
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);
const [paymentLoading, setPaymentLoading] = useState(false);

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

useEffect(() => {
if (
stripe &&
Expand Down Expand Up @@ -108,6 +110,7 @@ export const PaymentRequestCustomButton = ({
useEffect(() => {
if (paymentRequest && !paymentLoading) {
setPaymentLoading(true);
paymentRequest.off("paymentmethod");
paymentRequest.on(
"paymentmethod",
({ complete, paymentMethod }: PaymentRequestPaymentMethodEvent) => {
Expand All @@ -119,14 +122,9 @@ export const PaymentRequestCustomButton = ({
}
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 @@ export const PaymentRequestCustomButton = ({
/* 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 @@ interface NativePayProps {
frequency: string | null;
}
export const NativePay = ({
isApplePayEnabled = false,
isGooglePayEnabled = false,
country,
currency,
amount,
Expand Down Expand Up @@ -279,8 +273,6 @@ export const NativePay = ({
paymentLabel={paymentLabel}
frequency={frequency}
paymentSetup={paymentSetup}
isApplePayEnabled={isApplePayEnabled}
isGooglePayEnabled={isGooglePayEnabled}
/>
</Elements>
);
Expand Down

0 comments on commit 67b1d1b

Please sign in to comment.