import {z} from 'zod' export type GetApiV1MarketplaceEstablishmentsIdArgs = {'integration-key': string, 'x-token': string, id: string}; export type GetApiV1MarketplaceEstablishmentsIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const planFlagResponse = z.object({id: z.number(), name: z.enum(["MASTERCARD", "VISA", "ELO", "AMERICAN EXPRESS", "HIPERCARD", "OTHERS", "BACEN"])}); export const planResponse = z.object({id: z.number(), allow_anticipation: z.boolean(), days_anticipation: z.union([z.literal(1), z.literal(14), z.literal(30)]), name: z.string(), modality: z.enum(["PHYSICAL", "ONLINE", "TAP_PHONE"]), flag: planFlagResponse}); 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 gatewayResponseEstablishment = z.object({id: z.number(), name: z.string(), reference_id: z.number(), 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 feeDetails = z.object({pix: z.number(), ted: z.number(), billet: z.number(), dynamic_pix: z.number()}); export const feeBankingEstablishmentResponse = z.object({id: z.number(), name: z.string(), type: z.enum(["COMMERCIAL", "STANDARD"]), standard: feeDetails, markup: feeDetails, fees: feeDetails}); export const representativeResponse = z.object({id: z.number(), first_name: z.string(), last_name: z.string(), document: z.string(), active: z.object({})}); export const address = z.object({street: z.string(), number: z.string(), complement: z.string().optional(), neighborhood: z.string(), city: z.string(), state: z.enum(["AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MS", "MT", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO"]), zip_code: z.string().min(8).max(8)}); export const establishmentMarketplaceResponse = z.object({id: z.number(), type: z.enum(["INDIVIDUAL", "BUSINESS"]), first_name: z.string(), last_name: z.string(), document: z.string(), birthdate: z.string(), phone_number: z.string(), active: z.boolean(), revenue: z.string(), format: z.enum(["SS", "SC", "SPE", "LTDA", "SA", "ME", "MEI", "EI", "EIRELI", "SLU", "ESI"]).optional(), email: z.string(), risk: z.enum(["LOW", "MEDIUM", "HIGH"]), status: z.enum(["PENDING", "VALIDATION", "RISK_ANALYSIS", "APPROVED", "DISAPPROVED", "DISCREDITED", "DISCREDITED_PERMANENTLY", "BACKGROUND_CHECK"]), plans: z.array(planResponse), gateways: z.array(gatewayResponseEstablishment), fees_banking: z.array(feeBankingEstablishmentResponse), representative: representativeResponse, address: address, category: z.string(), code: z.string(), created_at: z.string(), updated_at: z.string(), deleted_at: z.string()}); 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 estabelecimento * * GET /v1/marketplace/establishments/{id} */ export const getApiV1MarketplaceEstablishmentsId = async (args: GetApiV1MarketplaceEstablishmentsIdArgs, options?: GetApiV1MarketplaceEstablishmentsIdOptions) => { 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))}${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(establishmentMarketplaceResponse, await res.json()) };