import { WyreAPIInterface } from './WyreAPIInterface' import { CreateSubscriptionRequest } from './CreateSubscriptionRequest' import { APIResponse } from './APIResponse' import { Subscription } from './Subscription' import { SubscriptionsList } from './SubscriptionsList' import { GetSubscriptionsRequest } from './GetSubscriptionsRequest' import { Transfer } from './Transfer' import { TransferRequest } from './TransferRequest' import { WyreAccount } from './WyreAccount' import { CreateAccountRequest } from './CreateAccountRequest' import { WyreAPIOptions } from './WyreAPIOptions' import { BaseWyreAPI } from './BaseWyreAPI' import { UploadDocumentParams } from './UploadDocumentParams' import { CreateWyreWalletParams } from './CreateWyreWalletParams' import { WyreWallet } from './WyreWallet' import { CreateMultipleWalletsParams } from './CreateMultipleWalletsParams' import { EditWalletParams } from './EditWalletParams' import { PaymentMethodParams } from './PaymentMethodParams' import { PaymentMethod } from './PaymentMethod' import { UploadPaymentMethodDocumentParams } from './UploadPaymentMethodDocumentParams' import { UpdateAccountRequest } from './UpdateAccountRequest' import { WyreUser } from './WyreUser' import { CreateUserRequest } from './CreateUserRequest' import { WyreUserKYCData } from './WyreUserKYCData' import { MigrateAccountResponse } from './MigrateAccountResponse' // tslint:disable: no-console export class BearerTokenWyreAPI extends BaseWyreAPI implements WyreAPIInterface { constructor( options: WyreAPIOptions, ) { super(options) } async createUser(params: CreateUserRequest): Promise> { throw new Error(`Unsupported`) } async getUser( userID: string, scopes: string = 'TRANSFER', ): Promise> { throw new Error(`Unsupported`) } uploadUserKYCData( userID: string, kycData: WyreUserKYCData, ): Promise> { throw new Error(`Unsupported`) } async createAccount(params: CreateAccountRequest): Promise> { const { error } = await this.createSession() if (error) { return { error } } const req = this.getAxiosInstance().post( '/v3/accounts', params, ) return await this.executeRequest(req) } async updateAccount( accountID: string, updates: UpdateAccountRequest, ): Promise> { const req = this.getAxiosInstance().post( `/v3/accounts/${accountID}`, updates, ) return await this.executeRequest(req) } async migrateAccount( accountID, ): Promise> { const req = this.getAxiosInstance().post( `/v3/users/migrateAccount/${accountID}`, ) return await this.executeRequest(req) } async uploadDocument( params: UploadDocumentParams, buff: Buffer, ): Promise> { const { accountId, fieldId, contentType } = params const headers = { 'Content-Type': contentType, 'Content-Length': buff.length, } const req = this.getAxiosInstance().post( `/v3/accounts/${accountId}/${fieldId}`, buff, { headers }, ) return await this.executeRequest(req) } async uploadPaymentMethodDocument( params: UploadPaymentMethodDocumentParams, buff: Buffer, ): Promise> { const { paymentMethodId, contentType } = params const headers = { 'Content-Type': contentType, 'Content-Length': buff.length, } const req = this.getAxiosInstance().post( `/v2/paymentMethod/${paymentMethodId}/followup`, buff, { headers }, ) return await this.executeRequest(req) } async addPaymentMethod( params: PaymentMethodParams, ): Promise> { const req = this.getAxiosInstance().post( '/v2/paymentMethods', params, ) return await this.executeRequest(req) } async getPaymentMethod( paymentMethodID: string, ): Promise> { const req = this.getAxiosInstance().get( `/v2/paymentMethod/${paymentMethodID}`, ) return await this.executeRequest(req) } async listPaymentMethods(): Promise> { const req = this.getAxiosInstance().get( `/v2/paymentMethod`, ) return await this.executeRequest(req) } async deletePaymentMethod( paymentMethodID: string, ): Promise> { const req = this.getAxiosInstance().delete( `/v2/paymentMethod/${paymentMethodID}`, ) return await this.executeRequest(req) } async attachBlockchainToPaymentMethod(paymentMethodId, params) { const req = this.getAxiosInstance().post( `/v2/paymentMethod/${paymentMethodId}/attach`, params, ) return await this.executeRequest(req) } async createTransfer(transferRequest: TransferRequest): Promise> { const req = this.getAxiosInstance().post( `/v3/transfers`, transferRequest, ) return await this.executeRequest(req) } async confirmTransfer(transferID): Promise> { const req = this.getAxiosInstance().post( `/v3/transfers/${transferID}/confirm`, ) return await this.executeRequest(req) } async getAccountInfoV2(): Promise> { const req = this.getAxiosInstance().get( `/v2/account`, ) return await this.executeRequest(req) } async getAccountInfoV3(accountID): Promise> { const req = this.getAxiosInstance().get( `/v3/accounts/${accountID}`, ) return await this.executeRequest(req) } async getTransfers(transferID): Promise> { let url = `/v3/transfers` if (transferID) { url += `/${transferID}` } const req = this.getAxiosInstance().get(url) return await this.executeRequest(req) } async createSubscription( subscribeRequest: CreateSubscriptionRequest ): Promise> { const req = this.getAxiosInstance().post( `/v3/subscriptions`, subscribeRequest ) const { response: subscription, error, } = await this.executeRequest(req) if (error) { return { error } } if (Object.keys(subscription).length === 0) { return { error: 'subscribeWebhook failed' } } return { response: subscription } } async deleteSubscription(subscriptionID): Promise> { const req = this.getAxiosInstance().delete( `/v3/subscriptions/${subscriptionID}` ) return await this.executeRequest(req) } async getSubscriptions( subscriptionsReq: GetSubscriptionsRequest ): Promise> { const { offset, length } = subscriptionsReq const req = this.getAxiosInstance().get( `/v3/subscriptions?offset=${offset}&length=${length}`, ) const { response, error, } = await this.executeRequest(req) if (error) { return { error } } return { response } } async getRates(as, pair) { const req = this.getAxiosInstance().get( `/v3/rates?as=${as}`, ) const { response: rates, error } = await this.executeRequest(req) if (error) { return { error } } if (pair) { return { rates: rates[pair] } } return { response: rates } } // Wallet Endpoints async createWallet(walletParams: CreateWyreWalletParams): Promise> { const req = this.getAxiosInstance().post( `/v2/wallets`, walletParams, ) return await this.executeRequest(req) } async createMultipleWallets(params: CreateMultipleWalletsParams): Promise> { const req = this.getAxiosInstance().post( `/v2/wallets/batch`, params, ) return await this.executeRequest(req) } async lookupWallet(walletID: string): Promise> { const req = this.getAxiosInstance().get( `/v2/wallet/${walletID}`, ) return await this.executeRequest(req) } async editWallet(walletID: string, params: EditWalletParams): Promise> { const req = this.getAxiosInstance().post( `/v2/wallet/${walletID}/update`, params, ) return await this.executeRequest(req) } async deleteWallet(walletID: string): Promise> { const req = this.getAxiosInstance().delete( `/v2/wallet/${walletID}`, ) return await this.executeRequest(req) } async listWallets(limit: number, offset: number): Promise> { const req = this.getAxiosInstance().get( `/v2/wallets?limit=${limit}&offset=${offset}`, ) return await this.executeRequest(req) } getMasqueraded(accountToken: string): WyreAPIInterface { return this } }