Skip to content

Commit e8caa51

Browse files
committed
Created function to do pence to pounds conversion
1 parent 3906504 commit e8caa51

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/server/plugins/engine/routes/payment-helper.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ export function buildPaymentInfo(
6363
}
6464
}
6565

66+
/**
67+
* @param {number} amount
68+
*/
69+
export function convertPenceToPounds(amount) {
70+
return `${amount / 100}`
71+
}
72+
6673
/**
6774
* @import { Request } from '@hapi/hapi'
6875
* @import { GetPaymentResponse, PaymentSessionData } from '~/src/server/plugins/payment/types.js'

src/server/plugins/engine/routes/payment.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createLogger } from '~/src/server/common/helpers/logging/logger.js'
66
import { EXTERNAL_STATE_APPENDAGE } from '~/src/server/constants.js'
77
import {
88
buildPaymentInfo,
9+
convertPenceToPounds,
910
getPaymentContext
1011
} from '~/src/server/plugins/engine/routes/payment-helper.js'
1112

@@ -64,7 +65,7 @@ function logPaymentSuccess(session, paymentStatus) {
6465
buildPaymentInfo(
6566
'pre-auth',
6667
'success',
67-
`${paymentStatus.state.status} amount=${paymentStatus.amount / 100}`,
68+
`${paymentStatus.state.status} amount=${convertPenceToPounds(paymentStatus.amount)}`,
6869
session.isLivePayment,
6970
paymentStatus.paymentId
7071
),
@@ -82,7 +83,7 @@ function logPaymentFailure(session, paymentStatus) {
8283
buildPaymentInfo(
8384
'pre-auth',
8485
'failed/cancelled',
85-
`${paymentStatus.state.status} amount=${paymentStatus.amount / 100}`,
86+
`${paymentStatus.state.status} amount=${convertPenceToPounds(paymentStatus.amount)}`,
8687
session.isLivePayment,
8788
paymentStatus.paymentId
8889
),

src/server/plugins/payment/service.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { StatusCodes } from 'http-status-codes'
22

33
import { createLogger } from '~/src/server/common/helpers/logging/logger.js'
4-
import { buildPaymentInfo } from '~/src/server/plugins/engine/routes/payment-helper.js'
4+
import {
5+
buildPaymentInfo,
6+
convertPenceToPounds
7+
} from '~/src/server/plugins/engine/routes/payment-helper.js'
58
import { get, post, postJson } from '~/src/server/services/httpService.js'
69

710
const PAYMENT_BASE_URL = 'https://publicapi.payments.service.gov.uk'
@@ -60,7 +63,7 @@ export class PaymentService {
6063
buildPaymentInfo(
6164
'create-payment',
6265
'success',
63-
`amount=${amount / 100}`,
66+
`amount=${convertPenceToPounds(amount)}`,
6467
isLivePayment,
6568
response.payment_id
6669
),
@@ -156,7 +159,7 @@ export class PaymentService {
156159
category: 'payment',
157160
action: 'capture-payment',
158161
outcome: 'success',
159-
reason: `amount=${amount / 100}`,
162+
reason: `amount=${convertPenceToPounds(amount)}`,
160163
reference: paymentId
161164
}
162165
},

0 commit comments

Comments
 (0)