import {z} from 'zod' export type GetApiApiPaymentsPvtAccountCardIdArgs = {'Content-Type': string, Accept: string, cardId: string}; export type GetApiApiPaymentsPvtAccountCardIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiPaymentsPvtAccountCardIdResponse = z.object({bin: z.string().optional(), lastDigits: z.string().optional(), expiryMonth: z.string().optional(), expiryYear: z.string().optional(), mask: z.string().optional(), paymentSystem: z.number().int().optional(), paymentSystemName: z.string().optional(), address: z.object({addressType: z.enum(["Residential", "Commercial"]).optional(), addressId: z.string().optional(), postalCode: z.string().optional(), street: z.string().optional(), neighborhood: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), number: z.string().optional(), complement: z.string().optional()}).optional(), document: z.string().optional(), tokens: z.object({providerId: z.string().optional(), type: z.enum(["FILE", "TOKEN_CLIENT_ID", "TOKEN_VALUE"]).optional(), value: z.string().optional(), expiration: z.string().optional(), label: z.string().optional(), href: z.string().optional(), providerCardTokenId: z.string().optional(), useCvvForAuthorization: z.boolean().optional(), extraData: z.object({customField1: z.string().optional()}).optional()}).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 card data * * GET /api/payments/pvt/account/{cardId} */ export const getApiApiPaymentsPvtAccountCardId = async (args: GetApiApiPaymentsPvtAccountCardIdArgs, options?: GetApiApiPaymentsPvtAccountCardIdOptions) => { const {baseUrl = "https://apiexamples.vtexpayments.com.br", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.Accept != null) headers.set("Accept", String(args.Accept)) const url = `${baseUrl.replace(/\/+$/, '')}/api/payments/pvt/account/${encodeURIComponent(String(args.cardId))}${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(getApiApiPaymentsPvtAccountCardIdResponse, await res.json()) };