/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { remap as remap$ } from "../../lib/primitives.js"; import { AddAddonToSubscriptionRequest, AddAddonToSubscriptionRequest$Outbound, AddAddonToSubscriptionRequest$outboundSchema, } from "./add-addon-to-subscription-request.js"; import { BillingCycle, BillingCycle$outboundSchema } from "./billing-cycle.js"; import { BillingPeriod, BillingPeriod$outboundSchema, } from "./billing-period.js"; import { CheckoutParams, CheckoutParams$Outbound, CheckoutParams$outboundSchema, } from "./checkout-params.js"; import { CollectionMethod, CollectionMethod$outboundSchema, } from "./collection-method.js"; import { CreateCreditGrantRequest, CreateCreditGrantRequest$Outbound, CreateCreditGrantRequest$outboundSchema, } from "./create-credit-grant-request.js"; import { CreateSubscriptionLineItemRequest, CreateSubscriptionLineItemRequest$Outbound, CreateSubscriptionLineItemRequest$outboundSchema, } from "./create-subscription-line-item-request.js"; import { LineItemCommitmentConfig, LineItemCommitmentConfig$Outbound, LineItemCommitmentConfig$outboundSchema, } from "./line-item-commitment-config.js"; import { OverrideEntitlementRequest, OverrideEntitlementRequest$Outbound, OverrideEntitlementRequest$outboundSchema, } from "./override-entitlement-request.js"; import { OverrideLineItemRequest, OverrideLineItemRequest$Outbound, OverrideLineItemRequest$outboundSchema, } from "./override-line-item-request.js"; import { PaymentBehavior, PaymentBehavior$outboundSchema, } from "./payment-behavior.js"; import { PaymentTerms, PaymentTerms$outboundSchema } from "./payment-terms.js"; import { ProrationBehavior, ProrationBehavior$outboundSchema, } from "./proration-behavior.js"; import { SubscriptionCouponInput, SubscriptionCouponInput$Outbound, SubscriptionCouponInput$outboundSchema, } from "./subscription-coupon-input.js"; import { SubscriptionInheritanceConfig, SubscriptionInheritanceConfig$Outbound, SubscriptionInheritanceConfig$outboundSchema, } from "./subscription-inheritance-config.js"; import { SubscriptionPhaseCreateRequest, SubscriptionPhaseCreateRequest$Outbound, SubscriptionPhaseCreateRequest$outboundSchema, } from "./subscription-phase-create-request.js"; import { SubscriptionStatus, SubscriptionStatus$outboundSchema, } from "./subscription-status.js"; import { TaxRateOverride, TaxRateOverride$Outbound, TaxRateOverride$outboundSchema, } from "./tax-rate-override.js"; export type CreateSubscriptionRequest = { addons?: Array | undefined; /** * AutoInvoiceThreshold triggers a mid-period invoice when usage (in subscription currency) exceeds this amount. * * @remarks * Standalone subscriptions only; all plan prices must be usage-based. Immutable after creation. */ autoInvoiceThreshold?: string | undefined; /** * BillingAnchor overrides the derived anchor for anniversary billing. For monthly billing, * * @remarks * the day-of-month defines cycle boundaries (shorter first period if start is before that day). */ billingAnchor?: Date | undefined; billingCycle?: BillingCycle | undefined; billingPeriod: BillingPeriod; billingPeriodCount?: number | undefined; checkout?: CheckoutParams | undefined; collectionMethod?: CollectionMethod | undefined; commitmentAmount?: string | undefined; commitmentDuration?: BillingPeriod | undefined; /** * Deprecated: use SubscriptionCoupons instead. */ coupons?: Array | undefined; creditGrants?: Array | undefined; currency: string; /** * CustomerID takes priority over ExternalCustomerID when both are provided. */ customerId?: string | undefined; enableTrueUp?: boolean | undefined; endDate?: Date | undefined; externalCustomerId?: string | undefined; gatewayPaymentMethodId?: string | undefined; inheritance?: SubscriptionInheritanceConfig | undefined; /** * LineItemCommitments sets per-line-item commitment config, keyed by price_id. */ lineItemCommitments?: { [k: string]: LineItemCommitmentConfig } | undefined; /** * Deprecated: use SubscriptionCoupons instead. */ lineItemCoupons?: { [k: string]: Array } | undefined; /** * LineItems are extra (non-plan) line items added at creation. */ lineItems?: Array | undefined; lookupKey?: string | undefined; metadata?: { [k: string]: string } | undefined; overageFactor?: string | undefined; overrideEntitlements?: Array | undefined; /** * OverrideLineItems overrides specific plan prices for this subscription. */ overrideLineItems?: Array | undefined; paymentBehavior?: PaymentBehavior | undefined; paymentTerms?: PaymentTerms | undefined; phases?: Array | undefined; planId: string; prorationBehavior?: ProrationBehavior | undefined; startDate?: Date | undefined; /** * SubscriptionCoupons is the preferred way to attach coupons at creation. * * @remarks * Accepts coupon_code; optionally targets a line item via price_id. */ subscriptionCoupons?: Array | undefined; subscriptionStatus?: SubscriptionStatus | undefined; taxRateOverrides?: Array | undefined; timezone?: string | undefined; /** * TrialPeriodDays: nil = inherit from plan prices, 0 = no trial, >0 = override in days. */ trialPeriodDays?: number | undefined; }; /** @internal */ export type CreateSubscriptionRequest$Outbound = { addons?: Array | undefined; auto_invoice_threshold?: string | undefined; billing_anchor?: string | undefined; billing_cycle?: string | undefined; billing_period: string; billing_period_count?: number | undefined; checkout?: CheckoutParams$Outbound | undefined; collection_method?: string | undefined; commitment_amount?: string | undefined; commitment_duration?: string | undefined; coupons?: Array | undefined; credit_grants?: Array | undefined; currency: string; customer_id?: string | undefined; enable_true_up?: boolean | undefined; end_date?: string | undefined; external_customer_id?: string | undefined; gateway_payment_method_id?: string | undefined; inheritance?: SubscriptionInheritanceConfig$Outbound | undefined; line_item_commitments?: | { [k: string]: LineItemCommitmentConfig$Outbound } | undefined; line_item_coupons?: { [k: string]: Array } | undefined; line_items?: Array | undefined; lookup_key?: string | undefined; metadata?: { [k: string]: string } | undefined; overage_factor?: string | undefined; override_entitlements?: | Array | undefined; override_line_items?: Array | undefined; payment_behavior?: string | undefined; payment_terms?: string | undefined; phases?: Array | undefined; plan_id: string; proration_behavior?: string | undefined; start_date?: string | undefined; subscription_coupons?: Array | undefined; subscription_status?: string | undefined; tax_rate_overrides?: Array | undefined; timezone?: string | undefined; trial_period_days?: number | undefined; }; /** @internal */ export const CreateSubscriptionRequest$outboundSchema: z.ZodMiniType< CreateSubscriptionRequest$Outbound, CreateSubscriptionRequest > = z.pipe( z.object({ addons: z.optional(z.array(AddAddonToSubscriptionRequest$outboundSchema)), autoInvoiceThreshold: z.optional(z.string()), billingAnchor: z.optional( z.pipe(z.date(), z.transform(v => v.toISOString())), ), billingCycle: z.optional(BillingCycle$outboundSchema), billingPeriod: BillingPeriod$outboundSchema, billingPeriodCount: z.optional(z.int()), checkout: z.optional(CheckoutParams$outboundSchema), collectionMethod: z.optional(CollectionMethod$outboundSchema), commitmentAmount: z.optional(z.string()), commitmentDuration: z.optional(BillingPeriod$outboundSchema), coupons: z.optional(z.array(z.string())), creditGrants: z.optional(z.array(CreateCreditGrantRequest$outboundSchema)), currency: z.string(), customerId: z.optional(z.string()), enableTrueUp: z.optional(z.boolean()), endDate: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), externalCustomerId: z.optional(z.string()), gatewayPaymentMethodId: z.optional(z.string()), inheritance: z.optional(SubscriptionInheritanceConfig$outboundSchema), lineItemCommitments: z.optional( z.record(z.string(), LineItemCommitmentConfig$outboundSchema), ), lineItemCoupons: z.optional(z.record(z.string(), z.array(z.string()))), lineItems: z.optional( z.array(CreateSubscriptionLineItemRequest$outboundSchema), ), lookupKey: z.optional(z.string()), metadata: z.optional(z.record(z.string(), z.string())), overageFactor: z.optional(z.string()), overrideEntitlements: z.optional( z.array(OverrideEntitlementRequest$outboundSchema), ), overrideLineItems: z.optional( z.array(OverrideLineItemRequest$outboundSchema), ), paymentBehavior: z.optional(PaymentBehavior$outboundSchema), paymentTerms: z.optional(PaymentTerms$outboundSchema), phases: z.optional(z.array(SubscriptionPhaseCreateRequest$outboundSchema)), planId: z.string(), prorationBehavior: z.optional(ProrationBehavior$outboundSchema), startDate: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))), subscriptionCoupons: z.optional( z.array(SubscriptionCouponInput$outboundSchema), ), subscriptionStatus: z.optional(SubscriptionStatus$outboundSchema), taxRateOverrides: z.optional(z.array(TaxRateOverride$outboundSchema)), timezone: z.optional(z.string()), trialPeriodDays: z.optional(z.int()), }), z.transform((v) => { return remap$(v, { autoInvoiceThreshold: "auto_invoice_threshold", billingAnchor: "billing_anchor", billingCycle: "billing_cycle", billingPeriod: "billing_period", billingPeriodCount: "billing_period_count", collectionMethod: "collection_method", commitmentAmount: "commitment_amount", commitmentDuration: "commitment_duration", creditGrants: "credit_grants", customerId: "customer_id", enableTrueUp: "enable_true_up", endDate: "end_date", externalCustomerId: "external_customer_id", gatewayPaymentMethodId: "gateway_payment_method_id", lineItemCommitments: "line_item_commitments", lineItemCoupons: "line_item_coupons", lineItems: "line_items", lookupKey: "lookup_key", overageFactor: "overage_factor", overrideEntitlements: "override_entitlements", overrideLineItems: "override_line_items", paymentBehavior: "payment_behavior", paymentTerms: "payment_terms", planId: "plan_id", prorationBehavior: "proration_behavior", startDate: "start_date", subscriptionCoupons: "subscription_coupons", subscriptionStatus: "subscription_status", taxRateOverrides: "tax_rate_overrides", trialPeriodDays: "trial_period_days", }); }), ); export function createSubscriptionRequestToJSON( createSubscriptionRequest: CreateSubscriptionRequest, ): string { return JSON.stringify( CreateSubscriptionRequest$outboundSchema.parse(createSubscriptionRequest), ); }