import {z} from 'zod' export type PaymentMethodConfigUpdateRequest = {is_enabled?: (boolean | null) | undefined, display_name?: (string | null) | undefined, sub_options?: ({[key: string]: boolean} | null) | undefined, min_amount_kopeks?: (number | null) | undefined, max_amount_kopeks?: (number | null) | undefined, user_type_filter?: (string | null) | undefined, first_topup_filter?: (string | null) | undefined, promo_group_filter_mode?: (string | null) | undefined, allowed_promo_group_ids?: (Array | null) | undefined, reset_display_name?: boolean | undefined, reset_min_amount?: boolean | undefined, reset_max_amount?: boolean | undefined}; export type UpdateApiCabinetAdminPaymentMethodsMethodIdArgs = {method_id: string, body: PaymentMethodConfigUpdateRequest}; export type UpdateApiCabinetAdminPaymentMethodsMethodIdOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const subOptionInfo = z.object({id: z.string(), name: z.string()}); export const paymentMethodConfigResponse = z.object({method_id: z.string(), sort_order: z.number().int(), is_enabled: z.boolean(), display_name: z.string().nullable().optional(), default_display_name: z.string(), sub_options: z.record(z.string(), z.unknown()).nullable().optional(), available_sub_options: z.array(subOptionInfo).nullable().optional(), min_amount_kopeks: z.number().int().nullable().optional(), max_amount_kopeks: z.number().int().nullable().optional(), default_min_amount_kopeks: z.number().int(), default_max_amount_kopeks: z.number().int(), user_type_filter: z.string(), first_topup_filter: z.string(), promo_group_filter_mode: z.string(), allowed_promo_group_ids: z.array(z.number().int()).optional(), is_provider_configured: z.boolean(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().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 Payment Method * * PUT /cabinet/admin/payment-methods/{method_id} */ export const updateApiCabinetAdminPaymentMethodsMethodId = async (args: UpdateApiCabinetAdminPaymentMethodsMethodIdArgs, options: UpdateApiCabinetAdminPaymentMethodsMethodIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/cabinet/admin/payment-methods/${encodeURIComponent(String(args.method_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(paymentMethodConfigResponse, await res.json()) };