export type CreatePaymentRequest = {nanoErg: number, tokenId?: string | undefined, tokenRawAmount?: number | undefined, receiverAddress: string, senderAddress?: string | undefined, message?: string | undefined}; export type CreateApiPaymentAddrequestArgs = {body: CreatePaymentRequest}; export type CreateApiPaymentAddrequestOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a new payment request. Will return request id to check for transaction state and ergopay url to show the user as QR code * * POST /payment/addrequest */ export const createApiPaymentAddrequest = async (args: CreateApiPaymentAddrequestArgs, options?: CreateApiPaymentAddrequestOptions) => { const {baseUrl = "https://api.tokenjay.app", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") const url = `${baseUrl.replace(/\/+$/, '')}/payment/addrequest${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() };