export type StoreId = string; export type OrderIdentifierFinance = {id: string, source?: (string | null) | undefined}; export type PayoutInfo = {id: string, date: string}; export type OrderIssue = {type: 'MISSING_ITEM' | 'INCOMPLETE' | 'WRONG_INGREDIENTS' | 'WRONG_SIZE' | 'WRONG_INSTRUCTIONS' | 'TEMPERATURE_COLD' | 'WRONG_ORDER' | 'POOR_QUALITY' | 'HANDLED_POORLY' | 'WRONG_ITEM' | 'WRONG_QUANTITY' | 'LATE_TO_COURIER'}; export type OrderItemInformation = {id: string, name?: (string | null) | undefined, issues?: (Array | null) | undefined}; export type SimpleFinanceLine = {subType: 'VALUE' | 'TAX' | 'VALUE_WITH_TAX' | 'VAT', name: string, value: number}; export type CompositeFinanceLine = {breakdown: Array}; export type FinancialData = {foodSales: CompositeFinanceLine, feeForRestaurantProvidedDelivery?: (CompositeFinanceLine | null) | undefined, restaurantFundedDiscount?: (CompositeFinanceLine | null) | undefined, voucherDiscount?: (CompositeFinanceLine | null) | undefined, promotionDiscount?: (CompositeFinanceLine | null) | undefined, operatorDiscount?: (CompositeFinanceLine | null) | undefined, loyaltyDiscount?: (CompositeFinanceLine | null) | undefined, tipForRestaurant?: (CompositeFinanceLine | null) | undefined, adjustments?: (CompositeFinanceLine | null) | undefined, packingFee?: (CompositeFinanceLine | null) | undefined, bagFee?: (CompositeFinanceLine | null) | undefined, serviceProviderDiscount?: (CompositeFinanceLine | null) | undefined, tipForServiceProviderCourier?: (CompositeFinanceLine | null) | undefined, feeForServiceProviderDelivery?: (CompositeFinanceLine | null) | undefined, smallOrderFee?: (CompositeFinanceLine | null) | undefined, serviceFee?: (CompositeFinanceLine | null) | undefined, otherFee?: (CompositeFinanceLine | null) | undefined, netPayout?: (CompositeFinanceLine | null) | undefined, couponCodes?: (Array | null) | undefined}; export type FinancialTransaction = {orderIdentifiers: OrderIdentifierFinance, id: string, pending: boolean, currencyCode: string, createdAt: string, customerId?: (string | null) | undefined, notes?: (string | null) | undefined, type: 'PAYMENT' | 'ADJUSTMENT' | 'CANCELLATION' | 'MISC', payout?: PayoutInfo | undefined, orderItems?: (Array | null) | undefined, issues?: (Array | null) | undefined, data: FinancialData}; export type CreateApiFinanceV1FinancialTransactionsArgs = {'X-Store-Id': StoreId, body: FinancialTransaction}; export type CreateApiFinanceV1FinancialTransactionsOptions = {baseUrl?: string | undefined, OAuth20?: string | undefined, fetch?: typeof fetch | undefined}; /** * Post financial transactions * * POST /finance/v1/financial-transactions */ export const createApiFinanceV1FinancialTransactions = async (args: CreateApiFinanceV1FinancialTransactionsArgs, options?: CreateApiFinanceV1FinancialTransactionsOptions) => { const {baseUrl = "https://partners.tryotter.com", fetch: fetchFn = fetch, OAuth20} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Store-Id'] != null) headers.set("X-Store-Id", String(args['X-Store-Id'])) if (OAuth20 !== undefined) headers.set('authorization', `Bearer ${OAuth20}`) const url = `${baseUrl.replace(/\/+$/, '')}/finance/v1/financial-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 undefined };