cleaned up custom checkout

This commit is contained in:
John Yeo
2026-03-12 20:52:17 +00:00
parent a28510a00e
commit 71642d4d94
64 changed files with 8679 additions and 194 deletions

View File

@@ -7,63 +7,39 @@ import {
CheckoutStatus,
} from "../../models/checkouts/checkoutTable";
/**
* Org branding for checkout display
*/
export const CheckoutOrgSchema = z.object({
name: z.string(),
logo: z.string().nullable(),
});
/**
* Customer info for checkout display
*/
export const CheckoutCustomerSchema = z.object({
id: z.string(),
name: z.string().nullable(),
email: z.string().nullable(),
});
/**
* Entity info for checkout display (optional)
*/
export const CheckoutEntitySchema = z.object({
id: z.string(),
name: z.string().nullable(),
});
/**
* GET /checkouts/:checkout_id response
*/
export const GetCheckoutResponseSchema = z.object({
export const CheckoutPreviewSchema = z.union([
AttachPreviewResponseSchema,
PreviewUpdateSubscriptionResponseSchema,
]);
export const CheckoutResponseBaseSchema = z.object({
env: z.string(),
action: z.nativeEnum(CheckoutAction),
status: z.nativeEnum(CheckoutStatus),
response: BillingResponseSchema.nullable(),
preview: z.union([
AttachPreviewResponseSchema,
PreviewUpdateSubscriptionResponseSchema,
]),
preview: CheckoutPreviewSchema,
org: CheckoutOrgSchema,
customer: CheckoutCustomerSchema,
entity: CheckoutEntitySchema.nullable(),
});
/**
* POST /checkouts/:checkout_id/confirm response
*/
export const ConfirmCheckoutResponseSchema = BillingResponseSchema.extend({
success: z.boolean(),
checkout_id: z.string(),
product_id: z.string(),
invoice_id: z.string().nullable(),
success_url: z.string().url(),
adjustable_feature_ids: z.array(z.string()),
});
export type CheckoutOrg = z.infer<typeof CheckoutOrgSchema>;
export type CheckoutCustomer = z.infer<typeof CheckoutCustomerSchema>;
export type CheckoutEntity = z.infer<typeof CheckoutEntitySchema>;
export type GetCheckoutResponse = z.infer<typeof GetCheckoutResponseSchema>;
export type ConfirmCheckoutResponse = z.infer<
typeof ConfirmCheckoutResponseSchema
>;

View File

@@ -2,7 +2,7 @@ import { FeatureOptionsSchema } from "@models/cusProductModels/cusProductModels"
import { z } from "zod/v4";
export const ConfirmCheckoutParamsSchema = z.object({
options: z.array(
feature_quantities: z.array(
FeatureOptionsSchema.pick({
feature_id: true,
quantity: true,

View File

@@ -0,0 +1,14 @@
import { z } from "zod/v4";
import { BillingResponseSchema } from "../../api/billing/common/billingResponse";
export const ConfirmCheckoutResponseSchema = BillingResponseSchema.extend({
success: z.boolean(),
checkout_id: z.string(),
product_id: z.string(),
invoice_id: z.string().nullable(),
success_url: z.string().url(),
});
export type ConfirmCheckoutResponse = z.infer<
typeof ConfirmCheckoutResponseSchema
>;

View File

@@ -0,0 +1,8 @@
import { z } from "zod/v4";
import { CheckoutResponseBaseSchema } from "./checkoutResponseCommon";
export const GetCheckoutResponseSchema = z.object({
...CheckoutResponseBaseSchema.shape,
});
export type GetCheckoutResponse = z.infer<typeof GetCheckoutResponseSchema>;

View File

@@ -1,2 +1,5 @@
export * from "./checkoutResponses";
export * from "./checkoutResponseCommon";
export * from "./confirmCheckoutParams";
export * from "./confirmCheckoutResponse";
export * from "./getCheckoutResponse";
export * from "./previewCheckoutResponse";

View File

@@ -0,0 +1,10 @@
import { z } from "zod/v4";
import { CheckoutResponseBaseSchema } from "./checkoutResponseCommon";
export const PreviewCheckoutResponseSchema = z.object({
...CheckoutResponseBaseSchema.shape,
});
export type PreviewCheckoutResponse = z.infer<
typeof PreviewCheckoutResponseSchema
>;

View File

@@ -3,7 +3,8 @@ import { z } from "zod/v4";
import {
ConfirmCheckoutResponseSchema,
GetCheckoutResponseSchema,
} from "../checkout/checkoutResponses";
PreviewCheckoutResponseSchema,
} from "../checkout";
import { ConfirmCheckoutParamsSchema } from "../checkout/confirmCheckoutParams";
export const getCheckoutContract = oc
@@ -26,7 +27,7 @@ export const previewCheckoutContract = oc
.object({ checkout_id: z.string() })
.extend(ConfirmCheckoutParamsSchema.shape),
)
.output(GetCheckoutResponseSchema);
.output(PreviewCheckoutResponseSchema);
export const confirmCheckoutContract = oc
.route({