import {z} from 'zod' export type PayoutDestinationId = string; export type BankAccountCountryCode = string; export type PayoutDestinationBankAccount = {bank_name?: string | undefined, bank_account_number?: string | undefined, bank_account_number_type?: ('IBAN' | 'BBAN') | undefined, bank_account_country_code?: BankAccountCountryCode | undefined, bank_account_currency: unknown, bank_identification_code?: string | undefined}; export type LegalEntityType = 'company' | 'individual'; export type Individual = {name?: string | undefined, birth_date?: string | undefined, phone_number?: string | undefined, email?: string | undefined, address_line?: string | undefined, address_line_2?: string | undefined, address_postal_code?: string | undefined, address_city?: string | undefined, address_country?: unknown | undefined}; export type Address = {address_line: string, address_line_2?: string | undefined, postal_code?: string | undefined, postal_place: string, country: unknown}; export type AuthPayoutDestinationCreateRequest = {payout_destination_id: PayoutDestinationId, payout_reference: string, bank_accounts: Array, type?: LegalEntityType | undefined, payout_interval_type?: ('day' | 'week' | 'month' | 'manual') | undefined, merchant_category_code?: unknown | undefined, organization?: ({organization_number: string, name?: string | undefined, trade_name?: string | undefined}) | undefined, individual?: Individual | undefined, address?: Address | undefined, payout_destination_name?: string | undefined, payout_destination_description?: string | undefined, form_submitter?: ({email?: string | undefined, name?: string | undefined, title?: string | undefined}) | undefined, settlement_report_configuration?: {emails: Array} | undefined, report_configuration?: ({create_report_configuration: boolean, email?: string | undefined, schedule?: ('daily' | 'weekly' | 'monthly') | undefined, reference?: string | undefined, content_types?: (Array<'application/pdf' | 'text/csv'>) | undefined}) | undefined}; export type CreateApiAccountsOidPayoutDestinationsArgs = {oid: unknown, body: AuthPayoutDestinationCreateRequest}; export type CreateApiAccountsOidPayoutDestinationsOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const payoutDestinationId = z.string().max(40); export const approvalStatus = z.enum(["ACTIVE", "DECLINED", "UNDER_MANUAL_REVIEW", "AUTOMATIC_REVIEW", "WAITING_FOR_SIGNATURE", "WAITING_FOR_DECLARATION", "ERROR", "ARCHIVED", "WAITING_FOR_DETAILS", "TERMINATED"]); export const legalEntityTypeReadOnly = z.enum(["company", "individual"]); export const individual = z.object({name: z.string().optional(), birth_date: z.string().optional(), phone_number: z.string().optional(), email: z.string().optional(), address_line: z.string().optional(), address_line_2: z.string().optional(), address_postal_code: z.string().optional(), address_city: z.string().optional(), address_country: z.string().optional()}); export const address = z.object({address_line: z.string(), address_line_2: z.string().optional(), postal_code: z.string().optional(), postal_place: z.string(), country: z.string()}); export const bankAccountCountryCode = z.string().min(2).max(2); export const payoutDestinationBankAccount = z.object({bank_name: z.string().optional(), bank_account_number: z.string().optional(), bank_account_number_type: z.enum(["IBAN", "BBAN"]).optional(), bank_account_country_code: bankAccountCountryCode.optional(), bank_account_currency: z.string(), bank_identification_code: z.string().optional()}); export const approvalLinks = z.array(z.object({href: z.string().optional(), rel: z.enum(["contract_url", "cdd_case_url", "dintero_cdd_case_url", "declaration_url", "signed_contract_file_url"]).optional()})); export const terminalStatus = z.enum(["DELETED", "PENDING", "ACTION_REQUIRED", "ACTIVE", "INACTIVE", "ERROR"]); export const authPayoutDestinationCreateResponse = z.object({id: z.string(), created_at: z.string(), created_by: z.string(), updated_at: z.string(), deleted_by: z.string().optional(), deleted_at: z.string().optional(), payout_destination_id: payoutDestinationId.optional(), updated_by: z.string(), account_id: z.string(), case_status: approvalStatus, type: legalEntityTypeReadOnly, merchant_category_code: z.string().optional(), organization: z.object({organization_number: z.string(), name: z.string().optional(), trade_name: z.string().optional()}).optional(), individual: individual.optional(), address: address.optional(), bank_accounts: z.array(payoutDestinationBankAccount).optional(), payout_interval_type: z.enum(["day", "week", "month", "manual"]).optional(), payout_reference: z.string().optional(), email: z.string().optional(), website: z.string().optional(), phone_number: z.string().optional(), payout_destination_name: z.string().optional(), payout_destination_description: z.string().optional(), links: approvalLinks.optional(), number_of_stores: z.number().int().optional(), number_of_terminals: z.number().int().optional(), terminals: z.array(z.object({terminal_id: z.string(), device_serial_number: z.string(), status: terminalStatus.optional()})).optional(), stores: z.array(z.object({store_id: z.string(), store_name: z.string().optional(), address: address.optional(), number_of_terminals: z.number().int().optional()})).optional(), form_submitter: z.object({email: z.string().optional(), name: z.string().optional(), title: z.string().optional()}).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 }; /** * aid_mgmnt_payout_destinations_post * * POST /accounts/{oid}/payout-destinations */ export const createApiAccountsOidPayoutDestinations = async (args: CreateApiAccountsOidPayoutDestinationsArgs, options?: CreateApiAccountsOidPayoutDestinationsOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.oid))}/payout-destinations${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(authPayoutDestinationCreateResponse, await res.json()) };