Skip to content

This project implements the payment instruction parser and executor.

Notifications You must be signed in to change notification settings

dineshkn-dev/payment-instruction-parser

Repository files navigation

Payment Instruction Parser – Node.js Backend

This project implements the payment instruction parser and executor described in the Resilience17 Node backend assessment, using the provided scaffold.

The main REST endpoint is:

  • POST /payment-instructions

It parses instructions like:

DEBIT 30 USD FROM ACCOUNT a FOR CREDIT TO ACCOUNT b

or

CREDIT 300 NGN TO ACCOUNT acc-002 FOR DEBIT FROM ACCOUNT acc-001 ON 2026-12-31

and returns a structured response with transaction status, codes, and updated account balances.


Tech Stack

  • Node.js (CommonJS)
  • Express (via @app-core/server)
  • In‑memory account processing (no database required for this assessment)

Local Setup

  1. Install dependencies:
npm install
  1. Create a .env file (optional). For this assessment:
  • No MongoDB is required.
  • Ensure either:
    • DISABLE_DB=1, or
    • MONGO_URI is not set.
  1. Start the server:
node app.js

By default the app listens on process.env.PORT (or 8811 if set in your environment).


Live Endpoint

If this project is deployed, the assessment endpoint is available at:

POST https://payment-instruction-parser-hykt.onrender.com/payment-instructions

Quick test with curl:

curl -X POST https://payment-instruction-parser-hykt.onrender.com/payment-instructions \
  -H "Content-Type: application/json" \
  -d '{
    "accounts": [
      { "id": "a", "balance": 230, "currency": "USD" },
      { "id": "b", "balance": 300, "currency": "USD" }
    ],
    "instruction": "DEBIT 30 USD FROM ACCOUNT a FOR CREDIT TO ACCOUNT b"
  }'

Endpoint: POST /payment-instructions

Request body:

{
  "accounts": [
    { "id": "a", "balance": 230, "currency": "USD" },
    { "id": "b", "balance": 300, "currency": "USD" }
  ],
  "instruction": "DEBIT 30 USD FROM ACCOUNT a FOR CREDIT TO ACCOUNT b"
}

Response (successful example):

{
  "type": "DEBIT",
  "amount": 30,
  "currency": "USD",
  "debit_account": "a",
  "credit_account": "b",
  "execute_by": null,
  "status": "successful",
  "status_reason": "Transaction executed successfully",
  "status_code": "AP00",
  "accounts": [
    {
      "id": "a",
      "balance": 200,
      "balance_before": 230,
      "currency": "USD"
    },
    {
      "id": "b",
      "balance": 330,
      "balance_before": 300,
      "currency": "USD"
    }
  ]
}

Common error responses use:

  • status: "failed" or "pending"
  • status_code: one of AM01, CU01, CU02, AC01, AC02, AC03, AC04, DT01, SY01, SY02, SY03, AP00, AP02

For completely unparseable instructions, all parseable fields are null and accounts is an empty array.


Implementation Notes

  • Parser is implemented in services/payment-instructions/parser.js using string methods only (no regex).
  • Business rules and status codes live in services/payment-instructions/validator.js.
  • Orchestration and response shaping are in services/payment-instructions/process-payment-instruction.js.
  • Endpoint handler is endpoints/payment-instructions/create.js and is wired in app.js via ENDPOINT_CONFIGS.

Deployment (e.g. Render)

When deploying to a platform like Render:

  • Build command: npm install
  • Start command: node app.js
  • Environment variables:
    • DISABLE_DB=1
    • NODE_ENV=production
    • Do not set MONGO_URI / MONGODB_URI

Deployed endpoint path remains:

POST https://<your-host>/payment-instructions

About

This project implements the payment instruction parser and executor.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published