From 452d728e355ef5ff89af51cc39118b1527ca2c30 Mon Sep 17 00:00:00 2001 From: nlaverde-godaddy Date: Mon, 20 Apr 2026 11:58:41 -0500 Subject: [PATCH 1/3] fix(react): use pickup location address for tax calculation on billing updates --- .../checkout/order/use-update-order.test.ts | 148 ++++++++++++++++++ .../checkout/order/use-update-order.ts | 20 ++- 2 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 packages/react/src/components/checkout/order/use-update-order.test.ts diff --git a/packages/react/src/components/checkout/order/use-update-order.test.ts b/packages/react/src/components/checkout/order/use-update-order.test.ts new file mode 100644 index 00000000..d2932f26 --- /dev/null +++ b/packages/react/src/components/checkout/order/use-update-order.test.ts @@ -0,0 +1,148 @@ +import { describe, expect, it } from 'vitest'; + +/** + * Helper function to get the tax destination address based on delivery method. + * This is the core logic used in useUpdateOrder to determine which address + * to send for tax calculation. + * + * For pickup orders: Always use the pickup location address + * For shipping orders: Let backend use the saved shipping address (undefined) + */ +function getTaxDestinationAddress( + deliveryMethod: string | undefined, + pickupLocationId: string | undefined, + locations: Array<{ id: string; address: Record }> | undefined +): Record | undefined { + const isPickup = deliveryMethod === 'PICKUP'; + + if (isPickup) { + const pickupLocationAddress = locations?.find( + loc => loc.id === pickupLocationId + )?.address; + return pickupLocationAddress; + } + + // For shipping, return undefined to let backend use saved shipping address + return undefined; +} + +describe('useUpdateOrder - Tax calculation address logic', () => { + const mockLocations = [ + { + id: 'location-1', + address: { + addressLine1: '599 Stegall Dr', + adminArea1: 'GA', + adminArea2: 'Jasper', + countryCode: 'US', + postalCode: '30143', + }, + }, + { + id: 'location-2', + address: { + addressLine1: '123 Main St', + adminArea1: 'NY', + adminArea2: 'New York', + countryCode: 'US', + postalCode: '10001', + }, + }, + ]; + + describe('Pickup orders', () => { + it('should return pickup location address for PICKUP delivery method', () => { + const result = getTaxDestinationAddress( + 'PICKUP', + 'location-1', + mockLocations + ); + + expect(result).toEqual({ + addressLine1: '599 Stegall Dr', + adminArea1: 'GA', + adminArea2: 'Jasper', + countryCode: 'US', + postalCode: '30143', + }); + }); + + it('should return correct location when multiple locations exist', () => { + const result = getTaxDestinationAddress( + 'PICKUP', + 'location-2', + mockLocations + ); + + expect(result).toEqual({ + addressLine1: '123 Main St', + adminArea1: 'NY', + adminArea2: 'New York', + countryCode: 'US', + postalCode: '10001', + }); + }); + + it('should return undefined if pickup location not found', () => { + const result = getTaxDestinationAddress( + 'PICKUP', + 'non-existent-location', + mockLocations + ); + + expect(result).toBeUndefined(); + }); + + it('should return undefined if locations array is empty', () => { + const result = getTaxDestinationAddress('PICKUP', 'location-1', []); + + expect(result).toBeUndefined(); + }); + + it('should return undefined if locations is undefined', () => { + const result = getTaxDestinationAddress( + 'PICKUP', + 'location-1', + undefined + ); + + expect(result).toBeUndefined(); + }); + }); + + describe('Shipping orders', () => { + it('should return undefined for SHIP delivery method', () => { + const result = getTaxDestinationAddress( + 'SHIP', + 'location-1', + mockLocations + ); + + expect(result).toBeUndefined(); + }); + + it('should return undefined when delivery method is undefined', () => { + const result = getTaxDestinationAddress( + undefined, + 'location-1', + mockLocations + ); + + expect(result).toBeUndefined(); + }); + }); + + describe('Edge cases', () => { + it('should handle pickupLocationId being undefined for pickup', () => { + const result = getTaxDestinationAddress('PICKUP', undefined, mockLocations); + + expect(result).toBeUndefined(); + }); + + it('should handle empty string pickupLocationId for pickup', () => { + const result = getTaxDestinationAddress('PICKUP', '', mockLocations); + + expect(result).toBeUndefined(); + }); + }); +}); diff --git a/packages/react/src/components/checkout/order/use-update-order.ts b/packages/react/src/components/checkout/order/use-update-order.ts index 3297e72c..36e864f9 100644 --- a/packages/react/src/components/checkout/order/use-update-order.ts +++ b/packages/react/src/components/checkout/order/use-update-order.ts @@ -1,5 +1,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { useFormContext } from 'react-hook-form'; import { useCheckoutContext } from '@/components/checkout/checkout'; +import { DeliveryMethods } from '@/components/checkout/delivery/delivery-method'; import { useUpdateTaxes } from '@/components/checkout/order/use-update-taxes'; import { useGoDaddyContext } from '@/godaddy-provider'; import { updateDraftOrder } from '@/lib/godaddy/godaddy'; @@ -10,6 +12,7 @@ export function useUpdateOrder() { const { apiHost } = useGoDaddyContext(); const updateTaxes = useUpdateTaxes(); const queryClient = useQueryClient(); + const form = useFormContext(); return useMutation({ mutationKey: ['update-draft-order'], @@ -32,7 +35,22 @@ export function useUpdateOrder() { (!input.shipping?.address && input.billing?.address) ) { if (session?.enableTaxCollection) { - updateTaxes.mutate(undefined); + // For pickup orders, always use the pickup location address for tax calculation + const deliveryMethod = form?.getValues?.('deliveryMethod'); + const isPickup = deliveryMethod === DeliveryMethods.PICKUP; + + if (isPickup) { + const pickupLocationId = form?.getValues?.('pickupLocationId'); + const pickupLocationAddress = session?.locations?.find( + loc => loc.id === pickupLocationId + )?.address; + + // Always send pickup location address for pickup orders + updateTaxes.mutate(pickupLocationAddress); + } else { + // For shipping, let backend use the saved shipping address + updateTaxes.mutate(undefined); + } } else { queryClient.invalidateQueries({ queryKey: ['draft-order', session.id], From 5ed839a28259f98403c8eedd8c735635d786c4d3 Mon Sep 17 00:00:00 2001 From: nlaverde-godaddy Date: Mon, 20 Apr 2026 12:22:54 -0500 Subject: [PATCH 2/3] add changeset --- .changeset/seven-signs-ask.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/seven-signs-ask.md diff --git a/.changeset/seven-signs-ask.md b/.changeset/seven-signs-ask.md new file mode 100644 index 00000000..2f259cd7 --- /dev/null +++ b/.changeset/seven-signs-ask.md @@ -0,0 +1,5 @@ +--- +"@godaddy/react": major +--- + +modify use-update-orders.ts to detect pickup orders and always send the pickup location address for tax calculation, ensuring consistent tax rates based on where the customer picks up their order. From 472bd02b173442b78105f7f3fcd295f363b4a2fc Mon Sep 17 00:00:00 2001 From: nlaverde-godaddy Date: Tue, 21 Apr 2026 12:33:32 -0500 Subject: [PATCH 3/3] modify changeset to be patch --- .changeset/seven-signs-ask.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/seven-signs-ask.md b/.changeset/seven-signs-ask.md index 2f259cd7..8f1e2d91 100644 --- a/.changeset/seven-signs-ask.md +++ b/.changeset/seven-signs-ask.md @@ -1,5 +1,5 @@ --- -"@godaddy/react": major +"@godaddy/react": patch --- -modify use-update-orders.ts to detect pickup orders and always send the pickup location address for tax calculation, ensuring consistent tax rates based on where the customer picks up their order. +Fix pickup tax recalculation to always use the pickup location address when billing address fields are updated.