diff --git a/src/index.ts b/src/index.ts index d2f91f9..cbd7747 100644 --- a/src/index.ts +++ b/src/index.ts @@ -76,7 +76,7 @@ export { export { TEQUILAPI_SSE_URL, SSEResponse, SSEEventType, parseSSEResponse, AppState } from './sse/sse' export { logger, Logger } from './logger' -export { TEQUILAPI_URL, TequilapiClient, HttpTequilapiClient } from './tequilapi-client' +export { TEQUILAPI_URL, TequilapiClient } from './tequilapi-client' export { TequilapiClientFactory } from './tequilapi-client-factory' export { TequilapiError, AxiosError } from './tequilapi-error' @@ -84,10 +84,11 @@ export { MMNReport, MMNApiKeyResponse, MMNReportResponse } from './mmn/mmn' export { Pageable } from './common/pageable' export { + PaymentAPI, Money, - PaymentOrderResponse, - PaymentOrderRequest, - PaymentOrderOptionsResponse, + CreatePaymentOrderRequest, + PaymentOrder, + PaymentGateway, } from './payment' export { EntertainmentEstimateQuery, EntertainmentEstimateResponse } from './payment/entertainment' export { ReferralTokenResponse } from './referral' diff --git a/src/payment/index.ts b/src/payment/index.ts index 1306963..b196cc1 100644 --- a/src/payment/index.ts +++ b/src/payment/index.ts @@ -4,34 +4,72 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +import { HttpInterface } from '../http/interface' -export interface PaymentOrderRequest { - lightningNetwork: boolean - mystAmount: number +export interface Money { + amount: number + currency: string +} + +export interface PaymentGateway { + currencies: string[] + name: string + orderOptions: { + minimum: number + suggested: number[] + } +} + +export interface CreatePaymentOrderRequest { + mystAmount: string payCurrency: string + gatewayCallerData: { + country?: string + lightningNetwork?: boolean + } } -export interface PaymentOrderResponse { - id: number +export interface PaymentOrder { + id: string + status: string identity: string - mystAmount: number - payAmount: number + gatewayName: string + receiveMyst: string + payAmount: string payCurrency: string - paymentAddress: string - paymentUrl: string - priceAmount: number - priceCurrency: string - receiveAmount: number - receiveCurrency: string - status: string + publicGatewayData?: { + secureForm?: string + createdAt?: Date + expireAt?: Date + lightningNetwork?: boolean + paymentAddress?: string + paymentUrl?: string + } } -export interface PaymentOrderOptionsResponse { - minimum: number - suggested: number[] -} +export class PaymentAPI { + private http: HttpInterface + constructor(http: HttpInterface) { + this.http = http + } -export interface Money { - amount: number - currency: string + public async gateways(): Promise { + return await this.http.get('/v2/payment-order-gateways') + } + + public async createOrder( + id: string, + gateway: string, + req: CreatePaymentOrderRequest + ): Promise { + return await this.http.post(`/v2/identities/${id}/${gateway}/payment-order`, req) + } + + public async orders(id: string): Promise { + return await this.http.get(`/v2/identities/${id}/payment-order`) + } + + public async order(id: string, orderId: string): Promise { + return await this.http.get(`/v2/identities/${id}/payment-order/${orderId}`) + } } diff --git a/src/tequilapi-client-factory.ts b/src/tequilapi-client-factory.ts index 21affef..1814b9e 100644 --- a/src/tequilapi-client-factory.ts +++ b/src/tequilapi-client-factory.ts @@ -10,7 +10,6 @@ import { HttpInterface } from './http/interface' import axios, { AxiosInstance } from 'axios' import { AxiosAdapter } from './http/axios-adapter' import { - HttpTequilapiClient, pathConfig, pathConfigDefault, pathConfigUser, @@ -32,7 +31,7 @@ export class TequilapiClientFactory { if (!adapter) { adapter = this.buildAdapter() } - return new HttpTequilapiClient(adapter) + return new TequilapiClient(adapter) } public axiosInstance(): AxiosInstance { diff --git a/src/tequilapi-client.spec.ts b/src/tequilapi-client.spec.ts index 3dee2ce..d6fb74d 100644 --- a/src/tequilapi-client.spec.ts +++ b/src/tequilapi-client.spec.ts @@ -7,7 +7,7 @@ import MockAdapter from 'axios-mock-adapter' import { AxiosAdapter } from './http/axios-adapter' -import { HttpTequilapiClient, TequilapiClient } from './tequilapi-client' +import { TequilapiClient } from './tequilapi-client' import { parseIdentityRef } from './identity/identity' import { parseServiceInfo, parseServiceListResponse } from './provider/service-info' import { TequilapiClientFactory } from './tequilapi-client-factory' @@ -21,7 +21,7 @@ describe('HttpTequilapiClient', () => { beforeEach(() => { const clientFactory = new TequilapiClientFactory() const axios = clientFactory.axiosInstance() - api = new HttpTequilapiClient(new AxiosAdapter(axios)) + api = new TequilapiClient(new AxiosAdapter(axios)) mock = new MockAdapter(axios) }) @@ -905,4 +905,28 @@ describe('HttpTequilapiClient', () => { expect(res.data['dashes-and_underscores']).toEqual(true) }) }) + describe('paymentGateways()', () => { + it('send payment gateways', async () => { + mock.onGet('v2/payment-order-gateways').reply(200, [ + { + currencies: ['BTC', 'BCH', 'DAI', 'ETH', 'LTC', 'USDT', 'MYST', 'DOGE'], + name: 'coingate', + order_options: { + minimum: 10.7, + suggested: [20, 40, 90, 120, 150, 240], + }, + }, + { + currencies: ['EUR', 'USD', 'GBP'], + name: 'cardinity', + order_options: { + minimum: 2.15, + suggested: [10, 20, 45, 60, 75, 120], + }, + }, + ]) + const res = await api.payment.gateways() + expect(res).toHaveLength(2) + }) + }) }) diff --git a/src/tequilapi-client.ts b/src/tequilapi-client.ts index 0d9ae4e..754dc54 100644 --- a/src/tequilapi-client.ts +++ b/src/tequilapi-client.ts @@ -64,12 +64,7 @@ import { } from './transactor/settlement' import { IdentityCurrentRequest } from './identity/selection' import { AuthRequest, AuthResponse, ChangePasswordRequest } from './auth/auth' -import { - Money, - PaymentOrderOptionsResponse, - PaymentOrderRequest, - PaymentOrderResponse, -} from './payment' +import { Money, PaymentAPI } from './payment' import { ReferralTokenResponse, ReferralTokenRewardsResponse } from './referral' import { CurrentPricesResponse } from './prices' import { parsePayoutAddressResponse, Payout } from './identity/payout' @@ -83,7 +78,7 @@ export const pathConfig = 'config' export const pathConfigUser = 'config/user' export const pathConfigDefault = 'config/default' -export interface TequilapiClient { +export interface BaseTequilapiClient { healthCheck(timeout?: number): Promise natStatus(): Promise nodeMonitoringStatus(): Promise @@ -158,11 +153,6 @@ export interface TequilapiClient { getMMNApiKey(): Promise clearMMNApiKey(): Promise - createPaymentOrder(identity: string, request: PaymentOrderRequest): Promise - getPaymentOrders(identity: string): Promise - getPaymentOrder(identity: string, orderId: number): Promise - getPaymentOrderOptions(): Promise - getPaymentOrderCurrencies(): Promise exchangeRate(quoteCurrency?: string): Promise estimateEntertainment(query: EntertainmentEstimateQuery): Promise @@ -171,11 +161,13 @@ export interface TequilapiClient { validateEthRPCL2(rpcUrls: string[], timeout?: number): Promise } -export class HttpTequilapiClient implements TequilapiClient { +class BaseHttpTequilapiClient implements BaseTequilapiClient { public http: HttpInterface + public readonly payment: PaymentAPI public constructor(http: HttpInterface) { this.http = http + this.payment = new PaymentAPI(http) } public async healthCheck(timeout?: number): Promise { @@ -562,29 +554,6 @@ export class HttpTequilapiClient implements TequilapiClient { return this.http.delete(`mmn/api-key`) } - public async createPaymentOrder( - identity: string, - request: PaymentOrderRequest - ): Promise { - return this.http.post(`/identities/${identity}/payment-order`, request) - } - - public async getPaymentOrders(identity: string): Promise { - return this.http.get(`/identities/${identity}/payment-order`) - } - - public async getPaymentOrder(identity: string, orderId: number): Promise { - return this.http.get(`/identities/${identity}/payment-order/${orderId}`) - } - - public async getPaymentOrderOptions(): Promise { - return this.http.get(`/payment-order-options`) - } - - public async getPaymentOrderCurrencies(): Promise { - return this.http.get(`/payment-order-currencies`) - } - public async getReferralToken(identity: string): Promise { return this.http.get(`/identities/${identity}/referral`) } @@ -611,3 +580,5 @@ export class HttpTequilapiClient implements TequilapiClient { return this.http.get(`/transactor/token/${token}/reward`) } } + +export class TequilapiClient extends BaseHttpTequilapiClient {} diff --git a/src/test-utils/empty-tequilapi-client-mock.ts b/src/test-utils/empty-tequilapi-client-mock.ts deleted file mode 100644 index 6c2c04f..0000000 --- a/src/test-utils/empty-tequilapi-client-mock.ts +++ /dev/null @@ -1,351 +0,0 @@ -/** - * Copyright (c) 2020 BlockDev AG - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -/* eslint-disable @typescript-eslint/no-unused-vars */ - -import { MMNApiKeyResponse } from '../mmn/mmn' -import { Issue, IssueId } from '../feedback/issue' -import { Config } from '../config/config' -import { AccessPolicy } from '../access-policy/access-policy' -import { IP } from '../location/ip' -import { ConnectionRequest } from '../connection/request' -import { ConnectionStatistics } from '../connection/statistics' -import { ConnectionInfo } from '../connection/status' -import { Location } from '../location/location' -import { NodeHealthcheck } from '../daemon/healthcheck' -import { IdentityBalanceResponse, Identity, IdentityRef } from '../identity/identity' -import { IdentityRegisterRequest, IdentityRegistrationResponse } from '../identity/registration' -import { NatStatusResponse } from '../nat/status' -import { NatTypeResponse } from '../nat/type' -import { NodeMonitoringStatusResponse } from '../node/status' -import { Proposal, ProposalQuery } from '../proposal/proposal' -import { ServiceInfo } from '../provider/service-info' -import { ServiceStartRequest } from '../provider/service-request' -import { - SessionListQuery, - SessionListResponse, - SessionQuery, - SessionStatsAggregatedResponse, - SessionStatsDailyResponse, -} from '../session/session' -import { TequilapiClient } from '../tequilapi-client' -import { ChainSummary } from '../transactor/chains' -import { Fees } from '../transactor/fees' -import { - BeneficiaryTxStatus, - DecreaseStakeRequest, - SettlementListQuery, - SettlementListResponse, - SettleRequest, - SettleWithBeneficiaryRequest, -} from '../transactor/settlement' -import { IdentityCurrentRequest } from '../identity/selection' -import { IdentityBeneficiaryResponse } from '../identity/beneficiary' -import { AuthRequest, AuthResponse, ChangePasswordRequest } from '../auth/auth' -import { - Money, - PaymentOrderOptionsResponse, - PaymentOrderRequest, - PaymentOrderResponse, -} from '../payment' -import { Terms, TermsRequest } from '../daemon/terms' -import { ReferralTokenResponse, ReferralTokenRewardsResponse } from '../referral' -import { FilterPresetsResponse } from '../proposal/filter-preset' -import { CurrentPricesResponse } from '../prices' -import { Payout } from '../identity/payout' -import { EntertainmentEstimateQuery, EntertainmentEstimateResponse } from '../payment/entertainment' -import { WithdrawRequest } from '../transactor/withdraw' - -export class EmptyTequilapiClientMock implements TequilapiClient { - public connectionCancel(): Promise { - throw Error('Not implemented') - } - - public connectionCreate(request: ConnectionRequest, timeout?: number): Promise { - throw Error('Not implemented') - } - - public connectionIp(timeout?: number): Promise { - throw Error('Not implemented') - } - - public connectionLocation(): Promise { - throw Error('Not implemented') - } - - public connectionStatistics(): Promise { - throw Error('Not implemented') - } - - public connectionStatus(): Promise { - throw Error('Not implemented') - } - - public findProposals(options?: ProposalQuery): Promise { - throw Error('Not implemented') - } - - public pricesCurrent(): Promise { - throw Error('Not implemented') - } - - public healthCheck(timeout?: number): Promise { - throw Error('Not implemented') - } - - public identityList(): Promise { - throw Error('Not implemented') - } - - public identity(id: string): Promise { - throw Error('Not implemented') - } - - public identityCreate(passphrase: string): Promise { - throw Error('Not implemented') - } - - public identityRegister(id: string, request?: IdentityRegisterRequest): Promise { - throw Error('Not implemented') - } - - public identityRegistration(id: string): Promise { - throw Error('Not implemented') - } - - public identityBeneficiary(id: string): Promise { - throw Error('Not implemented') - } - - public identityBalanceRefresh(id: string): Promise { - throw Error('Not implemented') - } - - public identityUnlock(id: string, passphrase: string, timeout?: number): Promise { - throw Error('Not implemented') - } - - public location(timeout?: number): Promise { - throw Error('Not implemented') - } - - public natType(): Promise { - throw new Error('Not implemented') - } - - public natStatus(): Promise { - throw new Error('Not implemented') - } - - public nodeMonitoringStatus(): Promise { - throw new Error('Not implemented') - } - - public serviceGet(serviceId: string): Promise { - throw Error('Not implemented') - } - - public serviceList(): Promise { - throw Error('Not implemented') - } - - public serviceStart(request: ServiceStartRequest, timeout?: number): Promise { - throw Error('Not implemented') - } - - public serviceStop(serviceId: string): Promise { - throw Error('Not implemented') - } - - public sessions(query?: SessionListQuery): Promise { - throw Error('Not implemented') - } - - public sessionStatsAggregated(query?: SessionQuery): Promise { - throw Error('Not implemented') - } - - public sessionStatsDaily(query?: SessionQuery): Promise { - throw Error('Not implemented') - } - - public stop(): Promise { - throw Error('Not implemented') - } - - public accessPolicies(): Promise { - throw Error('Not implemented') - } - - public identityCurrent(request: IdentityCurrentRequest): Promise { - throw Error('Not implemented') - } - - public payoutAddressSave(id: string, address: string): Promise { - throw Error('Not implemented') - } - - public payoutAddressGet(id: string): Promise { - throw Error('Not implemented') - } - - public authSetToken(token: string): void { - throw Error('Not implemented') - } - - public authAuthenticate(request: AuthRequest, useToken = true): Promise { - throw Error('Not implemented') - } - - public authLogin(request: AuthRequest): Promise { - throw Error('Not implemented') - } - - public authLogout(): Promise { - throw Error('Not implemented') - } - - public authChangePassword(request: ChangePasswordRequest): Promise { - throw Error('Not implemented') - } - - public async terms(): Promise { - throw Error('Not implemented') - } - - public async termsUpdate(request: TermsRequest): Promise { - throw Error('Not implemented') - } - - public config(): Promise { - throw Error('Not implemented') - } - - public defaultConfig(): Promise { - throw Error('Not implemented') - } - - public userConfig(): Promise { - throw Error('Not implemented') - } - - public updateUserConfig(config: Config): Promise { - throw Error('Not implemented') - } - - public reportIssue(issue: Issue, timeout?: number): Promise { - throw Error('Not implemented') - } - - public transactorFees(chainId?: number): Promise { - throw Error('Not implemented') - } - - public settleSync(request: SettleRequest): Promise { - throw Error('Not implemented') - } - - public settleAsync(request: SettleWithBeneficiaryRequest): Promise { - throw Error('Not implemented') - } - - public settleWithBeneficiary(request: SettleWithBeneficiaryRequest): Promise { - throw Error('Not implemented') - } - - public beneficiaryTxStatus(id: string): Promise { - throw Error('Not implemented') - } - - public settleIntoStakeSync(request: SettleRequest): Promise { - throw Error('Not implemented') - } - - public settleIntoStakeAsync(request: SettleRequest): Promise { - throw Error('Not implemented') - } - - public chainSummary(): Promise { - throw Error('Not implemented') - } - - public withdraw(request: WithdrawRequest): Promise { - throw Error('Not implemented') - } - - public decreaseStake(request: DecreaseStakeRequest): Promise { - throw Error('Not implemented') - } - - public settlementHistory(query?: SettlementListQuery): Promise { - throw Error('Not implemented') - } - - public getMMNNodeReport(): Promise { - throw Error('Not implemented') - } - - public setMMNApiKey(apiKey: string): Promise { - throw Error('Not implemented') - } - - public getMMNApiKey(): Promise { - throw Error('Not implemented') - } - - public clearMMNApiKey(): Promise { - throw Error('Not implemented') - } - - public createPaymentOrder( - identity: string, - request: PaymentOrderRequest - ): Promise { - throw Error('Not implemented') - } - - public getPaymentOrders(identity: string): Promise { - throw Error('Not implemented') - } - - public getPaymentOrder(identity: string, orderId: number): Promise { - throw Error('Not implemented') - } - - public getPaymentOrderOptions(): Promise { - throw Error('Not implemented') - } - public getPaymentOrderCurrencies(): Promise { - throw Error('Not implemented') - } - - public async getReferralToken(identity: string): Promise { - throw Error('Not implemented') - } - - public async exchangeRate(quoteCurrency?: string): Promise { - throw Error('Not implemented') - } - - public async validateEthRPCL2(rpcUrls: string[], timeout = 10_000): Promise { - throw Error('Not implemented') - } - - public async estimateEntertainment( - query: EntertainmentEstimateQuery - ): Promise { - throw new Error('Not implemented.') - } - - public async proposalFilterPresets(): Promise { - throw Error('Not implemented') - } - - public async referralTokenRewards(token: string): Promise { - throw Error('Not implemented') - } -} diff --git a/tsconfig.build.json b/tsconfig.build.json index 59dcf21..9ade9fd 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -6,7 +6,7 @@ ], "compilerOptions": { "declaration": true, - "target": "es5", + "target": "es2015", "module": "commonjs", "lib": ["es2015"], "outDir": "lib", diff --git a/tsconfig.json b/tsconfig.json index a78aced..e6c555a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es2015", "module": "commonjs", "lib": ["es2015"], "outDir": "lib",