import {z} from 'zod' export type GetApiV1TaxCalculationsCalculationLineItemsArgs = {calculation: string, ending_before?: string | undefined, expand?: Array | undefined, limit?: number | undefined, starting_after?: string | undefined, body: Record}; export type GetApiV1TaxCalculationsCalculationLineItemsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const taxProductResourceJurisdiction = z.object({country: z.string().max(5000), display_name: z.string().max(5000), level: z.enum(["city", "country", "county", "district", "state"]), state: z.string().max(5000).nullable().optional()}); export const taxProductResourceLineItemTaxRateDetails = z.object({display_name: z.string().max(5000), percentage_decimal: z.string().max(5000), tax_type: z.enum(["admissions_tax", "amusement_tax", "attendance_tax", "communications_tax", "digital_excise_tax", "entertainment_tax", "gross_receipts_tax", "gst", "hospitality_tax", "hst", "igst", "jct", "lease_tax", "luxury_tax", "mass_transit_parking_tax", "parking_tax", "pst", "qst", "recycling_fee", "resort_tax", "retail_delivery_fee", "rst", "sales_tax", "service_tax", "tourism_tax", "utility_users_tax", "vat"])}); export const taxProductResourceLineItemTaxBreakdown = z.object({amount: z.number().int(), jurisdiction: taxProductResourceJurisdiction, sourcing: z.enum(["destination", "origin", "performance"]), tax_rate_details: taxProductResourceLineItemTaxRateDetails.nullable().optional(), taxability_reason: z.enum(["customer_exempt", "not_collecting", "not_subject_to_tax", "not_supported", "portion_product_exempt", "portion_reduced_rated", "portion_standard_rated", "product_exempt", "product_exempt_holiday", "proportionally_rated", "reduced_rated", "reverse_charge", "standard_rated", "taxable_basis_reduced", "zero_rated"]), taxable_amount: z.number().int()}); export const taxCalculationLineItem = z.object({amount: z.number().int(), amount_tax: z.number().int(), id: z.string().max(5000), livemode: z.boolean(), metadata: z.record(z.string(), z.string().max(500)).nullable().optional(), object: z.literal("tax.calculation_line_item"), performance_location: z.string().max(5000).nullable().optional(), product: z.string().max(5000).nullable().optional(), quantity: z.number().int(), reference: z.string().max(5000), tax_behavior: z.enum(["exclusive", "inclusive"]), tax_breakdown: z.array(taxProductResourceLineItemTaxBreakdown).nullable().optional(), tax_code: z.string().max(5000)}); export const getApiV1TaxCalculationsCalculationLineItemsResponse = z.object({data: z.array(taxCalculationLineItem), has_more: z.boolean(), object: z.literal("list"), url: z.string().max(5000)}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Retrieve a Calculation's line items * * GET /v1/tax/calculations/{calculation}/line_items * * Also accepts auth: bearerAuth */ export const getApiV1TaxCalculationsCalculationLineItems = async (args: GetApiV1TaxCalculationsCalculationLineItemsArgs, options?: GetApiV1TaxCalculationsCalculationLineItemsOptions) => { const {baseUrl = "https://api.stripe.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/json") if (args.ending_before != null) query.append("ending_before", String(args.ending_before)) for (const item of args.expand ?? []) query.append("expand", String(item)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/tax/calculations/${encodeURIComponent(String(args.calculation))}/line_items${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1TaxCalculationsCalculationLineItemsResponse, await res.json()) };