Skip to content

Commit

Permalink
Merge pull request #458 from Plant-for-the-Planet-org/develop
Browse files Browse the repository at this point in the history
Release January 2024
  • Loading branch information
mariahosfeld authored Jan 22, 2024
2 parents e8b8867 + d720673 commit 17ea8a2
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 81 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=
8 changes: 7 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const scheme =
: "https";

let APPUrl;
if (process.env.NEXT_PUBLIC_VERCEL_ENV === "preview") {
if (
process.env.NEXT_PUBLIC_VERCEL_ENV === "preview" &&
process.env.DISABLE_VERCEL_REDIRECT !== "true"
) {
APPUrl = `${scheme}://${process.env.VERCEL_URL}`;
} else {
APPUrl = process.env.APP_URL;
Expand Down Expand Up @@ -115,6 +118,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
59 changes: 44 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@sparticuz/chromium": "^106.0.2",
"@stripe/react-stripe-js": "^1.4.0",
"@stripe/stripe-js": "^1.13.2",
"axios": "^0.21.1",
"axios": "^1.6.0",
"dom-to-image": "^2.6.0",
"geocoder-arcgis": "^2.0.5",
"i18next": "^22.4.10",
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
1 change: 1 addition & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"billingAddress": "Contact Details",
"treesInCountry": "{{treeCount}} trees, Plant-for-the-Planet",
"fundingPaymentLabel": "Donate {{amount}}, Plant-for-the-Planet",
"pcashPaymentLabel": "Load {{amount}} PlanetCash, Plant-for-the-Planet",
"bouquetPaymentLabel": "Donate {{amount}}, Plant-for-the-Planet",
"errorOccurred": "Something went wrong. Please feel free to take a screenshot and email us at [email protected].",
"dedicatedTo": "Dedicated to",
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Types/QueryParamContextInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export default interface QueryParamContextInterface {
paymentSetupCountry: string;
shouldSetPaymentDetails?: boolean;
}) => Promise<void>;
isPlanetCashActive: boolean;
setIsPlanetCashActive: Dispatch<SetStateAction<boolean>>;
isPlanetCashActive: boolean | null;
setIsPlanetCashActive: Dispatch<SetStateAction<boolean | null>>;
onBehalf: boolean;
setOnBehalf: Dispatch<SetStateAction<boolean>>;
onBehalfDonor: OnBehalfDonor;
Expand Down
22 changes: 20 additions & 2 deletions src/Donations/Components/DonationsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function DonationsForm(): ReactElement {
utmMedium,
utmSource,
isPackageWanted,
setPaymentRequest,
} = React.useContext(QueryParamContext);
const { t, i18n } = useTranslation(["common", "country", "donate"]);

Expand All @@ -78,6 +79,16 @@ function DonationsForm(): ReactElement {
React.useState(false);
const router = useRouter();

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

React.useEffect(() => {
if (isPlanetCashActive) {
setPaymentRequest(null);
}
}, [isPlanetCashActive]);

React.useEffect(() => {
setMinAmt(getMinimumAmountForCurrency(currency));
}, [currency]);
Expand Down Expand Up @@ -241,6 +252,15 @@ function DonationsForm(): ReactElement {
),
});
break;
case "planet-cash":
paymentLabel = t("pcashPaymentLabel", {
amount: getFormatedCurrency(
i18n.language,
currency,
paymentSetup.unitCost * quantity
),
});
break;
case "bouquet":
case "conservation":
paymentLabel = t("bouquetPaymentLabel", {
Expand Down Expand Up @@ -400,8 +420,6 @@ function DonationsForm(): ReactElement {
paymentSetup?.gateways?.stripe?.account &&
currency ? (
<NativePay
isApplePayEnabled={false}
isGooglePayEnabled={false}
country={country}
currency={currency}
amount={formatAmountForStripe(
Expand Down
10 changes: 6 additions & 4 deletions src/Donations/Components/PaymentsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function PaymentsForm(): ReactElement {
utmMedium,
utmSource,
isPackageWanted,
setPaymentRequest,
} = React.useContext(QueryParamContext);

const [stripePromise, setStripePromise] =
Expand All @@ -100,6 +101,7 @@ function PaymentsForm(): ReactElement {

React.useEffect(() => {
setPaymentType("CARD");
setPaymentRequest(null);
}, []);

const sofortCountries = ["AT", "BE", "DE", "IT", "NL", "ES"];
Expand All @@ -111,7 +113,7 @@ function PaymentsForm(): ReactElement {
| string
| PaymentMethod
| PaypalApproveData
| PaypalErrorData,
| PaypalErrorData
) => {
if (!paymentSetup || !donationID) {
console.log("Missing payment options"); //TODOO - better error handling
Expand Down Expand Up @@ -144,7 +146,7 @@ function PaymentsForm(): ReactElement {
// Seems to work only for native pay. Should this be removed?
const onPaymentFunction = async (
paymentMethod: PaymentMethod,
paymentRequest: PaymentRequest,
paymentRequest: PaymentRequest
) => {
setPaymentType(paymentRequest._activeBackingLibraryName); //TODOO --_activeBackingLibraryName is a private variable?
const gateway = "stripe";
Expand Down Expand Up @@ -289,7 +291,7 @@ function PaymentsForm(): ReactElement {
query: { ...router.query, step: CONTACT },
},
undefined,
{ shallow: true },
{ shallow: true }
);
}}
className="d-flex"
Expand Down Expand Up @@ -420,7 +422,7 @@ function PaymentsForm(): ReactElement {
totalCost={getFormatedCurrency(
i18n.language,
currency,
paymentSetup?.unitCost * quantity,
paymentSetup?.unitCost * quantity
)}
onPaymentFunction={(providerObject: PaymentMethod) =>
onSubmitPayment("stripe", "card", providerObject)
Expand Down
43 changes: 26 additions & 17 deletions src/Donations/Micros/PlanetCashSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const PlanetCashSelector: FC = () => {
country,
setcountry,
frequency,
paymentRequest,
} = useContext(QueryParamContext);
const router = useRouter();

Expand All @@ -37,20 +36,28 @@ const PlanetCashSelector: FC = () => {
}, [paymentSetup?.unitCost, quantity, setIsPlanetCashActive]);

useEffect(() => {
// On Load If selected country is planetCash Country and balance is sufficient activate planetCash.

if (
country === profile?.planetCash?.country &&
paymentSetup &&
paymentSetup.unitCost * quantity <=
profile.planetCash.balance / 100 + profile.planetCash.creditLimit / 100
) {
setIsPlanetCashActive(true);
}
if (frequency !== "once") {
if (frequency !== "once" && isPlanetCashActive !== null) {
setIsPlanetCashActive(false);
} else {
if (
isPlanetCashActive === null &&
country === profile?.planetCash?.country &&
paymentSetup &&
paymentSetup.unitCost * quantity <=
(profile.planetCash.balance + profile.planetCash.creditLimit) / 100
) {
setIsPlanetCashActive(true);
}
}
}, [paymentRequest, frequency]);
}, [
country,
profile,
paymentSetup,
quantity,
frequency,
isPlanetCashActive,
frequency,
]);

useEffect(() => {
// This is done to lock the transaction with PlanetCash in a single currency.
Expand Down Expand Up @@ -208,11 +215,13 @@ const PlanetCashSelector: FC = () => {
</div>
<div title={disabledReason() ? disabledReason() : ""}>
<ToggleSwitch
checked={isPlanetCashActive}
checked={isPlanetCashActive === true}
disabled={shouldPlanetCashDisable()}
onChange={() =>
setIsPlanetCashActive((isPlanetCashActive) => !isPlanetCashActive)
}
onChange={() => {
setIsPlanetCashActive(
(isPlanetCashActive) => !isPlanetCashActive
);
}}
/>
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/Donations/PaymentMethods/PaymentMethodTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ export default function PaymentMethodTabs({
),
});
break;
case "planet-cash":
paymentLabel = t("pcashPaymentLabel", {
amount: getFormatedCurrency(
i18n.language,
currency,
paymentSetup.unitCost * quantity
),
});
break;
case "bouquet":
case "conservation":
paymentLabel = t("bouquetPaymentLabel", {
Expand Down Expand Up @@ -218,8 +227,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
Loading

1 comment on commit 17ea8a2

@vercel
Copy link

@vercel vercel bot commented on 17ea8a2 Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.