/** * Customer information for checkout. * If not provided, the authenticated user's email will be used automatically. */ interface CheckoutCustomer { /** Customer email address */ email?: string; } /** * Configuration for a text custom field. */ interface TextFieldConfig { /** Maximum character length */ maxLength?: number; /** Minimum character length */ minLength?: number; } /** * Configuration for a checkbox custom field. */ interface CheckboxFieldConfig { /** Label displayed next to the checkbox */ label?: string; } /** * A custom field to display on the checkout page. * Up to 3 custom fields can be added per checkout. * * @example * ```typescript * const field: CustomFieldInput = { * type: "text", * key: "company_name", * label: "Company Name", * optional: false, * text: { maxLength: 100 } * }; * ``` */ interface CustomFieldInput { /** Field type */ type: "text" | "checkbox"; /** Unique key for the field (max 200 chars) */ key: string; /** Display label (max 50 chars) */ label: string; /** Whether the field is optional */ optional?: boolean; /** Text field configuration (only for type "text") */ text?: TextFieldConfig; /** Checkbox field configuration (only for type "checkbox") */ checkbox?: CheckboxFieldConfig; } /** * Parameters for creating a Creem checkout session. * * @example * ```typescript * const { data, error } = await authClient.creem.createCheckout({ * productId: "prod_abc123", * units: 1, * successUrl: "/thank-you" * }); * ``` */ interface CreateCheckoutInput { /** * The Creem product ID to checkout. * You can find this in your Creem dashboard under Products. * * @example "prod_abc123" */ productId: string; /** * Idempotency key to prevent duplicate checkouts. * If provided, subsequent requests with the same requestId will return the same checkout. * * @example "checkout-user123-20240101" */ requestId?: string; /** * Number of units to purchase. * Must be a positive number. Defaults to 1 if not provided. * * Defaults to 1. * * @example 3 */ units?: number; /** * Discount code to apply to the checkout. * The code must exist and be active in your Creem dashboard. * * @example "SUMMER2024" */ discountCode?: string; /** * Customer information for the checkout. * If not provided, uses the authenticated user's email from the session. * * @example { email: "user@example.com" } */ customer?: CheckoutCustomer; /** * Custom fields to display on the checkout page (max 3). * Collect additional information from customers during checkout. * * @example * ```typescript * customFields: [ * { type: "text", key: "company", label: "Company Name", text: { maxLength: 100 } }, * { type: "checkbox", key: "terms", label: "Accept Terms" } * ] * ``` */ customFields?: CustomFieldInput[]; /** * @deprecated Use `customFields` instead. */ customField?: CustomFieldInput[]; /** * URL to redirect to after successful checkout. * If not provided, uses the defaultSuccessUrl from plugin options. * * @example "/thank-you" * @example "https://example.com/success" */ successUrl?: string; /** * Additional metadata to store with the checkout. * Automatically includes the authenticated user's ID as `referenceId` if available. * * @example { orderId: "12345", source: "web" } */ metadata?: Record; } /** * Response from creating a checkout session. */ interface CreateCheckoutResponse { /** * The checkout URL to redirect the user to. * This URL directs to Creem's hosted checkout page. */ url: string; /** * Indicates whether to redirect the user to the checkout URL. */ redirect: boolean; } /** * Parameters for creating a Creem customer portal session. * * @example * ```typescript * const { data, error } = await authClient.creem.createPortal({ * customerId: "cust_abc123" // optional * }); * ``` */ interface CreatePortalInput { /** * Creem customer ID to create portal for. * If not provided, uses the authenticated user's Creem customer ID from session. * * @example "cust_abc123" */ customerId?: string; } /** * Response from creating a customer portal session. */ interface CreatePortalResponse { /** * The customer portal URL to redirect the user to. * This URL directs to Creem's hosted customer portal where users can * manage their subscriptions, view invoices, and update payment methods. */ url: string; /** * Indicates whether to redirect the user to the portal URL. */ redirect: boolean; } /** * Parameters for retrieving a Creem subscription. * * @example * ```typescript * const { data, error } = await authClient.creem.retrieveSubscription({ * id: "sub_abc123" * }); * ``` */ interface RetrieveSubscriptionInput { /** * The subscription ID to retrieve. * You can get this from webhook events or from your database. * * @example "sub_abc123" */ id: string; } /** * Subscription status values from Creem API. */ type SubscriptionDataStatus = "active" | "canceled" | "unpaid" | "paused" | "trialing" | "scheduled_cancel"; /** * Subscription item from Creem API. */ interface SubscriptionItemData { /** Unique identifier */ id: string; /** Environment mode */ mode: "test" | "prod" | "sandbox"; /** Object type */ object: "subscription_item"; /** The product ID */ productId?: string; /** The price ID */ priceId?: string; /** Number of units */ units?: number; } /** * Creem subscription object returned from the API. */ interface SubscriptionData { /** Unique subscription identifier */ id: string; /** Environment mode */ mode: "test" | "prod" | "sandbox"; /** Object type */ object: "subscription"; /** The product associated with the subscription (ID or expanded object) */ product: { id: string; name: string; price: number; currency: string; [key: string]: unknown; } | string; /** The customer associated with the subscription (ID or expanded object) */ customer: { id: string; email: string; name?: string; [key: string]: unknown; } | string; /** Subscription items */ items?: SubscriptionItemData[]; /** The method used for collecting payments */ collectionMethod: "charge_automatically"; /** Current subscription status */ status: SubscriptionDataStatus; /** The ID of the last paid transaction */ lastTransactionId?: string; /** The date of the last paid transaction */ lastTransactionDate?: Date; /** The date when the next subscription transaction will be charged */ nextTransactionDate?: Date; /** The start date of the current subscription period */ currentPeriodStartDate: Date; /** The end date of the current subscription period */ currentPeriodEndDate: Date; /** The date when the subscription was canceled, if applicable */ canceledAt: Date | null; /** The date when the subscription was created */ createdAt: Date; /** The date when the subscription was last updated */ updatedAt: Date; /** The discount applied to the subscription */ discount?: object; /** Optional metadata */ metadata?: Record; } /** * Parameters for searching Creem transactions. * * @example * ```typescript * const { data, error } = await authClient.creem.searchTransactions({ * customerId: "cust_abc123", * pageSize: 50 * }); * ``` */ interface SearchTransactionsInput { /** * Customer ID to filter transactions by. * If not provided, uses the authenticated user's Creem customer ID from session. * * @example "cust_abc123" */ customerId?: string; /** * Page number for pagination. * Must be at least 1. * * Defaults to 1. * * @example 2 */ pageNumber?: number; /** * Number of transactions to return per page. * Must be a positive number. * * Defaults to 20. * * @example 50 */ pageSize?: number; /** * Product ID to filter transactions by. * * @example "prod_abc123" */ productId?: string; /** * Order ID to filter transactions by. * * @example "ord_abc123" */ orderId?: string; } /** * A single transaction object from Creem. */ interface TransactionData { /** Unique transaction identifier */ id: string; /** Environment mode */ mode: "test" | "prod" | "sandbox"; /** String representing the object's type */ object: "transaction"; /** The transaction amount in cents. 1000 = $10.00 */ amount: number; /** The amount the customer paid in cents. 1000 = $10.00 */ amountPaid?: number; /** The discount amount in cents. 1000 = $10.00 */ discountAmount?: number; /** Three-letter ISO currency code, in uppercase */ currency: string; /** The type of transaction: payment (one time) or invoice (subscription) */ type: "payment" | "invoice"; /** The ISO alpha-2 country code where tax is collected */ taxCountry?: string; /** The sale tax amount in cents. 1000 = $10.00 */ taxAmount?: number; /** Status of the transaction */ status: "pending" | "paid" | "refunded" | "partialRefund" | "chargedBack" | "uncollectible" | "declined" | "void"; /** The amount that has been refunded in cents. 1000 = $10.00 */ refundedAmount?: number | null; /** The order ID associated with the transaction */ order?: string; /** The subscription ID associated with the transaction */ subscription?: string; /** The customer ID associated with the transaction */ customer?: string; /** The description of the transaction */ description?: string; /** Start period for the invoice as timestamp */ periodStart?: number; /** End period for the invoice as timestamp */ periodEnd?: number; /** Creation date of the transaction as timestamp */ createdAt: number; } /** * Pagination details from Creem API. */ interface TransactionPagination { /** Total number of records matching the query */ totalRecords: number; /** Total number of pages available */ totalPages: number; /** The current page number */ currentPage: number; /** The next page number, or null if there is no next page */ nextPage: number | null; /** The previous page number, or null if there is no previous page */ prevPage: number | null; } /** * Response from searching transactions. */ interface SearchTransactionsResponse { /** * Array of transaction objects */ items: TransactionData[]; /** * Pagination details */ pagination: TransactionPagination; } export type { CheckboxFieldConfig as C, RetrieveSubscriptionInput as R, SearchTransactionsInput as S, TextFieldConfig as T, CheckoutCustomer as a, CreateCheckoutInput as b, CreateCheckoutResponse as c, CreatePortalInput as d, CreatePortalResponse as e, CustomFieldInput as f, SearchTransactionsResponse as g, SubscriptionData as h, TransactionData as i };