export type ClientValue = number; export type InputAmount = string; export type CurrencyCode = string; export type CountryCode = string; export type PlaceOrderRequestInputBankAccount = {amount?: InputAmount | undefined, currency: CurrencyCode, iban?: string | undefined, owner?: ({address?: string | undefined, address_complement?: string | undefined, city?: string | undefined, country?: CountryCode | undefined, name?: string | undefined, state?: string | undefined, zip?: string | undefined}) | undefined, type: 'bank_account'}; export type PlaceOrderRequestInputBityAccount = {amount?: InputAmount | undefined, currency: CurrencyCode, type: 'bity_account'}; export type PlaceOrderRequestInputCryptoAddress = {amount?: InputAmount | undefined, currency: CurrencyCode, crypto_address?: string | undefined, type: 'crypto_address'}; export type PlaceOrderRequestInputOnlineInstantPayment = {amount?: InputAmount | undefined, currency: CurrencyCode, type?: 'online_instant_payment' | undefined}; export type PlaceOrderRequestInput = PlaceOrderRequestInputBankAccount | PlaceOrderRequestInputBityAccount | PlaceOrderRequestInputCryptoAddress | PlaceOrderRequestInputOnlineInstantPayment; export type OutputAmount = string; export type QrReference = string; export type StructuredCreditorReference = string; export type PlaceOrderRequestOutputBankAccount = {amount?: OutputAmount | undefined, currency: CurrencyCode, bic_swift?: string | undefined, iban: string, owner: {name?: string | undefined, address?: string | undefined, address_complement?: string | undefined, city?: string | undefined, country?: CountryCode | undefined, state?: string | undefined, zip?: string | undefined} | {name?: string | undefined, building_name?: string | undefined, building_number?: string | undefined, country?: CountryCode | undefined, country_subdivision?: string | undefined, department?: string | undefined, district_name?: string | undefined, floor?: string | undefined, post_box?: string | undefined, post_code?: string | undefined, room?: string | undefined, street_name?: string | undefined, subdepartment?: string | undefined, town_location_name?: string | undefined, town_name?: string | undefined}, qr_reference?: QrReference | undefined, reference?: string | undefined, structured_creditor_reference?: StructuredCreditorReference | undefined, type: 'bank_account', ultimate_debtor?: ({name?: string | undefined, address?: string | undefined, address_complement?: string | undefined, city?: string | undefined, country?: CountryCode | undefined, state?: string | undefined, zip?: string | undefined} | {name?: string | undefined, building_name?: string | undefined, building_number?: string | undefined, country?: CountryCode | undefined, country_subdivision?: string | undefined, department?: string | undefined, district_name?: string | undefined, floor?: string | undefined, post_box?: string | undefined, post_code?: string | undefined, room?: string | undefined, street_name?: string | undefined, subdepartment?: string | undefined, town_location_name?: string | undefined, town_name?: string | undefined}) | undefined}; export type PlaceOrderRequestOutputBityAccount = {amount?: OutputAmount | undefined, currency: CurrencyCode, type?: 'bity_account' | undefined}; export type PlaceOrderRequestOutputCryptoAddress = {amount?: OutputAmount | undefined, currency: CurrencyCode, crypto_address: string, type: 'crypto_address'}; export type PlaceOrderRequestOutput = PlaceOrderRequestOutputBankAccount | PlaceOrderRequestOutputBityAccount | PlaceOrderRequestOutputCryptoAddress; export type PartnerFee = {factor: number | string}; export type OrderPurposeCategory = string; export type OrderPurpose = {category?: OrderPurposeCategory | undefined, comment?: string | undefined}; export type PlaceOrderRequest = {client_value?: ClientValue | undefined, contact_person?: ({email?: string | undefined}) | undefined, input: PlaceOrderRequestInput, output: PlaceOrderRequestOutput, partner_fee?: PartnerFee | undefined, purpose?: OrderPurpose | undefined}; export type CreateApiOrdersArgs = {body: PlaceOrderRequest}; export type CreateApiOrdersOptions = {baseUrl?: string | undefined, bityAccountOauth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Place an order * * POST /orders * * Also accepts auth: bity_account_client_oauth, client_oauth */ export const createApiOrders = async (args: CreateApiOrdersArgs, options?: CreateApiOrdersOptions) => { const {baseUrl = "https://exchange.api.bity.com/v2", fetch: fetchFn = fetch, bityAccountOauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (bityAccountOauth !== undefined) headers.set('authorization', `Bearer ${bityAccountOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/orders${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 };