Skip to content

Commit 5ef879f

Browse files
authored
Merge pull request #304 from DEFRA/feat/df-634-further-logging
Feat/df 634 further logging
2 parents a9d7ba6 + 552f439 commit 5ef879f

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

src/server/plugins/engine/components/PaymentField.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ export class PaymentField extends FormComponent {
297297
)
298298
}
299299

300-
const captured = await paymentService.capturePayment(paymentId)
300+
const captured = await paymentService.capturePayment(
301+
paymentId,
302+
status.amount
303+
)
301304

302305
if (!captured) {
303306
throw new PaymentPreAuthError(

src/server/plugins/payment/service.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ export class PaymentService {
4848
})
4949

5050
logger.info(
51+
{
52+
event: {
53+
category: 'payment',
54+
action: 'create-payment',
55+
outcome: 'success',
56+
reference: response.payment_id
57+
}
58+
},
5159
`[payment] Created payment and user taken to enter pre-auth details for paymentId=${response.payment_id}`
5260
)
5361

@@ -83,7 +91,16 @@ export class PaymentService {
8391

8492
const state = response.payload.state
8593
logger.info(
86-
`[payment] Got payment status for paymentId=${paymentId}: ${state.status} message:${state.message ?? 'N/A'} code:${state.code ?? 'N/A'}`
94+
{
95+
event: {
96+
category: 'payment',
97+
action: 'get-payment-status',
98+
outcome: state.status,
99+
reason: `${state.code ?? 'N/A'} ${state.message ?? 'N/A'}`,
100+
reference: paymentId
101+
}
102+
},
103+
`[payment] Got payment status for paymentId=${paymentId}: status=${state.status}`
87104
)
88105

89106
return {
@@ -106,9 +123,10 @@ export class PaymentService {
106123
/**
107124
* Captures a payment that is in 'capturable' status
108125
* @param {string} paymentId
126+
* @param {number} amount
109127
* @returns {Promise<boolean>}
110128
*/
111-
async capturePayment(paymentId) {
129+
async capturePayment(paymentId, amount) {
112130
try {
113131
const response = await post(
114132
`${PAYMENT_BASE_URL}${PAYMENT_ENDPOINT}/${paymentId}/capture`,
@@ -124,6 +142,14 @@ export class PaymentService {
124142
statusCode === StatusCodes.NO_CONTENT
125143
) {
126144
logger.info(
145+
{
146+
event: {
147+
category: 'payment',
148+
action: 'capture-payment',
149+
outcome: `success amount=${amount}`,
150+
reference: paymentId
151+
}
152+
},
127153
`[payment] Successfully captured payment for paymentId=${paymentId}`
128154
)
129155
return true

src/server/plugins/payment/service.test.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ describe('payment service', () => {
154154
error: undefined
155155
})
156156

157-
const captureResult = await service.capturePayment('payment-id-12345')
157+
const captureResult = await service.capturePayment(
158+
'payment-id-12345',
159+
100
160+
)
158161
expect(captureResult).toBe(true)
159162
})
160163

@@ -169,7 +172,10 @@ describe('payment service', () => {
169172
error: undefined
170173
})
171174

172-
const captureResult = await service.capturePayment('payment-id-12345')
175+
const captureResult = await service.capturePayment(
176+
'payment-id-12345',
177+
100
178+
)
173179
expect(captureResult).toBe(true)
174180
})
175181

@@ -184,7 +190,10 @@ describe('payment service', () => {
184190
error: undefined
185191
})
186192

187-
const captureResult = await service.capturePayment('payment-id-12345')
193+
const captureResult = await service.capturePayment(
194+
'payment-id-12345',
195+
100
196+
)
188197
expect(captureResult).toBe(false)
189198
})
190199

@@ -194,7 +203,7 @@ describe('payment service', () => {
194203
.mockRejectedValueOnce(new Error('internal capture error'))
195204

196205
await expect(() =>
197-
service.capturePayment('payment-id-12345')
206+
service.capturePayment('payment-id-12345', 100)
198207
).rejects.toThrow('internal capture error')
199208
})
200209
})

0 commit comments

Comments
 (0)