import {z} from 'zod' export type GetApiAccountsOidPayoutDestinationsPayoutDestinationIdArgs = {oid: unknown, payout_destination_id: string, includes?: (Array<'terminals' | 'stores'>) | undefined}; export type GetApiAccountsOidPayoutDestinationsPayoutDestinationIdOptions = {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 authPayoutDestination = 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()}); 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_get_by_id * * GET /accounts/{oid}/payout-destinations/{payout_destination_id} */ export const getApiAccountsOidPayoutDestinationsPayoutDestinationId = async (args: GetApiAccountsOidPayoutDestinationsPayoutDestinationIdArgs, options?: GetApiAccountsOidPayoutDestinationsPayoutDestinationIdOptions) => { const {baseUrl = "https://api.dintero.com/v1", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.includes != null) query.append("includes", args.includes.join(',')) if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.oid))}/payout-destinations/${encodeURIComponent(String(args.payout_destination_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(authPayoutDestination, await res.json()) };