import {z} from 'zod' export type GetApiPaymentIntentsIdPaymentFeesArgs = {id: string, country: string, provider?: string | undefined, paymentMethod: 'mobile_money' | 'credit_card' | 'bank_transfer' | 'instant_payment', ApiKey: string, MerchantId: string, Environment: 'live' | 'sandbox'}; export type GetApiPaymentIntentsIdPaymentFeesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const paymentFeeTaxResponseDto = z.object({id: z.string(), feeId: z.string(), taxType: z.literal("tva"), type: z.enum(["flat", "percent"]), value: z.number()}); export const paymentFeeDto = z.object({id: z.string(), rate: z.number(), rateType: z.enum(["percent", "flat"]), amount: z.number(), currency: z.string(), label: z.string().optional(), taxes: z.array(paymentFeeTaxResponseDto).optional()}); export const getApiPaymentIntentsIdPaymentFeesResponse = z.array(paymentFeeDto); 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 }; /** * Retrieve fees * * GET /payment-intents/{id}/payment-fees */ export const getApiPaymentIntentsIdPaymentFees = async (args: GetApiPaymentIntentsIdPaymentFeesArgs, options: GetApiPaymentIntentsIdPaymentFeesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.country != null) query.append("country", String(args.country)) if (args.provider != null) query.append("provider", String(args.provider)) if (args.paymentMethod != null) query.append("paymentMethod", String(args.paymentMethod)) if (args.ApiKey != null) headers.set("ApiKey", String(args.ApiKey)) if (args.MerchantId != null) headers.set("MerchantId", String(args.MerchantId)) if (args.Environment != null) headers.set("Environment", String(args.Environment)) const url = `${baseUrl.replace(/\/+$/, '')}/payment-intents/${encodeURIComponent(String(args.id))}/payment-fees${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(getApiPaymentIntentsIdPaymentFeesResponse, await res.json()) };