import {z} from 'zod' export type BalanceAccountConfigurationUpdate = {description?: (string | null) | undefined, enabled?: (boolean | null) | undefined, frequency?: ('daily' | 'weekly' | 'weekdays' | 'monthly') | undefined, frequencyValue?: (number | null) | undefined, maxPayoutAmount?: (number | null) | undefined, minPayoutAmount?: (number | null) | undefined, reference?: (string | null) | undefined, referenceForBeneficiary?: (string | null) | undefined, retainedAmount?: (number | null) | undefined, salesDayClosingTime?: string | undefined, transferInstrumentId?: string | undefined}; export type PatchApiBalanceAccountsBalanceAccountIdPayoutSchedulesIdArgs = {balanceAccountId: string, id: string, body: BalanceAccountConfigurationUpdate}; export type PatchApiBalanceAccountsBalanceAccountIdPayoutSchedulesIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const scheduledPayoutFrequency = z.string(); export const balanceAccountConfiguration = z.object({balanceAccountId: z.string(), balancePlatformPayoutScheduleId: z.string(), createdAt: z.string(), currency: z.string().optional(), description: z.string().optional(), enabled: z.boolean().optional(), frequency: scheduledPayoutFrequency.optional(), frequencyValue: z.number().int().optional(), id: z.string().optional(), maxPayoutAmount: z.number().int().optional(), minPayoutAmount: z.number().int().optional(), reference: z.string().optional(), referenceForBeneficiary: z.string().optional(), retainedAmount: z.number().int().optional(), salesDayClosingTime: z.string().optional(), transferInstrumentId: z.string(), updatedAt: 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 }; /** * Update a managed payout schedule on a balance account * * PATCH /balanceAccounts/{balanceAccountId}/payoutSchedules/{id} * * Also accepts auth: ApiKeyAuth */ export const patchApiBalanceAccountsBalanceAccountIdPayoutSchedulesId = async (args: PatchApiBalanceAccountsBalanceAccountIdPayoutSchedulesIdArgs, options?: PatchApiBalanceAccountsBalanceAccountIdPayoutSchedulesIdOptions) => { const {baseUrl = "https://balanceplatform-api-test.adyen.com/bcl/v2", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/balanceAccounts/${encodeURIComponent(String(args.balanceAccountId))}/payoutSchedules/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(balanceAccountConfiguration, await res.json()) };