Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CheckoutProtocolTest {
@Test
fun `supported protocol methods exclude internal or unsupported methods`() {
assertThat(CheckoutProtocol.supportedProtocolMethods).doesNotContain(
"ec.buyer.change",
"ec.payment.credential_request",
"ep.cart.ready",
)
Expand Down
1 change: 0 additions & 1 deletion platforms/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ exactly the fields relevant to that moment.
| `checkout:close` | _(none)_ | The popup was dismissed (by the buyer, by `close()`, or by `focus` loss). |
| `checkout:error` | `{error}` | Session-level fatal error — tear down the embedded context. |
| `checkout:lineItemsChange` | `{checkout, lineItems}` | The cart's line items changed (item added/removed/quantity updated). |
| `checkout:buyerChange` | `{checkout, buyer}` | The buyer's information changed (email, address, etc.). |
| `checkout:totalsChange` | `{checkout, totals}` | The cart totals changed (subtotal, tax, shipping, discounts, total). |
| `checkout:messagesChange` | `{checkout, messages}` | Checkout-level warnings/errors/info shown inside the checkout changed. |

Expand Down
1 change: 0 additions & 1 deletion platforms/web/sample/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ const EVENT_TYPES = [
"checkout:close",
"checkout:error",
"checkout:lineItemsChange",
"checkout:buyerChange",
"checkout:totalsChange",
"checkout:messagesChange",
] as const;
Expand Down
62 changes: 16 additions & 46 deletions platforms/web/src/checkout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -821,21 +821,24 @@ describe("<shopify-checkout>", () => {
expect(mockCheckoutWindow.postMessage).not.toHaveBeenCalled();
});

it("ignores unsupported notifications", () => {
const { checkout, mockCheckoutWindow } = openPopupCheckout();
it.each(["customMethod", "ec.buyer.change"])(
"ignores unsupported notification %s",
(method) => {
const { checkout, mockCheckoutWindow } = openPopupCheckout();

simulateRawMessageEvent(
checkout,
{
jsonrpc: "2.0",
method: "customMethod",
params: {},
},
{ source: mockCheckoutWindow },
);
simulateRawMessageEvent(
checkout,
{
jsonrpc: "2.0",
method,
params: {},
},
{ source: mockCheckoutWindow },
);

expect(mockCheckoutWindow.postMessage).not.toHaveBeenCalled();
});
expect(mockCheckoutWindow.postMessage).not.toHaveBeenCalled();
},
);
});

describe("checkout:start", () => {
Expand Down Expand Up @@ -971,23 +974,6 @@ describe("<shopify-checkout>", () => {
});
});

describe("checkout:buyerChange", () => {
it("updates the checkout property and dispatches an ec:buyerChange event", async () => {
const { checkout, mockCheckoutWindow } = openPopupCheckout();
const onBuyerChangeSpy = vi.fn();
const listenForEvent = waitForEvent(checkout, "checkout:buyerChange", onBuyerChangeSpy);

const payload = makeCheckoutPayload();
simulateProtocolMessageEvent(checkout, "ec.buyer.change", payload, {
source: mockCheckoutWindow,
});
await listenForEvent;

expect(checkout.checkout).toBe(payload.checkout);
expect(onBuyerChangeSpy).toHaveBeenCalledOnce();
});
});

