import {z} from 'zod' export type CreateApiV1AccountsAccountIdVirtualAccountsVirtualAccountIdDeactivateArgs = {account_id: string, virtual_account_id: string}; export type CreateApiV1AccountsAccountIdVirtualAccountsVirtualAccountIdDeactivateOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const currency = z.enum(["USD", "EUR", "CNY", "HKD", "MXN", "BRL", "GBP", "AED", "INR", "PHP", "SGD", "JPY"]); export const virtualAccountStatus = z.enum(["PENDING", "ACTIVE", "DEACTIVE", "FAILED"]); export const accountId = z.string(); export const virtualAccountOwner = z.object({account_id: accountId, name: z.string()}); export const virtualAccountFeeRecurrence = z.literal("MONTHLY"); export const virtualAccountFee = z.object({value: z.string(), asset: z.string(), recurrence: virtualAccountFeeRecurrence}); export const chronoDateTimeSchema = z.string(); export const isoCountryAlpha2 = z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW"]); export const virtualAccountParty = z.object({name: z.string(), address: z.string(), country: isoCountryAlpha2.nullable().optional()}); export const addressDetails = z.object({full_address: z.string(), country_code: z.string(), address_line1: z.string(), address_line2: z.string().nullable().optional(), city: z.string(), region: z.string().nullable().optional(), postal_code: z.string()}); export const virtualAccountHolder = z.object({name: z.string(), address: addressDetails, country: isoCountryAlpha2.nullable().optional()}); export const virtualAccountNetwork = z.object({network: z.string(), account_identifier: z.string(), institution_identifier: z.string().nullable().optional(), memo: z.string().nullable().optional(), deposit_allowed: z.boolean(), withdrawal_allowed: z.boolean(), bank: virtualAccountParty, account_holder: virtualAccountHolder}); export const virtualAccountResponse = z.object({virtual_account_id: z.string(), asset: currency, nickname: z.string(), external_id: z.string().nullable().optional(), is_default: z.boolean(), status: virtualAccountStatus, owner: virtualAccountOwner, fee: virtualAccountFee.nullable().optional(), created_at: chronoDateTimeSchema, last_modified_at: chronoDateTimeSchema, networks: z.array(virtualAccountNetwork)}); 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 }; /** * Stop automatic crediting through an additional VA. The bank may still receive funds. * * POST /v1/accounts/{account_id}/virtual-accounts/{virtual_account_id}/deactivate */ export const createApiV1AccountsAccountIdVirtualAccountsVirtualAccountIdDeactivate = async (args: CreateApiV1AccountsAccountIdVirtualAccountsVirtualAccountIdDeactivateArgs, options?: CreateApiV1AccountsAccountIdVirtualAccountsVirtualAccountIdDeactivateOptions) => { const {baseUrl = "https://api.1money.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/virtual-accounts/${encodeURIComponent(String(args.virtual_account_id))}/deactivate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(virtualAccountResponse, await res.json()) };