import {z} from 'zod' export type GetApiV0PaymentsPaymentIdSubmissionsArgs = {'payment-id': string}; export type GetApiV0PaymentsPaymentIdSubmissionsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV0PaymentsPaymentIdSubmissionsResponse = z.object({submissions: z.array(z.object({"submission-scheme-information": z.union([z.object({"end-to-end-identification": z.string().min(1), "scheme-status-code": z.string().min(1).optional(), "scheme-status-code-description": z.string().min(1).optional(), "payment-scheme": z.literal("fps")}), z.object({"end-to-end-identification": z.string().min(1), "payment-scheme": z.literal("book-transfer")})]), "submission-status": z.enum(["scheduled", "failed", "processing", "returned", "delivered"]), "created-by-url": z.string().optional(), "scheduled-at": z.string().optional(), "created-at": z.string(), "submission-status-reason": z.string().min(1).optional(), "payment-url": z.string(), "unique-scheme-identifier": z.string().min(1).max(140).optional(), "account-url": z.union([z.string(), z.string()]), "submission-url": 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 }; /** * List payment submissions * * GET /v0/payments/{payment-id}/submissions */ export const getApiV0PaymentsPaymentIdSubmissions = async (args: GetApiV0PaymentsPaymentIdSubmissionsArgs, options?: GetApiV0PaymentsPaymentIdSubmissionsOptions) => { const {baseUrl = "https://api.griffin.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/payments/${encodeURIComponent(String(args['payment-id']))}/submissions${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(getApiV0PaymentsPaymentIdSubmissionsResponse, await res.json()) };