Skip to content

Commit 2eced0a

Browse files
committed
feat: add authentication to loadPaymentSetup
- adds authentication to loadPaymentSetup call (as "planet-cash" gateway is only returned in authenticated call) - adds debouncing while loading payment setup for non planet cash projects
1 parent 2839bc1 commit 2eced0a

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

src/Layout/QueryParamContext.tsx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import ErrorPopup from "src/Common/ErrorPopup/ErrorPopup";
4141
import { APIError, handleError, SerializedError } from "@planet-sdk/common";
4242
import { PaymentRequest } from "@stripe/stripe-js/types/stripe-js/payment-request";
4343
import { createProjectDetails } from "src/Utils/createProjectDetails";
44+
import { useDebouncedEffect } from "src/Utils/useDebouncedEffect";
4445

4546
export const QueryParamContext =
4647
createContext<QueryParamContextInterface>(null);
@@ -346,23 +347,27 @@ const QueryParamProvider: FC = ({ children }) => {
346347
router.query.token,
347348
]);
348349

349-
useEffect(() => {
350-
const regex = /^pcash_/;
351-
if (
352-
router.query.to &&
353-
!regex.test(router.query.to as string) &&
354-
country !== undefined &&
355-
country !== "" &&
356-
router.query.to?.toString().toLowerCase() !== "planetcash"
357-
) {
358-
const to = String(router.query.to).replace(/\//g, "");
359-
loadPaymentSetup({
360-
projectGUID: to,
361-
paymentSetupCountry: country,
362-
shouldSetPaymentDetails: true,
363-
});
364-
}
365-
}, [router.query.to, country]);
350+
useDebouncedEffect(
351+
() => {
352+
const regex = /^pcash_/;
353+
if (
354+
router.query.to &&
355+
!regex.test(router.query.to as string) &&
356+
country !== undefined &&
357+
country !== "" &&
358+
router.query.to?.toString().toLowerCase() !== "planetcash"
359+
) {
360+
const to = String(router.query.to).replace(/\//g, "");
361+
loadPaymentSetup({
362+
projectGUID: to,
363+
paymentSetupCountry: country,
364+
shouldSetPaymentDetails: true,
365+
});
366+
}
367+
},
368+
1000,
369+
[router.query.to, country, profile?.slug]
370+
);
366371

367372
async function loadConfig() {
368373
try {
@@ -488,11 +493,19 @@ const QueryParamProvider: FC = ({ children }) => {
488493
paymentSetupCountry: string;
489494
shouldSetPaymentDetails?: boolean;
490495
}) => {
496+
const token =
497+
profile === null
498+
? null
499+
: queryToken ||
500+
(router.query.token as string) ||
501+
(await getAccessTokenSilently());
502+
491503
setIsPaymentOptionsLoading(true);
492504
try {
493505
const requestParams = {
494506
url: `/app/paymentOptions/${projectGUID}?country=${paymentSetupCountry}`,
495507
setshowErrorCard,
508+
token,
496509
tenant,
497510
locale: i18n.language,
498511
};

0 commit comments

Comments
 (0)