Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FishPay_Backend

πŸ’³ Production-Oriented Payment Management Infrastructure

FishPay is a production-oriented payment management infrastructure built using Java, Spring Boot, PostgreSQL, Razorpay, and Docker that enables businesses to integrate a complete payment management system without investing significant development time or dealing with the complexities involved in building one from scratch.

The system manages the complete payment lifecycle, including payment processing, payment verification, webhook reconciliation, invoice generation, refund management, transaction history, and analytics through reusable REST APIs.

Although FishPay currently integrates with Razorpay, its modular architecture allows future support for multiple payment gateways such as Stripe, PayPal, PayU, and others with minimal architectural changes.


✨ Features

πŸ’³ Payment

  • Order Creation
  • Payment Verification
  • Payment History
  • Transaction Tracking

πŸ“„ Invoice

  • Automatic Invoice Generation
  • Invoice History
  • PDF Download

πŸ’° Refund

  • Refund Processing
  • Refund Status
  • Refund History

πŸ”” Webhooks

  • Payment Reconciliation
  • Refund Synchronization

⚑ Performance

  • Async Invoice Generation
  • Fast Payment Confirmation
  • Backend Pagination

🐳 Infrastructure

  • Dockerized Backend
  • PostgreSQL
  • RESTful APIs

πŸ—οΈ System Design

FishPay follows a modular payment workflow where payment requests are securely processed through Razorpay, verified using cryptographic signature validation, persisted in PostgreSQL, and integrated with asynchronous invoice generation, refund management, and webhook-based reconciliation.

Data Flow & Architecture

πŸ”— https://miro.com/app/board/uXjVHcgkeag=/?moveToWidget=3458764678553613549&cot=14


⚑ Payment Performance

Stage Time
Signature Verification ~50 ms
Payment Persistence ~100 ms
Success Response < 750 ms
Invoice Generation (Async) Background
Cloudinary Upload Background
Invoice URL Persistence Background

⭐ Engineering Problems Solved

Unlike a simple payment gateway integration, FishPay addresses several real-world backend engineering challenges commonly encountered in payment systems.


⚑ 1. Reduced Payment Response Time by ~75%

Problem

Initially, the payment verification API performed every operation synchronously.

Verify Signature
      ↓
Save Payment
      ↓
Generate Invoice PDF
      ↓
Upload to Cloudinary
      ↓
Save Invoice URL
      ↓
Return Response

Since PDF generation and cloud upload are expensive operations, the client had to wait approximately 3 seconds before receiving payment confirmation.


Solution

Invoice generation was moved into an asynchronous background task.

Verify Signature
      ↓
Save Payment
      ↓
Return Success Response
      ↓
──────── Background Thread ────────
Generate Invoice
      ↓
Upload to Cloudinary
      ↓
Update invoiceUrl

Result

βœ… Payment confirmation reduced from approximately 3 seconds to under 1 second while maintaining eventual consistency.


πŸ”„ 2. Webhook-Based Event Reconciliation

Problem

Frontend responses cannot always be trusted as the single source of truth because network failures or application crashes may occur after payment completion.


Solution

Implemented secure Razorpay Webhook integration that verifies webhook signatures and automatically reconciles payment and refund events.

Supported events include:

  • payment.captured
  • payment.failed
  • refund.processed
  • order.paid

This guarantees database consistency even if the frontend never reports the payment outcome.


⏳ 3. Race Condition Handling

Problem

Sometimes Razorpay sends the webhook before the payment record is inserted into PostgreSQL.

Without handling this race condition, webhook processing would fail.


Solution

Implemented retry-based reconciliation logic that repeatedly searches for the payment before processing the webhook.

This ensures eventual consistency between asynchronous systems.


πŸ“¦ 4. Complete Refund Lifecycle Synchronization

Instead of only creating refund records, FishPay synchronizes refund status across multiple entities.

Refund Created
      ↓
PENDING
      ↓
PROCESSING
      ↓
PROCESSED
      ↓
Payment.refunded = true

This keeps both Payment and Refund records synchronized automatically.


πŸ“‘ 5. Background Invoice Pipeline

Invoice generation was intentionally separated from payment confirmation.

Background pipeline:

Payment Success
      ↓
Async Task
      ↓
Generate PDF
      ↓
Upload to Cloudinary
      ↓
Persist invoiceUrl

This significantly improves checkout experience while preserving complete invoice generation.


πŸ“š 6. Efficient Pagination

Instead of loading entire datasets, FishPay uses backend pagination for:

  • Payments
  • Invoices
  • Refunds

