import {z} from 'zod' export type GetApiApiV14ExternalPaymentsIntentsIntentIdArgs = {intent_id: string}; export type GetApiApiV14ExternalPaymentsIntentsIntentIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getIntentDetails = z.object({id: z.string(), status: z.string().max(50).optional(), amount: z.number(), amount_currency: z.string(), type: z.string(), account: z.string(), custom_fields: z.record(z.string(), z.unknown()), customer: z.record(z.string(), z.unknown()), customer_last_used_payment_method: z.string().nullable(), last_used_method: z.string().nullable(), billing_data: z.record(z.string(), z.unknown()), transaction_provider_fields: z.record(z.string(), z.unknown()), active_transaction: z.string(), transactions_history: z.array(z.record(z.string(), z.unknown())), tokenized_card: z.string(), flow: z.string(), flow_data: z.record(z.string(), z.unknown()), is_live: z.boolean().optional(), created: z.string(), template: z.unknown(), merchant_reference: z.string().max(90).nullable().optional(), state: z.string(), state_details: z.record(z.string(), z.unknown()), payment_status: 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 }; /** * Get payment intent details * * GET /api/v1.4/external/payments/intents/{intent_id}/ * * Also accepts auth: AccessTokenAuth */ export const getApiApiV14ExternalPaymentsIntentsIntentId = async (args: GetApiApiV14ExternalPaymentsIntentsIntentIdArgs, options?: GetApiApiV14ExternalPaymentsIntentsIntentIdOptions) => { const {baseUrl = "https://web.moneyhash.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1.4/external/payments/intents/${encodeURIComponent(String(args.intent_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(getIntentDetails, await res.json()) };