import {z} from 'zod' export type MerchantBankAccountCreateInput = {account_number?: string | undefined, currency: string, country: string, iban?: string | undefined, bic?: string | undefined, sort_code?: string | undefined, routing_number?: string | undefined, bank_id?: string | undefined, bban?: string | undefined, plusgiro_number?: string | undefined, bsb?: string | undefined, account_holder_name?: string | undefined, supported_payment_schemes?: (Array<{type: 'SEPA_CREDIT_TRANSFER' | 'MULTIBANCO' | 'DANISH_DOMESTIC_CREDIT_TRANSFER' | 'FASTER_PAYMENTS' | 'BACS' | 'BECS' | 'ACH', is_active?: boolean | undefined}>) | undefined, client_evidence?: ({checkout_page_version?: string | undefined, timezone?: string | undefined, fingerprint?: string | undefined, consented_agreements: Array<{kind: string, agreement_id: string}>, checkbox_language: Array<{checkbox_id: string, rendered_text: string, covers_kinds: Array}>}) | undefined}; export type CreateApiApiV1MerchantsIdBankAccountsArgs = {id: string, body: MerchantBankAccountCreateInput}; export type CreateApiApiV1MerchantsIdBankAccountsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const merchantBankAccountResponse = z.object({success: z.boolean(), data: z.object({id: z.string().optional(), account_number: z.string().optional(), currency: z.string().min(3).max(3).optional(), country: z.string().min(2).max(2).optional(), status: z.union([z.literal("active"), z.literal("archived")]).optional(), account_information_session_id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), iban: z.string().optional(), bic: z.string().optional(), sort_code: z.string().optional(), routing_number: z.string().optional(), bban: z.string().optional(), plusgiro_number: z.string().optional(), bsb: z.string().optional(), account_holder_name: z.string().optional(), supported_payment_schemes: z.array(z.object({id: z.string(), type: z.union([z.literal("SEPA_CREDIT_TRANSFER"), z.literal("MULTIBANCO"), z.literal("DANISH_DOMESTIC_CREDIT_TRANSFER"), z.literal("FASTER_PAYMENTS"), z.literal("BACS"), z.literal("BECS"), z.literal("ACH")]), name: z.string(), is_active: z.boolean(), additional_payment_method: z.boolean()})).optional(), roles: z.array(z.union([z.literal("receiving"), z.literal("settlement"), z.literal("refund")])).optional(), balance: z.string().optional()})}); 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 a bank account for a merchant * * POST /api/v1/merchants/{id}/bank-accounts */ export const createApiApiV1MerchantsIdBankAccounts = async (args: CreateApiApiV1MerchantsIdBankAccountsArgs, options?: CreateApiApiV1MerchantsIdBankAccountsOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/merchants/${encodeURIComponent(String(args.id))}/bank-accounts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(merchantBankAccountResponse, await res.json()) };