describe("checkout:totalsChange", () => {
it("updates the checkout property and dispatches an ec:totalsChange event", async () => {
const { checkout, mockCheckoutWindow } = openPopupCheckout();
Expand Down Expand Up @@ -1092,22 +1078,6 @@ describe("<shopify-checkout>", () => {
expect(event.detail.checkout).toBe(payload.checkout);
});

it("checkout:buyerChange carries {buyer, checkout}", async () => {
const { checkout, mockCheckoutWindow } = openPopupCheckout();
const spy = vi.fn();
const wait = waitForEvent(checkout, "checkout:buyerChange", spy);

const payload = makeCheckoutPayload();
simulateProtocolMessageEvent(checkout, "ec.buyer.change", payload, {
source: mockCheckoutWindow,
});
await wait;

const event = spy.mock.calls[0]![0] as CustomEvent;
expect(event.detail.buyer).toBe(payload.checkout.buyer);
expect(event.detail.checkout).toBe(payload.checkout);
});

it("checkout:totalsChange carries {totals, checkout}", async () => {
const { checkout, mockCheckoutWindow } = openPopupCheckout();
const spy = vi.fn();
Expand Down
34 changes: 0 additions & 34 deletions platforms/web/src/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
CheckoutLineItem,
CheckoutMessage,
Total,
Buyer,
OrderConfirmation,
UcpErrorResponse,
} from "./checkout.types";
Expand Down Expand Up @@ -66,7 +65,6 @@ const SHADOW_TEMPLATE = createTemplate(html`
* @event checkout:complete - Dispatched when the checkout was successfully completed
* @event checkout:error - Dispatched on a session-level fatal error
* @event checkout:lineItemsChange - Dispatched when cart line items change
* @event checkout:buyerChange - Dispatched when buyer information changes
* @event checkout:totalsChange - Dispatched when totals change
* @event checkout:messagesChange - Dispatched when checkout messages change
* @event checkout:close - Dispatched when the checkout overlay is closed (synthetic, not part of ECP)
Expand Down Expand Up @@ -580,16 +578,6 @@ export class ShopifyCheckout
);
break;
}
case "ec.buyer.change": {
const checkout = (message.body as CheckoutProtocolMessageMap["ec.buyer.change"]).checkout;
this.dispatchEvent(
new ShopifyCheckoutBuyerChangeEvent({
checkout,
buyer: checkout.buyer,
}),
);
break;
}
case "ec.totals.change": {
const checkout = (message.body as CheckoutProtocolMessageMap["ec.totals.change"]).checkout;
this.dispatchEvent(
Expand Down Expand Up @@ -761,12 +749,6 @@ export class ShopifyCheckout
options?: boolean | AddEventListenerOptions,
): void;

override addEventListener(
type: "checkout:buyerChange",
listener: TypedEventListener<ShopifyCheckoutBuyerChangeEvent> | null,
options?: boolean | AddEventListenerOptions,
): void;

override addEventListener(
type: "checkout:totalsChange",
listener: TypedEventListener<ShopifyCheckoutTotalsChangeEvent> | null,
Expand Down Expand Up @@ -818,13 +800,6 @@ export interface ShopifyCheckoutLineItemsChangeEventDetail {
checkout: Checkout;
}

export interface ShopifyCheckoutBuyerChangeEventDetail {
/** Updated buyer (may be undefined when buyer information is cleared). */
buyer: Buyer | undefined;
/** Full checkout snapshot for handlers that want broader context. */
checkout: Checkout;
}

export interface ShopifyCheckoutTotalsChangeEventDetail {
/** Updated totals. */
totals: readonly Total[];
Expand Down Expand Up @@ -884,14 +859,6 @@ export class ShopifyCheckoutLineItemsChangeEvent extends CustomEvent<ShopifyChec
}
}

export class ShopifyCheckoutBuyerChangeEvent extends CustomEvent<ShopifyCheckoutBuyerChangeEventDetail> {
declare type: "checkout:buyerChange";

constructor(detail: ShopifyCheckoutBuyerChangeEventDetail) {
super("checkout:buyerChange", { detail, bubbles: true });
}
}

export class ShopifyCheckoutTotalsChangeEvent extends CustomEvent<ShopifyCheckoutTotalsChangeEventDetail> {
declare type: "checkout:totalsChange";

Expand All @@ -918,7 +885,6 @@ const CHECKOUT_PROTOCOL_MESSAGES: (keyof CheckoutProtocolMessageMap)[] = [
"ec.complete",
"ec.error",
"ec.line_items.change",
"ec.buyer.change",
"ec.totals.change",
"ec.messages.change",
"ec.window.open_request",
Expand Down
17 changes: 0 additions & 17 deletions platforms/web/src/checkout.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// checkout protocol. Embed payload shapes live in `./ucp-embed-types.ts`.

import type {
Buyer,
Checkout,
CheckoutLineItem,
CheckoutMessage,
Expand Down Expand Up @@ -118,11 +117,6 @@ export interface CheckoutEvents {
*/
"checkout:lineItemsChange": CheckoutLineItemsChangeEvent;

/**
* Dispatched when the buyer information changes.
*/
"checkout:buyerChange": CheckoutBuyerChangeEvent;

/**
* Dispatched when the totals change.
*/
Expand Down Expand Up @@ -175,16 +169,6 @@ export interface CheckoutLineItemsChangeEvent {
};
}

export interface CheckoutBuyerChangeEvent {
type: "checkout:buyerChange";
detail: {
/** Updated buyer (may be undefined when buyer information is cleared). */
buyer: Buyer | undefined;
/** Full checkout snapshot for handlers that want broader context. */
checkout: Checkout;
};
}

export interface CheckoutTotalsChangeEvent {
type: "checkout:totalsChange";
detail: {
Expand Down Expand Up @@ -252,7 +236,6 @@ export interface CheckoutProtocolMessageMap {
"ec.complete": CheckoutPayload;
"ec.error": EcErrorParams;
"ec.line_items.change": CheckoutPayload;
"ec.buyer.change": CheckoutPayload;
"ec.totals.change": CheckoutPayload;
"ec.messages.change": CheckoutPayload;
"ec.window.open_request": { url: string };
Expand Down
1 change: 0 additions & 1 deletion platforms/web/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe("@shopify/checkout-kit public entry", () => {
pkg.ShopifyCheckoutCloseEvent,
pkg.ShopifyCheckoutErrorEvent,
pkg.ShopifyCheckoutLineItemsChangeEvent,
pkg.ShopifyCheckoutBuyerChangeEvent,
pkg.ShopifyCheckoutTotalsChangeEvent,
pkg.ShopifyCheckoutMessagesChangeEvent,
];
Expand Down
2 changes: 0 additions & 2 deletions platforms/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export {
ShopifyCheckoutCloseEvent,
ShopifyCheckoutErrorEvent,
ShopifyCheckoutLineItemsChangeEvent,
ShopifyCheckoutBuyerChangeEvent,
ShopifyCheckoutTotalsChangeEvent,
ShopifyCheckoutMessagesChangeEvent,
} from "./checkout";
Expand All @@ -22,7 +21,6 @@ export type {
ShopifyCheckoutCompleteEventDetail,
ShopifyCheckoutErrorEventDetail,
ShopifyCheckoutLineItemsChangeEventDetail,
ShopifyCheckoutBuyerChangeEventDetail,
ShopifyCheckoutTotalsChangeEventDetail,
ShopifyCheckoutMessagesChangeEventDetail,
} from "./checkout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct DescriptorTests {
}

@Test func excludesInternalOrUnsupportedMethods() {
#expect(!CheckoutProtocol.supportedProtocolMethods.contains("ec.buyer.change"))
#expect(!CheckoutProtocol.supportedProtocolMethods.contains("ec.payment.credential_request"))
#expect(!CheckoutProtocol.supportedProtocolMethods.contains("ep.cart.ready"))
}
Expand Down
Loading