Skip to content

Commit 7eccca5

Browse files
authored
remove buyer change in web (#290)
### What changes are you making? It looks like we intentionally removed this from native - so this is aimed at parity. Totally fine to go the otherway and introduce to native though. --- Removes the `checkout:buyerChange` event (`ec.buyer.change` protocol message) from the web platform. This includes removing the event class (`ShopifyCheckoutBuyerChangeEvent`), its associated detail interface (`ShopifyCheckoutBuyerChangeEventDetail`), the typed `addEventListener` overload, the protocol message handler, and all related type definitions (`CheckoutBuyerChangeEvent`, `CheckoutProtocolMessageMap["ec.buyer.change"]`). The event is also removed from the public exports, the sample app event list, and the README documentation. The test suite is updated to verify that `ec.buyer.change` is now treated as an unsupported/ignored notification alongside other unknown methods. ### How to test 1. Run the existing test suite: `pnpm test` in `platforms/web`. 2. Confirm that the `"ignores unsupported notification"` test now covers both `"customMethod"` and `"ec.buyer.change"`. 3. Confirm that no `checkout:buyerChange` events are dispatched or exported by the package. 4. Verify the sample app no longer lists `checkout:buyerChange` as a subscribable event type. --- ### Before you merge > [!IMPORTANT] > - [ ] I've added tests to support my implementation > - [ ] I have read and agree with the [Contribution Guidelines](./CONTRIBUTING.md) > - [ ] I have read and agree with the [Code of Conduct](./CODE_OF_CONDUCT.md) > - [ ] I've updated the relevant platform README (`platforms/swift/README.md` and/or `platforms/android/README.md`) --- <details> <summary>Releasing a new Swift version?</summary> - [ ] I have bumped the version in `ShopifyCheckoutKit.podspec` - [ ] I have bumped the version in `platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift` - [ ] I have updated `platforms/swift/CHANGELOG.md` - [ ] I have updated the SwiftPM/CocoaPods version snippets in `platforms/swift/README.md` (major version only) </details> <details> <summary>Releasing a new Android version?</summary> - [ ] I have bumped the `versionName` in `platforms/android/lib/build.gradle` - [ ] I have updated `platforms/android/CHANGELOG.md` - [ ] I have updated the Gradle/Maven version snippets in `platforms/android/README.md` </details> > [!TIP] > See the [Contributing documentation](./CONTRIBUTING.md) for the full release process per platform.
1 parent eef347c commit 7eccca5

9 files changed

Lines changed: 26 additions & 110 deletions

File tree

platforms/android/lib/src/test/java/com/shopify/checkoutkit/CheckoutProtocolTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class CheckoutProtocolTest {
6060
@Test
6161
fun `supported protocol methods exclude internal or unsupported methods`() {
6262
assertThat(CheckoutProtocol.supportedProtocolMethods).doesNotContain(
63+
"ec.buyer.change",
6364
"ec.payment.credential_request",
6465
"ep.cart.ready",
6566
)

platforms/web/README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,15 @@ DOM — including a single delegated listener at `document` if you have many
388388
elements on the page. Each event carries a typed `event.detail` payload with
389389
exactly the fields relevant to that moment.
390390

391-
| Event | `event.detail` | When it fires |
392-
| -------------------- | ----------------------- | -------------------------------------------------------------------------- |
393-
| `ec.start` | `{checkout}` | Checkout has loaded and is interactive. |
394-
| `ec.complete` | `{checkout, order}` | The buyer completed the order successfully. |
395-
| `ec.close` | _(none)_ | The popup was dismissed (by the buyer, by `close()`, or by `focus` loss). |
396-
| `ec.error` | `{error}` | Session-level fatal error — tear down the embedded context. |
391+
| Event | `event.detail` | When it fires |
392+
| ---------------------- | ----------------------- | -------------------------------------------------------------------------- |
393+
| `ec.start` | `{checkout}` | Checkout has loaded and is interactive. |
394+
| `ec.complete` | `{checkout, order}` | The buyer completed the order successfully. |
395+
| `ec.close` | _(none)_ | The popup was dismissed (by the buyer, by `close()`, or by `focus` loss). |
396+
| `ec.error` | `{error}` | Session-level fatal error — tear down the embedded context. |
397397
| `ec.line_items.change` | `{checkout, lineItems}` | The cart's line items changed (item added/removed/quantity updated). |
398-
| `ec.buyer.change` | `{checkout, buyer}` | The buyer's information changed (email, address, etc.). |
399-
| `ec.totals.change` | `{checkout, totals}` | The cart totals changed (subtotal, tax, shipping, discounts, total). |
400-
| `ec.messages.change` | `{checkout, messages}` | Checkout-level warnings/errors/info shown inside the checkout changed. |
398+
| `ec.totals.change` | `{checkout, totals}` | The cart totals changed (subtotal, tax, shipping, discounts, total). |
399+
| `ec.messages.change` | `{checkout, messages}` | Checkout-level warnings/errors/info shown inside the checkout changed. |
401400

402401
The `checkout` field on every change event is the full UCP `Checkout`
403402
snapshot, included for handlers that want broader context. Most handlers only

platforms/web/sample/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ const EVENT_TYPES = [
134134
"ec.close",
135135
"ec.error",
136136
"ec.line_items.change",
137-
"ec.buyer.change",
138137
"ec.totals.change",
139138
"ec.messages.change",
140139
] as const;

platforms/web/src/checkout.test.ts

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -821,21 +821,24 @@ describe("<shopify-checkout>", () => {
821821
expect(mockCheckoutWindow.postMessage).not.toHaveBeenCalled();
822822
});
823823

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

827-
simulateRawMessageEvent(
828-
checkout,
829-
{
830-
jsonrpc: "2.0",
831-
method: "customMethod",
832-
params: {},
833-
},
834-
{ source: mockCheckoutWindow },
835-
);
829+
simulateRawMessageEvent(
830+
checkout,
831+
{
832+
jsonrpc: "2.0",
833+
method,
834+
params: {},
835+
},
836+
{ source: mockCheckoutWindow },
837+
);
836838

837-
expect(mockCheckoutWindow.postMessage).not.toHaveBeenCalled();
838-
});
839+
expect(mockCheckoutWindow.postMessage).not.toHaveBeenCalled();
840+
},
841+
);
839842
});
840843

