Skip to content

Commit 83aae9a

Browse files
Confirm businessId before loading gdp (#1228)
* check session businessId existance * add businessId to checkout session query * add missing url to session query * add changeset
1 parent 74642f2 commit 83aae9a

File tree

7 files changed

+25
-4
lines changed

7 files changed

+25
-4
lines changed

.changeset/nine-cooks-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@godaddy/react": patch
3+
---
4+
5+
Fix bug where GDP tries to load before having session values

packages/react/src/components/checkout/payment/checkout-buttons/express/godaddy.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ export function ExpressCheckoutButton() {
336336
if (
337337
!collect.current &&
338338
godaddyPaymentsConfig &&
339+
(godaddyPaymentsConfig?.businessId || session?.businessId) &&
339340
isPoyntLoaded &&
340341
isCollectLoading &&
341342
!hasMounted.current &&
@@ -404,7 +405,8 @@ export function ExpressCheckoutButton() {
404405
!godaddyPaymentsConfig ||
405406
!isCollectLoading ||
406407
!collect.current ||
407-
hasMounted.current
408+
hasMounted.current ||
409+
(!godaddyPaymentsConfig?.businessId && !session?.businessId)
408410
)
409411
return;
410412

@@ -456,6 +458,7 @@ export function ExpressCheckoutButton() {
456458
godaddyPaymentsConfig,
457459
isCollectLoading,
458460
handleExpressPayClick,
461+
session?.businessId,
459462
]);
460463

461464
// Function to convert shipping address to shippingLines format for price adjustments

packages/react/src/components/checkout/payment/checkout-buttons/paze/godaddy.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export function PazeCheckoutButton() {
100100
if (
101101
!collect.current &&
102102
godaddyPaymentsConfig &&
103+
(godaddyPaymentsConfig?.businessId || session?.businessId) &&
103104
isCollectLoading &&
104105
isPoyntLoaded &&
105106
!hasMounted.current
@@ -132,6 +133,7 @@ export function PazeCheckoutButton() {
132133
if (
133134
!isPoyntLoaded ||
134135
!godaddyPaymentsConfig ||
136+
(!godaddyPaymentsConfig?.businessId && !session?.businessId) ||
135137
!isCollectLoading ||
136138
!collect.current ||
137139
hasMounted.current

packages/react/src/components/checkout/payment/payment-form.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export function PaymentForm(
149149
if (
150150
!collect.current &&
151151
godaddyPaymentsConfig &&
152+
(godaddyPaymentsConfig?.businessId || session?.businessId) &&
152153
isPoyntLoaded &&
153154
countryCode &&
154155
currencyCode &&

packages/react/src/components/checkout/payment/payment-methods/credit-card/godaddy.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ export function GoDaddyCreditCardForm() {
187187
const collect = useRef<TokenizeJs | null>(null);
188188

189189
useLayoutEffect(() => {
190-
if (!isPoyntLoaded || !godaddyPaymentsConfig || collect.current) return;
190+
if (
191+
!isPoyntLoaded ||
192+
!godaddyPaymentsConfig ||
193+
collect.current ||
194+
(!godaddyPaymentsConfig?.businessId && !session?.businessId)
195+
)
196+
return;
191197

192198
collect.current = new (window as any).TokenizeJs(
193199
godaddyPaymentsConfig?.businessId || session?.businessId,

packages/react/src/components/checkout/payment/utils/use-load-poynt-collect.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const listeners = new Set<(loaded: boolean) => void>();
99
// load collect.js globally so it can be used for card component and Apple/G Pay buttons
1010
export function useLoadPoyntCollect() {
1111
const { godaddyPaymentsConfig } = useCheckoutContext();
12+
const { session } = useCheckoutContext();
1213
const collectCDN = useGetPoyntCollectCdn();
1314
const [loaded, setLoaded] = useState(isPoyntLoaded);
1415

@@ -32,7 +33,8 @@ export function useLoadPoyntCollect() {
3233
isPoyntCDNLoaded ||
3334
isPoyntLoaded ||
3435
!godaddyPaymentsConfig ||
35-
!collectCDN
36+
!collectCDN ||
37+
(!session?.businessId && !godaddyPaymentsConfig?.businessId)
3638
) {
3739
return;
3840
}
@@ -48,7 +50,7 @@ export function useLoadPoyntCollect() {
4850
};
4951

5052
document?.body?.appendChild(script);
51-
}, [godaddyPaymentsConfig, collectCDN]);
53+
}, [godaddyPaymentsConfig, collectCDN, session?.businessId]);
5254

5355
return { isPoyntLoaded: loaded };
5456
}

packages/react/src/lib/godaddy/checkout-queries.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ export const GetCheckoutSessionQuery = graphql(`
55
checkoutSession {
66
id
77
token
8+
url
89
sourceApp
910
returnUrl
1011
successUrl
1112
storeId
1213
channelId
14+
businessId
1315
customerId
1416
storeName
1517
environment

0 commit comments

Comments
 (0)