// Products: what you sell. import { collect, request, segment } from "./stripe" import type { Client, Deleted, Page, RequestOptions, StripeError } from "./stripe" /// A product. `default_price` is expandable: `idOf` gives its id. export type Product = { id: string, name?: string, active?: boolean, description?: string, images?: string[], metadata?: json, default_price?: json, tax_code?: json, unit_label?: string, url?: string, created?: float, updated?: float, livemode?: boolean, } /// The fields of a product you can set. `extra` holds any field this type doesn't list. export type ProductParams = { name?: string, id?: string, active?: boolean, description?: string, images?: string[], metadata?: Map, default_price?: string, tax_code?: string, unit_label?: string, url?: string, extra?: json, } /// What to list. export type ProductListParams = { active?: boolean, ids?: string[], url?: string, limit?: float, starting_after?: string, ending_before?: string, extra?: json, } /// Creates a product. export async fn create( c: Client, params: ProductParams, options: RequestOptions = {}, ): Product ! StripeError { return try await request(c, "POST", "/v1/products", params, options, j => try j as Product) } /// Gets a product by id. export async fn retrieve( c: Client, id: string, options: RequestOptions = {}, ): Product ! StripeError { return try await request( c, "GET", `/v1/products/${segment(id)}`, null, options, j => try j as Product, ) } /// Changes the fields given. export async fn update( c: Client, id: string, params: ProductParams, options: RequestOptions = {}, ): Product ! StripeError { return try await request( c, "POST", `/v1/products/${segment(id)}`, params, options, j => try j as Product, ) } /// Deletes a product that has no prices. export async fn remove(c: Client, id: string, options: RequestOptions = {}): Deleted ! StripeError { return try await request( c, "DELETE", `/v1/products/${segment(id)}`, null, options, j => try j as Deleted, ) } /// One page of products. export async fn list(c: Client, params: ProductListParams = {}, options: RequestOptions = {}): Page< Product, > ! StripeError { return try await request(c, "GET", "/v1/products", params, options, j => try j as Page) } /// Every product matching `params`, up to `max`. export async fn listAll( c: Client, params: ProductListParams = {}, options: RequestOptions = {}, max: int = 10000, ): Product[] ! StripeError { return try await collect( c, "/v1/products", params, options, j => try j as Page, x => x.id, max, ) }