diff --git a/src/domain/fx/cyril.js b/src/domain/fx/cyril.js index 054de999a..bafb40c6b 100644 --- a/src/domain/fx/cyril.js +++ b/src/domain/fx/cyril.js @@ -230,7 +230,7 @@ const processFxFulfilMessage = async (commitRequestId) => { * @param {Array} transferIdList - List of transfer IDs to retrieve regular transfer-related position changes. * @returns {Promise} - A promise that resolves to an array of position change objects. */ -const _getPositionChanges = async (commitRequestIdList, transferIdList) => { +const _getPositionChanges = async (commitRequestIdList, transferIdList, originalId) => { const positionChanges = [] for (const commitRequestId of commitRequestIdList) { const fxRecord = await fxTransfer.getAllDetailsByCommitRequestIdForProxiedFxTransfer(commitRequestId) @@ -239,6 +239,7 @@ const _getPositionChanges = async (commitRequestIdList, transferIdList) => { positionChanges.push({ isFxTransferStateChange: true, commitRequestId, + isOriginalId: originalId === commitRequestId, notifyTo: fxRecord.externalInitiatingFspName || fxRecord.initiatingFspName, participantCurrencyId: fxPositionChange.participantCurrencyId, amount: -fxPositionChange.change @@ -253,6 +254,7 @@ const _getPositionChanges = async (commitRequestIdList, transferIdList) => { positionChanges.push({ isFxTransferStateChange: false, transferId, + isOriginalId: originalId === transferId, notifyTo: transferRecord.externalPayerName || transferRecord.payerFsp, participantCurrencyId: transferPositionChange.participantCurrencyId, amount: -transferPositionChange.change @@ -280,7 +282,7 @@ const processFxAbortMessage = async (commitRequestId) => { const relatedFxTransferRecords = await fxTransfer.getByDeterminingTransferId(fxTransferRecord.determiningTransferId) // Get position changes - const positionChanges = await _getPositionChanges(relatedFxTransferRecords.map(item => item.commitRequestId), [fxTransferRecord.determiningTransferId]) + const positionChanges = await _getPositionChanges(relatedFxTransferRecords.map(item => item.commitRequestId), [fxTransferRecord.determiningTransferId], commitRequestId) histTimer({ success: true }) return { @@ -299,7 +301,7 @@ const processAbortMessage = async (transferId) => { const relatedFxTransferRecords = await fxTransfer.getByDeterminingTransferId(transferId) // Get position changes - const positionChanges = await _getPositionChanges(relatedFxTransferRecords.map(item => item.commitRequestId), [transferId]) + const positionChanges = await _getPositionChanges(relatedFxTransferRecords.map(item => item.commitRequestId), [transferId], transferId) histTimer({ success: true }) return { diff --git a/src/domain/position/abort.js b/src/domain/position/abort.js index 30a342169..07559d43f 100644 --- a/src/domain/position/abort.js +++ b/src/domain/position/abort.js @@ -92,11 +92,11 @@ const processPositionAbortBin = async ( for (const positionChange of cyrilResult.positionChanges) { if (positionChange.isFxTransferStateChange) { // Construct notification message for fx transfer state change - const resultMessage = _constructAbortResultMessage(binItem, positionChange.commitRequestId, from, positionChange.notifyTo) + const resultMessage = _constructAbortResultMessage(binItem, positionChange.commitRequestId, from, positionChange.notifyTo, positionChange.isOriginalId, true) resultMessages.push({ binItem, message: resultMessage }) } else { // Construct notification message for transfer state change - const resultMessage = _constructAbortResultMessage(binItem, positionChange.transferId, from, positionChange.notifyTo) + const resultMessage = _constructAbortResultMessage(binItem, positionChange.transferId, from, positionChange.notifyTo, positionChange.isOriginalId, false) resultMessages.push({ binItem, message: resultMessage }) } } @@ -126,13 +126,16 @@ const processPositionAbortBin = async ( } } -const _constructAbortResultMessage = (binItem, id, from, notifyTo) => { +const _constructAbortResultMessage = (binItem, id, from, notifyTo, isOriginalId, isFx) => { let apiErrorCode = ErrorHandler.Enums.FSPIOPErrorCodes.PAYEE_REJECTION let fromCalculated = from if (binItem.message?.value.metadata.event.action === Enum.Events.Event.Action.FX_ABORT_VALIDATION || binItem.message?.value.metadata.event.action === Enum.Events.Event.Action.ABORT_VALIDATION) { fromCalculated = Config.HUB_NAME apiErrorCode = ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR } + if (!isOriginalId) { + fromCalculated = Config.HUB_NAME + } const fspiopError = ErrorHandler.Factory.createFSPIOPError( apiErrorCode, null, @@ -151,7 +154,7 @@ const _constructAbortResultMessage = (binItem, id, from, notifyTo) => { const metadata = Utility.StreamingProtocol.createMetadataWithCorrelatedEvent( id, Enum.Kafka.Topics.POSITION, - binItem.message?.value.metadata.event.action, // This will be replaced anyway in Kafka.produceGeneralMessage function + (isFx && !isOriginalId) ? Enum.Events.Event.Action.FX_ABORT : binItem.message?.value.metadata.event.action, // This will be replaced anyway in Kafka.produceGeneralMessage function state ) const resultMessage = Utility.StreamingProtocol.createMessage(