// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as SubscriptionsAPI from './subscriptions'; import { SubscriptionCancelParams, SubscriptionCancelResponse, SubscriptionListForSessionParams, SubscriptionListForSessionResponse, Subscriptions, } from './subscriptions'; import * as TransactionsAPI from './transactions'; import { TransactionListForSessionParams, TransactionListForSessionResponse, TransactionListParams, TransactionListResponse, TransactionRefundParams, TransactionRefundResponse, Transactions, } from './transactions'; import { APIPromise } from '../../core/api-promise'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class CheckoutSessions extends APIResource { transactions: TransactionsAPI.Transactions = new TransactionsAPI.Transactions(this._client); subscriptions: SubscriptionsAPI.Subscriptions = new SubscriptionsAPI.Subscriptions(this._client); /** * Create a checkout session */ create( body: CheckoutSessionCreateParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.post('/checkout-sessions', { body, ...options }); } /** * Get a checkout session by ID */ retrieve(checkoutSessionID: string, options?: RequestOptions): APIPromise { return this._client.get(path`/checkout-sessions/${checkoutSessionID}`, options); } /** * Delete a checkout session */ delete(checkoutSessionID: string, options?: RequestOptions): APIPromise { return this._client.delete(path`/checkout-sessions/${checkoutSessionID}`, options); } /** * Create an embedded checkout session */ embedded( params: CheckoutSessionEmbeddedParams | null | undefined = undefined, options?: RequestOptions, ): APIPromise { const { body } = params ?? {}; return this._client.post('/checkout-sessions/embedded', { body: body, ...options }); } /** * Get subscriptions for a specific product */ getSubscriptions( productID: string, query: CheckoutSessionGetSubscriptionsParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.get(path`/checkout-sessions/${productID}/subscriptions`, { query, ...options }); } } export interface CheckoutSessionCreateResponse { data?: CheckoutSessionCreateResponse.Data; message?: string; status?: string; } export namespace CheckoutSessionCreateResponse { export interface Data { checkout_session_id?: number; payment_link?: string; } } export interface CheckoutSessionRetrieveResponse { data?: CheckoutSessionRetrieveResponse.Data; message?: string; status?: string; } export namespace CheckoutSessionRetrieveResponse { export interface Data { amount_cents?: number; expiration_date?: string | null; metadata?: { [key: string]: unknown }; product?: Data.Product; subscription?: Data.Subscription | null; success_url?: string; type?: 'subscription' | 'onetime_reusable' | 'onetime_non_reusable'; webhook_url?: string | null; } export namespace Data { export interface Product { id?: string; description?: string | null; title?: string; } export interface Subscription { auto_expire_after_x_periods?: number | null; free_trial_days?: number | null; frequency_days?: number; initial_fee?: number | null; initial_fee_days?: number | null; } } } export interface CheckoutSessionDeleteResponse { data?: Array; message?: string; status?: string; } export interface CheckoutSessionEmbeddedResponse { data?: CheckoutSessionEmbeddedResponse.Data; message?: string; status?: string; } export namespace CheckoutSessionEmbeddedResponse { export interface Data { id?: string; checkout_session_secret?: string; created_at?: string; } } export interface CheckoutSessionGetSubscriptionsResponse { data?: CheckoutSessionGetSubscriptionsResponse.Data; message?: string; status?: string; } export namespace CheckoutSessionGetSubscriptionsResponse { export interface Data { pagination?: Data.Pagination; subscriptions?: Array; } export namespace Data { export interface Pagination { current_page?: number; has_more?: boolean; per_page?: number; total_items?: number; total_pages?: number; } export interface Subscription { id?: string; country_code?: string | null; created_at?: string; email?: string | null; first_name?: string | null; last_name?: string | null; next_renewal_date?: string; phone?: string | null; subscription_status?: string; } } } export interface CheckoutSessionCreateParams { amount_cents?: number; application_fee?: number | null; expiration_date?: string | null; metadata?: { [key: string]: unknown }; product?: CheckoutSessionCreateParams.Product; subscription?: CheckoutSessionCreateParams.Subscription | null; success_url?: string; type?: 'subscription' | 'onetime_reusable' | 'onetime_non_reusable'; webhook_url?: string | null; } export namespace CheckoutSessionCreateParams { export interface Product { title: string; description?: string | null; } export interface Subscription { auto_expire_after_x_periods?: number | null; free_trial_days?: number | null; /** * Required if type is subscription */ frequency_days?: number; initial_fee?: number | null; initial_fee_days?: number | null; } } export interface CheckoutSessionEmbeddedParams { body?: unknown; } export interface CheckoutSessionGetSubscriptionsParams { /** * Page number for pagination */ page?: number; /** * Number of items per page */ per_page?: number; /** * Alternative way to specify the product ID */ product_id?: number; } CheckoutSessions.Transactions = Transactions; CheckoutSessions.Subscriptions = Subscriptions; export declare namespace CheckoutSessions { export { type CheckoutSessionCreateResponse as CheckoutSessionCreateResponse, type CheckoutSessionRetrieveResponse as CheckoutSessionRetrieveResponse, type CheckoutSessionDeleteResponse as CheckoutSessionDeleteResponse, type CheckoutSessionEmbeddedResponse as CheckoutSessionEmbeddedResponse, type CheckoutSessionGetSubscriptionsResponse as CheckoutSessionGetSubscriptionsResponse, type CheckoutSessionCreateParams as CheckoutSessionCreateParams, type CheckoutSessionEmbeddedParams as CheckoutSessionEmbeddedParams, type CheckoutSessionGetSubscriptionsParams as CheckoutSessionGetSubscriptionsParams, }; export { Transactions as Transactions, type TransactionListResponse as TransactionListResponse, type TransactionListForSessionResponse as TransactionListForSessionResponse, type TransactionRefundResponse as TransactionRefundResponse, type TransactionListParams as TransactionListParams, type TransactionListForSessionParams as TransactionListForSessionParams, type TransactionRefundParams as TransactionRefundParams, }; export { Subscriptions as Subscriptions, type SubscriptionCancelResponse as SubscriptionCancelResponse, type SubscriptionListForSessionResponse as SubscriptionListForSessionResponse, type SubscriptionCancelParams as SubscriptionCancelParams, type SubscriptionListForSessionParams as SubscriptionListForSessionParams, }; }