Files
cfw-autumn/shared/internal/checkout/checkoutResponses.ts
2026-02-13 15:50:07 +00:00

88 lines
2.5 KiB
TypeScript

import { ApiBalanceV1Schema } from "@api/customers/cusFeatures/apiBalanceV1.js";
import { ApiPlanV1Schema } from "@api/products/apiPlanV1.js";
import { FeatureOptionsSchema } from "@models/cusProductModels/cusProductModels.js";
import { z } from "zod/v4";
import { BillingPreviewResponseSchema } from "../../api/billing/common/billingPreviewResponse.js";
/**
* 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(),
});
// /**
// * Subscription with required plan (always expanded for checkout)
// */
// export const CheckoutSubscriptionSchema = ApiSubscriptionSchema.extend({
// plan: ApiPlanV0Schema,
// });
/**
* A change in the checkout (product being added, canceled, or expiring)
*/
export const CheckoutChangeSchema = z.object({
plan: ApiPlanV1Schema,
feature_quantities: z.array(
FeatureOptionsSchema.pick({
feature_id: true,
quantity: true,
}),
),
balances: z.record(z.string(), ApiBalanceV1Schema),
period_start: z.number().optional(),
period_end: z.number().optional(),
});
/**
* GET /checkouts/:checkout_id response
*/
export const GetCheckoutResponseSchema = z.object({
env: z.string(),
preview: BillingPreviewResponseSchema,
org: CheckoutOrgSchema,
customer: CheckoutCustomerSchema,
entity: CheckoutEntitySchema.nullable(),
incoming: z.array(CheckoutChangeSchema),
outgoing: z.array(CheckoutChangeSchema),
});
/**
* POST /checkouts/:checkout_id/confirm response
*/
export const ConfirmCheckoutResponseSchema = z.object({
success: z.boolean(),
checkout_id: z.string(),
customer_id: z.string(),
product_id: z.string(),
invoice_id: z.string().nullable(),
});
export type CheckoutOrg = z.infer<typeof CheckoutOrgSchema>;
export type CheckoutCustomer = z.infer<typeof CheckoutCustomerSchema>;
export type CheckoutEntity = z.infer<typeof CheckoutEntitySchema>;
// export type CheckoutSubscription = z.infer<typeof CheckoutSubscriptionSchema>;
export type CheckoutChange = z.infer<typeof CheckoutChangeSchema>;
export type GetCheckoutResponse = z.infer<typeof GetCheckoutResponseSchema>;
export type ConfirmCheckoutResponse = z.infer<
typeof ConfirmCheckoutResponseSchema
>;