import {z} from 'zod' export type PaymentProviderType = 'Stripe' | 'CitiBank' | 'Checkout' | 'EvyPay' | 'Mpgs' | 'PayGate'; export type GetApiPaymentApiV1PaymentPayInListArgs = {paymentMethodExternalId?: string | undefined, pubKey?: string | undefined, paymentProviderType?: PaymentProviderType | undefined}; export type GetApiPaymentApiV1PaymentPayInListOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const countryDTO = z.object({iso: z.string().nullable().optional(), name: z.string().nullable().optional()}); export const currencyDTO = z.object({name: z.string().nullable().optional(), iso: z.string().nullable().optional(), isDefault: z.boolean().optional(), decimals: z.number().int().optional()}); export const paymentPayInList = z.object({currencyToPayIn: z.string().nullable().optional(), country: countryDTO.optional(), currencyList: z.array(currencyDTO).nullable().optional(), warningMessage: 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 }; /** * GET /payment-api/v1/Payment/pay-in-list */ export const getApiPaymentApiV1PaymentPayInList = async (args: GetApiPaymentApiV1PaymentPayInListArgs, options: GetApiPaymentApiV1PaymentPayInListOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.paymentMethodExternalId != null) query.append("paymentMethodExternalId", String(args.paymentMethodExternalId)) if (args.pubKey != null) query.append("pubKey", String(args.pubKey)) if (args.paymentProviderType != null) query.append("paymentProviderType", String(args.paymentProviderType)) const url = `${baseUrl.replace(/\/+$/, '')}/payment-api/v1/Payment/pay-in-list${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(paymentPayInList, await res.json()) };