Skip to content

Commit

Permalink
PP-11681 Refactor 'axios-base-client' call following code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
JFSGDS committed Mar 27, 2024
1 parent 56070c5 commit 64a4848
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions app/services/clients/ledger.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,44 @@ const defaultOptions = {
limit_total: true
}

const client = new Client(defaultOptions.service)

const transaction = async function transaction (id, gatewayAccountId, options = {}) {
this.client = new Client(defaultOptions.service)
const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl
let url = `${baseUrl}/v1/transaction/${id}?account_id=${gatewayAccountId}`
if ( options.transaction_type ) {
url = `${url}&transaction_type=${options.transaction_type}`
}
configureClient(this.client, url)
const response = await this.client.get(url, 'Get individual transaction details')
configureClient(client, url)
const response = await client.get(url, 'Get individual transaction details')
const body = legacyConnectorTransactionParity(response.data)
return body
}

const transactionWithAccountOverride = async function transactionWithAccountOverride (id, options = {}) {
const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl
const url = urlJoin(baseUrl,'/v1/transaction', id)
this.client = new Client(defaultOptions.service)
const fullUrl = `${url}?override_account_id_restriction=true`
configureClient(this.client, fullUrl)
const response = await this.client.get(fullUrl, 'Get individual transaction details with no accountId restriction')
configureClient(client, fullUrl)
const response = await client.get(fullUrl, 'Get individual transaction details with no accountId restriction')
return response.data
}

async function getDisputesForTransaction (id, gatewayAccountId, options = {}) {
const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl
const url = urlJoin(baseUrl,'/v1/transaction', id, 'transaction')
this.client = new Client(defaultOptions.service)
const fullUrl = `${url}?gateway_account_id=${gatewayAccountId}&transaction_type=DISPUTE`
configureClient(this.client, fullUrl)
const response = await this.client.get(fullUrl, 'Get disputes for payment')
configureClient(client, fullUrl)
const response = await client.get(fullUrl, 'Get disputes for payment')
return response.data
}

const events = async function events (transactionId, gatewayAccountId, options = {}) {
const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl
const url = urlJoin(baseUrl,'/v1/transaction', transactionId, 'event')
this.client = new Client(defaultOptions.service)
const fullUrl = `${url}?gateway_account_id=${gatewayAccountId}`
configureClient(this.client, fullUrl)
const response = await this.client.get(fullUrl, 'List events for a given transaction')
configureClient(client, fullUrl)
const response = await client.get(fullUrl, 'List events for a given transaction')
const body = legacyConnectorEventsParity(response.data)
return body
}
Expand All @@ -77,9 +75,8 @@ const transactions = async function transactions (gatewayAccountIds = [], filter
const formattedFilterParams = getQueryStringForParams(filters, true, true)
const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl
const url = `${baseUrl}${path}?${formattedParams}&${formattedFilterParams}`
this.client = new Client(defaultOptions.service)
configureClient(this.client, url)
const response = await this.client.get(
configureClient(client, url)
const response = await client.get(
url,
'List transactions for a given gateway account ID',
{
Expand All @@ -98,9 +95,8 @@ const transactionSummary = async function transactionSummary (gatewayAccountId,
const path = '/v1/report/transactions-summary'
const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl
const url = `${baseUrl}${path}?account_id=${gatewayAccountId}&from_date=${fromDate}&to_date=${toDate}`
this.client = new Client(defaultOptions.service)
configureClient(this.client, url)
const response = await this.client.get(url,'Transaction summary statistics for a given gateway account ID')
configureClient(client, url)
const response = await client.get(url,'Transaction summary statistics for a given gateway account ID')
const body = legacyConnectorTransactionSummaryParity(response.data)
return body
}
Expand All @@ -111,9 +107,8 @@ const payouts = async function payouts (gatewayAccountIds = [], page = 1, displa
if ( displaySize ) {
url = `${url}&display_size=${displaySize}`
}
this.client = new Client(defaultOptions.service)
configureClient(this.client, url)
const response = await this.client.get(url,'List payouts for a given gateway account ID')
configureClient(client, url)
const response = await client.get(url,'List payouts for a given gateway account ID')
return response.data
}

Expand All @@ -130,18 +125,16 @@ const agreements = async function agreements (serviceId, live, accountId, page =
const filterParams = new URLSearchParams(options.filters).toString()
url = `${url}&${filterParams}`
}
this.client = new Client(defaultOptions.service)
configureClient(this.client, url)
const response = await this.client.get(url,'List agreements for a given service and environment')
configureClient(client, url)
const response = await client.get(url,'List agreements for a given service and environment')
return response.data
}

const agreement = async function agreement (id, serviceId, options = {}) {
const baseUrl = options.baseUrl ? options.baseUrl : defaultOptions.baseUrl
let url = `${baseUrl}/v1/agreement/${id}?service_id=${serviceId}`
this.client = new Client(defaultOptions.service)
configureClient(this.client, url)
const response = await this.client.get(url,'Get agreement by ID')
configureClient(client, url)
const response = await client.get(url,'Get agreement by ID')
return response.data
}

Expand Down

0 comments on commit 64a4848

Please sign in to comment.