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
7 changes: 7 additions & 0 deletions .changeset/commex-2267-google-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@godaddy/gd-commerce-server': patch
---

Forward server-configured checkout payment methods, including standard Google Pay, for cart, Buy Now, and non-catalog checkout. Keep the standard GoDaddy card default when optional payment settings are absent or malformed, without resetting valid checkout flags.

Warn through the configured logger when invalid payment methods fall back to standard GoDaddy card payments, without logging configuration values.
33 changes: 32 additions & 1 deletion packages/commerce-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ The default configuration reads these **server-only environment variables** on e
- `GODADDY_CURRENCY_CODE`
- Optional `GODADDY_CHECKOUT_CONFIGURATION`: JSON with boolean `enablePromotionCodes`, `enableTaxCollection`, and `enableShipping` fields. All three default to false when this variable is absent or malformed so configuration discovery cannot prevent checkout creation. Optional `shipping` accepts the checkout API's `originAddress` or `fulfillmentLocationId`; omit it to use store configuration.

### Standard Google Pay

Set `paymentMethods` inside the server-only checkout JSON. Keep the existing values for the three capability flags; this example has all three disabled:

```json
{
"enablePromotionCodes": false,
"enableTaxCollection": false,
"enableShipping": false,
"paymentMethods": {
"card": { "processor": "godaddy", "checkoutTypes": ["standard"] },
"googlePay": { "processor": "godaddy", "checkoutTypes": ["standard"] }
}
}
```

The server forwards payment methods for cart, Buy Now, and trusted non-catalog checkout. Checkout API requires `processor` and `checkoutTypes` for each configured payment method; an empty `googlePay` object is invalid. The merchant's processor and the shopper's browser still determine availability. This configuration does not enable Apple Pay.

Without `paymentMethods`, checkout keeps standard GoDaddy card payments. Empty, all-null, or invalid payment maps use that same fallback without clearing valid shipping, tax, or promotion flags. The same payment validation applies to environment configuration and custom `CommerceConfiguration.readCheckout()` implementations. Payment methods accept the Checkout API method names and nullable method values, with at least one non-null method. Each non-null method requires a nonempty `processor` and a nonempty array of `checkoutTypes`; padded strings, unknown names, and unknown method fields are invalid. Cardless configurations are accepted; the returned session must retain at least one configured method with its requested processor. Browser request bodies cannot select payment methods.

An invalid payment map emits a warning with code `invalid_checkout_payment_methods` and fallback `standard_godaddy_card`. The warning contains no configuration values. Missing or valid payment settings do not warn. Router requests use the configured logger's optional `warn` method; error-only or failing warning loggers fall back to `console.warn`. Each checkout attempt that reads an invalid map warns once.

Forwarding a method does not initialize its frontend SDK. This Google Pay integration uses GoDaddy Payments. Other providers, including Stripe, Square, and Mercado Pago, also require their provider-specific SDK configuration in hosted checkout.

Existing apps must install a release containing this change, update their lockfile, rebuild, and redeploy. A configuration update alone does not upgrade an installed package. A rebuild with an unchanged lockfile can keep the old code. The Airo integration also needs an updated configuration bridge that retains `paymentMethods`.

See [Checkout configuration](docs/checkout-configuration.md) for the temporary build-time synchronization flow and its eventual-consistency limitation.

The API origin defaults to `https://api.godaddy.com`. The package does not load files, provision merchants, or assign application attribution. Hosts own these concerns and any readiness checks or retries before invoking Commerce.
Expand Down Expand Up @@ -140,10 +166,15 @@ Upstream errors without a specific mapping stay 502; business errors such as inv
```ts
createCommerceRouter({
configuration,
logger: { error: (message, context) => log.error(context, message) },
logger: {
error: (message, context) => log.error(context, message),
warn: (message, context) => log.warn(context, message),
},
// Use the host's request id when its edge sets one; unsafe or missing ids fall back to a UUID.
getRequestId: (req) => req.get('x-request-id'),
});
```

`createCommerceCatalogRouter` and `createGoDaddyPaymentsRouter` accept the same `{ logger, getRequestId }` as their last argument. The logger defaults to `console.error`. In-process helpers throw the exported `CommerceError` subclasses (`InvalidRequestError`, `NotFoundError`, `CommerceNotConfiguredError`, `UpstreamError`), including when a host configuration throws while being read. Check `error.code` (for example `'not_found'`) rather than `instanceof`, which fails when a host has more than one copy of this package.

