feat: new attach / update subscription params

This commit is contained in:
John Yeo
2026-02-17 12:48:11 +00:00
parent a668c5d9e9
commit e6077458a2
112 changed files with 2555 additions and 419 deletions

View File

@@ -1,13 +1,11 @@
import { RedirectModeSchema } from "@api/billing/common/redirectMode.js";
import { z } from "zod/v4";
import { PlanTimingSchema } from "../../../models/billingModels/context/attachBillingContext.js";
import { ProductItemSchema } from "../../../models/productV2Models/productItemModels/productItemModels.js";
import { BillingBehaviorSchema } from "../common/billingBehavior.js";
import { BillingParamsBaseSchema } from "../common/billingParamsBase.js";
import { BillingParamsBaseV0Schema } from "../common/billingParamsBase/billingParamsBaseV0.js";
export const RedirectModeSchema = z.enum(["always", "if_required", "never"]);
export type RedirectMode = z.infer<typeof RedirectModeSchema>;
export const ExtAttachParamsV0Schema = BillingParamsBaseSchema.extend({
export const ExtAttachParamsV0Schema = BillingParamsBaseV0Schema.extend({
// Product identification
product_id: z.string(),

View File

@@ -0,0 +1,48 @@
import { BillingParamsBaseV1Schema } from "@api/billing/common/billingParamsBase/billingParamsBaseV1.js";
import { z } from "zod/v4";
import { PlanTimingSchema } from "../../../models/billingModels/context/attachBillingContext.js";
import { BillingBehaviorSchema } from "../common/billingBehavior.js";
import { RedirectModeSchema } from "../common/redirectMode.js";
export const AttachParamsV1Schema = BillingParamsBaseV1Schema.extend({
// Product identification
product_id: z.string(),
// Invoice mode
invoice: z.boolean().optional(),
enable_product_immediately: z.boolean().optional(),
finalize_invoice: z.boolean().optional(),
// invoice_mode: z
// .object({
// enabled: z.boolean(),
// enable_product_immediately: z.boolean(),
// finalize_invoice: z.boolean(),
// })
// .optional(),
// Checkout behavior
redirect_mode: RedirectModeSchema.default("always"),
success_url: z.string().optional(),
new_billing_subscription: z.boolean().optional(),
plan_schedule: PlanTimingSchema.optional(),
billing_behavior: BillingBehaviorSchema.optional(),
adjustable_quantity: z.boolean().optional(),
});
// export const AttachParamsV1Schema = ExtAttachParamsV1Schema.extend({
// // Custom product configuration
// items: z.array(ProductItemSchema).optional(),
// }).refine(
// (data) => {
// if (data.items && data.items.length === 0) {
// return false;
// }
// return true;
// },
// {
// message: "Must provide at least one item when using custom plan",
// },
// );
export type AttachParamsV1 = z.infer<typeof AttachParamsV1Schema>;
export type AttachParamsV1Input = z.input<typeof AttachParamsV1Schema>;

View File

@@ -0,0 +1,50 @@
import { freeTrialParamsV0ToV1 } from "@api/common/freeTrial/mappers/freeTrialParamsV0ToV1.js";
import { ApiVersion } from "@api/versionUtils/ApiVersion.js";
import {
AffectedResource,
defineVersionChange,
} from "@api/versionUtils/versionChangeUtils/VersionChange.js";
import { productItemsToCustomizePlanV1 } from "@utils/productV2Utils/productItemUtils/convertProductItem/productItemsToCustomizePlanV1.js";
import type { z } from "zod/v4";
import type { SharedContext } from "../../../../types/sharedContext.js";
import { AttachParamsV0Schema } from "../attachParamsV0.js";
import { AttachParamsV1Schema } from "../attachParamsV1.js";
export const V1_2_AttachParamsChange = defineVersionChange({
name: "V1.2 Attach Params Change",
newVersion: ApiVersion.V2_0,
oldVersion: ApiVersion.V1_Beta,
description: [
"Maps free_trial {length,duration} to {duration_length,duration_type}",
"Maps top-level items to customize.items",
],
affectedResources: [AffectedResource.Attach],
newSchema: AttachParamsV1Schema,
oldSchema: AttachParamsV0Schema,
affectsRequest: true,
affectsResponse: false,
transformRequest: ({
ctx,
input,
}: {
ctx: SharedContext;
input: z.infer<typeof AttachParamsV0Schema>;
}): z.infer<typeof AttachParamsV1Schema> => {
const customizeV1 = input.items
? productItemsToCustomizePlanV1({
ctx,
items: input.items,
})
: undefined;
const freeTrialV1 = freeTrialParamsV0ToV1({
freeTrialParamsV0: input.free_trial,
});
return {
...input,
free_trial: freeTrialV1,
customize: customizeV1,
};
},
});