Skip to content

Commit

Permalink
Fix bug where transaction id is not recognised (#2071)
Browse files Browse the repository at this point in the history
* Fix bug where transaction id is not recognised

https://eaflood.atlassian.net/browse/IWTF-4352

On return from GovPay, the transaction is not retrieved because the
transaction id has changed

Fix:
* Only set a transaction id if one hasn't already been set
  • Loading branch information
jaucourt authored Nov 7, 2024
1 parent 94d5677 commit b06fd27
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('The agreed handler', () => {
cache: () => ({
helpers: {
transaction: {
get: async () => ({ id: 'id-111', cost: 0 }),
get: async () => ({ cost: 0 }),
set: async () => {}
},
status: {
Expand Down Expand Up @@ -90,6 +90,41 @@ describe('The agreed handler', () => {
expect(transactionPayload.id).toBe(v4guid)
})

it("doesn't overwrite transaction id if one is already set", async () => {
const setTransaction = jest.fn()
const transactionId = 'abc-123-def-456'
uuidv4.mockReturnValue('def-789-ghi-012')
salesApi.finaliseTransaction.mockReturnValueOnce({
permissions: []
})
const mockRequest = {
cache: () => ({
helpers: {
status: {
get: async () => ({
[COMPLETION_STATUS.agreed]: true,
[COMPLETION_STATUS.posted]: true,
[COMPLETION_STATUS.finalised]: false,
[RECURRING_PAYMENT]: false
}),
set: () => {}
},
transaction: {
get: async () => ({ cost: 0, id: transactionId }),
set: setTransaction
}
}
})
}

await agreedHandler(mockRequest, getRequestToolkit())

expect(salesApi.finaliseTransaction).toHaveBeenCalledWith(
transactionId,
undefined // prepareApiFinalisationPayload has no mocked return value
)
})

it('sends a recurring payment creation request to Gov.UK Pay', async () => {
const preparedPayment = Symbol('preparedPayment')
prepareRecurringPayment.mockResolvedValueOnce(preparedPayment)
Expand Down
5 changes: 4 additions & 1 deletion packages/gafl-webapp-service/src/handlers/agreed-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ const finaliseTransaction = async (request, transaction, status) => {
export default async (request, h) => {
const status = await request.cache().helpers.status.get()
const transaction = await request.cache().helpers.transaction.get()
transaction.id = uuidv4()
if (!transaction.id) {
transaction.id = uuidv4()
}

// If the agreed flag is not set to true then throw an exception
if (!status[COMPLETION_STATUS.agreed]) {
Expand Down Expand Up @@ -279,6 +281,7 @@ export default async (request, h) => {

// If the transaction has already been finalised then redirect to the order completed page
if (!status[COMPLETION_STATUS.finalised]) {
console.log('finalising transaction', request, transaction, status)
await finaliseTransaction(request, transaction, status)
} else {
debug('Transaction %s already finalised, redirect to order complete: %s', transaction.id)
Expand Down

0 comments on commit b06fd27

Please sign in to comment.