Skip to content
Draft
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 @@ -12,6 +12,27 @@ class CheckoutProtocolTest {

// region NotificationDescriptor

@Test
fun `public notification descriptors match supported embedded checkout methods`() {
assertThat(
listOf(
CheckoutProtocol.start.method,
CheckoutProtocol.complete.method,
CheckoutProtocol.error.method,
CheckoutProtocol.lineItemsChange.method,
CheckoutProtocol.totalsChange.method,
CheckoutProtocol.messagesChange.method,
)
).containsExactly(
"ec.start",
"ec.complete",
"ec.error",
"ec.line_items.change",
"ec.totals.change",
"ec.messages.change",
)
}

@Test
fun `start descriptor has correct method`() {
assertThat(CheckoutProtocol.start.method).isEqualTo("ec.start")
Expand All @@ -32,6 +53,11 @@ class CheckoutProtocolTest {
assertThat(CheckoutProtocol.lineItemsChange.method).isEqualTo("ec.line_items.change")
}

@Test
fun `totalsChange descriptor has correct method`() {
assertThat(CheckoutProtocol.totalsChange.method).isEqualTo("ec.totals.change")
}

@Test
fun `buyerChange descriptor has correct method`() {
assertThat(CheckoutProtocol.buyerChange.method).isEqualTo("ec.buyer.change")
Expand All @@ -44,6 +70,15 @@ class CheckoutProtocolTest {

// endregion

// region DelegationDescriptor

@Test
fun `windowOpen descriptor has correct method`() {
assertThat(CheckoutProtocol.windowOpen.method).isEqualTo("ec.window.open_request")
}

// endregion

// region process — notification dispatch

@Test
Expand Down Expand Up @@ -175,8 +210,8 @@ class CheckoutProtocolTest {
// region specVersion

@Test
fun `specVersion is non-empty`() {
assertThat(CheckoutProtocol.specVersion).isNotEmpty()
fun `specVersion matches embedded checkout snapshot`() {
assertThat(CheckoutProtocol.specVersion).isEqualTo("2026-04-08")
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import type {
Checkout,
EmbeddedCheckoutPublicNotificationMethod,
ErrorResponse,
} from '@shopify/checkout-kit-protocol';

describe('protocol type parity', () => {
it('can type check React Native against generated protocol models', () => {
const method: EmbeddedCheckoutPublicNotificationMethod = 'ec.start';
const checkout: Checkout = {
id: 'chk_1',
currency: 'USD',
status: 'incomplete',
lineItems: [],
links: [],
totals: [],
ucp: {
paymentHandlers: {},
version: '2026-04-08',
},
};
const error: ErrorResponse = {
ucp: {
version: '2026-04-08',
status: 'error',
},
messages: [
{
type: 'error',
code: 'unknown_error',
content: 'Something went wrong.',
severity: 'unrecoverable',
},
],
};

expect(method).toBe('ec.start');
expect(checkout.id).toBe('chk_1');
expect(error.ucp.status).toBe('error');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ struct DescriptorTests {

@Suite("Notifications")
struct Notifications {
@Test func publicNotificationMethods() {
#expect([
CheckoutProtocol.start.method,
CheckoutProtocol.complete.method,
CheckoutProtocol.error.method,
CheckoutProtocol.lineItemsChange.method,
CheckoutProtocol.totalsChange.method,
CheckoutProtocol.messagesChange.method,
] == [
"ec.start",
"ec.complete",
"ec.error",
"ec.line_items.change",
"ec.totals.change",
"ec.messages.change",
])
}

@Test func startMethod() {
#expect(CheckoutProtocol.start.method == "ec.start")
}
Expand Down Expand Up @@ -40,4 +58,16 @@ struct DescriptorTests {
#expect(CheckoutProtocol.error.method == "ec.error")
}
}

@Suite("Delegations")
struct Delegations {
@Test func defaultDelegations() {
#expect(CheckoutProtocol.defaultDelegations == ["window.open"])
}

@Test func windowOpenDescriptor() {
#expect(CheckoutProtocol.windowOpen.method == "ec.window.open_request")
#expect(CheckoutProtocol.windowOpen.delegation == "window.open")
}
}
}
77 changes: 77 additions & 0 deletions protocol/languages/typescript/src/embedded-checkout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import type {Checkout, ErrorResponse} from './generated/Models';

export const CHECKOUT_PROTOCOL_VERSION = '2026-04-08' as const;

export const EMBEDDED_CHECKOUT_PUBLIC_NOTIFICATION_METHODS = [
'ec.start',
'ec.complete',
'ec.error',
'ec.line_items.change',
'ec.totals.change',
'ec.messages.change',
] as const;

export const EMBEDDED_CHECKOUT_INTERNAL_NOTIFICATION_METHODS = [
'ec.buyer.change',
] as const;

export const EMBEDDED_CHECKOUT_DELEGATIONS = ['window.open'] as const;

export const EMBEDDED_CHECKOUT_DELEGATION_METHODS = [
'ec.window.open_request',
] as const;

export type EmbeddedCheckoutPublicNotificationMethod =
(typeof EMBEDDED_CHECKOUT_PUBLIC_NOTIFICATION_METHODS)[number];

export type EmbeddedCheckoutInternalNotificationMethod =
(typeof EMBEDDED_CHECKOUT_INTERNAL_NOTIFICATION_METHODS)[number];

export type EmbeddedCheckoutNotificationMethod =
| EmbeddedCheckoutPublicNotificationMethod
| EmbeddedCheckoutInternalNotificationMethod;

export type EmbeddedCheckoutDelegation =
(typeof EMBEDDED_CHECKOUT_DELEGATIONS)[number];

export type EmbeddedCheckoutDelegationMethod =
(typeof EMBEDDED_CHECKOUT_DELEGATION_METHODS)[number];

export interface EmbeddedCheckoutReadyParams {
delegate?: string[];
}

export interface EmbeddedCheckoutCheckoutParams {
checkout: Checkout;
}

export interface EmbeddedCheckoutErrorParams {
error: ErrorResponse;
}

export interface EmbeddedCheckoutWindowOpenParams {
url: string;
}
24 changes: 24 additions & 0 deletions protocol/languages/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

export * from './embedded-checkout';
export type * from './generated/Models';
Loading