import {z} from 'zod' export type CreateApiV1CustomersCustomerFundingInstructionsArgs = {customer: string, body: {bank_transfer: {eu_bank_transfer?: {country: string} | undefined, requested_address_types?: (Array<'iban' | 'sort_code' | 'spei' | 'zengin'>) | undefined, type: 'eu_bank_transfer' | 'gb_bank_transfer' | 'jp_bank_transfer' | 'mx_bank_transfer' | 'us_bank_transfer'}, currency: unknown, expand?: Array | undefined, funding_type: 'bank_transfer'}}; export type CreateApiV1CustomersCustomerFundingInstructionsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({city: z.string().max(5000).nullable().optional(), country: z.string().max(5000).nullable().optional(), line1: z.string().max(5000).nullable().optional(), line2: z.string().max(5000).nullable().optional(), postal_code: z.string().max(5000).nullable().optional(), state: z.string().max(5000).nullable().optional()}); export const fundingInstructionsBankTransferAbaRecord = z.object({account_holder_address: address, account_holder_name: z.string().max(5000), account_number: z.string().max(5000), account_type: z.string().max(5000), bank_address: address, bank_name: z.string().max(5000), routing_number: z.string().max(5000)}); export const fundingInstructionsBankTransferIbanRecord = z.object({account_holder_address: address, account_holder_name: z.string().max(5000), bank_address: address, bic: z.string().max(5000), country: z.string().max(5000), iban: z.string().max(5000)}); export const fundingInstructionsBankTransferSortCodeRecord = z.object({account_holder_address: address, account_holder_name: z.string().max(5000), account_number: z.string().max(5000), bank_address: address, sort_code: z.string().max(5000)}); export const fundingInstructionsBankTransferSpeiRecord = z.object({account_holder_address: address, account_holder_name: z.string().max(5000), bank_address: address, bank_code: z.string().max(5000), bank_name: z.string().max(5000), clabe: z.string().max(5000)}); export const fundingInstructionsBankTransferSwiftRecord = z.object({account_holder_address: address, account_holder_name: z.string().max(5000), account_number: z.string().max(5000), account_type: z.string().max(5000), bank_address: address, bank_name: z.string().max(5000), swift_code: z.string().max(5000)}); export const fundingInstructionsBankTransferZenginRecord = z.object({account_holder_address: address, account_holder_name: z.string().max(5000).nullable().optional(), account_number: z.string().max(5000).nullable().optional(), account_type: z.string().max(5000).nullable().optional(), bank_address: address, bank_code: z.string().max(5000).nullable().optional(), bank_name: z.string().max(5000).nullable().optional(), branch_code: z.string().max(5000).nullable().optional(), branch_name: z.string().max(5000).nullable().optional()}); export const fundingInstructionsBankTransferFinancialAddress = z.object({aba: fundingInstructionsBankTransferAbaRecord.optional(), iban: fundingInstructionsBankTransferIbanRecord.optional(), sort_code: fundingInstructionsBankTransferSortCodeRecord.optional(), spei: fundingInstructionsBankTransferSpeiRecord.optional(), supported_networks: z.array(z.enum(["ach", "bacs", "chaps", "domestic_wire_us", "fps", "sepa", "spei", "swift", "zengin"])).optional(), swift: fundingInstructionsBankTransferSwiftRecord.optional(), type: z.enum(["aba", "iban", "sort_code", "spei", "swift", "zengin"]), zengin: fundingInstructionsBankTransferZenginRecord.optional()}); export const fundingInstructionsBankTransfer = z.object({country: z.string().max(5000), financial_addresses: z.array(fundingInstructionsBankTransferFinancialAddress), type: z.enum(["eu_bank_transfer", "jp_bank_transfer"])}); export const fundingInstructions = z.object({bank_transfer: fundingInstructionsBankTransfer, currency: z.string().max(5000), funding_type: z.literal("bank_transfer"), livemode: z.boolean(), object: z.literal("funding_instructions")}); 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 }; /** * Create or retrieve funding instructions for a customer cash balance * * POST /v1/customers/{customer}/funding_instructions * * Also accepts auth: bearerAuth */ export const createApiV1CustomersCustomerFundingInstructions = async (args: CreateApiV1CustomersCustomerFundingInstructionsArgs, options?: CreateApiV1CustomersCustomerFundingInstructionsOptions) => { 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 (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customer))}/funding_instructions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(fundingInstructions, await res.json()) };