import type { SupportedCurrencies } from '@entities' import type { HttpClient, Locale } from '@services' import { type HttpType, http } from '../http/client' import { type HttpClientType, omyHttp } from '../httpExternal/omyClient' export type ShareGroopOrderStatus = | 'initiated' | 'confirmed' | 'pendingCommit' | 'completed' | 'refunded' | 'canceled' export type ShareGroopOrder = { id: string platformId: string amount: number amountAuthorized: number amountVoided: number amountConfirmed: number amountCaptured: number amountRefunded: number delay: number dueDate: number secure3D: boolean currency: SupportedCurrencies locale: Locale ux: string type: string status: ShareGroopOrderStatus createdAt: number email: string firstName: string lastName: string trackId: string items: { id: string name: string amount: number quantity: number trackId: string description: string }[] metadata: { house_id: string } } export class ShareGroop { private httpOptions = {} private http = {} as HttpClient private apiUrl = '' static SUCCESSFUL_STATUSES: ShareGroopOrderStatus[] = [ 'completed', 'confirmed', 'pendingCommit', ] constructor(provider: { apiUrl: string apiKey: string httpClientType: HttpClientType }) { this.httpOptions = { headers: { Authorization: provider.apiKey }, } this.apiUrl = provider.apiUrl const api: HttpType['api'] = { name: 'sharegroop', url: this.apiUrl } this.http = provider.httpClientType === 'axios' ? http({ api, unserialized: true }) : omyHttp({ api }) } async getOrderById(orderId: string) { const res = await this.http.get<{ data: ShareGroopOrder success: boolean }>(`v1/orders/${orderId}`, this.httpOptions) return res.data } }