feat: new attach / update subscription params
This commit is contained in:
@@ -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(),
|
||||
|
||||
|
||||
48
shared/api/billing/attachV2/attachParamsV1.ts
Normal file
48
shared/api/billing/attachV2/attachParamsV1.ts
Normal 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>;
|
||||
@@ -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,
|
||||
};
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user