export type CaptureObjectRequest = {amount?: number | undefined, currency?: string | undefined}; export type CreateApiCapturesArgs = {transactionId: string, 'X-Amzn-Trace-Id'?: string | undefined, body: CaptureObjectRequest}; export type CreateApiCapturesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Capture totally or partially a transaction previously authorized * * POST /captures */ export const createApiCaptures = async (args: CreateApiCapturesArgs, options?: CreateApiCapturesOptions) => { const {baseUrl = "https://api.test.bictorys.com/pay/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.transactionId != null) query.append("transactionId", String(args.transactionId)) if (args['X-Amzn-Trace-Id'] != null) headers.set("X-Amzn-Trace-Id", String(args['X-Amzn-Trace-Id'])) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/captures${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };