// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../core/resource'; import * as Shared from './shared'; import { APIPromise } from '../core/api-promise'; import { RequestOptions } from '../internal/request-options'; import { path } from '../internal/utils/path'; export class CheckoutSessions extends APIResource { /** * Create Checkout Session */ create( body: CheckoutSessionCreateParams, options?: RequestOptions, ): APIPromise { return this._client.post('/api/v1/checkout-sessions', { body, ...options }); } /** * Get Checkout Session */ retrieve(id: string, options?: RequestOptions): APIPromise { return this._client.get(path`/api/v1/checkout-sessions/${id}`, options); } /** * List Checkout Sessions */ list( query: CheckoutSessionListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.get('/api/v1/checkout-sessions', { query, ...options }); } } export interface ActivateSubscriptionCheckoutSessionClientSelectSchema { id: string; automaticallyUpdateSubscriptions: boolean | null; /** * Epoch milliseconds. */ createdAt: number; customerEmail: string | null; customerId: string | null; customerName: string | null; discountId: string | null; /** * Epoch milliseconds. */ expires: number; livemode: boolean; organizationId: string; outputName: string | null; priceId: string | null; pricingModelId: string; quantity: number; status: 'open' | 'pending' | 'succeeded' | 'failed' | 'expired'; targetSubscriptionId: string; type: 'activate_subscription'; /** * Epoch milliseconds. */ updatedAt: number; billingAddress?: Shared.BillingAddress | null; cancelUrl?: string | null; invoiceId?: null; /** * JSON object */ outputMetadata?: { [key: string]: string | number | boolean } | null; paymentMethodType?: 'card' | 'link' | 'us_bank_account' | 'sepa_debit' | null; /** * Whether to preserve the billing cycle anchor date in the case that the customer * already has an active subscription that renews. If not provided, defaults to * false. */ preserveBillingCycleAnchor?: boolean; purchaseId?: null; successUrl?: string | null; } export interface AddPaymentMethodCheckoutSessionClientSelectSchema { id: string; /** * Epoch milliseconds. */ createdAt: number; customerEmail: string | null; /** * The customer that the payment method will be added to as the default payment * method. */ customerId: string; customerName: string | null; discountId: string | null; /** * Epoch milliseconds. */ expires: number; invoiceId: string | null; livemode: boolean; organizationId: string; outputName: string | null; preserveBillingCycleAnchor: boolean; priceId: string | null; pricingModelId: string; purchaseId: string | null; quantity: number; status: 'open' | 'pending' | 'succeeded' | 'failed' | 'expired'; type: 'add_payment_method'; /** * Epoch milliseconds. */ updatedAt: number; /** * Whether to automatically update all current subscriptions to the new payment * method. Defaults to false. */ automaticallyUpdateSubscriptions?: boolean | null; billingAddress?: Shared.BillingAddress | null; cancelUrl?: string | null; /** * JSON object */ outputMetadata?: { [key: string]: string | number | boolean } | null; paymentMethodType?: 'card' | 'link' | 'us_bank_account' | 'sepa_debit' | null; successUrl?: string | null; /** * The subscription that the payment method will be added to as the default payment * method. */ targetSubscriptionId?: string | null; } export interface ProductCheckoutSessionClientSelectSchema { id: string; /** * Epoch milliseconds. */ createdAt: number; customerEmail: string | null; customerId: string | null; customerName: string | null; discountId: string | null; /** * Epoch milliseconds. */ expires: number; livemode: boolean; organizationId: string; outputName: string | null; priceId: string; pricingModelId: string; purchaseId: string | null; quantity: number; status: 'open' | 'pending' | 'succeeded' | 'failed' | 'expired'; type: 'product'; /** * Epoch milliseconds. */ updatedAt: number; /** * Omitted. */ automaticallyUpdateSubscriptions?: null; billingAddress?: Shared.BillingAddress | null; cancelUrl?: string | null; invoiceId?: null; /** * JSON object */ outputMetadata?: { [key: string]: string | number | boolean } | null; paymentMethodType?: 'card' | 'link' | 'us_bank_account' | 'sepa_debit' | null; /** * Whether to preserve the billing cycle anchor date in the case that the customer * already has an active subscription that renews. If not provided, defaults to * false. */ preserveBillingCycleAnchor?: boolean; successUrl?: string | null; /** * Omitted. */ targetSubscriptionId?: null; } export interface PurchaseCheckoutSessionClientSelectSchema { id: string; /** * Epoch milliseconds. */ createdAt: number; customerEmail: string | null; customerId: string | null; customerName: string | null; discountId: string | null; /** * Epoch milliseconds. */ expires: number; invoiceId: string | null; livemode: boolean; organizationId: string; outputName: string | null; priceId: string; pricingModelId: string; purchaseId: string; quantity: number; status: 'open' | 'pending' | 'succeeded' | 'failed' | 'expired'; type: 'purchase'; /** * Epoch milliseconds. */ updatedAt: number; /** * Omitted. */ automaticallyUpdateSubscriptions?: null; billingAddress?: Shared.BillingAddress | null; cancelUrl?: string | null; /** * JSON object */ outputMetadata?: { [key: string]: string | number | boolean } | null; paymentMethodType?: 'card' | 'link' | 'us_bank_account' | 'sepa_debit' | null; preserveBillingCycleAnchor?: boolean; successUrl?: string | null; /** * Omitted. */ targetSubscriptionId?: null; } export interface CheckoutSessionCreateResponse { /** * A time-limited checkout session, which captures the payment details needed to * create a subscription, or purchase, or pay a standalone invoice. */ checkoutSession: | PurchaseCheckoutSessionClientSelectSchema | ProductCheckoutSessionClientSelectSchema | AddPaymentMethodCheckoutSessionClientSelectSchema | ActivateSubscriptionCheckoutSessionClientSelectSchema; /** * The URL to redirect to complete the purchase */ url: string; } export interface CheckoutSessionRetrieveResponse { /** * A time-limited checkout session, which captures the payment details needed to * create a subscription, or purchase, or pay a standalone invoice. */ checkoutSession: | PurchaseCheckoutSessionClientSelectSchema | ProductCheckoutSessionClientSelectSchema | AddPaymentMethodCheckoutSessionClientSelectSchema | ActivateSubscriptionCheckoutSessionClientSelectSchema; /** * The URL to redirect to complete the purchase */ url: string; } export interface CheckoutSessionListResponse { data: Array< | PurchaseCheckoutSessionClientSelectSchema | ProductCheckoutSessionClientSelectSchema | AddPaymentMethodCheckoutSessionClientSelectSchema | ActivateSubscriptionCheckoutSessionClientSelectSchema >; hasMore: boolean; total: number; currentCursor?: string; nextCursor?: string; } export interface CheckoutSessionCreateParams { checkoutSession: | CheckoutSessionCreateParams.IdentifiedProductCheckoutSessionInput | CheckoutSessionCreateParams.AnonymousProductCheckoutSessionInput | CheckoutSessionCreateParams.ActivateSubscriptionCheckoutSessionInput | CheckoutSessionCreateParams.AddPaymentMethodCheckoutSessionInput; } export namespace CheckoutSessionCreateParams { export interface IdentifiedProductCheckoutSessionInput { /** * The URL to redirect to after the purchase is canceled or fails */ cancelUrl: string; /** * The id of the Customer for this purchase session, as defined in your system */ customerExternalId: string; /** * The URL to redirect to after the purchase is successful */ successUrl: string; type: 'product'; anonymous?: boolean; /** * JSON object */ outputMetadata?: { [key: string]: string | number | boolean } | null; /** * The name of the purchase or subscription created when this checkout session * succeeds. Ignored if the checkout session is of type `invoice`. */ outputName?: string; /** * Whether to preserve the billing cycle anchor date in the case that the customer * already has an active subscription that renews. If not provided, defaults to * false. */ preserveBillingCycleAnchor?: boolean; /** * The ID of the price the customer shall purchase. If not provided, priceSlug is * required. */ priceId?: string; /** * The slug of the price the customer shall purchase. If not provided, priceId is * required. */ priceSlug?: string; /** * The quantity of the purchase or subscription created when this checkout session * succeeds. Must be a positive integer. Defaults to 1 if not provided. */ quantity?: number; } export interface AnonymousProductCheckoutSessionInput { anonymous: true; /** * The URL to redirect to after the purchase is canceled or fails */ cancelUrl: string; /** * The URL to redirect to after the purchase is successful */ successUrl: string; type: 'product'; customerExternalId?: null; /** * JSON object */ outputMetadata?: { [key: string]: string | number | boolean } | null; /** * The name of the purchase or subscription created when this checkout session * succeeds. Ignored if the checkout session is of type `invoice`. */ outputName?: string; /** * Whether to preserve the billing cycle anchor date in the case that the customer * already has an active subscription that renews. If not provided, defaults to * false. */ preserveBillingCycleAnchor?: boolean; /** * The ID of the price the customer shall purchase. If not provided, priceSlug is * required. */ priceId?: string; /** * The slug of the price the customer shall purchase from the organization's * default pricing model. If not provided, priceId is required. */ priceSlug?: string; /** * The quantity of the purchase or subscription created when this checkout session * succeeds. Must be a positive integer. Defaults to 1 if not provided. */ quantity?: number; } export interface ActivateSubscriptionCheckoutSessionInput { /** * The URL to redirect to after the purchase is canceled or fails */ cancelUrl: string; /** * The id of the Customer for this purchase session, as defined in your system */ customerExternalId: string; /** * The URL to redirect to after the purchase is successful */ successUrl: string; targetSubscriptionId: string; type: 'activate_subscription'; /** * JSON object */ outputMetadata?: { [key: string]: string | number | boolean } | null; /** * The name of the purchase or subscription created when this checkout session * succeeds. Ignored if the checkout session is of type `invoice`. */ outputName?: string; /** * Whether to preserve the billing cycle anchor date in the case that the customer * already has an active subscription that renews. If not provided, defaults to * false. */ preserveBillingCycleAnchor?: boolean; } export interface AddPaymentMethodCheckoutSessionInput { /** * The URL to redirect to after the purchase is canceled or fails */ cancelUrl: string; /** * The id of the Customer for this purchase session, as defined in your system */ customerExternalId: string; /** * The URL to redirect to after the purchase is successful */ successUrl: string; type: 'add_payment_method'; /** * Whether to automatically update all current subscriptions to the new payment * method. Defaults to false. */ automaticallyUpdateSubscriptions?: boolean | null; /** * JSON object */ outputMetadata?: { [key: string]: string | number | boolean } | null; /** * The name of the purchase or subscription created when this checkout session * succeeds. Ignored if the checkout session is of type `invoice`. */ outputName?: string; /** * The id of the subscription that the payment method will be added to as the * default payment method. */ targetSubscriptionId?: string; } } export interface CheckoutSessionListParams { cursor?: string; limit?: string; } export declare namespace CheckoutSessions { export { type ActivateSubscriptionCheckoutSessionClientSelectSchema as ActivateSubscriptionCheckoutSessionClientSelectSchema, type AddPaymentMethodCheckoutSessionClientSelectSchema as AddPaymentMethodCheckoutSessionClientSelectSchema, type ProductCheckoutSessionClientSelectSchema as ProductCheckoutSessionClientSelectSchema, type PurchaseCheckoutSessionClientSelectSchema as PurchaseCheckoutSessionClientSelectSchema, type CheckoutSessionCreateResponse as CheckoutSessionCreateResponse, type CheckoutSessionRetrieveResponse as CheckoutSessionRetrieveResponse, type CheckoutSessionListResponse as CheckoutSessionListResponse, type CheckoutSessionCreateParams as CheckoutSessionCreateParams, type CheckoutSessionListParams as CheckoutSessionListParams, }; }