Skip to content

Commit

Permalink
Merge pull request #3823 from alphagov/PP-11682_replace_request_with_…
Browse files Browse the repository at this point in the history
…axios_cardid_client

PP-11682 Replace 'request' package with 'axios' for 'cardid.client'.
  • Loading branch information
iqbalgds authored Apr 17, 2024
2 parents 9459043 + 20ff29e commit cf6a065
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 6 additions & 6 deletions app/models/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ const checkCard = function (cardNo, allowed, blockPrepaidCards, language, correl
}
cardIdClient.post({ payload: data, correlationId: correlationId })
.then((response) => {
incrementStatusCodeCounter('checkCard', response.statusCode)
incrementStatusCodeCounter('checkCard', response.status)
logger.info('POST to %s ended - total time %dms', cardIdClient.CARD_URL, new Date() - startTime, loggingFields)

if (response.statusCode === 404) {
if (response.status === 404) {
return reject(new Error('Your card is not supported'))
}
if (response.statusCode === 422) {
if (response.status === 422) {
return reject(new Error(i18n.__('fieldErrors.fields.cardNo.message')))
}
// if the server is down, or returns non 500, just continue
if (response.statusCode !== 200) {
if (response.status !== 200) {
logger.error(`Error communicating with ${cardIdClient.CARD_URL}`, {
...loggingFields,
service: 'cardid',
method: 'POST',
status_code: response.statusCode,
status_code: response.status,
url: cardIdClient.CARD_URL
})
return resolve()
}

const body = response.body
const body = response.data

const card = {
brand: changeCase.paramCase(body.brand),
Expand Down
15 changes: 13 additions & 2 deletions app/services/clients/cardid.client.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
'use strict'

// Local dependencies
const baseClient = require('./base.client/base.client')
const { Client } = require('@govuk-pay/pay-js-commons/lib/utils/axios-base-client/axios-base-client')
const { configureClient } = require('./base/config')

// Constants
const CARD_URL = process.env.CARDID_HOST + '/v1/api/card'
const client = new Client('cardid')
configureClient(client, CARD_URL)

/**
*
* @param args
*
* @returns {Request}
*/
exports.post = (args) => baseClient.post(CARD_URL, args, null)

exports.post = async (args) => {
try {
const response = await client.post(CARD_URL, args.payload, 'card id')
return response
} catch (err) {
return { status: err.errorCode }
}
}
exports.CARD_URL = CARD_URL

0 comments on commit cf6a065

Please sign in to comment.