In-process checkout callers can pass their logger as `createCheckoutSession(params, configuration, logger)`. Direct configuration readers can use `configuration.readCheckout(logger)` or `parseCommerceCheckoutConfiguration(raw, logger)` to receive the same payment warnings. These arguments are optional and default to console warnings.
4 changes: 3 additions & 1 deletion packages/commerce-server/docs/checkout-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Commerce Admin already exposes this lookup to builders through the `commerce_che
Until Checkout API performs App Registry discovery itself:

1. During every initial build and rebuild/redeploy, the builder calls `commerce_checkout_configuration_get`.
2. The deployment writes the three returned feature flags to the server-only `GODADDY_CHECKOUT_CONFIGURATION` value; it does not copy the full MCP response or generate conditional application code.
2. The deployment writes the three returned feature flags and its server-owned payment-method policy to `GODADDY_CHECKOUT_CONFIGURATION`; it does not copy the full MCP response or generate conditional application code. For standard GoDaddy Payments Google Pay, add `paymentMethods: { card: { processor: 'godaddy', checkoutTypes: ['standard'] }, googlePay: { processor: 'godaddy', checkoutTypes: ['standard'] } }` to the existing JSON.
3. When Checkout is selected, `commerce-server` reads that value and explicitly configures the new checkout session.
4. The enabled providers calculate live rates and adjustments during checkout.

Expand All @@ -49,6 +49,8 @@ For example:

Restoring the server reader alone does not discover merchant settings: the builder/deployment integration must populate this value. Shipping-origin address details do not need to be copied into application code; hosted checkout can use store configuration.

The package forwards configured payment methods for all three session paths. Missing, empty, all-null, or malformed optional payment settings fall back to standard GoDaddy card checkout and do not reset valid feature flags. Environment and custom host payment settings use the same validation. A valid configuration may omit card, provided the returned session retains at least one configured method with the requested processor. Forwarding a provider does not supply its frontend SDK configuration; this integration enables Google Pay through GoDaddy Payments. Upgrade and rebuild existing consumers before relying on this field. Apple Pay and its domain-registration prerequisites are separate work.

The accepted stopgap is eventually consistent: a provider enabled or disabled after deployment is reflected on the next rebuild, not immediately. This is acceptable only while the Checkout API change is pending.

If the MCP lookup fails, the deployment does not receive the expected flags, or the server value is malformed, checkout falls back to all optional capabilities disabled. In particular, it sends `enableShipping: false` rather than preventing checkout creation. Builders should surface the lookup problem during the build, but it must not make the deployed checkout unusable.
Expand Down
12 changes: 10 additions & 2 deletions packages/commerce-server/src/checkout-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ describe('public checkout boundary', () => {
async (route): Promise<void> => {
const response = await post(valid, route);
expect(response.status).toBe(200);
expect(createCheckoutSession).toHaveBeenCalledWith(expect.objectContaining(valid), expect.anything());
expect(createCheckoutSession).toHaveBeenCalledWith(
expect.objectContaining(valid),
expect.anything(),
expect.objectContaining({ error: expect.any(Function) }),
);
},
);

Expand All @@ -82,7 +86,11 @@ describe('public checkout boundary', () => {
successUrl: 'https://shop.example.com/receipt?orderId=cart-1&campaign=spring',
};
expect((await post(body)).status).toBe(200);
expect(createCheckoutSession).toHaveBeenCalledWith(expect.objectContaining(body), expect.anything());
expect(createCheckoutSession).toHaveBeenCalledWith(
expect.objectContaining(body),
expect.anything(),
expect.objectContaining({ error: expect.any(Function) }),
);
});

it.each([false, true])(
Expand Down
113 changes: 111 additions & 2 deletions packages/commerce-server/src/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { parseCommerceCheckoutConfiguration } from './lib/commerce/checkout-config';
import { createRuntimeCommerceConfiguration, readCommerceConfig } from './lib/commerce/config';

function environment(): NodeJS.ProcessEnv {
Expand All @@ -13,9 +14,42 @@ function environment(): NodeJS.ProcessEnv {

afterEach((): void => {
vi.unstubAllEnvs();
vi.restoreAllMocks();
});

describe('Commerce runtime configuration', () => {
it.each(['missing', 'throwing'] as const)(
'keeps the safe fallback and emits a console warning when the host warn method is %s',
(mode): void => {
const consoleWarning = vi.spyOn(console, 'warn').mockImplementation(() => {});
const logger = {
error: vi.fn(),
...(mode === 'throwing'
? {
warn: vi.fn(() => {
throw new Error('private-logger-error');
}),
}
: {}),
};
const checkout = { enablePromotionCodes: true, enableTaxCollection: false, enableShipping: false };
expect(
parseCommerceCheckoutConfiguration(
JSON.stringify({
...checkout,
paymentMethods: { googlePay: { secret: 'private-payment-config' } },
}),
logger,
),
).toEqual(checkout);
expect(consoleWarning).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('falling back'), {
code: 'invalid_checkout_payment_methods',
fallback: 'standard_godaddy_card',
});
expect(logger.error).not.toHaveBeenCalled();
},
);

it('defaults to production and does not select an API origin from environment variables', (): void => {
const config = readCommerceConfig({
environment: { ...environment(), GODADDY_API_BASE_URL: 'https://api.example.com' },
Expand Down Expand Up @@ -76,9 +110,10 @@ describe('Commerce runtime configuration', () => {
});

it('reads checkout flags and API shipping options', (): void => {
const logger = { error: vi.fn(), warn: vi.fn() };
const values = environment();
const configuration = createRuntimeCommerceConfiguration({ environment: values });
expect(configuration.readCheckout()).toEqual({
expect(configuration.readCheckout(logger)).toEqual({
enablePromotionCodes: false,
enableTaxCollection: false,
enableShipping: false,
Expand All @@ -89,12 +124,13 @@ describe('Commerce runtime configuration', () => {
enableShipping: true,
shipping: { fulfillmentLocationId: 'location-1' },
});
expect(configuration.readCheckout()).toEqual({
expect(configuration.readCheckout(logger)).toEqual({
enablePromotionCodes: true,
enableTaxCollection: false,
enableShipping: true,
shipping: { fulfillmentLocationId: 'location-1' },
});
expect(logger.warn).not.toHaveBeenCalled();
});

it.each([
Expand All @@ -113,4 +149,77 @@ describe('Commerce runtime configuration', () => {
enableShipping: false,
});
});

it('retains standard Google Pay settings alongside existing checkout capabilities', (): void => {
const logger = { error: vi.fn(), warn: vi.fn() };
const paymentMethods = {
card: { processor: 'godaddy', checkoutTypes: ['standard'] },
googlePay: { processor: 'godaddy', checkoutTypes: ['standard'] },
};
const checkout = { enablePromotionCodes: true, enableTaxCollection: true, enableShipping: false };
const configuration = createRuntimeCommerceConfiguration({
environment: {
...environment(),
GODADDY_CHECKOUT_CONFIGURATION: JSON.stringify({ ...checkout, paymentMethods }),
},
});
expect(configuration.readCheckout(logger)).toEqual({ ...checkout, paymentMethods });
expect(logger.warn).not.toHaveBeenCalled();
});

it.each([
{ googlePay: { processor: 'godaddy', checkoutTypes: ['standard'] } },
{ card: null, googlePay: { processor: 'godaddy', checkoutTypes: ['standard'] } },
])('retains a valid cardless payment configuration: %j', (paymentMethods): void => {
const checkout = { enablePromotionCodes: false, enableTaxCollection: true, enableShipping: false };
const configuration = createRuntimeCommerceConfiguration({
environment: {
...environment(),
GODADDY_CHECKOUT_CONFIGURATION: JSON.stringify({ ...checkout, paymentMethods }),
},
});
expect(configuration.readCheckout()).toEqual({ ...checkout, paymentMethods });
});

it.each([
null,
[],
{},
{ card: null },
{ card: null, googlePay: null },
{ unsupported: {} },
{ googlepay: { processor: 'godaddy', checkoutTypes: ['standard'] } },
{ googlePay: { processor: 'godaddy', checkoutTypes: ['standard'], secret: 'not-allowed' } },
{ googlePay: {} },
{ googlePay: { processor: 'godaddy' } },
{ googlePay: { checkoutTypes: ['standard'] } },
{ googlePay: 'true' },
{ googlePay: { processor: 123 } },
{ googlePay: { checkoutTypes: 'standard' } },
{ googlePay: { checkoutTypes: [] } },
{ googlePay: { checkoutTypes: [null] } },
{ googlePay: { secret: 'not-allowed' } },
{ googlePay: { processor: ' godaddy ', checkoutTypes: ['standard'] } },
{ googlePay: { processor: 'godaddy', checkoutTypes: [' standard '] } },
{ googlePay: { processor: ' ', checkoutTypes: ['standard'] } },
{ googlePay: { processor: 'godaddy', checkoutTypes: [' '] } },
])(
'falls back from invalid optional payment methods without clearing valid flags: %j',
(paymentMethods): void => {
const logger = { error: vi.fn(), warn: vi.fn() };
const checkout = { enablePromotionCodes: true, enableTaxCollection: true, enableShipping: false };
const configuration = createRuntimeCommerceConfiguration({
environment: {
...environment(),
GODADDY_CHECKOUT_CONFIGURATION: JSON.stringify({ ...checkout, paymentMethods }),
},
});
expect(configuration.readCheckout(logger)).toEqual(checkout);
expect(logger.warn).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('falling back'), {
code: 'invalid_checkout_payment_methods',
fallback: 'standard_godaddy_card',
});
expect(logger.error).not.toHaveBeenCalled();
},
);
});
Loading