Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fx notify #544

Merged
merged 9 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/ml-api-adapter",
"version": "14.1.0-snapshot.23",
"version": "14.1.0-snapshot.25",
"description": "Convert from ML API to/from internal Central Services messaging format",
"license": "Apache-2.0",
"private": true,
Expand Down Expand Up @@ -85,7 +85,7 @@
"@mojaloop/central-services-shared": "18.9.0",
"@mojaloop/central-services-stream": "11.3.1",
"@mojaloop/event-sdk": "14.1.1",
"@mojaloop/sdk-standard-components": "18.4.1",
"@mojaloop/sdk-standard-components": "19.0.0",
"@now-ims/hapi-now-auth": "2.1.0",
"axios": "1.7.7",
"blipp": "4.0.2",
Expand Down
20 changes: 15 additions & 5 deletions src/handlers/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ const processMessage = async (msg, span) => {
return true
}

if ([Action.FX_NOTIFY].includes(action)) {
if (action === Action.FX_NOTIFY) {
if (!isSuccess) {
throw ErrorHandler.Factory.createFSPIOPError(
ErrorHandler.Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR,
Expand All @@ -635,17 +635,27 @@ const processMessage = async (msg, span) => {

const { url: callbackURLTo } = await getEndpointFn(destination, REQUEST_TYPE.PATCH, true)
const endpointTemplate = getEndpointTemplate(REQUEST_TYPE.PATCH)
headers = createCallbackHeaders({ headers: content.headers, httpMethod: PATCH, endpointTemplate })
logger.debug(`Notification::processMessage - Callback.sendRequest({ ${callbackURLTo}, ${PATCH}, ${JSON.stringify(content.headers)}, ${payload}, ${id}, ${source}, ${destination} ${hubNameRegex} })`)

let payloadForFXP = JSON.parse(payload)
if (payloadForFXP.fulfilment) {
delete payloadForFXP.fulfilment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit unclear for me, why we need to delete fulfilment from payloadForFXP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @geka-evk as per the spec, there is no fulfilment in the patch notification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
payloadForFXP = JSON.stringify(payloadForFXP)
const method = PATCH
headers = createCallbackHeaders({ dfspId: destination, transferId: id, headers: content.headers, httpMethod: method, endpointTemplate }, fromSwitch)
headers['content-type'] = `application/vnd.interoperability.fxTransfers+json;version=${Util.resourceVersions[Enum.Http.HeaderResources.FX_TRANSFERS].contentVersion}`

logger.debug(`Notification::processMessage - Callback.sendRequest({ ${callbackURLTo}, ${method}, ${JSON.stringify(headers)}, ${payloadForFXP}, ${id}, ${Config.HUB_NAME}, ${source} ${hubNameRegex} })`)
let response = { status: 'unknown' }
const histTimerEndSendRequest = Metrics.getHistogram(
'notification_event_delivery',
'notification_event_delivery - metric for sending notification requests to FSPs',
['success', 'from', 'to', 'dest', 'action', 'status']
['success', 'from', 'dest', 'action', 'status']
).startTimer()

try {
response = await Callback.sendRequest({ url: callbackURLTo, headers, source, destination, method: PATCH, payload, responseType, span, protocolVersions, hubNameRegex })
jwsSigner = getJWSSigner(Config.HUB_NAME)
response = await Callback.sendRequest({ url: callbackURLTo, headers, source, destination, method, payload: payloadForFXP, responseType, span, jwsSigner, protocolVersions, hubNameRegex })
} catch (err) {
logger.error(err)
histTimerEndSendRequest({ success: false, from: source, dest: destination, action, status: response.status })
Expand Down
9 changes: 7 additions & 2 deletions test/integration/handlers/notification/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,10 @@ Test('Notification Handler', notificationHandlerTest => {

const response = await testNotification(messageProtocol, 'patch', commitRequestId, kafkaConfig, topicConfig)

test.deepEqual(response.payload, messageProtocol.content.payload, 'Notification sent successfully to FXP')
const payloadWithoutFulfilment = JSON.parse(JSON.stringify(messageProtocol.content.payload))
delete payloadWithoutFulfilment.fulfilment

test.deepEqual(response.payload, payloadWithoutFulfilment, 'Notification sent successfully to FXP')
test.end()
})

Expand All @@ -1525,7 +1528,9 @@ Test('Notification Handler', notificationHandlerTest => {

const response = await testNotification(messageProtocol, 'patch', commitRequestId, kafkaConfig, topicConfig, undefined, undefined, 'proxyFsp')

test.deepEqual(response.payload, messageProtocol.content.payload, 'Notification sent successfully to FXP')
const payloadWithoutFulfilment = JSON.parse(JSON.stringify(messageProtocol.content.payload))
delete payloadWithoutFulfilment.fulfilment
test.deepEqual(response.payload, payloadWithoutFulfilment, 'Notification sent successfully to FXP')
test.end()
})

Expand Down