export type CreateApiApiCardTokenArgs = {body: {cardNumber: string}}; export type CreateApiApiCardTokenOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, PayloadAuth?: string | undefined, SignatureAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Issue card token * * POST /api/card-token */ export const createApiApiCardToken = async (args: CreateApiApiCardTokenArgs, options?: CreateApiApiCardTokenOptions) => { const {baseUrl = "https://fgw.whitebit.com", fetch: fetchFn = fetch, ApiKeyAuth, PayloadAuth, SignatureAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-TXC-APIKEY", ApiKeyAuth) if (PayloadAuth !== undefined) headers.set("X-TXC-PAYLOAD", PayloadAuth) if (SignatureAuth !== undefined) headers.set("X-TXC-SIGNATURE", SignatureAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/card-token${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 };