import {z} from 'zod' export type GetApiV1MarketplaceEstablishmentsIdGatewaysGatewayIdArgs = {'integration-key': string, 'x-token': string, id: string, gatewayId: string}; export type GetApiV1MarketplaceEstablishmentsIdGatewaysGatewayIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const gatewayResponse = z.object({id: z.number(), name: z.string()}); export const bankType = z.object({name: z.string(), code: z.string(), ispb: z.string()}); export const bankAccountType = z.object({account_check_digit: z.string(), account_number: z.string(), routing_check_digit: z.string(), routing_number: z.string().max(4), type: z.enum(["CHECKING", "SAVING"]), bank: bankType}); export const spbAccountType = z.object({account_check_digit: z.string(), account_number: z.string(), routing_check_digit: z.string(), routing_number: z.string().max(4), type: z.enum(["CHECKING", "SAVING"]), bank: bankType}); export const metadataResponse = z.object({code: z.string(), email: z.string(), token: z.string(), statement_descriptor: z.string()}); export const establishmentGatewayResponse = z.object({id: z.number(), gateway: gatewayResponse, establishment_id: z.number(), gateway_key: z.string().nullable(), status: z.enum(["PENDING", "WAITING", "ANALYZE", "BLOCKED", "CANCELED", "DISAPPROVED", "APPROVED"]), active: z.boolean(), form_receipt: z.enum(["BANKACCOUNT", "PAYTIME", "PAGBANK", "ZOOPBANK"]).nullable(), bank_account: bankAccountType.nullable(), spb_account: spbAccountType.nullable(), metadata: metadataResponse, created_at: z.string(), updated_at: z.string().nullable()}); 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 }; /** * Exibir gateway do estabelecimento * * GET /v1/marketplace/establishments/{id}/gateways/{gatewayId} */ export const getApiV1MarketplaceEstablishmentsIdGatewaysGatewayId = async (args: GetApiV1MarketplaceEstablishmentsIdGatewaysGatewayIdArgs, options?: GetApiV1MarketplaceEstablishmentsIdGatewaysGatewayIdOptions) => { const {baseUrl = "https://api.sandbox.paytime.com.br", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['integration-key'] != null) headers.set("integration-key", String(args['integration-key'])) if (args['x-token'] != null) headers.set("x-token", String(args['x-token'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/marketplace/establishments/${encodeURIComponent(String(args.id))}/gateways/${encodeURIComponent(String(args.gatewayId))}${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(establishmentGatewayResponse, await res.json()) };