diff --git a/.changeset/whole-horses-stare.md b/.changeset/whole-horses-stare.md new file mode 100644 index 00000000..7b41d7bc --- /dev/null +++ b/.changeset/whole-horses-stare.md @@ -0,0 +1,8 @@ +--- +"@godaddy/react": patch +"@godaddy/localizations": patch +--- + +- Update collect SDK CDN urls +- Add localization keys for cart components +- Optional businessId for GDP config (will pull from store data if not provided) diff --git a/packages/react/src/components/checkout/checkout.tsx b/packages/react/src/components/checkout/checkout.tsx index 8fbd1937..bbe460d2 100644 --- a/packages/react/src/components/checkout/checkout.tsx +++ b/packages/react/src/components/checkout/checkout.tsx @@ -65,7 +65,7 @@ export type StripeConfig = { }; export type GodaddyPaymentsConfig = { - businessId: string; + businessId?: string; appId: string; }; diff --git a/packages/react/src/components/checkout/payment/checkout-buttons/express/godaddy.tsx b/packages/react/src/components/checkout/payment/checkout-buttons/express/godaddy.tsx index ea5c8090..d15a0de6 100644 --- a/packages/react/src/components/checkout/payment/checkout-buttons/express/godaddy.tsx +++ b/packages/react/src/components/checkout/payment/checkout-buttons/express/godaddy.tsx @@ -367,7 +367,7 @@ export function ExpressCheckoutButton() { // couponConfig, // }); collect.current = new (window as any).TokenizeJs( - godaddyPaymentsConfig?.businessId, + godaddyPaymentsConfig?.businessId || session?.businessId, godaddyPaymentsConfig?.appId, { country: countryCode, diff --git a/packages/react/src/components/checkout/payment/checkout-buttons/paze/godaddy.tsx b/packages/react/src/components/checkout/payment/checkout-buttons/paze/godaddy.tsx index 5e2f06ff..79e3a865 100644 --- a/packages/react/src/components/checkout/payment/checkout-buttons/paze/godaddy.tsx +++ b/packages/react/src/components/checkout/payment/checkout-buttons/paze/godaddy.tsx @@ -106,7 +106,7 @@ export function PazeCheckoutButton() { ) { // console.log("[poynt collect] Initializing TokenizeJs instance"); collect.current = new (window as any).TokenizeJs( - godaddyPaymentsConfig?.businessId, + godaddyPaymentsConfig?.businessId || session?.businessId, godaddyPaymentsConfig?.appId, { country: countryCode, diff --git a/packages/react/src/components/checkout/payment/payment-form.tsx b/packages/react/src/components/checkout/payment/payment-form.tsx index c1d7d0e8..6f0408ed 100644 --- a/packages/react/src/components/checkout/payment/payment-form.tsx +++ b/packages/react/src/components/checkout/payment/payment-form.tsx @@ -155,7 +155,7 @@ export function PaymentForm( session?.paymentMethods?.paze?.processor === PaymentProvider.GODADDY ) { collect.current = new (window as any).TokenizeJs( - godaddyPaymentsConfig?.businessId, + godaddyPaymentsConfig?.businessId || session?.businessId, godaddyPaymentsConfig?.appId, { country: countryCode, @@ -178,6 +178,7 @@ export function PaymentForm( currencyCode, session?.paymentMethods?.paze?.processor, session?.storeName, + session?.businessId, isPoyntLoaded, ]); diff --git a/packages/react/src/components/checkout/payment/payment-methods/credit-card/godaddy.tsx b/packages/react/src/components/checkout/payment/payment-methods/credit-card/godaddy.tsx index 30e7022c..5b824889 100644 --- a/packages/react/src/components/checkout/payment/payment-methods/credit-card/godaddy.tsx +++ b/packages/react/src/components/checkout/payment/payment-methods/credit-card/godaddy.tsx @@ -16,6 +16,7 @@ import { PaymentMethodType } from '@/types'; export function GoDaddyCreditCardForm() { const { t } = useGoDaddyContext(); + const { session } = useCheckoutContext(); const { setCollect, setIsLoadingNonce } = usePoyntCollect(); const { isPoyntLoaded } = useLoadPoyntCollect(); const { godaddyPaymentsConfig, setCheckoutErrors } = useCheckoutContext(); @@ -189,7 +190,7 @@ export function GoDaddyCreditCardForm() { if (!isPoyntLoaded || !godaddyPaymentsConfig || collect.current) return; collect.current = new (window as any).TokenizeJs( - godaddyPaymentsConfig?.businessId, + godaddyPaymentsConfig?.businessId || session?.businessId, godaddyPaymentsConfig?.appId ); @@ -240,6 +241,7 @@ export function GoDaddyCreditCardForm() { setCheckoutErrors, t, setIsLoadingNonce, + session?.businessId, ]); return ( diff --git a/packages/react/src/components/checkout/payment/utils/conditional-providers.tsx b/packages/react/src/components/checkout/payment/utils/conditional-providers.tsx index 6ed59f55..8194087b 100644 --- a/packages/react/src/components/checkout/payment/utils/conditional-providers.tsx +++ b/packages/react/src/components/checkout/payment/utils/conditional-providers.tsx @@ -26,10 +26,7 @@ export function ConditionalPaymentProviders({ } // Only wrap with PoyntCollectProvider (GoDaddy Payments) if configured - if ( - godaddyPaymentsConfig?.businessId?.trim() && - godaddyPaymentsConfig?.appId?.trim() - ) { + if (godaddyPaymentsConfig?.appId?.trim()) { wrappedChildren = ( {wrappedChildren} ); diff --git a/packages/react/src/components/checkout/payment/utils/use-load-square.ts b/packages/react/src/components/checkout/payment/utils/use-load-square.ts index 746796f5..fdd530b9 100644 --- a/packages/react/src/components/checkout/payment/utils/use-load-square.ts +++ b/packages/react/src/components/checkout/payment/utils/use-load-square.ts @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; import { useCheckoutContext } from '@/components/checkout/checkout'; -import { useGetEnvFromContext } from '@/components/checkout/utils/use-get-env-from-context.ts'; +import { useGoDaddyContext } from '@/godaddy-provider.tsx'; let isSquareLoaded = false; let isSquareCDNLoaded = false; @@ -8,11 +8,11 @@ const listeners = new Set<(loaded: boolean) => void>(); export function useLoadSquare() { const { squareConfig } = useCheckoutContext(); + const { apiHost } = useGoDaddyContext(); const [loaded, setLoaded] = useState(isSquareLoaded); - const environment = useGetEnvFromContext(); const squareCDN = - environment === 'prod' + apiHost && !apiHost.includes('test') && !apiHost.includes('dev') ? 'https://web.squarecdn.com/v1/square.js' : 'https://sandbox.web.squarecdn.com/v1/square.js'; diff --git a/packages/react/src/components/checkout/payment/utils/use-poynt-collect-cdn.ts b/packages/react/src/components/checkout/payment/utils/use-poynt-collect-cdn.ts index 9c0781a7..3f186a31 100644 --- a/packages/react/src/components/checkout/payment/utils/use-poynt-collect-cdn.ts +++ b/packages/react/src/components/checkout/payment/utils/use-poynt-collect-cdn.ts @@ -1,19 +1,11 @@ import { useMemo } from 'react'; -import { useGetEnvFromContext } from '@/components/checkout/utils/use-get-env-from-context.ts'; +import { useGoDaddyContext } from '@/godaddy-provider.tsx'; export const useGetPoyntCollectCdn = () => { - const environment = useGetEnvFromContext(); + const { apiHost } = useGoDaddyContext(); + const HOST = apiHost?.replace('api.', 'collect.commerce.') || ''; return useMemo(() => { - switch (environment) { - case 'prod': - return 'https://cdn.poynt.net/collect.js'; - case 'test': - return 'https://cdn.poynt.net/test/collect-test.js'; - case 'dev': - return 'https://cdn.poynt.net/ci/collect-ci.js'; - default: - return 'https://cdn.poynt.net/collect.js'; - } - }, [environment]); + return `https://${HOST}/sdk.js`; + }, [apiHost]); }; diff --git a/packages/react/src/components/checkout/utils/use-get-env-from-context.ts b/packages/react/src/components/checkout/utils/use-get-env-from-context.ts deleted file mode 100644 index 02ad3a5c..00000000 --- a/packages/react/src/components/checkout/utils/use-get-env-from-context.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { useGoDaddyContext } from '@/godaddy-provider.tsx'; - -export type Environment = 'prod' | 'test' | 'dev'; - -export const useGetEnvFromContext = (): Environment => { - const { apiHost } = useGoDaddyContext(); - - if (apiHost?.includes('.test-')) { - return 'test'; - } - if (apiHost?.includes('.dev-')) { - return 'dev'; - } - return 'prod'; -}; diff --git a/packages/react/src/lib/godaddy/checkout-env.ts b/packages/react/src/lib/godaddy/checkout-env.ts index 68ce5ae7..75f0599b 100644 --- a/packages/react/src/lib/godaddy/checkout-env.ts +++ b/packages/react/src/lib/godaddy/checkout-env.ts @@ -1015,730 +1015,6 @@ const introspection = { ], interfaces: [], }, - { - kind: 'OBJECT', - name: 'Catalog', - fields: [ - { - name: 'sku', - type: { - kind: 'OBJECT', - name: 'CatalogSku', - }, - args: [ - { - name: 'id', - type: { - kind: 'NON_NULL', - ofType: { - kind: 'SCALAR', - name: 'ID', - }, - }, - }, - ], - isDeprecated: false, - }, - { - name: 'skuGroup', - type: { - kind: 'OBJECT', - name: 'CatalogSkuGroup', - }, - args: [ - { - name: 'id', - type: { - kind: 'NON_NULL', - ofType: { - kind: 'SCALAR', - name: 'ID', - }, - }, - }, - ], - isDeprecated: false, - }, - { - name: 'skuGroups', - type: { - kind: 'OBJECT', - name: 'CatalogSkuGroupConnection', - }, - args: [ - { - name: 'after', - type: { - kind: 'SCALAR', - name: 'String', - }, - }, - { - name: 'first', - type: { - kind: 'SCALAR', - name: 'Int', - }, - }, - { - name: 'ids', - type: { - kind: 'LIST', - ofType: { - kind: 'NON_NULL', - ofType: { - kind: 'SCALAR', - name: 'ID', - }, - }, - }, - }, - ], - isDeprecated: false, - }, - { - name: 'skus', - type: { - kind: 'OBJECT', - name: 'CatalogSkuConnection', - }, - args: [ - { - name: 'after', - type: { - kind: 'SCALAR', - name: 'String', - }, - }, - { - name: 'first', - type: { - kind: 'SCALAR', - name: 'Int', - }, - }, - { - name: 'ids', - type: { - kind: 'LIST', - ofType: { - kind: 'NON_NULL', - ofType: { - kind: 'SCALAR', - name: 'ID', - }, - }, - }, - }, - ], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogAttribute', - fields: [ - { - name: 'id', - type: { - kind: 'SCALAR', - name: 'ID', - }, - args: [], - isDeprecated: false, - }, - { - name: 'label', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'name', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'values', - type: { - kind: 'LIST', - ofType: { - kind: 'NON_NULL', - ofType: { - kind: 'OBJECT', - name: 'CatalogAttributeValue', - }, - }, - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogAttributeValue', - fields: [ - { - name: 'id', - type: { - kind: 'SCALAR', - name: 'ID', - }, - args: [], - isDeprecated: false, - }, - { - name: 'label', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'name', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogMedia', - fields: [ - { - name: 'id', - type: { - kind: 'SCALAR', - name: 'ID', - }, - args: [], - isDeprecated: false, - }, - { - name: 'label', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'name', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'type', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'url', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogPrice', - fields: [ - { - name: 'currencyCode', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'value', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogPriceRange', - fields: [ - { - name: 'max', - type: { - kind: 'SCALAR', - name: 'Float', - }, - args: [], - isDeprecated: false, - }, - { - name: 'min', - type: { - kind: 'SCALAR', - name: 'Float', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogSKUMediaObjectsConnection', - fields: [ - { - name: 'edges', - type: { - kind: 'LIST', - ofType: { - kind: 'NON_NULL', - ofType: { - kind: 'OBJECT', - name: 'CatalogSKUMediaObjectsConnectionEdge', - }, - }, - }, - args: [], - isDeprecated: false, - }, - { - name: 'pageInfo', - type: { - kind: 'OBJECT', - name: 'SKUMediaObjectsPageInfo', - }, - args: [], - isDeprecated: false, - }, - { - name: 'totalCount', - type: { - kind: 'SCALAR', - name: 'Int', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogSKUMediaObjectsConnectionEdge', - fields: [ - { - name: 'cursor', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'node', - type: { - kind: 'OBJECT', - name: 'CatalogMedia', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogSku', - fields: [ - { - name: 'attributes', - type: { - kind: 'LIST', - ofType: { - kind: 'NON_NULL', - ofType: { - kind: 'OBJECT', - name: 'CatalogAttribute', - }, - }, - }, - args: [], - isDeprecated: false, - }, - { - name: 'code', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'description', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'htmlDescription', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'id', - type: { - kind: 'SCALAR', - name: 'ID', - }, - args: [], - isDeprecated: false, - }, - { - name: 'label', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'mediaObjects', - type: { - kind: 'OBJECT', - name: 'CatalogSKUMediaObjectsConnection', - }, - args: [], - isDeprecated: false, - }, - { - name: 'name', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'prices', - type: { - kind: 'LIST', - ofType: { - kind: 'NON_NULL', - ofType: { - kind: 'OBJECT', - name: 'CatalogPrice', - }, - }, - }, - args: [], - isDeprecated: false, - }, - { - name: 'status', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogSkuConnection', - fields: [ - { - name: 'edges', - type: { - kind: 'LIST', - ofType: { - kind: 'OBJECT', - name: 'CatalogSkuEdge', - }, - }, - args: [], - isDeprecated: false, - }, - { - name: 'pageInfo', - type: { - kind: 'NON_NULL', - ofType: { - kind: 'OBJECT', - name: 'PageInfo', - }, - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogSkuEdge', - fields: [ - { - name: 'cursor', - type: { - kind: 'NON_NULL', - ofType: { - kind: 'SCALAR', - name: 'String', - }, - }, - args: [], - isDeprecated: false, - }, - { - name: 'node', - type: { - kind: 'OBJECT', - name: 'CatalogSku', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogSkuGroup', - fields: [ - { - name: 'compareAtPriceRange', - type: { - kind: 'OBJECT', - name: 'CatalogPriceRange', - }, - args: [], - isDeprecated: false, - }, - { - name: 'description', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'htmlDescription', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'id', - type: { - kind: 'SCALAR', - name: 'ID', - }, - args: [], - isDeprecated: false, - }, - { - name: 'label', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'mediaObjects', - type: { - kind: 'OBJECT', - name: 'CatalogSKUMediaObjectsConnection', - }, - args: [ - { - name: 'after', - type: { - kind: 'SCALAR', - name: 'String', - }, - }, - { - name: 'before', - type: { - kind: 'SCALAR', - name: 'String', - }, - }, - { - name: 'first', - type: { - kind: 'SCALAR', - name: 'Int', - }, - }, - { - name: 'last', - type: { - kind: 'SCALAR', - name: 'Int', - }, - }, - ], - isDeprecated: false, - }, - { - name: 'name', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'priceRange', - type: { - kind: 'OBJECT', - name: 'CatalogPriceRange', - }, - args: [], - isDeprecated: false, - }, - { - name: 'status', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - { - name: 'type', - type: { - kind: 'SCALAR', - name: 'String', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogSkuGroupConnection', - fields: [ - { - name: 'edges', - type: { - kind: 'LIST', - ofType: { - kind: 'OBJECT', - name: 'CatalogSkuGroupEdge', - }, - }, - args: [], - isDeprecated: false, - }, - { - name: 'pageInfo', - type: { - kind: 'NON_NULL', - ofType: { - kind: 'OBJECT', - name: 'PageInfo', - }, - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, - { - kind: 'OBJECT', - name: 'CatalogSkuGroupEdge', - fields: [ - { - name: 'cursor', - type: { - kind: 'NON_NULL', - ofType: { - kind: 'SCALAR', - name: 'String', - }, - }, - args: [], - isDeprecated: false, - }, - { - name: 'node', - type: { - kind: 'OBJECT', - name: 'CatalogSkuGroup', - }, - args: [], - isDeprecated: false, - }, - ], - interfaces: [], - }, { kind: 'OBJECT', name: 'CheckoutAuthToken', @@ -1833,6 +1109,15 @@ const introspection = { args: [], isDeprecated: false, }, + { + name: 'businessId', + type: { + kind: 'SCALAR', + name: 'String', + }, + args: [], + isDeprecated: false, + }, { name: 'channelId', type: { @@ -1866,6 +1151,15 @@ const introspection = { args: [], isDeprecated: false, }, + { + name: 'defaultChannelId', + type: { + kind: 'SCALAR', + name: 'String', + }, + args: [], + isDeprecated: false, + }, { name: 'defaultOperatingHours', type: { @@ -8853,15 +8147,6 @@ const introspection = { kind: 'OBJECT', name: 'Query', fields: [ - { - name: 'catalog', - type: { - kind: 'OBJECT', - name: 'Catalog', - }, - args: [], - isDeprecated: false, - }, { name: 'checkoutSession', type: { @@ -9030,6 +8315,24 @@ const introspection = { args: [], isDeprecated: false, }, + { + name: 'mediaObjects', + type: { + kind: 'NON_NULL', + ofType: { + kind: 'LIST', + ofType: { + kind: 'NON_NULL', + ofType: { + kind: 'OBJECT', + name: 'SKUMediaObject', + }, + }, + }, + }, + args: [], + isDeprecated: false, + }, { name: 'metafields', type: { @@ -9261,37 +8564,40 @@ const introspection = { }, { kind: 'OBJECT', - name: 'SKUMediaObjectsPageInfo', + name: 'SKUMediaObject', fields: [ { - name: 'endCursor', + name: 'id', type: { - kind: 'SCALAR', - name: 'String', + kind: 'NON_NULL', + ofType: { + kind: 'SCALAR', + name: 'ID', + }, }, args: [], isDeprecated: false, }, { - name: 'hasNextPage', + name: 'label', type: { kind: 'SCALAR', - name: 'Boolean', + name: 'String', }, args: [], isDeprecated: false, }, { - name: 'hasPreviousPage', + name: 'name', type: { kind: 'SCALAR', - name: 'Boolean', + name: 'String', }, args: [], isDeprecated: false, }, { - name: 'startCursor', + name: 'type', type: { kind: 'SCALAR', name: 'String', @@ -9299,6 +8605,18 @@ const introspection = { args: [], isDeprecated: false, }, + { + name: 'url', + type: { + kind: 'NON_NULL', + ofType: { + kind: 'SCALAR', + name: 'String', + }, + }, + args: [], + isDeprecated: false, + }, ], interfaces: [], }, diff --git a/packages/react/src/lib/godaddy/checkout-mutations.ts b/packages/react/src/lib/godaddy/checkout-mutations.ts index d493425c..92577dba 100644 --- a/packages/react/src/lib/godaddy/checkout-mutations.ts +++ b/packages/react/src/lib/godaddy/checkout-mutations.ts @@ -10,6 +10,7 @@ export const CreateCheckoutSessionMutation = graphql(` returnUrl successUrl storeId + businessId channelId customerId storeName