Git Product home page Git Product logo

payment-engine's Introduction

Payment Engine

Overview

This project implements a payment engine for processing transaction statuses in a financial application. It handles various transaction states (initiated, pending, successful, declined), provides real-time updates, and ensures data integrity and security.

Table of Contents

Functional Requirements

  1. Transaction State Management: The system should be able to manage different transaction states (initiated, pending, successful, declined). It should accurately and securely handle state transition workflows.

  2. Real-Time Updates: The system provides real-time updates for transaction statuses using event-driven mechanisms (webhook).

  3. Error Handling and Recovery:

  • Robust Error-Handling Mechanisms: The system is designed to handle various types of errors, including exceptions (unexpected errors that occur during execution), timeouts (when a request to a service takes too long), and network failures (when there's a problem with the network connection). These mechanisms ensure that the system can handle these errors gracefully without crashing or losing data.

  • Informative Error Messages and Logs: When an error occurs, the system will log detailed information about the error. This includes an error message that describes what went wrong, and a stack trace that shows the sequence of function calls that led to the error. These logs can be used for troubleshooting and debugging, making it easier to identify and fix the cause of the error.

  1. Integration with Payment Gateways: The system is be able to process transactions with different payment gateways (e.g., Stripe, PayPal). For the purpose of this project, a mocked service was implemented to play the role of the payment gateway.

  2. Testing: The system includes unit tests to validate functionality and edge cases.

Non-Functional Requirements

  1. Scalability: The system is be designed to handle a high volume of transactions and should be able to scale horizontally as demand increases.

  2. Performance: The system processes transactions and provide updates in real-time with minimal latency.

  3. Reliability: The system is reliable and available, with minimal downtime. It should handle errors gracefully and recover from failures quickly.

  4. Security: Using Mock API key in the payment gateway to verify the request.

  5. Maintainability: The system should be easy to maintain and extend. It follows clean code principles and SOLID principles.

Technologies Used

  • NodeJS
  • ExpressJS
  • PostgreSQL (Main Datastore)
  • Sequelize (ORM)
  • Jest (Testing)
  • Docker (Containerization)

Database Schema

Transactions Table

Column Name Data Type Description
id INTEGER Primary key
amount INTEGER The amount of money
status STRING The status of the transaction
gateway STRING The used payment gateway

System Design and State Transition Workflows

System Design

Project Structure

State Transition Workflows

State Transition Workflows

Running the Application

  1. Ensure Docker and Docker Compose are installed on your system.
  2. Clone the repository and navigate to the project directory:
git clone https://github.com/Ghallab98/payment-engine.git
cd payment-engine
  1. Rename the .env.example file to .env.
  2. Start the project:
docker-compose up

this will start the application, the payment gateway and the database.

Usage

Create a transaction: Send a POST request to http://localhost:3000/v1/transactions endpoint with transaction data in the request body.

Body example:

{
  "amount": 2500,
  "gateway": "stripe" // or "paypal"
}

Update transaction status: By creating a transaction, it starts the flow with status initiated, then a request is sent to the gateway to process the transaction, if no errors occur the transaction status will change to pending. The gateway will process the transaction then notify the engine via the webhook with the final status either success or failed.

CRUD operations are available for transactions.

Testing

To run unit tests, execute the following command:

docker-compose run --rm app npm test

payment-engine's People

Contributors

ghallab98 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.