This project implements a simple Payment Service Provider (PSP) system using Scala and Akka HTTP. It handles payment requests, validates them, and simulates interactions with a payment acquirer.
- API Endpoint: Accepts payment details and processes them.
- Validation: Validations on fields for payment like credit card number is validated by luhn's algorithm.
- Mock Acquirer: Simulates transaction approval or denial based on card details.
- In-Memory Storage: Records transactions and their status changes.
- Scala 2.13.13
- sbt (Scala Build Tool) 1.10.0
Clone the repository to your local machine:
git clone https://github.com/arunkmishra/PaymentSystem.git
cd paymentsystem
- Compile the project and run tests:
sbt clean compile test
- Build docker image:
docker build -t payment-system .
- To start the server, use:
sbt run
.
- Pull image
- Mac:
docker pull arunmishra/payment-system:latest
- Linux/amd:
docker pull arunmishra/paymentsystem_amd:latest
- Mac:
- Or build image
docker build -t payment-system .
- Run application
docker run -p 8080:8080 arunmishra/payment-system:latest
- Application will start on http://localhost:8080.
To check application running status:
curl -X GET http://localhost:8080/status
To process a payment, send a POST request to /v1/api/payment
with the following JSON payload:
{
"cardNumber": "4242424242424242",
"expiryDate": "12/27",
"cvv": 123,
"amount": 100.00,
"currency": "USD",
"merchantId": "merchant_001"
}
Curl to send the request:
curl -X POST http://localhost:8080/v1/api/payment \
-H "Content-Type: application/json" \
-d '{"cardNumber": "4242424242424242", "expiryDate": "12/27", "cvv": 123, "amount": 100.00, "currency": "USD", "merchantId": "merchant_001"}'
Check the logs for application at ./application.log
file.
- In this implementation, sensitive data is not encrypted before storing to DB here. In this case, sensitive data includes credit card number, cvv.
- Ideally, aligning with PCI guidelines, we need to encrypt sensitive data before storing/logging it.
- For encryption, we can use AES or SHA-256, and store private key in some secure place where access is restricted to only some users(maybe vault).