841844
describe("ec.start", () => {
@@ -967,23 +970,6 @@ describe("<shopify-checkout>", () => {
967970
});
968971
});
969972

970-
describe("ec.buyer.change", () => {
971-
it("updates the checkout property and dispatches an ec.buyer.change event", async () => {
972-
const { checkout, mockCheckoutWindow } = openPopupCheckout();
973-
const onBuyerChangeSpy = vi.fn();
974-
const listenForEvent = waitForEvent(checkout, "ec.buyer.change", onBuyerChangeSpy);
975-
976-
const payload = makeCheckoutPayload();
977-
simulateProtocolMessageEvent(checkout, "ec.buyer.change", payload, {
978-
source: mockCheckoutWindow,
979-
});
980-
await listenForEvent;
981-
982-
expect(checkout.checkout).toBe(payload.checkout);
983-
expect(onBuyerChangeSpy).toHaveBeenCalledOnce();
984-
});
985-
});
986-
987973
describe("ec.totals.change", () => {
988974
it("updates the checkout property and dispatches an ec.totals.change event", async () => {
989975
const { checkout, mockCheckoutWindow } = openPopupCheckout();
@@ -1084,22 +1070,6 @@ describe("<shopify-checkout>", () => {
10841070
expect(event.detail.checkout).toBe(payload.checkout);
10851071
});
10861072

1087-
it("ec.buyer.change carries {buyer, checkout}", async () => {
1088-
const { checkout, mockCheckoutWindow } = openPopupCheckout();
1089-
const spy = vi.fn();
1090-
const wait = waitForEvent(checkout, "ec.buyer.change", spy);
1091-
1092-
const payload = makeCheckoutPayload();
1093-
simulateProtocolMessageEvent(checkout, "ec.buyer.change", payload, {
1094-
source: mockCheckoutWindow,
1095-
});
1096-
await wait;
1097-
1098-
const event = spy.mock.calls[0]![0] as CustomEvent;
1099-
expect(event.detail.buyer).toBe(payload.checkout.buyer);
1100-
expect(event.detail.checkout).toBe(payload.checkout);
1101-
});
1102-
11031073
it("ec.totals.change carries {totals, checkout}", async () => {
11041074
const { checkout, mockCheckoutWindow } = openPopupCheckout();
11051075
const spy = vi.fn();

platforms/web/src/checkout.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
CheckoutLineItem,
1212
CheckoutMessage,
1313
Total,
14-
Buyer,
1514
OrderConfirmation,
1615
UcpErrorResponse,
1716
} from "./checkout.types";
@@ -66,7 +65,6 @@ const SHADOW_TEMPLATE = createTemplate(html`
6665
* @event ec.complete - Dispatched when the checkout was successfully completed
6766
* @event ec.error - Dispatched on a session-level fatal error
6867
* @event ec.line_items.change - Dispatched when cart line items change
69-
* @event ec.buyer.change - Dispatched when buyer information changes
7068
* @event ec.totals.change - Dispatched when totals change
7169
* @event ec.messages.change - Dispatched when checkout messages change
7270
* @event ec.close - Dispatched when the checkout overlay is closed (synthetic, not part of ECP)
@@ -580,16 +578,6 @@ export class ShopifyCheckout
580578
);
581579
break;
582580
}
583-
case "ec.buyer.change": {
584-
const checkout = (message.body as CheckoutProtocolMessageMap["ec.buyer.change"]).checkout;
585-
this.dispatchEvent(
586-
new ShopifyCheckoutBuyerChangeEvent({
587-
checkout,
588-
buyer: checkout.buyer,
589-
}),
590-
);
591-
break;
592-
}
593581
case "ec.totals.change": {
594582
const checkout = (message.body as CheckoutProtocolMessageMap["ec.totals.change"]).checkout;
595583
this.dispatchEvent(
@@ -761,12 +749,6 @@ export class ShopifyCheckout
761749
options?: boolean | AddEventListenerOptions,
762750
): void;
763751

764-
override addEventListener(
765-
type: "ec.buyer.change",
766-
listener: TypedEventListener<ShopifyCheckoutBuyerChangeEvent> | null,
767-
options?: boolean | AddEventListenerOptions,
768-
): void;
769-
770752
override addEventListener(
771753
type: "ec.totals.change",
772754
listener: TypedEventListener<ShopifyCheckoutTotalsChangeEvent> | null,
@@ -818,13 +800,6 @@ export interface ShopifyCheckoutLineItemsChangeEventDetail {
818800
checkout: Checkout;
819801
}
820802

821-
export interface ShopifyCheckoutBuyerChangeEventDetail {
822-
/** Updated buyer (may be undefined when buyer information is cleared). */
823-
buyer: Buyer | undefined;
824-
/** Full checkout snapshot for handlers that want broader context. */
825-
checkout: Checkout;
826-
}
827-
828803
export interface ShopifyCheckoutTotalsChangeEventDetail {
829804
/** Updated totals. */
830805
totals: readonly Total[];
@@ -884,14 +859,6 @@ export class ShopifyCheckoutLineItemsChangeEvent extends CustomEvent<ShopifyChec
884859
}
885860
}
886861

887-
export class ShopifyCheckoutBuyerChangeEvent extends CustomEvent<ShopifyCheckoutBuyerChangeEventDetail> {
888-
declare type: "ec.buyer.change";
889-
890-
constructor(detail: ShopifyCheckoutBuyerChangeEventDetail) {
891-
super("ec.buyer.change", { detail, bubbles: true });
892-
}
893-
}
894-
895862
export class ShopifyCheckoutTotalsChangeEvent extends CustomEvent<ShopifyCheckoutTotalsChangeEventDetail> {
896863
declare type: "ec.totals.change";
897864

@@ -918,7 +885,6 @@ const CHECKOUT_PROTOCOL_MESSAGES: (keyof CheckoutProtocolMessageMap)[] = [
918885
"ec.complete",
919886
"ec.error",
920887
"ec.line_items.change",
921-
"ec.buyer.change",
922888
"ec.totals.change",
923889
"ec.messages.change",
924890
"ec.window.open_request",

platforms/web/src/checkout.types.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// checkout protocol. Embed payload shapes live in `./ucp-embed-types.ts`.
33

44
import type {
5-
Buyer,
65
Checkout,
76
CheckoutLineItem,
87
CheckoutMessage,
@@ -118,11 +117,6 @@ export interface CheckoutEvents {
118117
*/
119118
"ec.line_items.change": CheckoutLineItemsChangeEvent;
120119

121-
/**
122-
* Dispatched when the buyer information changes.
123-
*/
124-
"ec.buyer.change": CheckoutBuyerChangeEvent;
125-
126120
/**
127121
* Dispatched when the totals change.
128122
*/
@@ -175,16 +169,6 @@ export interface CheckoutLineItemsChangeEvent {
175169
};
176170
}
177171

178-
export interface CheckoutBuyerChangeEvent {
179-
type: "ec.buyer.change";
180-
detail: {
181-
/** Updated buyer (may be undefined when buyer information is cleared). */
182-
buyer: Buyer | undefined;
183-
/** Full checkout snapshot for handlers that want broader context. */
184-
checkout: Checkout;
185-
};
186-
}
187-
188172
export interface CheckoutTotalsChangeEvent {
189173
type: "ec.totals.change";
190174
detail: {
@@ -252,7 +236,6 @@ export interface CheckoutProtocolMessageMap {
252236
"ec.complete": CheckoutPayload;
253237
"ec.error": EcErrorParams;
254238
"ec.line_items.change": CheckoutPayload;
255-
"ec.buyer.change": CheckoutPayload;
256239
"ec.totals.change": CheckoutPayload;
257240
"ec.messages.change": CheckoutPayload;
258241
"ec.window.open_request": { url: string };

platforms/web/src/index.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ describe("@shopify/checkout-kit public entry", () => {
1515
pkg.ShopifyCheckoutCloseEvent,
1616
pkg.ShopifyCheckoutErrorEvent,
1717
pkg.ShopifyCheckoutLineItemsChangeEvent,
18-
pkg.ShopifyCheckoutBuyerChangeEvent,
1918
pkg.ShopifyCheckoutTotalsChangeEvent,
2019
pkg.ShopifyCheckoutMessagesChangeEvent,
2120
];

platforms/web/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export {
1111
ShopifyCheckoutCloseEvent,
1212
ShopifyCheckoutErrorEvent,
1313
ShopifyCheckoutLineItemsChangeEvent,
14-
ShopifyCheckoutBuyerChangeEvent,
1514
ShopifyCheckoutTotalsChangeEvent,
1615
ShopifyCheckoutMessagesChangeEvent,
1716
} from "./checkout";
@@ -22,7 +21,6 @@ export type {
2221
ShopifyCheckoutCompleteEventDetail,
2322
ShopifyCheckoutErrorEventDetail,
2423
ShopifyCheckoutLineItemsChangeEventDetail,
25-
ShopifyCheckoutBuyerChangeEventDetail,
2624
ShopifyCheckoutTotalsChangeEventDetail,
2725
ShopifyCheckoutMessagesChangeEventDetail,
2826
} from "./checkout";

protocol/languages/swift/Tests/ShopifyCheckoutProtocolTests/DescriptorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct DescriptorTests {
5454
}
5555

5656
@Test func excludesInternalOrUnsupportedMethods() {
57+
#expect(!CheckoutProtocol.supportedProtocolMethods.contains("ec.buyer.change"))
5758
#expect(!CheckoutProtocol.supportedProtocolMethods.contains("ec.payment.credential_request"))
5859
#expect(!CheckoutProtocol.supportedProtocolMethods.contains("ep.cart.ready"))
5960
}

0 commit comments

Comments
 (0)