export type InitiateTransactionRequest = {senderTag: string, receiverTag: string, amount: number, currency?: string | undefined, narration?: string | undefined, callbackUrl?: string | undefined, idempotencyKey?: string | undefined}; export type CreateApiV1TransactionsArgs = {'Idempotency-Key'?: string | undefined, body: InitiateTransactionRequest}; export type CreateApiV1TransactionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Initiate a tag-to-tag payment * * POST /v1/transactions */ export const createApiV1Transactions = async (args: CreateApiV1TransactionsArgs, options?: CreateApiV1TransactionsOptions) => { const {baseUrl = "https://idaas.yourflexpay.com/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/transactions${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 res.blob() };