/* * 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 { smartUnion } from "../../types/smartUnion.js"; import { AddressInput, AddressInput$Outbound, AddressInput$outboundSchema, } from "./addressinput.js"; import { PresentmentCurrency, PresentmentCurrency$outboundSchema, } from "./presentmentcurrency.js"; import { TrialInterval, TrialInterval$outboundSchema, } from "./trialinterval.js"; export type CheckoutUpdateCustomFieldData = string | number | boolean | Date; export type CheckoutUpdateMetadata = string | number | number | boolean; export type CheckoutUpdateCustomerMetadata = string | number | number | boolean; /** * Update an existing checkout session using an access token. */ export type CheckoutUpdate = { /** * Key-value object storing custom field values. */ customFieldData?: | { [k: string]: string | number | boolean | Date | null } | undefined; /** * ID of the product to checkout. Must be present in the checkout's product list. */ productId?: string | null | undefined; /** * ID of the product price to checkout. Must correspond to a price present in the checkout's product list. * * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible. */ productPriceId?: string | null | undefined; amount?: number | null | undefined; /** * Number of seats for seat-based pricing. */ seats?: number | null | undefined; isBusinessCustomer?: boolean | null | undefined; customerName?: string | null | undefined; customerEmail?: string | null | undefined; customerBillingName?: string | null | undefined; customerBillingAddress?: AddressInput | null | undefined; customerTaxId?: string | null | undefined; locale?: string | null | undefined; /** * The interval unit for the trial period. */ trialInterval?: TrialInterval | null | undefined; /** * The number of interval units for the trial period. */ trialIntervalCount?: number | null | undefined; /** * Key-value object allowing you to store additional information. * * @remarks * * The key must be a string with a maximum length of **40 characters**. * The value must be either: * * * A string with a maximum length of **500 characters** * * An integer * * A floating-point number * * A boolean * * You can store up to **50 key-value pairs**. */ metadata?: { [k: string]: string | number | number | boolean } | undefined; currency?: PresentmentCurrency | null | undefined; /** * ID of the discount to apply to the checkout. */ discountId?: string | null | undefined; /** * Whether to allow the customer to apply discount codes. If you apply a discount through `discount_id`, it'll still be applied, but the customer won't be able to change it. */ allowDiscountCodes?: boolean | null | undefined; /** * Whether to require the customer to fill their full billing address, instead of just the country. Customers in the US will always be required to fill their full address, regardless of this setting. If you preset the billing address, this setting will be automatically set to `true`. */ requireBillingAddress?: boolean | null | undefined; /** * Whether to enable the trial period for the checkout session. If `false`, the trial period will be disabled, even if the selected product has a trial configured. */ allowTrial?: boolean | null | undefined; customerIpAddress?: string | null | undefined; /** * Key-value object allowing you to store additional information that'll be copied to the created customer. * * @remarks * * The key must be a string with a maximum length of **40 characters**. * The value must be either: * * * A string with a maximum length of **500 characters** * * An integer * * A floating-point number * * A boolean * * You can store up to **50 key-value pairs**. */ customerMetadata?: | { [k: string]: string | number | number | boolean } | null | undefined; /** * URL where the customer will be redirected after a successful payment.You can add the `checkout_id={CHECKOUT_ID}` query parameter to retrieve the checkout session id. */ successUrl?: string | null | undefined; /** * When set, a back button will be shown in the checkout to return to this URL. */ returnUrl?: string | null | undefined; /** * If you plan to embed the checkout session, set this to the Origin of the embedding page. It'll allow the Polar iframe to communicate with the parent page. */ embedOrigin?: string | null | undefined; }; /** @internal */ export type CheckoutUpdateCustomFieldData$Outbound = | string | number | boolean | string; /** @internal */ export const CheckoutUpdateCustomFieldData$outboundSchema: z.ZodMiniType< CheckoutUpdateCustomFieldData$Outbound, CheckoutUpdateCustomFieldData > = smartUnion([ z.string(), z.int(), z.boolean(), z.pipe(z.date(), z.transform(v => v.toISOString())), ]); export function checkoutUpdateCustomFieldDataToJSON( checkoutUpdateCustomFieldData: CheckoutUpdateCustomFieldData, ): string { return JSON.stringify( CheckoutUpdateCustomFieldData$outboundSchema.parse( checkoutUpdateCustomFieldData, ), ); } /** @internal */ export type CheckoutUpdateMetadata$Outbound = | string | number | number | boolean; /** @internal */ export const CheckoutUpdateMetadata$outboundSchema: z.ZodMiniType< CheckoutUpdateMetadata$Outbound, CheckoutUpdateMetadata > = smartUnion([z.string(), z.int(), z.number(), z.boolean()]); export function checkoutUpdateMetadataToJSON( checkoutUpdateMetadata: CheckoutUpdateMetadata, ): string { return JSON.stringify( CheckoutUpdateMetadata$outboundSchema.parse(checkoutUpdateMetadata), ); } /** @internal */ export type CheckoutUpdateCustomerMetadata$Outbound = | string | number | number | boolean; /** @internal */ export const CheckoutUpdateCustomerMetadata$outboundSchema: z.ZodMiniType< CheckoutUpdateCustomerMetadata$Outbound, CheckoutUpdateCustomerMetadata > = smartUnion([z.string(), z.int(), z.number(), z.boolean()]); export function checkoutUpdateCustomerMetadataToJSON( checkoutUpdateCustomerMetadata: CheckoutUpdateCustomerMetadata, ): string { return JSON.stringify( CheckoutUpdateCustomerMetadata$outboundSchema.parse( checkoutUpdateCustomerMetadata, ), ); } /** @internal */ export type CheckoutUpdate$Outbound = { custom_field_data?: | { [k: string]: string | number | boolean | string | null } | undefined; product_id?: string | null | undefined; product_price_id?: string | null | undefined; amount?: number | null | undefined; seats?: number | null | undefined; is_business_customer?: boolean | null | undefined; customer_name?: string | null | undefined; customer_email?: string | null | undefined; customer_billing_name?: string | null | undefined; customer_billing_address?: AddressInput$Outbound | null | undefined; customer_tax_id?: string | null | undefined; locale?: string | null | undefined; trial_interval?: string | null | undefined; trial_interval_count?: number | null | undefined; metadata?: { [k: string]: string | number | number | boolean } | undefined; currency?: string | null | undefined; discount_id?: string | null | undefined; allow_discount_codes?: boolean | null | undefined; require_billing_address?: boolean | null | undefined; allow_trial?: boolean | null | undefined; customer_ip_address?: string | null | undefined; customer_metadata?: | { [k: string]: string | number | number | boolean } | null | undefined; success_url?: string | null | undefined; return_url?: string | null | undefined; embed_origin?: string | null | undefined; }; /** @internal */ export const CheckoutUpdate$outboundSchema: z.ZodMiniType< CheckoutUpdate$Outbound, CheckoutUpdate > = z.pipe( z.object({ customFieldData: z.optional( z.record( z.string(), z.nullable( smartUnion([ z.string(), z.int(), z.boolean(), z.pipe(z.date(), z.transform(v => v.toISOString())), ]), ), ), ), productId: z.optional(z.nullable(z.string())), productPriceId: z.optional(z.nullable(z.string())), amount: z.optional(z.nullable(z.int())), seats: z.optional(z.nullable(z.int())), isBusinessCustomer: z.optional(z.nullable(z.boolean())), customerName: z.optional(z.nullable(z.string())), customerEmail: z.optional(z.nullable(z.string())), customerBillingName: z.optional(z.nullable(z.string())), customerBillingAddress: z.optional(z.nullable(AddressInput$outboundSchema)), customerTaxId: z.optional(z.nullable(z.string())), locale: z.optional(z.nullable(z.string())), trialInterval: z.optional(z.nullable(TrialInterval$outboundSchema)), trialIntervalCount: z.optional(z.nullable(z.int())), metadata: z.optional( z.record( z.string(), smartUnion([z.string(), z.int(), z.number(), z.boolean()]), ), ), currency: z.optional(z.nullable(PresentmentCurrency$outboundSchema)), discountId: z.optional(z.nullable(z.string())), allowDiscountCodes: z.optional(z.nullable(z.boolean())), requireBillingAddress: z.optional(z.nullable(z.boolean())), allowTrial: z.optional(z.nullable(z.boolean())), customerIpAddress: z.optional(z.nullable(z.string())), customerMetadata: z.optional( z.nullable( z.record( z.string(), smartUnion([z.string(), z.int(), z.number(), z.boolean()]), ), ), ), successUrl: z.optional(z.nullable(z.string())), returnUrl: z.optional(z.nullable(z.string())), embedOrigin: z.optional(z.nullable(z.string())), }), z.transform((v) => { return remap$(v, { customFieldData: "custom_field_data", productId: "product_id", productPriceId: "product_price_id", isBusinessCustomer: "is_business_customer", customerName: "customer_name", customerEmail: "customer_email", customerBillingName: "customer_billing_name", customerBillingAddress: "customer_billing_address", customerTaxId: "customer_tax_id", trialInterval: "trial_interval", trialIntervalCount: "trial_interval_count", discountId: "discount_id", allowDiscountCodes: "allow_discount_codes", requireBillingAddress: "require_billing_address", allowTrial: "allow_trial", customerIpAddress: "customer_ip_address", customerMetadata: "customer_metadata", successUrl: "success_url", returnUrl: "return_url", embedOrigin: "embed_origin", }); }), ); export function checkoutUpdateToJSON(checkoutUpdate: CheckoutUpdate): string { return JSON.stringify(CheckoutUpdate$outboundSchema.parse(checkoutUpdate)); }