/* * 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 { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { AggregatedFeature, AggregatedFeature$inboundSchema, } from "./aggregated-feature.js"; import { BillingCadence, BillingCadence$inboundSchema, } from "./billing-cadence.js"; import { BillingCycle, BillingCycle$inboundSchema } from "./billing-cycle.js"; import { BillingPeriod, BillingPeriod$inboundSchema, } from "./billing-period.js"; import { CheckoutSessionResponse, CheckoutSessionResponse$inboundSchema, } from "./checkout-session-response.js"; import { CouponAssociationResponse, CouponAssociationResponse$inboundSchema, } from "./coupon-association-response.js"; import { CreditGrantResponse, CreditGrantResponse$inboundSchema, } from "./credit-grant-response.js"; import { CustomerResponse, CustomerResponse$inboundSchema, } from "./customer-response.js"; import { InvoiceResponse, InvoiceResponse$inboundSchema, } from "./invoice-response.js"; import { PauseStatus, PauseStatus$inboundSchema } from "./pause-status.js"; import { PaymentTerms, PaymentTerms$inboundSchema } from "./payment-terms.js"; import { PlanResponse, PlanResponse$inboundSchema } from "./plan-response.js"; import { ProrationBehavior, ProrationBehavior$inboundSchema, } from "./proration-behavior.js"; import { SDKValidationError } from "./sdk-validation-error.js"; import { Status, Status$inboundSchema } from "./status.js"; import { SubscriptionPhaseResponse, SubscriptionPhaseResponse$inboundSchema, } from "./subscription-phase-response.js"; import { SubscriptionStatus, SubscriptionStatus$inboundSchema, } from "./subscription-status.js"; import { SubscriptionSubscriptionLineItem, SubscriptionSubscriptionLineItem$inboundSchema, } from "./subscription-subscription-line-item.js"; import { SubscriptionSubscriptionPause, SubscriptionSubscriptionPause$inboundSchema, } from "./subscription-subscription-pause.js"; import { SubscriptionType, SubscriptionType$inboundSchema, } from "./subscription-type.js"; export type SubscriptionResponse = { /** * ActivePauseID references the current active pause configuration * * @remarks * This will be null if no pause is active or scheduled */ activePauseId?: string | undefined; /** * AutoInvoiceThreshold is the usage amount (in subscription currency) that triggers * * @remarks * an intermediate invoice. Overrides the plan-level threshold when set. * Nil means: inherit from the plan's threshold (which may also be nil = disabled). */ autoInvoiceThreshold?: string | undefined; /** * BillingAnchor is the reference point that aligns future billing cycle dates. * * @remarks * It sets the day of week for week intervals, the day of month for month and year intervals, * and the month of year for year intervals. The timestamp is in UTC format. */ billingAnchor?: Date | undefined; billingCadence?: BillingCadence | undefined; billingCycle?: BillingCycle | undefined; billingPeriod?: BillingPeriod | undefined; /** * BillingPeriodCount is the total number units of the billing period. */ billingPeriodCount?: number | undefined; /** * CancelAt is the date the subscription will be canceled */ cancelAt?: Date | undefined; /** * CancelAtPeriodEnd is whether the subscription was canceled at the end of the current period */ cancelAtPeriodEnd?: boolean | undefined; /** * CanceledAt is the date the subscription was canceled */ cancelledAt?: Date | undefined; checkoutSession?: CheckoutSessionResponse | undefined; /** * CollectionMethod determines how invoices are collected */ collectionMethod?: string | undefined; /** * CommitmentAmount is the minimum amount a customer commits to paying for a billing period */ commitmentAmount?: string | undefined; commitmentDuration?: BillingPeriod | undefined; /** * CouponAssociations are the coupon associations for this subscription */ couponAssociations?: Array | undefined; createdAt?: Date | undefined; createdBy?: string | undefined; /** * Credit grants are the credit grants for this subscription */ creditGrants?: Array | undefined; /** * Currency is the currency of the subscription in lowercase 3 digit ISO codes */ currency?: string | undefined; /** * CurrentPeriodEnd is the end of the current period that the subscription has been invoiced for. * * @remarks * At the end of this period, a new invoice will be created. */ currentPeriodEnd?: Date | undefined; /** * CurrentPeriodStart is the end of the current period that the subscription has been invoiced for. * * @remarks * At the end of this period, a new invoice will be created. */ currentPeriodStart?: Date | undefined; /** * Customer response object containing all customer information */ customer?: CustomerResponse | undefined; /** * CustomerID is the identifier for the customer in our system */ customerId?: string | undefined; enableTrueUp?: boolean | undefined; /** * EndDate is the end date of the subscription */ endDate?: Date | undefined; /** * Entitlements is populated only when the caller adds "entitlements" to * * @remarks * the search filter's expand string. Each entry is a feature with its * aggregated entitlement info (same shape as CustomerEntitlementsResponse.Features). */ entitlements?: Array | undefined; /** * EnvironmentID is the environment identifier for the subscription */ environmentId?: string | undefined; /** * GatewayPaymentMethodID is the gateway payment method ID for this subscription */ gatewayPaymentMethodId?: string | undefined; /** * ID is the unique identifier for the subscription */ id?: string | undefined; /** * InvoicingCustomerID is the customer ID to use for invoicing * * @remarks * This can differ from the subscription customer (e.g., parent company invoicing for child company) */ invoicingCustomerId?: string | undefined; latestInvoice?: InvoiceResponse | undefined; lineItems?: Array | undefined; /** * LookupKey is the key used to lookup the subscription in our system */ lookupKey?: string | undefined; metadata?: { [k: string]: string } | undefined; /** * OverageFactor is a multiplier applied to usage beyond the commitment amount */ overageFactor?: string | undefined; /** * ParentSubscriptionID is the parent subscription ID for hierarchy (e.g. child subscription under a parent) */ parentSubscriptionId?: string | undefined; pauseStatus?: PauseStatus | undefined; pauses?: Array | undefined; /** * PaymentBehavior determines how subscription payments are handled */ paymentBehavior?: string | undefined; paymentTerms?: PaymentTerms | undefined; /** * Phases are the subscription phases for this subscription */ phases?: Array | undefined; plan?: PlanResponse | undefined; /** * PlanID is the identifier for the plan in our system */ planId?: string | undefined; prorationBehavior?: ProrationBehavior | undefined; /** * StartDate is the start date of the subscription */ startDate?: Date | undefined; status?: Status | undefined; subscriptionStatus?: SubscriptionStatus | undefined; subscriptionType?: SubscriptionType | undefined; /** * SyncedPriceSequence is the plan-price sequence up to which this * * @remarks * subscription's line items have been reconciled. Bumped by the * plan-price sync after a successful pass. */ syncedPriceSequence?: number | undefined; tenantId?: string | undefined; timezone?: string | undefined; /** * TrialEnd is the end date of the trial period */ trialEnd?: Date | undefined; /** * TrialStart is the start date of the trial period */ trialStart?: Date | undefined; updatedAt?: Date | undefined; updatedBy?: string | undefined; /** * Version is used for optimistic locking */ version?: number | undefined; }; /** @internal */ export const SubscriptionResponse$inboundSchema: z.ZodMiniType< SubscriptionResponse, unknown > = z.pipe( z.object({ active_pause_id: types.optional(types.string()), auto_invoice_threshold: types.optional(types.string()), billing_anchor: types.optional(types.date()), billing_cadence: types.optional(BillingCadence$inboundSchema), billing_cycle: types.optional(BillingCycle$inboundSchema), billing_period: types.optional(BillingPeriod$inboundSchema), billing_period_count: types.optional(types.number()), cancel_at: types.optional(types.date()), cancel_at_period_end: types.optional(types.boolean()), cancelled_at: types.optional(types.date()), checkout_session: types.optional(CheckoutSessionResponse$inboundSchema), collection_method: types.optional(types.string()), commitment_amount: types.optional(types.string()), commitment_duration: types.optional(BillingPeriod$inboundSchema), coupon_associations: types.optional( z.array(CouponAssociationResponse$inboundSchema), ), created_at: types.optional(types.date()), created_by: types.optional(types.string()), credit_grants: types.optional(z.array(CreditGrantResponse$inboundSchema)), currency: types.optional(types.string()), current_period_end: types.optional(types.date()), current_period_start: types.optional(types.date()), customer: types.optional(CustomerResponse$inboundSchema), customer_id: types.optional(types.string()), enable_true_up: types.optional(types.boolean()), end_date: types.optional(types.date()), entitlements: types.optional(z.array(AggregatedFeature$inboundSchema)), environment_id: types.optional(types.string()), gateway_payment_method_id: types.optional(types.string()), id: types.optional(types.string()), invoicing_customer_id: types.optional(types.string()), latest_invoice: types.optional(z.lazy(() => InvoiceResponse$inboundSchema)), line_items: types.optional( z.array(SubscriptionSubscriptionLineItem$inboundSchema), ), lookup_key: types.optional(types.string()), metadata: types.optional(z.record(z.string(), types.string())), overage_factor: types.optional(types.string()), parent_subscription_id: types.optional(types.string()), pause_status: types.optional(PauseStatus$inboundSchema), pauses: types.optional( z.array(SubscriptionSubscriptionPause$inboundSchema), ), payment_behavior: types.optional(types.string()), payment_terms: types.optional(PaymentTerms$inboundSchema), phases: types.optional(z.array(SubscriptionPhaseResponse$inboundSchema)), plan: types.optional(PlanResponse$inboundSchema), plan_id: types.optional(types.string()), proration_behavior: types.optional(ProrationBehavior$inboundSchema), start_date: types.optional(types.date()), status: types.optional(Status$inboundSchema), subscription_status: types.optional(SubscriptionStatus$inboundSchema), subscription_type: types.optional(SubscriptionType$inboundSchema), synced_price_sequence: types.optional(types.number()), tenant_id: types.optional(types.string()), timezone: types.optional(types.string()), trial_end: types.optional(types.date()), trial_start: types.optional(types.date()), updated_at: types.optional(types.date()), updated_by: types.optional(types.string()), version: types.optional(types.number()), }), z.transform((v) => { return remap$(v, { "active_pause_id": "activePauseId", "auto_invoice_threshold": "autoInvoiceThreshold", "billing_anchor": "billingAnchor", "billing_cadence": "billingCadence", "billing_cycle": "billingCycle", "billing_period": "billingPeriod", "billing_period_count": "billingPeriodCount", "cancel_at": "cancelAt", "cancel_at_period_end": "cancelAtPeriodEnd", "cancelled_at": "cancelledAt", "checkout_session": "checkoutSession", "collection_method": "collectionMethod", "commitment_amount": "commitmentAmount", "commitment_duration": "commitmentDuration", "coupon_associations": "couponAssociations", "created_at": "createdAt", "created_by": "createdBy", "credit_grants": "creditGrants", "current_period_end": "currentPeriodEnd", "current_period_start": "currentPeriodStart", "customer_id": "customerId", "enable_true_up": "enableTrueUp", "end_date": "endDate", "environment_id": "environmentId", "gateway_payment_method_id": "gatewayPaymentMethodId", "invoicing_customer_id": "invoicingCustomerId", "latest_invoice": "latestInvoice", "line_items": "lineItems", "lookup_key": "lookupKey", "overage_factor": "overageFactor", "parent_subscription_id": "parentSubscriptionId", "pause_status": "pauseStatus", "payment_behavior": "paymentBehavior", "payment_terms": "paymentTerms", "plan_id": "planId", "proration_behavior": "prorationBehavior", "start_date": "startDate", "subscription_status": "subscriptionStatus", "subscription_type": "subscriptionType", "synced_price_sequence": "syncedPriceSequence", "tenant_id": "tenantId", "trial_end": "trialEnd", "trial_start": "trialStart", "updated_at": "updatedAt", "updated_by": "updatedBy", }); }), ); export function subscriptionResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => SubscriptionResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SubscriptionResponse' from JSON`, ); }