import { BillingParamsBaseV1Schema } from "@api/billing/common/billingParamsBase/billingParamsBaseV1"; import { z } from "zod/v4"; import { PlanTimingSchema } from "../../../models/billingModels/context/attachBillingContext"; import { RedirectModeSchema } from "../common/redirectMode"; import { AttachDiscountSchema } from "./attachDiscount"; export const AttachParamsV1Schema = BillingParamsBaseV1Schema.extend({ discounts: z.array(AttachDiscountSchema).optional().meta({ description: "List of discounts to apply. Each discount can be an Autumn reward ID, Stripe coupon ID, or Stripe promotion code.", }), success_url: z.string().optional().meta({ description: "URL to redirect to after successful checkout.", }), redirect_mode: RedirectModeSchema.default("if_required").meta({ internal: true, description: "Controls when to return a checkout URL. 'always' returns a URL even if payment succeeds, 'if_required' only when payment action is needed, 'never' disables redirects.", }), new_billing_subscription: z.boolean().optional().meta({ description: "Only applicable when the customer has an existing Stripe subscription. If true, creates a new separate subscription instead of merging into the existing one.", }), plan_schedule: PlanTimingSchema.optional().meta({ description: "When the plan change should take effect. 'immediate' applies now, 'end_of_cycle' schedules for the end of the current billing cycle. By default, upgrades are immediate and downgrades are scheduled.", }), checkout_session_params: z.record(z.string(), z.unknown()).optional().meta({ description: "Additional parameters to pass into the creation of the Stripe checkout session.", }), carry_over_balances: z .object({ enabled: z.boolean().meta({ description: "Whether to carry over balances from the previous plan.", }), feature_ids: z.array(z.string()).optional().meta({ description: "The IDs of the features to carry over balances from. If left undefined, all features will be carried over.", }), }) .optional() .meta({ description: "Whether to carry over balances from the previous plan.", }), carry_over_usages: z .object({ enabled: z.boolean().meta({ description: "Whether to carry over usages from the previous plan.", }), feature_ids: z.array(z.string()).optional().meta({ description: "The IDs of the features to carry over usages for. If left undefined, all consumable features will be carried over.", }), }) .optional() .meta({ description: "Whether to carry over usages from the previous plan.", }), }); export type AttachParamsV1 = z.infer; export type AttachParamsV1Input = z.input;