Skip to content

Commit a45cd66

Browse files
authored
Add checkout kit web component ck_version query param (#120)
### What changes are you making? Appends `ck_version`query parameter to checkout URLs when opening a popup or rendering the overlay link. --- ### 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 02f306f commit a45cd66

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

platforms/web/src/checkout.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { afterEach, describe, expect, it, vi } from "vitest";
22

33
import type { Checkout, CheckoutProtocolMessageMap, UcpErrorResponse } from "./checkout.types";
44
import "./checkout-web-component";
5-
import { DEFAULT_POPUP_WIDTH, DEFAULT_POPUP_HEIGHT, EMBED_PROTOCOL_VERSION } from "./checkout";
5+
import {
6+
DEFAULT_POPUP_WIDTH,
7+
DEFAULT_POPUP_HEIGHT,
8+
EMBED_PROTOCOL_VERSION,
9+
CK_VERSION,
10+
} from "./checkout";
611
import type { ShopifyCheckout } from "./checkout";
712

813
const POPUP_TARGETS = ["popup"] as const;
@@ -826,6 +831,43 @@ describe("<shopify-checkout>", () => {
826831
});
827832
});
828833

834+
describe("ck_version parameter", () => {
835+
it("appends ck_version to the opened URL", () => {
836+
const checkout = renderCheckout({ target: "popup" });
837+
838+
const windowOpenSpy = vi.spyOn(window, "open").mockReturnValue(createMockWindow());
839+
840+
checkout.open();
841+
842+
const url = new URL(expectWindowOpenArgs(windowOpenSpy)[0] as string);
843+
expect(url.searchParams.get("ck_version")).toBe(CK_VERSION);
844+
});
845+
846+
it("uses the documented constant value", () => {
847+
expect(CK_VERSION).toBe("4.0.0");
848+
});
849+
850+
it("includes ck_version on the overlay link", () => {
851+
const checkout = renderCheckout({ src: "https://shop.example.com/checkout" });
852+
const link = checkout.shadowRoot!.querySelector<HTMLAnchorElement>("#overlay-link");
853+
const url = new URL(link!.getAttribute("href") ?? "");
854+
expect(url.searchParams.get("ck_version")).toBe(CK_VERSION);
855+
});
856+
857+
it("preserves caller-provided ck_version rather than appending a duplicate", () => {
858+
const checkout = renderCheckout({
859+
src: "https://shop.example.com/checkout?ck_version=old",
860+
});
861+
862+
const windowOpenSpy = vi.spyOn(window, "open").mockReturnValue(createMockWindow());
863+
864+
checkout.open();
865+
866+
const url = new URL(expectWindowOpenArgs(windowOpenSpy)[0] as string);
867+
expect(url.searchParams.getAll("ck_version")).toEqual([CK_VERSION]);
868+
});
869+
});
870+
829871
describe("debug attribute", () => {
830872
it("logs a console warning for dropped messages when the debug attribute is set", async () => {
831873
const { checkout, mockCheckoutWindow } = openPopupCheckout();

platforms/web/src/checkout.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { STYLES } from "./checkout.styles";
3838
export const DEFAULT_POPUP_WIDTH = 600;
3939
export const DEFAULT_POPUP_HEIGHT = 600;
4040
export const EMBED_PROTOCOL_VERSION = "2026-04-08";
41+
export const CK_VERSION = "4.0.0";
4142
const EMBED_DELEGATIONS: readonly string[] = ["window.open"];
4243

4344
const SHADOW_TEMPLATE = createTemplate(html`
@@ -157,6 +158,7 @@ export class ShopifyCheckout
157158
if (EMBED_DELEGATIONS.length > 0) {
158159
url.searchParams.set("ec_delegate", EMBED_DELEGATIONS.join(","));
159160
}
161+
url.searchParams.set("ck_version", CK_VERSION);
160162
return url;
161163
}
162164

0 commit comments

Comments
 (0)