Skip to content

Mahdieh8827/order

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Payment Processing Service

This project implements a payment processing service for merchants using Java and the Spring framework. The service exposes a REST API that accepts HTTP requests and responds with JSON payloads.

Prerequisites

To build and run this application, you need to have the following installed:

Getting Started

Follow these instructions to get the project up and running on your local machine.
1.Clone the repository from GitHub:

git clone ...

2.Navigate to the project directory

3.Build the project using Maven:

mvn clean install

4.Run Docker:

docker-compose up -d

5.Run Spring boot application:

mvn spring-boot:run

6.Run Tests:

mvn test

Endpoints

Payment Endpoints

New Payment: POST /api/payment/process

  • Request: JSON payload with amount, customer name, credit card number,merchant Id, and expiry date
  • Response: paymentId, status
  • Payments will fail if the credit card number starts with 5.

Refund Payment: POST /api/payment/refund/{paymentId}

  • Request: Empty
  • Response: paymentId, status
  • Refund is only possible for payments from the same merchant.
  • Refund is only possible for Successful payments.
  • Refund is only possible for payments that have not already been refunded.

View Payment: GET /api/payment/{paymentId}

  • Request: Empty
  • Response: payment details based on paymentId, including refund records if applicable.
  • View is only allowed for payments from the same merchant.

List Payments: GET /api/payment

  • Parameters: sort by date, filter by customer name
  • Response: List of payments.

Show Merchant Payments Statistics: GET /api/payment/statistics

  • Request: Empty
  • Response: JSON payload with total payments count, total payments amount, total fees amount for the merchant.
  • payload with total payments with successful status and refunds.

Security

All payment endpoints are secured via JWT token authentication/authorization.
Set PAYMENT_MERCHANT as the default role for accessing all APIs.

Generate JWT Token for a Merchant: POST /api/authenticate/{merchantId}

  • Request: Empty
  • Response: JWT token
  • generate JWT token with merchantId and PAYMENT_MERCHANT GrantedAuthority

Merchant Table Initialization

Included in the application is a Flyway migration file that initializes the Merchant table. Two merchants with IDs 1000 and 1001 are created for testing purposes.

Flyway Migration File:

Location: [ db/migration: V1__initial_schema.sql ] Purpose: Create initial merchant entries (ID: 1000, 1001), Please be aware if you are going to test via Postman, you need to change the merchantId in the request body to 1000 or 1001.

Assumptions

  • I incorporate a dedicated table to store information about merchants, ensuring a systematic record of every payment.
  • Additionally, I treat refunds as negative payments, allowing them to be distinct yet seamlessly integrated into the payment system.
  • Moreover, each successful payment has the potential for a corresponding refund, with a one-time limit for refund transactions.
  • Statistics is only available for all successful and Refund payments.

About

Oder

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages