Skip to content

Commit 9bef152

Browse files
committed
feat: add productId for single-product selector model
Switch from cart model (buy all products) to selector model (choose one product from available options). The productId field on checkout confirm specifies which product the user selected, and is reflected in the checkout response after confirmation.
1 parent 5562dae commit 9bef152

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/contracts/checkout.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ export const ConfirmCheckoutInputSchema = z.object({
7272
* Customer data provided at confirm time.
7373
*/
7474
customer: CustomerInputSchema.optional(),
75+
/**
76+
* The selected product ID from the checkout's available products.
77+
* In the selector model, multiple products represent options to choose from,
78+
* and the user selects ONE product at confirm time.
79+
*/
80+
productId: z.string().optional(),
81+
/**
82+
* Products array for CUSTOM pricing amounts only.
83+
* Use productId for standard product selection.
84+
*/
7585
products: z
7686
.array(
7787
z.object({

src/schemas/checkout.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,18 @@ const BaseCheckoutSchema = z.object({
5757
*/
5858
customer: CustomerOutputSchema.nullable(),
5959
customerBillingAddress: z.record(z.any()).nullable(),
60+
/**
61+
* Available product options for this checkout.
62+
* In the selector model, these represent choices the user can pick from.
63+
* The user selects ONE product, which is then stored in productId.
64+
*/
6065
products: z.array(CheckoutProductSchema).nullable(),
66+
/**
67+
* The selected product ID (set after confirm).
68+
* In the selector model, this indicates which product the user chose
69+
* from the available products array.
70+
*/
71+
productId: z.string().nullable(),
6172
providedAmount: z.number().nullable(),
6273
totalAmount: z.number().nullable(),
6374
discountAmount: z.number().nullable(),

tests/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe('API Contract Index', () => {
6060
currency: 'USD',
6161
}],
6262
}],
63+
productId: null,
6364
providedAmount: null,
6465
totalAmount: null,
6566
discountAmount: null,
@@ -191,4 +192,4 @@ describe('API Contract Index', () => {
191192
expect(contract.checkout.paymentReceived).toBeDefined();
192193
});
193194
});
194-
});
195+
});

tests/schemas/checkout.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const baseCheckoutData = {
2323
customer: null,
2424
customerBillingAddress: null,
2525
products: null,
26+
productId: null,
2627
providedAmount: null,
2728
totalAmount: null,
2829
discountAmount: null,
@@ -383,4 +384,4 @@ describe('CheckoutSchema', () => {
383384
expect(result.success).toBe(false);
384385
});
385386
});
386-
});
387+
});

0 commit comments

Comments
 (0)