Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stale-spoons-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@godaddy/react": patch
---

Add gopay appId override experimental rule
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ describe('useUpdateOrder - Tax calculation address logic', () => {

describe('Edge cases', () => {
it('should handle pickupLocationId being undefined for pickup', () => {
const result = getTaxDestinationAddress('PICKUP', undefined, mockLocations);
const result = getTaxDestinationAddress(
'PICKUP',
undefined,
mockLocations
);

expect(result).toBeUndefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
TokenizeJs,
WalletError,
} from '@/components/checkout/payment/types';
import { getApplicationId } from '@/components/checkout/payment/utils/get-application-id';
import { useBuildPaymentRequest } from '@/components/checkout/payment/utils/use-build-payment-request';
import {
PaymentProvider,
Expand Down Expand Up @@ -90,7 +91,10 @@ export function GoDaddyApplePayCheckoutButton() {
businessId: godaddyPaymentsConfig?.businessId || session?.businessId,
storeId: session?.storeId,
channelId: session?.channelId,
applicationId: godaddyPaymentsConfig?.appId,
applicationId: getApplicationId(
session,
godaddyPaymentsConfig?.appId
),
},
{
country: countryCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
WalletError,
WalletRequestUpdate,
} from '@/components/checkout/payment/types';
import { getApplicationId } from '@/components/checkout/payment/utils/get-application-id';
import {
type PoyntExpressRequest,
useBuildPaymentRequest,
Expand Down Expand Up @@ -438,7 +439,10 @@ export function ExpressCheckoutButton() {
businessId: godaddyPaymentsConfig?.businessId || session?.businessId,
storeId: session?.storeId,
channelId: session?.channelId,
applicationId: godaddyPaymentsConfig?.appId,
applicationId: getApplicationId(
session,
godaddyPaymentsConfig?.appId
),
},
{
country: countryCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
TokenizeJs,
WalletError,
} from '@/components/checkout/payment/types';
import { getApplicationId } from '@/components/checkout/payment/utils/get-application-id';
import { useBuildPaymentRequest } from '@/components/checkout/payment/utils/use-build-payment-request';
import {
PaymentProvider,
Expand Down Expand Up @@ -90,7 +91,10 @@ export function GoDaddyGooglePayCheckoutButton() {
businessId: godaddyPaymentsConfig?.businessId || session?.businessId,
storeId: session?.storeId,
channelId: session?.channelId,
applicationId: godaddyPaymentsConfig?.appId,
applicationId: getApplicationId(
session,
godaddyPaymentsConfig?.appId
),
},
{
country: countryCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import React, { useCallback, useLayoutEffect, useState } from 'react';
import { useFormContext } from 'react-hook-form';
import { useCheckoutContext } from '@/components/checkout/checkout';
import { useDraftOrderTotals } from '@/components/checkout/order/use-draft-order';
import { useAuthorizeCheckout } from '@/components/checkout/payment/utils/use-authorize-checkout';
import {
PaymentProvider,
useConfirmCheckout,
} from '@/components/checkout/payment/utils/use-confirm-checkout';
import { useIsPaymentDisabled } from '@/components/checkout/payment/utils/use-is-payment-disabled';
import { useLoadMercadoPago } from '@/components/checkout/payment/utils/use-load-mercadopago';
import { useAuthorizeCheckout } from '@/components/checkout/payment/utils/use-authorize-checkout';
import { formatCurrency } from '@/components/checkout/utils/format-currency';
import { Button } from '@/components/ui/button';
import { useGoDaddyContext } from '@/godaddy-provider';
Expand Down Expand Up @@ -53,7 +53,7 @@ export function MercadoPagoCheckoutButton() {
paymentProvider: PaymentProvider.MERCADOPAGO,
});
return response?.transactionRefNum;
}
};

const handleSubmit = useCallback(
async ({ formData }: any) => {
Expand Down Expand Up @@ -124,7 +124,7 @@ export function MercadoPagoCheckoutButton() {

const { bricksBuilderInstance: bricksBuilder } =
getMercadoPagoInstance(mercadoPagoConfig.publicKey);

const mercadoPagoPreferenceId = await getPreferenceId();

brickController = await bricksBuilder.create('payment', elementId, {
Expand Down Expand Up @@ -168,7 +168,6 @@ export function MercadoPagoCheckoutButton() {
},
},
});

} catch (_err) {
setError(t.errors.failedToInitializePayment);
setIsBrickReady(false);
Expand Down Expand Up @@ -230,7 +229,9 @@ export function MercadoPagoCheckoutButton() {
size='lg'
type='button'
onClick={handleClick}
disabled={isPaymentDisabled || authorizeCheckout.isPending || !isBrickReady}
disabled={
isPaymentDisabled || authorizeCheckout.isPending || !isBrickReady
}
>
{authorizeCheckout.isPending && !error ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
TokenizeJs,
WalletError,
} from '@/components/checkout/payment/types';
import { getApplicationId } from '@/components/checkout/payment/utils/get-application-id';
import { useBuildPaymentRequest } from '@/components/checkout/payment/utils/use-build-payment-request';
import {
PaymentProvider,
Expand Down Expand Up @@ -89,7 +90,10 @@ export function PazeCheckoutButton() {
businessId: godaddyPaymentsConfig?.businessId || session?.businessId,
storeId: session?.storeId,
channelId: session?.channelId,
applicationId: godaddyPaymentsConfig?.appId,
applicationId: getApplicationId(
session,
godaddyPaymentsConfig?.appId
),
},
{
country: countryCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
PaymentMethodRenderer,
} from '@/components/checkout/payment/payment-method-renderer';
import type { TokenizeJs } from '@/components/checkout/payment/types';
import { getApplicationId } from '@/components/checkout/payment/utils/get-application-id';
import { PaymentAddressToggle } from '@/components/checkout/payment/utils/payment-address-toggle';
import { useGetSelectedPaymentMethod } from '@/components/checkout/payment/utils/use-get-selected-payment-method';
import { useLoadPoyntCollect } from '@/components/checkout/payment/utils/use-load-poynt-collect';
Expand Down Expand Up @@ -184,7 +185,10 @@ export function PaymentForm(
businessId: godaddyPaymentsConfig?.businessId || session?.businessId,
storeId: session?.storeId,
channelId: session?.channelId,
applicationId: godaddyPaymentsConfig?.appId,
applicationId: getApplicationId(
session,
godaddyPaymentsConfig?.appId
),
},
{
country: countryCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
TokenizeJs,
TokenizeJsEvent,
} from '@/components/checkout/payment/types';
import { getApplicationId } from '@/components/checkout/payment/utils/get-application-id';
import { usePoyntCollect } from '@/components/checkout/payment/utils/poynt-provider';
import {
PaymentProvider,
Expand Down Expand Up @@ -199,7 +200,7 @@ export function GoDaddyCreditCardForm() {
businessId: godaddyPaymentsConfig?.businessId || session?.businessId,
storeId: session?.storeId,
channelId: session?.channelId,
applicationId: godaddyPaymentsConfig?.appId,
applicationId: getApplicationId(session, godaddyPaymentsConfig?.appId),
});

collect?.current?.on('ready', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { CheckoutSession } from '@/types';

/**
* Resolves the applicationId for TokenizeJs initialization.
* When the session has `experimental_rules.gopay_override` enabled,
* the goPayAppId from that rule takes precedence over the default appId.
*/
export function getApplicationId(
session: CheckoutSession | null | undefined,
defaultAppId: string | undefined
): string | undefined {
const goPayOverride = session?.experimental_rules?.gopay_override;
if (goPayOverride?.enabled && goPayOverride?.goPayAppId) {
return goPayOverride.goPayAppId;
}
return defaultAppId;
}
Loading
Loading