Files
cfw-autumn/packages/sdk/src/models/attach-op.ts
Owen Greenhalgh 596a9bb7db regen sdk
2026-05-28 15:03:10 +01:00

2024 lines
56 KiB
TypeScript

/*
* 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 * as openEnums from "../types/enums.js";
import { ClosedEnum, OpenEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smart-union.js";
import { SDKValidationError } from "./sdk-validation-error.js";
export type AttachGlobals = {
xApiVersion?: string | undefined;
};
/**
* Quantity configuration for a prepaid feature.
*/
export type AttachFeatureQuantity = {
/**
* The ID of the feature to set quantity for.
*/
featureId: string;
/**
* The quantity of the feature.
*/
quantity?: number | undefined;
/**
* Whether the customer can adjust the quantity.
*/
adjustable?: boolean | undefined;
};
/**
* Billing interval (e.g. 'month', 'year').
*/
export const AttachPriceInterval = {
OneOff: "one_off",
Week: "week",
Month: "month",
Quarter: "quarter",
SemiAnnual: "semi_annual",
Year: "year",
} as const;
/**
* Billing interval (e.g. 'month', 'year').
*/
export type AttachPriceInterval = ClosedEnum<typeof AttachPriceInterval>;
/**
* Base price configuration for a plan.
*/
export type AttachBasePrice = {
/**
* Base price amount for the plan.
*/
amount: number;
/**
* Billing interval (e.g. 'month', 'year').
*/
interval: AttachPriceInterval;
/**
* Number of intervals per billing cycle. Defaults to 1.
*/
intervalCount?: number | undefined;
};
/**
* Interval at which balance resets (e.g. 'month', 'year'). For consumable features only.
*/
export const AttachItemResetInterval = {
OneOff: "one_off",
Minute: "minute",
Hour: "hour",
Day: "day",
Week: "week",
Month: "month",
Quarter: "quarter",
SemiAnnual: "semi_annual",
Year: "year",
} as const;
/**
* Interval at which balance resets (e.g. 'month', 'year'). For consumable features only.
*/
export type AttachItemResetInterval = ClosedEnum<
typeof AttachItemResetInterval
>;
/**
* Reset configuration for consumable features. Omit for non-consumable features like seats.
*/
export type AttachItemReset = {
/**
* Interval at which balance resets (e.g. 'month', 'year'). For consumable features only.
*/
interval: AttachItemResetInterval;
/**
* Number of intervals between resets. Defaults to 1.
*/
intervalCount?: number | undefined;
};
export type AttachItemTo = number | string;
export type AttachItemTier = {
to: number | string;
amount?: number | undefined;
flatAmount?: number | undefined;
};
export const AttachItemTierBehavior = {
Graduated: "graduated",
Volume: "volume",
} as const;
export type AttachItemTierBehavior = ClosedEnum<typeof AttachItemTierBehavior>;
/**
* Billing interval. For consumable features, should match reset.interval.
*/
export const AttachItemPriceInterval = {
OneOff: "one_off",
Week: "week",
Month: "month",
Quarter: "quarter",
SemiAnnual: "semi_annual",
Year: "year",
} as const;
/**
* Billing interval. For consumable features, should match reset.interval.
*/
export type AttachItemPriceInterval = ClosedEnum<
typeof AttachItemPriceInterval
>;
/**
* 'prepaid' for upfront payment (seats), 'usage_based' for pay-as-you-go.
*/
export const AttachItemBillingMethod = {
Prepaid: "prepaid",
UsageBased: "usage_based",
} as const;
/**
* 'prepaid' for upfront payment (seats), 'usage_based' for pay-as-you-go.
*/
export type AttachItemBillingMethod = ClosedEnum<
typeof AttachItemBillingMethod
>;
/**
* Pricing for usage beyond included units. Omit for free features.
*/
export type AttachItemPrice = {
/**
* Price per billing_units after included usage. Either 'amount' or 'tiers' is required.
*/
amount?: number | undefined;
/**
* Tiered pricing. Either 'amount' or 'tiers' is required.
*/
tiers?: Array<AttachItemTier> | undefined;
tierBehavior?: AttachItemTierBehavior | undefined;
/**
* Billing interval. For consumable features, should match reset.interval.
*/
interval: AttachItemPriceInterval;
/**
* Number of intervals per billing cycle. Defaults to 1.
*/
intervalCount?: number | undefined;
/**
* Units per price increment. Usage is rounded UP when billed (e.g. billing_units=100 means 101 rounds to 200).
*/
billingUnits?: number | undefined;
/**
* 'prepaid' for upfront payment (seats), 'usage_based' for pay-as-you-go.
*/
billingMethod: AttachItemBillingMethod;
/**
* Max units purchasable beyond included. E.g. included=100, max_purchase=300 allows 400 total.
*/
maxPurchase?: number | undefined;
};
/**
* Billing behavior when quantity increases mid-cycle.
*/
export const AttachItemOnIncrease = {
BillImmediately: "bill_immediately",
ProrateImmediately: "prorate_immediately",
ProrateNextCycle: "prorate_next_cycle",
BillNextCycle: "bill_next_cycle",
} as const;
/**
* Billing behavior when quantity increases mid-cycle.
*/
export type AttachItemOnIncrease = ClosedEnum<typeof AttachItemOnIncrease>;
/**
* Credit behavior when quantity decreases mid-cycle.
*/
export const AttachItemOnDecrease = {
Prorate: "prorate",
ProrateImmediately: "prorate_immediately",
ProrateNextCycle: "prorate_next_cycle",
None: "none",
NoProrations: "no_prorations",
} as const;
/**
* Credit behavior when quantity decreases mid-cycle.
*/
export type AttachItemOnDecrease = ClosedEnum<typeof AttachItemOnDecrease>;
/**
* Proration settings for prepaid features. Controls mid-cycle quantity change billing.
*/
export type AttachItemProration = {
/**
* Billing behavior when quantity increases mid-cycle.
*/
onIncrease: AttachItemOnIncrease;
/**
* Credit behavior when quantity decreases mid-cycle.
*/
onDecrease: AttachItemOnDecrease;
};
/**
* When rolled over units expire.
*/
export const AttachItemExpiryDurationType = {
Month: "month",
Forever: "forever",
} as const;
/**
* When rolled over units expire.
*/
export type AttachItemExpiryDurationType = ClosedEnum<
typeof AttachItemExpiryDurationType
>;
/**
* Rollover config for unused units. If set, unused included units carry over.
*/
export type AttachItemRollover = {
/**
* Max rollover units. Omit for unlimited rollover.
*/
max?: number | undefined;
/**
* Maximum rollover as a percentage (0-100) of included + prepaid grant. Mutually exclusive with max.
*/
maxPercentage?: number | undefined;
/**
* When rolled over units expire.
*/
expiryDurationType: AttachItemExpiryDurationType;
/**
* Number of periods before expiry.
*/
expiryDurationLength?: number | undefined;
};
/**
* Configuration for a feature item in a plan, including usage limits, pricing, and rollover settings.
*/
export type AttachItemPlanItem = {
/**
* The ID of the feature to configure.
*/
featureId: string;
/**
* Number of free units included. Balance resets to this each interval for consumable features.
*/
included?: number | undefined;
/**
* If true, customer has unlimited access to this feature.
*/
unlimited?: boolean | undefined;
/**
* Reset configuration for consumable features. Omit for non-consumable features like seats.
*/
reset?: AttachItemReset | undefined;
/**
* Pricing for usage beyond included units. Omit for free features.
*/
price?: AttachItemPrice | undefined;
/**
* Proration settings for prepaid features. Controls mid-cycle quantity change billing.
*/
proration?: AttachItemProration | undefined;
/**
* Rollover config for unused units. If set, unused included units carry over.
*/
rollover?: AttachItemRollover | undefined;
};
/**
* Interval at which balance resets (e.g. 'month', 'year'). For consumable features only.
*/
export const AttachAddItemResetInterval = {
OneOff: "one_off",
Minute: "minute",
Hour: "hour",
Day: "day",
Week: "week",
Month: "month",
Quarter: "quarter",
SemiAnnual: "semi_annual",
Year: "year",
} as const;
/**
* Interval at which balance resets (e.g. 'month', 'year'). For consumable features only.
*/
export type AttachAddItemResetInterval = ClosedEnum<
typeof AttachAddItemResetInterval
>;
/**
* Reset configuration for consumable features. Omit for non-consumable features like seats.
*/
export type AttachAddItemReset = {
/**
* Interval at which balance resets (e.g. 'month', 'year'). For consumable features only.
*/
interval: AttachAddItemResetInterval;
/**
* Number of intervals between resets. Defaults to 1.
*/
intervalCount?: number | undefined;
};
export type AttachAddItemTo = number | string;
export type AttachAddItemTier = {
to: number | string;
amount?: number | undefined;
flatAmount?: number | undefined;
};
export const AttachAddItemTierBehavior = {
Graduated: "graduated",
Volume: "volume",
} as const;
export type AttachAddItemTierBehavior = ClosedEnum<
typeof AttachAddItemTierBehavior
>;
/**
* Billing interval. For consumable features, should match reset.interval.
*/
export const AttachAddItemPriceInterval = {
OneOff: "one_off",
Week: "week",
Month: "month",
Quarter: "quarter",
SemiAnnual: "semi_annual",
Year: "year",
} as const;
/**
* Billing interval. For consumable features, should match reset.interval.
*/
export type AttachAddItemPriceInterval = ClosedEnum<
typeof AttachAddItemPriceInterval
>;
/**
* 'prepaid' for upfront payment (seats), 'usage_based' for pay-as-you-go.
*/
export const AttachAddItemBillingMethod = {
Prepaid: "prepaid",
UsageBased: "usage_based",
} as const;
/**
* 'prepaid' for upfront payment (seats), 'usage_based' for pay-as-you-go.
*/
export type AttachAddItemBillingMethod = ClosedEnum<
typeof AttachAddItemBillingMethod
>;
/**
* Pricing for usage beyond included units. Omit for free features.
*/
export type AttachAddItemPrice = {
/**
* Price per billing_units after included usage. Either 'amount' or 'tiers' is required.
*/
amount?: number | undefined;
/**
* Tiered pricing. Either 'amount' or 'tiers' is required.
*/
tiers?: Array<AttachAddItemTier> | undefined;
tierBehavior?: AttachAddItemTierBehavior | undefined;
/**
* Billing interval. For consumable features, should match reset.interval.
*/
interval: AttachAddItemPriceInterval;
/**
* Number of intervals per billing cycle. Defaults to 1.
*/
intervalCount?: number | undefined;
/**
* Units per price increment. Usage is rounded UP when billed (e.g. billing_units=100 means 101 rounds to 200).
*/
billingUnits?: number | undefined;
/**
* 'prepaid' for upfront payment (seats), 'usage_based' for pay-as-you-go.
*/
billingMethod: AttachAddItemBillingMethod;
/**
* Max units purchasable beyond included. E.g. included=100, max_purchase=300 allows 400 total.
*/
maxPurchase?: number | undefined;
};
/**
* Billing behavior when quantity increases mid-cycle.
*/
export const AttachAddItemOnIncrease = {
BillImmediately: "bill_immediately",
ProrateImmediately: "prorate_immediately",
ProrateNextCycle: "prorate_next_cycle",
BillNextCycle: "bill_next_cycle",
} as const;
/**
* Billing behavior when quantity increases mid-cycle.
*/
export type AttachAddItemOnIncrease = ClosedEnum<
typeof AttachAddItemOnIncrease
>;
/**
* Credit behavior when quantity decreases mid-cycle.
*/
export const AttachAddItemOnDecrease = {
Prorate: "prorate",
ProrateImmediately: "prorate_immediately",
ProrateNextCycle: "prorate_next_cycle",
None: "none",
NoProrations: "no_prorations",
} as const;
/**
* Credit behavior when quantity decreases mid-cycle.
*/
export type AttachAddItemOnDecrease = ClosedEnum<
typeof AttachAddItemOnDecrease
>;
/**
* Proration settings for prepaid features. Controls mid-cycle quantity change billing.
*/
export type AttachAddItemProration = {
/**
* Billing behavior when quantity increases mid-cycle.
*/
onIncrease: AttachAddItemOnIncrease;
/**
* Credit behavior when quantity decreases mid-cycle.
*/
onDecrease: AttachAddItemOnDecrease;
};
/**
* When rolled over units expire.
*/
export const AttachAddItemExpiryDurationType = {
Month: "month",
Forever: "forever",
} as const;
/**
* When rolled over units expire.
*/
export type AttachAddItemExpiryDurationType = ClosedEnum<
typeof AttachAddItemExpiryDurationType
>;
/**
* Rollover config for unused units. If set, unused included units carry over.
*/
export type AttachAddItemRollover = {
/**
* Max rollover units. Omit for unlimited rollover.
*/
max?: number | undefined;
/**
* Maximum rollover as a percentage (0-100) of included + prepaid grant. Mutually exclusive with max.
*/
maxPercentage?: number | undefined;
/**
* When rolled over units expire.
*/
expiryDurationType: AttachAddItemExpiryDurationType;
/**
* Number of periods before expiry.
*/
expiryDurationLength?: number | undefined;
};
/**
* Configuration for a feature item in a plan, including usage limits, pricing, and rollover settings.
*/
export type AttachAddItemPlanItem = {
/**
* The ID of the feature to configure.
*/
featureId: string;
/**
* Number of free units included. Balance resets to this each interval for consumable features.
*/
included?: number | undefined;
/**
* If true, customer has unlimited access to this feature.
*/
unlimited?: boolean | undefined;
/**
* Reset configuration for consumable features. Omit for non-consumable features like seats.
*/
reset?: AttachAddItemReset | undefined;
/**
* Pricing for usage beyond included units. Omit for free features.
*/
price?: AttachAddItemPrice | undefined;
/**
* Proration settings for prepaid features. Controls mid-cycle quantity change billing.
*/
proration?: AttachAddItemProration | undefined;
/**
* Rollover config for unused units. If set, unused included units carry over.
*/
rollover?: AttachAddItemRollover | undefined;
};
/**
* Match items with this billing method (prepaid or usage_based).
*/
export const AttachRemoveItemBillingMethod = {
Prepaid: "prepaid",
UsageBased: "usage_based",
} as const;
/**
* Match items with this billing method (prepaid or usage_based).
*/
export type AttachRemoveItemBillingMethod = ClosedEnum<
typeof AttachRemoveItemBillingMethod
>;
/**
* Match items with this interval.
*/
export const AttachRemoveItemInterval = {
OneOff: "one_off",
Week: "week",
Month: "month",
Quarter: "quarter",
SemiAnnual: "semi_annual",
Year: "year",
} as const;
/**
* Match items with this interval.
*/
export type AttachRemoveItemInterval = ClosedEnum<
typeof AttachRemoveItemInterval
>;
/**
* Filter for matching plan items. All provided fields must match (AND).
*/
export type AttachPlanItemFilter = {
/**
* Match items linked to this feature.
*/
featureId?: string | undefined;
/**
* Match items with this billing method (prepaid or usage_based).
*/
billingMethod?: AttachRemoveItemBillingMethod | undefined;
/**
* Match items with this interval.
*/
interval?: AttachRemoveItemInterval | undefined;
};
/**
* Unit of time for the trial ('day', 'month', 'year').
*/
export const AttachDurationType = {
Day: "day",
Month: "month",
Year: "year",
} as const;
/**
* Unit of time for the trial ('day', 'month', 'year').
*/
export type AttachDurationType = ClosedEnum<typeof AttachDurationType>;
/**
* Behavior when the trial ends. 'bill' charges the customer (default). 'revert' expires the trial and restores the customer's previous plan.
*/
export const AttachOnEnd = {
Bill: "bill",
Revert: "revert",
} as const;
/**
* Behavior when the trial ends. 'bill' charges the customer (default). 'revert' expires the trial and restores the customer's previous plan.
*/
export type AttachOnEnd = ClosedEnum<typeof AttachOnEnd>;
/**
* Free trial configuration for a plan.
*/
export type AttachFreeTrialParams = {
/**
* Number of duration_type periods the trial lasts.
*/
durationLength: number;
/**
* Unit of time for the trial ('day', 'month', 'year').
*/
durationType?: AttachDurationType | undefined;
/**
* If true, payment method required to start trial. Customer is charged after trial ends.
*/
cardRequired?: boolean | undefined;
/**
* Behavior when the trial ends. 'bill' charges the customer (default). 'revert' expires the trial and restores the customer's previous plan.
*/
onEnd?: AttachOnEnd | undefined;
};
/**
* Customize the plan to attach. Can override the price, items, free trial, or a combination.
*/
export type AttachCustomize = {
/**
* Override the base price of the plan. Pass null to remove the base price.
*/
price?: AttachBasePrice | null | undefined;
/**
* Override the items in the plan (PUT-style — replaces all existing items). Mutually exclusive with add_items / remove_items / update_items.
*/
items?: Array<AttachItemPlanItem> | undefined;
/**
* Items to add to the plan.
*/
addItems?: Array<AttachAddItemPlanItem> | undefined;
/**
* Filters selecting items to remove from the plan.
*/
removeItems?: Array<AttachPlanItemFilter> | undefined;
/**
* Override the plan's default free trial. Pass an object to set a custom trial, or null to remove the trial entirely.
*/
freeTrial?: AttachFreeTrialParams | null | undefined;
};
/**
* Invoice mode creates a draft or open invoice and sends it to the customer, instead of charging their card immediately. This uses Stripe's send_invoice collection method.
*/
export type AttachInvoiceMode = {
/**
* When true, creates an invoice and sends it to the customer instead of charging their card immediately. Uses Stripe's send_invoice collection method.
*/
enabled: boolean;
/**
* If true, enables the plan immediately even though the invoice is not paid yet.
*/
enablePlanImmediately?: boolean | undefined;
/**
* If true, finalizes the invoice so it can be sent to the customer. If false, keeps it as a draft for manual review.
*/
finalize?: boolean | undefined;
};
/**
* How to handle proration when updating an existing subscription. 'prorate_immediately' charges/credits prorated amounts now, 'none' skips creating any charges.
*/
export const AttachProrationBehavior = {
ProrateImmediately: "prorate_immediately",
None: "none",
} as const;
/**
* How to handle proration when updating an existing subscription. 'prorate_immediately' charges/credits prorated amounts now, 'none' skips creating any charges.
*/
export type AttachProrationBehavior = ClosedEnum<
typeof AttachProrationBehavior
>;
/**
* 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.
*/
export const AttachRedirectMode = {
Always: "always",
IfRequired: "if_required",
Never: "never",
} as const;
/**
* 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.
*/
export type AttachRedirectMode = ClosedEnum<typeof AttachRedirectMode>;
/**
* A discount to apply. Can be either a reward ID or a promotion code.
*/
export type AttachAttachDiscount = {
/**
* The ID of the reward to apply as a discount.
*/
rewardId?: string | undefined;
/**
* The promotion code to apply as a discount.
*/
promotionCode?: string | undefined;
};
/**
* 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.
*/
export const AttachPlanSchedule = {
Immediate: "immediate",
EndOfCycle: "end_of_cycle",
} as const;
/**
* 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.
*/
export type AttachPlanSchedule = ClosedEnum<typeof AttachPlanSchedule>;
export type AttachCustomLineItem = {
/**
* Amount in dollars for this line item (e.g. 10.50). Can be negative for credits.
*/
amount: number;
/**
* Description for the line item.
*/
description: string;
};
/**
* Whether to carry over balances from the previous plan.
*/
export type AttachCarryOverBalances = {
/**
* Whether to carry over balances from the previous plan.
*/
enabled: boolean;
/**
* The IDs of the features to carry over balances from. If left undefined, all features will be carried over.
*/
featureIds?: Array<string> | undefined;
};
/**
* Whether to carry over usages from the previous plan.
*/
export type AttachCarryOverUsages = {
/**
* Whether to carry over usages from the previous plan.
*/
enabled: boolean;
/**
* The IDs of the features to carry over usages for. If left undefined, all consumable features will be carried over.
*/
featureIds?: Array<string> | undefined;
};
export type AttachParams = {
/**
* The ID of the customer to attach the plan to.
*/
customerId: string;
/**
* The ID of the entity to attach the plan to.
*/
entityId?: string | undefined;
/**
* The ID of the plan.
*/
planId: string;
/**
* If this plan contains prepaid features, use this field to specify the quantity of each prepaid feature. This quantity includes the included amount and billing units defined when setting up the plan.
*/
featureQuantities?: Array<AttachFeatureQuantity> | undefined;
/**
* The version of the plan to attach.
*/
version?: number | undefined;
/**
* Customize the plan to attach. Can override the price, items, free trial, or a combination.
*/
customize?: AttachCustomize | undefined;
/**
* Invoice mode creates a draft or open invoice and sends it to the customer, instead of charging their card immediately. This uses Stripe's send_invoice collection method.
*/
invoiceMode?: AttachInvoiceMode | undefined;
/**
* How to handle proration when updating an existing subscription. 'prorate_immediately' charges/credits prorated amounts now, 'none' skips creating any charges.
*/
prorationBehavior?: AttachProrationBehavior | undefined;
/**
* 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.
*/
redirectMode?: AttachRedirectMode | undefined;
/**
* A unique ID to identify this subscription. Can be used to target specific subscriptions in update operations when a customer has multiple products with the same plan.
*/
subscriptionId?: string | undefined;
/**
* List of discounts to apply. Each discount can be an Autumn reward ID, Stripe coupon ID, or Stripe promotion code.
*/
discounts?: Array<AttachAttachDiscount> | undefined;
/**
* URL to redirect to after successful checkout.
*/
successUrl?: string | undefined;
/**
* Only applicable when the customer has an existing Stripe subscription. If true, creates a new separate subscription instead of merging into the existing one.
*/
newBillingSubscription?: boolean | undefined;
/**
* Reset the billing cycle anchor immediately with 'now'.
*/
billingCycleAnchor?: "now" | undefined;
/**
* 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.
*/
planSchedule?: AttachPlanSchedule | undefined;
/**
* Unix timestamp in milliseconds for when the attached plan should start. Future dates create a scheduled subscription.
*/
startsAt?: number | undefined;
/**
* Unix timestamp in milliseconds for when the attached plan should end.
*/
endsAt?: number | undefined;
/**
* Additional parameters to pass into the creation of the Stripe checkout session.
*/
checkoutSessionParams?: { [k: string]: any } | undefined;
/**
* Custom line items that override the auto-generated proration invoice. Only valid for immediate plan changes (eg. upgrades or one off plans).
*/
customLineItems?: Array<AttachCustomLineItem> | undefined;
/**
* The processor subscription ID to link. Use this to attach an existing Stripe subscription instead of creating a new one.
*/
processorSubscriptionId?: string | undefined;
/**
* Whether to carry over balances from the previous plan.
*/
carryOverBalances?: AttachCarryOverBalances | undefined;
/**
* Whether to carry over usages from the previous plan.
*/
carryOverUsages?: AttachCarryOverUsages | undefined;
/**
* Key-value metadata to attach to the Stripe subscription, invoice, and checkout session created during this attach flow. Keys prefixed with 'autumn_' are reserved and will be stripped.
*/
metadata?: { [k: string]: string } | undefined;
/**
* If true, skips any billing changes for the attach operation.
*/
noBillingChanges?: boolean | undefined;
/**
* If true, the customer's plan is activated immediately even when payment is deferred (invoice mode) or pending (Stripe checkout). For Stripe checkout, the customer_product is inserted before the customer completes the hosted form.
*/
enablePlanImmediately?: boolean | undefined;
/**
* Stripe tax rate ID (txr_...) to apply as the default tax rate on the created subscription, invoice, or checkout session line items.
*/
taxRateId?: string | undefined;
};
/**
* Invoice details if an invoice was created. Only present when a charge was made.
*/
export type AttachInvoice = {
/**
* The status of the invoice (e.g., 'paid', 'open', 'draft').
*/
status: string | null;
/**
* The Stripe invoice ID.
*/
stripeId: string;
/**
* The total amount of the invoice in cents.
*/
total: number;
/**
* The three-letter ISO currency code (e.g., 'usd').
*/
currency: string;
/**
* URL to the hosted invoice page where the customer can view and pay the invoice.
*/
hostedInvoiceUrl: string | null;
};
/**
* The type of action required to complete the payment.
*/
export const AttachCode = {
ThreedsRequired: "3ds_required",
PaymentMethodRequired: "payment_method_required",
PaymentFailed: "payment_failed",
} as const;
/**
* The type of action required to complete the payment.
*/
export type AttachCode = OpenEnum<typeof AttachCode>;
/**
* Details about any action required to complete the payment. Present when the payment could not be processed automatically.
*/
export type AttachRequiredAction = {
/**
* The type of action required to complete the payment.
*/
code: AttachCode;
/**
* A human-readable explanation of why this action is required.
*/
reason: string;
};
/**
* OK
*/
export type AttachResponse = {
/**
* The ID of the customer.
*/
customerId: string;
/**
* The ID of the entity, if the plan was attached to an entity.
*/
entityId?: string | undefined;
/**
* Invoice details if an invoice was created. Only present when a charge was made.
*/
invoice?: AttachInvoice | undefined;
/**
* URL to redirect the customer to complete payment. Null if no payment action is required.
*/
paymentUrl: string | null;
/**
* Details about any action required to complete the payment. Present when the payment could not be processed automatically.
*/
requiredAction?: AttachRequiredAction | undefined;
};
/** @internal */
export type AttachFeatureQuantity$Outbound = {
feature_id: string;
quantity?: number | undefined;
adjustable?: boolean | undefined;
};
/** @internal */
export const AttachFeatureQuantity$outboundSchema: z.ZodMiniType<
AttachFeatureQuantity$Outbound,
AttachFeatureQuantity
> = z.pipe(
z.object({
featureId: z.string(),
quantity: z.optional(z.number()),
adjustable: z.optional(z.boolean()),
}),
z.transform((v) => {
return remap$(v, {
featureId: "feature_id",
});
}),
);
export function attachFeatureQuantityToJSON(
attachFeatureQuantity: AttachFeatureQuantity,
): string {
return JSON.stringify(
AttachFeatureQuantity$outboundSchema.parse(attachFeatureQuantity),
);
}
/** @internal */
export const AttachPriceInterval$outboundSchema: z.ZodMiniEnum<
typeof AttachPriceInterval
> = z.enum(AttachPriceInterval);
/** @internal */
export type AttachBasePrice$Outbound = {
amount: number;
interval: string;
interval_count?: number | undefined;
};
/** @internal */
export const AttachBasePrice$outboundSchema: z.ZodMiniType<
AttachBasePrice$Outbound,
AttachBasePrice
> = z.pipe(
z.object({
amount: z.number(),
interval: AttachPriceInterval$outboundSchema,
intervalCount: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
intervalCount: "interval_count",
});
}),
);
export function attachBasePriceToJSON(
attachBasePrice: AttachBasePrice,
): string {
return JSON.stringify(AttachBasePrice$outboundSchema.parse(attachBasePrice));
}
/** @internal */
export const AttachItemResetInterval$outboundSchema: z.ZodMiniEnum<
typeof AttachItemResetInterval
> = z.enum(AttachItemResetInterval);
/** @internal */
export type AttachItemReset$Outbound = {
interval: string;
interval_count?: number | undefined;
};
/** @internal */
export const AttachItemReset$outboundSchema: z.ZodMiniType<
AttachItemReset$Outbound,
AttachItemReset
> = z.pipe(
z.object({
interval: AttachItemResetInterval$outboundSchema,
intervalCount: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
intervalCount: "interval_count",
});
}),
);
export function attachItemResetToJSON(
attachItemReset: AttachItemReset,
): string {
return JSON.stringify(AttachItemReset$outboundSchema.parse(attachItemReset));
}
/** @internal */
export type AttachItemTo$Outbound = number | string;
/** @internal */
export const AttachItemTo$outboundSchema: z.ZodMiniType<
AttachItemTo$Outbound,
AttachItemTo
> = smartUnion([z.number(), z.string()]);
export function attachItemToToJSON(attachItemTo: AttachItemTo): string {
return JSON.stringify(AttachItemTo$outboundSchema.parse(attachItemTo));
}
/** @internal */
export type AttachItemTier$Outbound = {
to: number | string;
amount?: number | undefined;
flat_amount?: number | undefined;
};
/** @internal */
export const AttachItemTier$outboundSchema: z.ZodMiniType<
AttachItemTier$Outbound,
AttachItemTier
> = z.pipe(
z.object({
to: smartUnion([z.number(), z.string()]),
amount: z.optional(z.number()),
flatAmount: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
flatAmount: "flat_amount",
});
}),
);
export function attachItemTierToJSON(attachItemTier: AttachItemTier): string {
return JSON.stringify(AttachItemTier$outboundSchema.parse(attachItemTier));
}
/** @internal */
export const AttachItemTierBehavior$outboundSchema: z.ZodMiniEnum<
typeof AttachItemTierBehavior
> = z.enum(AttachItemTierBehavior);
/** @internal */
export const AttachItemPriceInterval$outboundSchema: z.ZodMiniEnum<
typeof AttachItemPriceInterval
> = z.enum(AttachItemPriceInterval);
/** @internal */
export const AttachItemBillingMethod$outboundSchema: z.ZodMiniEnum<
typeof AttachItemBillingMethod
> = z.enum(AttachItemBillingMethod);
/** @internal */
export type AttachItemPrice$Outbound = {
amount?: number | undefined;
tiers?: Array<AttachItemTier$Outbound> | undefined;
tier_behavior?: string | undefined;
interval: string;
interval_count: number;
billing_units: number;
billing_method: string;
max_purchase?: number | undefined;
};
/** @internal */
export const AttachItemPrice$outboundSchema: z.ZodMiniType<
AttachItemPrice$Outbound,
AttachItemPrice
> = z.pipe(
z.object({
amount: z.optional(z.number()),
tiers: z.optional(z.array(z.lazy(() => AttachItemTier$outboundSchema))),
tierBehavior: z.optional(AttachItemTierBehavior$outboundSchema),
interval: AttachItemPriceInterval$outboundSchema,
intervalCount: z._default(z.number(), 1),
billingUnits: z._default(z.number(), 1),
billingMethod: AttachItemBillingMethod$outboundSchema,
maxPurchase: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
tierBehavior: "tier_behavior",
intervalCount: "interval_count",
billingUnits: "billing_units",
billingMethod: "billing_method",
maxPurchase: "max_purchase",
});
}),
);
export function attachItemPriceToJSON(
attachItemPrice: AttachItemPrice,
): string {
return JSON.stringify(AttachItemPrice$outboundSchema.parse(attachItemPrice));
}
/** @internal */
export const AttachItemOnIncrease$outboundSchema: z.ZodMiniEnum<
typeof AttachItemOnIncrease
> = z.enum(AttachItemOnIncrease);
/** @internal */
export const AttachItemOnDecrease$outboundSchema: z.ZodMiniEnum<
typeof AttachItemOnDecrease
> = z.enum(AttachItemOnDecrease);
/** @internal */
export type AttachItemProration$Outbound = {
on_increase: string;
on_decrease: string;
};
/** @internal */
export const AttachItemProration$outboundSchema: z.ZodMiniType<
AttachItemProration$Outbound,
AttachItemProration
> = z.pipe(
z.object({
onIncrease: AttachItemOnIncrease$outboundSchema,
onDecrease: AttachItemOnDecrease$outboundSchema,
}),
z.transform((v) => {
return remap$(v, {
onIncrease: "on_increase",
onDecrease: "on_decrease",
});
}),
);
export function attachItemProrationToJSON(
attachItemProration: AttachItemProration,
): string {
return JSON.stringify(
AttachItemProration$outboundSchema.parse(attachItemProration),
);
}
/** @internal */
export const AttachItemExpiryDurationType$outboundSchema: z.ZodMiniEnum<
typeof AttachItemExpiryDurationType
> = z.enum(AttachItemExpiryDurationType);
/** @internal */
export type AttachItemRollover$Outbound = {
max?: number | undefined;
max_percentage?: number | undefined;
expiry_duration_type: string;
expiry_duration_length?: number | undefined;
};
/** @internal */
export const AttachItemRollover$outboundSchema: z.ZodMiniType<
AttachItemRollover$Outbound,
AttachItemRollover
> = z.pipe(
z.object({
max: z.optional(z.number()),
maxPercentage: z.optional(z.number()),
expiryDurationType: AttachItemExpiryDurationType$outboundSchema,
expiryDurationLength: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
maxPercentage: "max_percentage",
expiryDurationType: "expiry_duration_type",
expiryDurationLength: "expiry_duration_length",
});
}),
);
export function attachItemRolloverToJSON(
attachItemRollover: AttachItemRollover,
): string {
return JSON.stringify(
AttachItemRollover$outboundSchema.parse(attachItemRollover),
);
}
/** @internal */
export type AttachItemPlanItem$Outbound = {
feature_id: string;
included?: number | undefined;
unlimited?: boolean | undefined;
reset?: AttachItemReset$Outbound | undefined;
price?: AttachItemPrice$Outbound | undefined;
proration?: AttachItemProration$Outbound | undefined;
rollover?: AttachItemRollover$Outbound | undefined;
};
/** @internal */
export const AttachItemPlanItem$outboundSchema: z.ZodMiniType<
AttachItemPlanItem$Outbound,
AttachItemPlanItem
> = z.pipe(
z.object({
featureId: z.string(),
included: z.optional(z.number()),
unlimited: z.optional(z.boolean()),
reset: z.optional(z.lazy(() => AttachItemReset$outboundSchema)),
price: z.optional(z.lazy(() => AttachItemPrice$outboundSchema)),
proration: z.optional(z.lazy(() => AttachItemProration$outboundSchema)),
rollover: z.optional(z.lazy(() => AttachItemRollover$outboundSchema)),
}),
z.transform((v) => {
return remap$(v, {
featureId: "feature_id",
});
}),
);
export function attachItemPlanItemToJSON(
attachItemPlanItem: AttachItemPlanItem,
): string {
return JSON.stringify(
AttachItemPlanItem$outboundSchema.parse(attachItemPlanItem),
);
}
/** @internal */
export const AttachAddItemResetInterval$outboundSchema: z.ZodMiniEnum<
typeof AttachAddItemResetInterval
> = z.enum(AttachAddItemResetInterval);
/** @internal */
export type AttachAddItemReset$Outbound = {
interval: string;
interval_count?: number | undefined;
};
/** @internal */
export const AttachAddItemReset$outboundSchema: z.ZodMiniType<
AttachAddItemReset$Outbound,
AttachAddItemReset
> = z.pipe(
z.object({
interval: AttachAddItemResetInterval$outboundSchema,
intervalCount: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
intervalCount: "interval_count",
});
}),
);
export function attachAddItemResetToJSON(
attachAddItemReset: AttachAddItemReset,
): string {
return JSON.stringify(
AttachAddItemReset$outboundSchema.parse(attachAddItemReset),
);
}
/** @internal */
export type AttachAddItemTo$Outbound = number | string;
/** @internal */
export const AttachAddItemTo$outboundSchema: z.ZodMiniType<
AttachAddItemTo$Outbound,
AttachAddItemTo
> = smartUnion([z.number(), z.string()]);
export function attachAddItemToToJSON(
attachAddItemTo: AttachAddItemTo,
): string {
return JSON.stringify(AttachAddItemTo$outboundSchema.parse(attachAddItemTo));
}
/** @internal */
export type AttachAddItemTier$Outbound = {
to: number | string;
amount?: number | undefined;
flat_amount?: number | undefined;
};
/** @internal */
export const AttachAddItemTier$outboundSchema: z.ZodMiniType<
AttachAddItemTier$Outbound,
AttachAddItemTier
> = z.pipe(
z.object({
to: smartUnion([z.number(), z.string()]),
amount: z.optional(z.number()),
flatAmount: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
flatAmount: "flat_amount",
});
}),
);
export function attachAddItemTierToJSON(
attachAddItemTier: AttachAddItemTier,
): string {
return JSON.stringify(
AttachAddItemTier$outboundSchema.parse(attachAddItemTier),
);
}
/** @internal */
export const AttachAddItemTierBehavior$outboundSchema: z.ZodMiniEnum<
typeof AttachAddItemTierBehavior
> = z.enum(AttachAddItemTierBehavior);
/** @internal */
export const AttachAddItemPriceInterval$outboundSchema: z.ZodMiniEnum<
typeof AttachAddItemPriceInterval
> = z.enum(AttachAddItemPriceInterval);
/** @internal */
export const AttachAddItemBillingMethod$outboundSchema: z.ZodMiniEnum<
typeof AttachAddItemBillingMethod
> = z.enum(AttachAddItemBillingMethod);
/** @internal */
export type AttachAddItemPrice$Outbound = {
amount?: number | undefined;
tiers?: Array<AttachAddItemTier$Outbound> | undefined;
tier_behavior?: string | undefined;
interval: string;
interval_count: number;
billing_units: number;
billing_method: string;
max_purchase?: number | undefined;
};
/** @internal */
export const AttachAddItemPrice$outboundSchema: z.ZodMiniType<
AttachAddItemPrice$Outbound,
AttachAddItemPrice
> = z.pipe(
z.object({
amount: z.optional(z.number()),
tiers: z.optional(z.array(z.lazy(() => AttachAddItemTier$outboundSchema))),
tierBehavior: z.optional(AttachAddItemTierBehavior$outboundSchema),
interval: AttachAddItemPriceInterval$outboundSchema,
intervalCount: z._default(z.number(), 1),
billingUnits: z._default(z.number(), 1),
billingMethod: AttachAddItemBillingMethod$outboundSchema,
maxPurchase: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
tierBehavior: "tier_behavior",
intervalCount: "interval_count",
billingUnits: "billing_units",
billingMethod: "billing_method",
maxPurchase: "max_purchase",
});
}),
);
export function attachAddItemPriceToJSON(
attachAddItemPrice: AttachAddItemPrice,
): string {
return JSON.stringify(
AttachAddItemPrice$outboundSchema.parse(attachAddItemPrice),
);
}
/** @internal */
export const AttachAddItemOnIncrease$outboundSchema: z.ZodMiniEnum<
typeof AttachAddItemOnIncrease
> = z.enum(AttachAddItemOnIncrease);
/** @internal */
export const AttachAddItemOnDecrease$outboundSchema: z.ZodMiniEnum<
typeof AttachAddItemOnDecrease
> = z.enum(AttachAddItemOnDecrease);
/** @internal */
export type AttachAddItemProration$Outbound = {
on_increase: string;
on_decrease: string;
};
/** @internal */
export const AttachAddItemProration$outboundSchema: z.ZodMiniType<
AttachAddItemProration$Outbound,
AttachAddItemProration
> = z.pipe(
z.object({
onIncrease: AttachAddItemOnIncrease$outboundSchema,
onDecrease: AttachAddItemOnDecrease$outboundSchema,
}),
z.transform((v) => {
return remap$(v, {
onIncrease: "on_increase",
onDecrease: "on_decrease",
});
}),
);
export function attachAddItemProrationToJSON(
attachAddItemProration: AttachAddItemProration,
): string {
return JSON.stringify(
AttachAddItemProration$outboundSchema.parse(attachAddItemProration),
);
}
/** @internal */
export const AttachAddItemExpiryDurationType$outboundSchema: z.ZodMiniEnum<
typeof AttachAddItemExpiryDurationType
> = z.enum(AttachAddItemExpiryDurationType);
/** @internal */
export type AttachAddItemRollover$Outbound = {
max?: number | undefined;
max_percentage?: number | undefined;
expiry_duration_type: string;
expiry_duration_length?: number | undefined;
};
/** @internal */
export const AttachAddItemRollover$outboundSchema: z.ZodMiniType<
AttachAddItemRollover$Outbound,
AttachAddItemRollover
> = z.pipe(
z.object({
max: z.optional(z.number()),
maxPercentage: z.optional(z.number()),
expiryDurationType: AttachAddItemExpiryDurationType$outboundSchema,
expiryDurationLength: z.optional(z.number()),
}),
z.transform((v) => {
return remap$(v, {
maxPercentage: "max_percentage",
expiryDurationType: "expiry_duration_type",
expiryDurationLength: "expiry_duration_length",
});
}),
);
export function attachAddItemRolloverToJSON(
attachAddItemRollover: AttachAddItemRollover,
): string {
return JSON.stringify(
AttachAddItemRollover$outboundSchema.parse(attachAddItemRollover),
);
}
/** @internal */
export type AttachAddItemPlanItem$Outbound = {
feature_id: string;
included?: number | undefined;
unlimited?: boolean | undefined;
reset?: AttachAddItemReset$Outbound | undefined;
price?: AttachAddItemPrice$Outbound | undefined;
proration?: AttachAddItemProration$Outbound | undefined;
rollover?: AttachAddItemRollover$Outbound | undefined;
};
/** @internal */
export const AttachAddItemPlanItem$outboundSchema: z.ZodMiniType<
AttachAddItemPlanItem$Outbound,
AttachAddItemPlanItem
> = z.pipe(
z.object({
featureId: z.string(),
included: z.optional(z.number()),
unlimited: z.optional(z.boolean()),
reset: z.optional(z.lazy(() => AttachAddItemReset$outboundSchema)),
price: z.optional(z.lazy(() => AttachAddItemPrice$outboundSchema)),
proration: z.optional(z.lazy(() => AttachAddItemProration$outboundSchema)),
rollover: z.optional(z.lazy(() => AttachAddItemRollover$outboundSchema)),
}),
z.transform((v) => {
return remap$(v, {
featureId: "feature_id",
});
}),
);
export function attachAddItemPlanItemToJSON(
attachAddItemPlanItem: AttachAddItemPlanItem,
): string {
return JSON.stringify(
AttachAddItemPlanItem$outboundSchema.parse(attachAddItemPlanItem),
);
}
/** @internal */
export const AttachRemoveItemBillingMethod$outboundSchema: z.ZodMiniEnum<
typeof AttachRemoveItemBillingMethod
> = z.enum(AttachRemoveItemBillingMethod);
/** @internal */
export const AttachRemoveItemInterval$outboundSchema: z.ZodMiniEnum<
typeof AttachRemoveItemInterval
> = z.enum(AttachRemoveItemInterval);
/** @internal */
export type AttachPlanItemFilter$Outbound = {
feature_id?: string | undefined;
billing_method?: string | undefined;
interval?: string | undefined;
};
/** @internal */
export const AttachPlanItemFilter$outboundSchema: z.ZodMiniType<
AttachPlanItemFilter$Outbound,
AttachPlanItemFilter
> = z.pipe(
z.object({
featureId: z.optional(z.string()),
billingMethod: z.optional(AttachRemoveItemBillingMethod$outboundSchema),
interval: z.optional(AttachRemoveItemInterval$outboundSchema),
}),
z.transform((v) => {
return remap$(v, {
featureId: "feature_id",
billingMethod: "billing_method",
});
}),
);
export function attachPlanItemFilterToJSON(
attachPlanItemFilter: AttachPlanItemFilter,
): string {
return JSON.stringify(
AttachPlanItemFilter$outboundSchema.parse(attachPlanItemFilter),
);
}
/** @internal */
export const AttachDurationType$outboundSchema: z.ZodMiniEnum<
typeof AttachDurationType
> = z.enum(AttachDurationType);
/** @internal */
export const AttachOnEnd$outboundSchema: z.ZodMiniEnum<typeof AttachOnEnd> = z
.enum(AttachOnEnd);
/** @internal */
export type AttachFreeTrialParams$Outbound = {
duration_length: number;
duration_type: string;
card_required: boolean;
on_end?: string | undefined;
};
/** @internal */
export const AttachFreeTrialParams$outboundSchema: z.ZodMiniType<
AttachFreeTrialParams$Outbound,
AttachFreeTrialParams
> = z.pipe(
z.object({
durationLength: z.number(),
durationType: z._default(AttachDurationType$outboundSchema, "month"),
cardRequired: z._default(z.boolean(), true),
onEnd: z.optional(AttachOnEnd$outboundSchema),
}),
z.transform((v) => {
return remap$(v, {
durationLength: "duration_length",
durationType: "duration_type",
cardRequired: "card_required",
onEnd: "on_end",
});
}),
);
export function attachFreeTrialParamsToJSON(
attachFreeTrialParams: AttachFreeTrialParams,
): string {
return JSON.stringify(
AttachFreeTrialParams$outboundSchema.parse(attachFreeTrialParams),
);
}
/** @internal */
export type AttachCustomize$Outbound = {
price?: AttachBasePrice$Outbound | null | undefined;
items?: Array<AttachItemPlanItem$Outbound> | undefined;
add_items?: Array<AttachAddItemPlanItem$Outbound> | undefined;
remove_items?: Array<AttachPlanItemFilter$Outbound> | undefined;
free_trial?: AttachFreeTrialParams$Outbound | null | undefined;
};
/** @internal */
export const AttachCustomize$outboundSchema: z.ZodMiniType<
AttachCustomize$Outbound,
AttachCustomize
> = z.pipe(
z.object({
price: z.optional(z.nullable(z.lazy(() => AttachBasePrice$outboundSchema))),
items: z.optional(z.array(z.lazy(() => AttachItemPlanItem$outboundSchema))),
addItems: z.optional(
z.array(z.lazy(() => AttachAddItemPlanItem$outboundSchema)),
),
removeItems: z.optional(
z.array(z.lazy(() => AttachPlanItemFilter$outboundSchema)),
),
freeTrial: z.optional(
z.nullable(z.lazy(() => AttachFreeTrialParams$outboundSchema)),
),
}),
z.transform((v) => {
return remap$(v, {
addItems: "add_items",
removeItems: "remove_items",
freeTrial: "free_trial",
});
}),
);
export function attachCustomizeToJSON(
attachCustomize: AttachCustomize,
): string {
return JSON.stringify(AttachCustomize$outboundSchema.parse(attachCustomize));
}
/** @internal */
export type AttachInvoiceMode$Outbound = {
enabled: boolean;
enable_plan_immediately: boolean;
finalize: boolean;
};
/** @internal */
export const AttachInvoiceMode$outboundSchema: z.ZodMiniType<
AttachInvoiceMode$Outbound,
AttachInvoiceMode
> = z.pipe(
z.object({
enabled: z.boolean(),
enablePlanImmediately: z._default(z.boolean(), false),
finalize: z._default(z.boolean(), true),
}),
z.transform((v) => {
return remap$(v, {
enablePlanImmediately: "enable_plan_immediately",
});
}),
);
export function attachInvoiceModeToJSON(
attachInvoiceMode: AttachInvoiceMode,
): string {
return JSON.stringify(
AttachInvoiceMode$outboundSchema.parse(attachInvoiceMode),
);
}
/** @internal */
export const AttachProrationBehavior$outboundSchema: z.ZodMiniEnum<
typeof AttachProrationBehavior
> = z.enum(AttachProrationBehavior);
/** @internal */
export const AttachRedirectMode$outboundSchema: z.ZodMiniEnum<
typeof AttachRedirectMode
> = z.enum(AttachRedirectMode);
/** @internal */
export type AttachAttachDiscount$Outbound = {
reward_id?: string | undefined;
promotion_code?: string | undefined;
};
/** @internal */
export const AttachAttachDiscount$outboundSchema: z.ZodMiniType<
AttachAttachDiscount$Outbound,
AttachAttachDiscount
> = z.pipe(
z.object({
rewardId: z.optional(z.string()),
promotionCode: z.optional(z.string()),
}),
z.transform((v) => {
return remap$(v, {
rewardId: "reward_id",
promotionCode: "promotion_code",
});
}),
);
export function attachAttachDiscountToJSON(
attachAttachDiscount: AttachAttachDiscount,
): string {
return JSON.stringify(
AttachAttachDiscount$outboundSchema.parse(attachAttachDiscount),
);
}
/** @internal */
export const AttachPlanSchedule$outboundSchema: z.ZodMiniEnum<
typeof AttachPlanSchedule
> = z.enum(AttachPlanSchedule);
/** @internal */
export type AttachCustomLineItem$Outbound = {
amount: number;
description: string;
};
/** @internal */
export const AttachCustomLineItem$outboundSchema: z.ZodMiniType<
AttachCustomLineItem$Outbound,
AttachCustomLineItem
> = z.object({
amount: z.number(),
description: z.string(),
});
export function attachCustomLineItemToJSON(
attachCustomLineItem: AttachCustomLineItem,
): string {
return JSON.stringify(
AttachCustomLineItem$outboundSchema.parse(attachCustomLineItem),
);
}
/** @internal */
export type AttachCarryOverBalances$Outbound = {
enabled: boolean;
feature_ids?: Array<string> | undefined;
};
/** @internal */
export const AttachCarryOverBalances$outboundSchema: z.ZodMiniType<
AttachCarryOverBalances$Outbound,
AttachCarryOverBalances
> = z.pipe(
z.object({
enabled: z.boolean(),
featureIds: z.optional(z.array(z.string())),
}),
z.transform((v) => {
return remap$(v, {
featureIds: "feature_ids",
});
}),
);
export function attachCarryOverBalancesToJSON(
attachCarryOverBalances: AttachCarryOverBalances,
): string {
return JSON.stringify(
AttachCarryOverBalances$outboundSchema.parse(attachCarryOverBalances),
);
}
/** @internal */
export type AttachCarryOverUsages$Outbound = {
enabled: boolean;
feature_ids?: Array<string> | undefined;
};
/** @internal */
export const AttachCarryOverUsages$outboundSchema: z.ZodMiniType<
AttachCarryOverUsages$Outbound,
AttachCarryOverUsages
> = z.pipe(
z.object({
enabled: z.boolean(),
featureIds: z.optional(z.array(z.string())),
}),
z.transform((v) => {
return remap$(v, {
featureIds: "feature_ids",
});
}),
);
export function attachCarryOverUsagesToJSON(
attachCarryOverUsages: AttachCarryOverUsages,
): string {
return JSON.stringify(
AttachCarryOverUsages$outboundSchema.parse(attachCarryOverUsages),
);
}
/** @internal */
export type AttachParams$Outbound = {
customer_id: string;
entity_id?: string | undefined;
plan_id: string;
feature_quantities?: Array<AttachFeatureQuantity$Outbound> | undefined;
version?: number | undefined;
customize?: AttachCustomize$Outbound | undefined;
invoice_mode?: AttachInvoiceMode$Outbound | undefined;
proration_behavior?: string | undefined;
redirect_mode: string;
subscription_id?: string | undefined;
discounts?: Array<AttachAttachDiscount$Outbound> | undefined;
success_url?: string | undefined;
new_billing_subscription?: boolean | undefined;
billing_cycle_anchor?: "now" | undefined;
plan_schedule?: string | undefined;
starts_at?: number | undefined;
ends_at?: number | undefined;
checkout_session_params?: { [k: string]: any } | undefined;
custom_line_items?: Array<AttachCustomLineItem$Outbound> | undefined;
processor_subscription_id?: string | undefined;
carry_over_balances?: AttachCarryOverBalances$Outbound | undefined;
carry_over_usages?: AttachCarryOverUsages$Outbound | undefined;
metadata?: { [k: string]: string } | undefined;
no_billing_changes?: boolean | undefined;
enable_plan_immediately?: boolean | undefined;
tax_rate_id?: string | undefined;
};
/** @internal */
export const AttachParams$outboundSchema: z.ZodMiniType<
AttachParams$Outbound,
AttachParams
> = z.pipe(
z.object({
customerId: z.string(),
entityId: z.optional(z.string()),
planId: z.string(),
featureQuantities: z.optional(
z.array(z.lazy(() => AttachFeatureQuantity$outboundSchema)),
),
version: z.optional(z.number()),
customize: z.optional(z.lazy(() => AttachCustomize$outboundSchema)),
invoiceMode: z.optional(z.lazy(() => AttachInvoiceMode$outboundSchema)),
prorationBehavior: z.optional(AttachProrationBehavior$outboundSchema),
redirectMode: z._default(AttachRedirectMode$outboundSchema, "if_required"),
subscriptionId: z.optional(z.string()),
discounts: z.optional(
z.array(z.lazy(() => AttachAttachDiscount$outboundSchema)),
),
successUrl: z.optional(z.string()),
newBillingSubscription: z.optional(z.boolean()),
billingCycleAnchor: z.optional(z.literal("now")),
planSchedule: z.optional(AttachPlanSchedule$outboundSchema),
startsAt: z.optional(z.int()),
endsAt: z.optional(z.int()),
checkoutSessionParams: z.optional(z.record(z.string(), z.any())),
customLineItems: z.optional(
z.array(z.lazy(() => AttachCustomLineItem$outboundSchema)),
),
processorSubscriptionId: z.optional(z.string()),
carryOverBalances: z.optional(
z.lazy(() => AttachCarryOverBalances$outboundSchema),
),
carryOverUsages: z.optional(
z.lazy(() => AttachCarryOverUsages$outboundSchema),
),
metadata: z.optional(z.record(z.string(), z.string())),
noBillingChanges: z.optional(z.boolean()),
enablePlanImmediately: z.optional(z.boolean()),
taxRateId: z.optional(z.string()),
}),
z.transform((v) => {
return remap$(v, {
customerId: "customer_id",
entityId: "entity_id",
planId: "plan_id",
featureQuantities: "feature_quantities",
invoiceMode: "invoice_mode",
prorationBehavior: "proration_behavior",
redirectMode: "redirect_mode",
subscriptionId: "subscription_id",
successUrl: "success_url",
newBillingSubscription: "new_billing_subscription",
billingCycleAnchor: "billing_cycle_anchor",
planSchedule: "plan_schedule",
startsAt: "starts_at",
endsAt: "ends_at",
checkoutSessionParams: "checkout_session_params",
customLineItems: "custom_line_items",
processorSubscriptionId: "processor_subscription_id",
carryOverBalances: "carry_over_balances",
carryOverUsages: "carry_over_usages",
noBillingChanges: "no_billing_changes",
enablePlanImmediately: "enable_plan_immediately",
taxRateId: "tax_rate_id",
});
}),
);
export function attachParamsToJSON(attachParams: AttachParams): string {
return JSON.stringify(AttachParams$outboundSchema.parse(attachParams));
}
/** @internal */
export const AttachInvoice$inboundSchema: z.ZodMiniType<
AttachInvoice,
unknown
> = z.pipe(
z.object({
status: types.nullable(types.string()),
stripe_id: types.string(),
total: types.number(),
currency: types.string(),
hosted_invoice_url: types.nullable(types.string()),
}),
z.transform((v) => {
return remap$(v, {
"stripe_id": "stripeId",
"hosted_invoice_url": "hostedInvoiceUrl",
});
}),
);
export function attachInvoiceFromJSON(
jsonString: string,
): SafeParseResult<AttachInvoice, SDKValidationError> {
return safeParse(
jsonString,
(x) => AttachInvoice$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'AttachInvoice' from JSON`,
);
}
/** @internal */
export const AttachCode$inboundSchema: z.ZodMiniType<AttachCode, unknown> =
openEnums.inboundSchema(AttachCode);
/** @internal */
export const AttachRequiredAction$inboundSchema: z.ZodMiniType<
AttachRequiredAction,
unknown
> = z.object({
code: AttachCode$inboundSchema,
reason: types.string(),
});
export function attachRequiredActionFromJSON(
jsonString: string,
): SafeParseResult<AttachRequiredAction, SDKValidationError> {
return safeParse(
jsonString,
(x) => AttachRequiredAction$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'AttachRequiredAction' from JSON`,
);
}
/** @internal */
export const AttachResponse$inboundSchema: z.ZodMiniType<
AttachResponse,
unknown
> = z.pipe(
z.object({
customer_id: types.string(),
entity_id: types.optional(types.string()),
invoice: types.optional(z.lazy(() => AttachInvoice$inboundSchema)),
payment_url: types.nullable(types.string()),
required_action: types.optional(
z.lazy(() => AttachRequiredAction$inboundSchema),
),
}),
z.transform((v) => {
return remap$(v, {
"customer_id": "customerId",
"entity_id": "entityId",
"payment_url": "paymentUrl",
"required_action": "requiredAction",
});
}),
);
export function attachResponseFromJSON(
jsonString: string,
): SafeParseResult<AttachResponse, SDKValidationError> {
return safeParse(
jsonString,
(x) => AttachResponse$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'AttachResponse' from JSON`,
);
}