import {z} from 'zod' export type GetApiV1PaymentIntentsIntentAmountDetailsLineItemsArgs = {ending_before?: string | undefined, expand?: Array | undefined, intent: string, limit?: number | undefined, starting_after?: string | undefined, body: Record}; export type GetApiV1PaymentIntentsIntentAmountDetailsLineItemsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const paymentFlowsPrivatePaymentMethodsCardPaymentIntentAmountDetailsLineItemPaymentMethodOptions = z.object({commodity_code: z.string().max(5000).nullable().optional()}); export const paymentFlowsPrivatePaymentMethodsCardPresentAmountDetailsLineItemPaymentMethodOptions = z.object({commodity_code: z.string().max(5000).nullable().optional()}); export const paymentFlowsPrivatePaymentMethodsKlarnaPaymentIntentAmountDetailsLineItemPaymentMethodOptions = z.object({image_url: z.string().max(2048).nullable().optional(), product_url: z.string().max(2048).nullable().optional(), reference: z.string().max(255).nullable().optional(), subscription_reference: z.string().max(2048).nullable().optional()}); export const paymentFlowsPrivatePaymentMethodsPaypalAmountDetailsLineItemPaymentMethodOptions = z.object({category: z.enum(["digital_goods", "donation", "physical_goods"]).optional(), description: z.string().max(5000).optional(), sold_by: z.string().max(5000).optional()}); export const paymentFlowsAmountDetailsResourceLineItemsListResourceLineItemResourcePaymentMethodOptions = z.object({card: paymentFlowsPrivatePaymentMethodsCardPaymentIntentAmountDetailsLineItemPaymentMethodOptions.optional(), card_present: paymentFlowsPrivatePaymentMethodsCardPresentAmountDetailsLineItemPaymentMethodOptions.optional(), klarna: paymentFlowsPrivatePaymentMethodsKlarnaPaymentIntentAmountDetailsLineItemPaymentMethodOptions.optional(), paypal: paymentFlowsPrivatePaymentMethodsPaypalAmountDetailsLineItemPaymentMethodOptions.optional()}); export const paymentFlowsAmountDetailsResourceLineItemsListResourceLineItemResourceTax = z.object({total_tax_amount: z.number().int()}); export const paymentIntentAmountDetailsLineItem = z.object({discount_amount: z.number().int().nullable().optional(), id: z.string().max(5000), object: z.literal("payment_intent_amount_details_line_item"), payment_method_options: paymentFlowsAmountDetailsResourceLineItemsListResourceLineItemResourcePaymentMethodOptions.nullable().optional(), product_code: z.string().max(5000).nullable().optional(), product_name: z.string().max(5000), quantity: z.number().int(), tax: paymentFlowsAmountDetailsResourceLineItemsListResourceLineItemResourceTax.nullable().optional(), unit_cost: z.number().int(), unit_of_measure: z.string().max(5000).nullable().optional()}); export const getApiV1PaymentIntentsIntentAmountDetailsLineItemsResponse = z.object({data: z.array(paymentIntentAmountDetailsLineItem), 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 }; /** * List all PaymentIntent LineItems * * GET /v1/payment_intents/{intent}/amount_details_line_items * * Also accepts auth: bearerAuth */ export const getApiV1PaymentIntentsIntentAmountDetailsLineItems = async (args: GetApiV1PaymentIntentsIntentAmountDetailsLineItemsArgs, options?: GetApiV1PaymentIntentsIntentAmountDetailsLineItemsOptions) => { 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/payment_intents/${encodeURIComponent(String(args.intent))}/amount_details_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(getApiV1PaymentIntentsIntentAmountDetailsLineItemsResponse, await res.json()) };