allowing efficient handling of large transaction histories.


🐳 7. Containerized Backend

The backend is fully containerized using Docker, making deployments reproducible across development, staging, and production environments.


FishPay_Backend/
β”‚
β”œβ”€β”€ src/main/java/com/fishpay
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ RazorpayConfig.java
β”‚   β”œβ”€β”€ SecurityConfig.java
β”‚   β”œβ”€β”€ CloudinaryConfig.java
β”‚   └── AsyncConfig.java
β”‚
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ PaymentController.java
β”‚   β”œβ”€β”€ InvoiceController.java
β”‚   β”œβ”€β”€ RefundController.java
β”‚   β”œβ”€β”€ WebhookController.java
β”‚   └── HealthController.java
β”‚
β”œβ”€β”€ service/
β”‚   β”œβ”€β”€ PaymentService.java
β”‚   β”œβ”€β”€ InvoiceService.java
β”‚   β”œβ”€β”€ RefundService.java
β”‚   β”œβ”€β”€ WebhookService.java
β”‚   β”œβ”€β”€ AsyncInvoiceService.java
β”‚   └── CloudinaryService.java
β”‚
β”œβ”€β”€ repository/
β”‚   β”œβ”€β”€ PaymentRepository.java
β”‚   β”œβ”€β”€ InvoiceRepository.java
β”‚   β”œβ”€β”€ InvoiceItemRepository.java
β”‚   └── RefundRepository.java
β”‚
β”œβ”€β”€ entity/
β”‚   β”œβ”€β”€ Payment.java
β”‚   β”œβ”€β”€ Invoice.java
β”‚   β”œβ”€β”€ InvoiceItem.java
β”‚   └── Refund.java
β”‚
β”œβ”€β”€ dto/
β”‚   β”œβ”€β”€ CreateOrderRequest.java
β”‚   β”œβ”€β”€ VerifyPaymentRequest.java
β”‚   β”œβ”€β”€ VerifyPaymentResponse.java
β”‚   β”œβ”€β”€ InvoiceHistoryResponse.java
β”‚   β”œβ”€β”€ RefundRequest.java
β”‚   β”œβ”€β”€ RefundResponse.java
β”‚   β”œβ”€β”€ RefundHistoryResponse.java
β”‚   β”œβ”€β”€ PaymentHistoryResponse.java
β”‚   └── ...
β”‚
β”œβ”€β”€ util/
β”‚   β”œβ”€β”€ RazorpaySignatureUtil.java
β”‚   β”œβ”€β”€ InvoiceGenerator.java
β”‚   β”œβ”€β”€ RefundStatus.java
β”‚   └── PaymentStatus.java
β”‚
β”œβ”€β”€ exception/
β”‚
β”œβ”€β”€ FishpayApplication.java
β”‚
β”œβ”€β”€ src/main/resources/
β”‚   β”œβ”€β”€ application.yml
β”‚   └── ...
β”‚
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ pom.xml
└── README.md

🧱 8. Modular Spring Boot Architecture

The backend follows production-standard layered architecture.

Controller
      ↓
Service
      ↓
Repository
      ↓
Hibernate / JPA
      ↓
PostgreSQL

This separation improves maintainability, scalability, testing, and code organization.


πŸ—οΈ High-Level Architecture

Merchant Application
        β”‚
        β–Ό
 REST Controllers
        β”‚
        β–Ό
 Service Layer
        β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β–Ό                 β–Ό
PostgreSQL     Razorpay APIs
                     β”‚
                     β–Ό
                Razorpay Webhooks
                     β”‚
                     β–Ό
             Webhook Reconciliation
                     β”‚
                     β–Ό
             Payment Synchronization
                     β”‚
                     β–Ό
           Invoice / Refund Modules

πŸ›  Backend Tech Stack

Core Backend

  • Java 24
  • Spring Boot 3.5.x
  • Spring Web
  • Spring Security
  • Spring Data JPA
  • Hibernate ORM
  • Maven

Database

  • PostgreSQL

External Services

  • Razorpay Java SDK
  • Cloudinary

Infrastructure

  • Docker
  • REST APIs
  • Environment Variables

Supporting Libraries

  • Jackson
  • BigDecimal
  • Pageable
  • JPA Repository
  • Hibernate
  • Async Processing (@Async)

About

FishPay is a payment management infrastructure that enables businesses to integrate secure payments, invoices, refunds, and transaction management without building the entire payment system from scratch.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages