diff --git a/layouts/default.vue b/layouts/default.vue index 3234e775..e358c6a0 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -273,6 +273,14 @@ export default class DefaultLayoutsClass extends Vue { title: 'GET /settlements/{id}', to: '/debug/settlements/details', }, + { + title: 'GET /wires/{id}', + to: '/debug/wires/details', + }, + { + title: 'POST /wires', + to: '/debug/wires/create', + }, ] walletsLinks = [ diff --git a/lib/wiresApi.ts b/lib/wiresApi.ts new file mode 100644 index 00000000..d22b36a4 --- /dev/null +++ b/lib/wiresApi.ts @@ -0,0 +1,84 @@ +import { get } from 'lodash' +import axios from 'axios' + +import { getAPIHostname } from './apiTarget' + +export interface CreateWireAccountPayload { + idempotencyKey: string + beneficiaryName: string + bankName: string + accountNumber: string + bankIdentifier: string + billingDetails: { + name: string + city: string + country: string + line1: string + line2: string + district: string + postalCode: string + } + bankAddress: { + city: string + country: string + line1: string + line2: string + district: string + postalCode: string + } +} + +const instance = axios.create({ + baseURL: getAPIHostname(), +}) + +/** + * Global error handler: + * Intercepts all axios reponses and maps + * to errorHandler object + */ +instance.interceptors.response.use( + function (response) { + if (get(response, 'data.data')) { + return response.data.data + } + return response + }, + function (error) { + let response = get(error, 'response') + if (!response) { + response = error.toJSON() + } + return Promise.reject(response) + } +) + +/** Returns the axios instance */ +function getInstance() { + return instance +} + +/** + * Create Wire Account + * @param {*} payload (contains form data) + */ +function createWireAccount(payload: CreateWireAccountPayload) { + const url = '/v1/wires' + return instance.post(url, payload) +} + +/** + * Get Wire Account By Id + * @param {String} accountId + */ +function getWireAccountById(accountId: string) { + const url = `/v1/wires/${accountId}` + + return instance.get(url) +} + +export default { + getInstance, + createWireAccount, + getWireAccountById, +} diff --git a/lib/wiresTestData.ts b/lib/wiresTestData.ts new file mode 100644 index 00000000..ce3ba3d0 --- /dev/null +++ b/lib/wiresTestData.ts @@ -0,0 +1,28 @@ +export const exampleWireAccounts = [ + { + title: 'Test Data', + formData: { + beneficiaryName: 'Satoshi Nakamoto', + bankName: 'WELLS FARGO BANK', + accountNumber: '11111111111', + bankIdentifier: '121000248', + billingDetails: { + name: 'Satoshi Nakamoto', + city: 'Boston', + country: 'US', + line1: '100 Money Street', + line2: 'Suite 1', + district: 'MA', + postalCode: '01234', + }, + bankAddress: { + city: 'SAN FRANCISCO', + country: 'US', + line1: 'line1', + line2: 'line2', + district: 'CA', + postalCode: '11111', + }, + }, + }, +] diff --git a/nuxt.config.js b/nuxt.config.js index cb200a6d..cc70ea79 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -44,6 +44,7 @@ export default { '~/plugins/walletsApi', '~/plugins/transfersApi', '~/plugins/addressesApi', + '~/plugins/wiresApi', ], /* ** Nuxt.js dev-modules diff --git a/pages/debug/index.vue b/pages/debug/index.vue index 1c67ce17..774032a2 100644 --- a/pages/debug/index.vue +++ b/pages/debug/index.vue @@ -153,54 +153,28 @@

- -

Wallets endpoints

- Requires: api key -

-

- Api endpoints to manage wallets. -

-

- GET - Get all wallets -

-

- GET - - - Get wallet details by id - -

-

- POST - - Add wallet - -

-
- - -

Transfers endpoints

+ +

Wires endpoints

Requires: api key

- Api endpoints to manage transfers. + Api endpoints to manage wire accounts.

GET - Get all transfers -

-

- GET - - - Get transfer details by id + + Get wire account details by id

POST - - Add transfer + + Create wire account

diff --git a/pages/debug/wallets/transfers/create.vue b/pages/debug/wallets/transfers/create.vue index 1b3f128a..b49283af 100644 --- a/pages/debug/wallets/transfers/create.vue +++ b/pages/debug/wallets/transfers/create.vue @@ -144,7 +144,6 @@ export default class CreateTransferClass extends Vue { try { const res = await this.$walletsApi.getMasterWallet() - console.log(res) if (res.payments.masterWalletId) { this.formData.source.id = res.payments.masterWalletId } diff --git a/pages/debug/wires/create.vue b/pages/debug/wires/create.vue new file mode 100644 index 00000000..38e272c6 --- /dev/null +++ b/pages/debug/wires/create.vue @@ -0,0 +1,230 @@ + + + diff --git a/pages/debug/wires/details.vue b/pages/debug/wires/details.vue new file mode 100644 index 00000000..ca7f2412 --- /dev/null +++ b/pages/debug/wires/details.vue @@ -0,0 +1,83 @@ + + + diff --git a/plugins/wiresApi.ts b/plugins/wiresApi.ts new file mode 100644 index 00000000..ad4a1248 --- /dev/null +++ b/plugins/wiresApi.ts @@ -0,0 +1,43 @@ +import wiresApi, { CreateWireAccountPayload } from '@/lib/wiresApi' + +declare module 'vue/types/vue' { + interface Vue { + $wiresApi: { + createWireAccount: (payload: CreateWireAccountPayload) => any + getWireAccountById: any + getInstance: any + } + } +} + +export default ({ store }: any, inject: any) => { + const instance = wiresApi.getInstance() + + instance.interceptors.request.use( + function (config) { + store.commit('CLEAR_REQUEST_DATA') + store.commit('SET_REQUEST_URL', `${config.baseURL}${config.url}`) + store.commit('SET_REQUEST_PAYLOAD', config.data) + + if (store.state.bearerToken) { + config.headers = { Authorization: `Bearer ${store.state.bearerToken}` } + } + return config + }, + function (error) { + return Promise.reject(error) + } + ) + + instance.interceptors.response.use( + function (response) { + store.commit('SET_RESPONSE', response) + return response + }, + function (error) { + return Promise.reject(error) + } + ) + + inject('wiresApi', wiresApi) +}