Skip to content

Commit

Permalink
feat: added external settlement endpoint (#85)
Browse files Browse the repository at this point in the history
* added external settlement endpoint

@shashi165 thanks for the PR.

I accept this PR, but note inconsistencies in Settlement Endpoint configuration and backwards-compatibility support must be addressed in future as part of this story --> mojaloop/project#2639
  • Loading branch information
shashi165 authored Jan 12, 2022
1 parent 06d3392 commit 965673b
Show file tree
Hide file tree
Showing 5 changed files with 2,840 additions and 2,356 deletions.
69 changes: 45 additions & 24 deletions src/handlers/settlement-window-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,53 @@ const handler = (router, routesContext) => {
router.put('/settlement-window-close/:settlementWindowId', async (ctx, next) => {
const { startDate: fromDateTime, endDate: toDateTime } = ctx.request.body;

const resp = await axios.post(
`${routesContext.config.centralSettlementsEndpoint}/settlementWindows/${ctx.params.settlementWindowId}`,
{
state: 'CLOSED',
reason: 'Finance portal user request',
},
{
validateStatus: null,
},
);
// if an external settlement service is provided use that
if (routesContext.config.externalSettlementsEndpoint) {
try {
const resp = await axios.post(`${routesContext.config.externalSettlementsEndpoint}`, {});
if (resp.status === 202) {
ctx.response.status = 200;
} else {
ctx.response.status = 500;
}
} catch (err) {
ctx.response.status = 500;
} finally {
// this delay is introduced in order to give the external settlement API enough time
// to close the window
// TODO revise the implementation of the external settlement API so it sends back an
// acknowledgment somehow
await sleep(3000);
ctx.response.body = await handlerHelpers.getSettlementWindows(
routesContext,
fromDateTime,
toDateTime,
);
}
} else { // use the default OSS settlement service
const resp = await axios.post(
`${routesContext.config.centralSettlementsEndpoint}/settlementWindows/${ctx.params.settlementWindowId}`,
{
state: 'CLOSED',
reason: 'Finance portal user request',
},
{
validateStatus: null,
},
);

ctx.response.status = resp.status;
ctx.response.status = resp.status;

if (resp.status === 200) {
// this delay is introduced in order to give the central settlement API enough time
// to close the window
// TODO revise the implementation of the central settlement API so it sends back an
// acknowledgment somehow
await sleep(3000);
ctx.response.body = await handlerHelpers.getSettlementWindows(
routesContext,
fromDateTime,
toDateTime,
);
} else {
ctx.response.body = resp.data;
if (resp.status === 200) {
await sleep(3000);
ctx.response.body = await handlerHelpers.getSettlementWindows(
routesContext,
fromDateTime,
toDateTime,
);
} else {
ctx.response.body = resp.data;
}
}

await next();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/azureLogUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const getTransferMessageWithJWSSignature = async (config, transferId, log) => {

const messagePattern = new RegExp(config.kafkaMessagePattern);
const match = data.match(messagePattern);
let cleanMessage = match[1];
let cleanMessage = (Array.isArray(match) && match.length > 0) && match[1];

if (!cleanMessage) {
return null;
Expand Down
Loading

0 comments on commit 965673b

Please sign in to comment.