Skip to content

A simulated payment API designed to replicate real-world payment systems (e.g., IremboPay, Stripe, or mobile money APIs)

License

Notifications You must be signed in to change notification settings

Corenegasore123/paymenttest

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PaymentLater API πŸš€

A simulated payment API designed to replicate real-world payment systems (e.g., IremboPay, Stripe, or mobile money APIs)

Kotlin Spring Boot MongoDB License: MIT

πŸ“– Overview

PaymentLater is a developer-friendly mock payment API that eliminates the barriers developers face when integrating payment systems into their projects. Built with Kotlin and Spring Boot, it provides comprehensive RESTful endpoints that simulate real-world payment provider behavior without the overhead of legal documentation, sandbox registration, or compliance requirements.

Perfect for prototyping, testing, learning, and building demos without the complexity of real payment integrations.

🎯 Motivation

Most developers face common barriers when building payment-enabled applications:

  • Complex registration processes requiring business documentation
  • Lengthy approval workflows with government-issued documents
  • Complicated sandbox environments with usage limitations
  • Legal terms and compliance requirements for simple prototypes

PaymentLater solves these problems by providing:

  • βœ… Instant access - No paperwork or registration required
  • βœ… Simple integration - Standard RESTful API design
  • βœ… Real-world simulation - Webhooks, wallets, and transaction flows
  • βœ… Developer-focused - Built for learning and rapid prototyping

✨ Key Features

Feature Description
πŸ” Dual Authentication JWT tokens for admins, API keys for merchants
πŸ’³ Payment Processing Complete payment lifecycle simulation
πŸ”„ Webhook Support Real-time event notifications
πŸ’° Multi-Currency Support for multiple currency types
πŸ“Š Analytics Dashboard Merchant and system analytics
♻️ Refund Management Full refund processing workflow
πŸ” Transaction History Comprehensive transaction tracking
πŸ“§ Email Notifications Automated email alerts and confirmations
πŸ“š Interactive API Docs Swagger UI for easy testing
πŸ›‘οΈ Security Features BCrypt hashing, JWT tokens, API key authentication

πŸ—οΈ Architecture

Tech Stack

  • Backend: Kotlin + Spring Boot 3.5.3
  • Database: MongoDB with auto-indexing
  • Security: Spring Security with JWT & API Key authentication
  • Documentation: OpenAPI 3 with Swagger UI
  • Email: Spring Mail with SMTP integration
  • Testing: JUnit 5, MockK, Spring Boot Test

Project Structure

src/main/kotlin/com/blaise/paymentlater/
β”œβ”€β”€ config/                 # Application configurations
β”œβ”€β”€ controller/             # REST API controllers
β”œβ”€β”€ domain/                # Domain models and entities
β”‚   β”œβ”€β”€ enum/              # Enumerations
β”‚   β”œβ”€β”€ exception/         # Custom exceptions
β”‚   β”œβ”€β”€ extension/         # Kotlin extensions
β”‚   └── model/            # Data models
β”œβ”€β”€ dto/                   # Data Transfer Objects
β”‚   β”œβ”€β”€ request/           # Request DTOs
β”‚   └── response/          # Response DTOs
β”œβ”€β”€ repository/            # MongoDB repositories
β”œβ”€β”€ security/              # Security configurations & filters
β”‚   β”œβ”€β”€ admin/             # Admin authentication
β”‚   β”œβ”€β”€ merchant/          # Merchant authentication
β”‚   └── shared/            # Shared security components
└── service/               # Business logic services
    └── v1/                # API version 1 services

πŸš€ Quick Start

Prerequisites

  • Java 21+
  • MongoDB 4.4+
  • SMTP Email Server (Gmail recommended)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/PaymentLaterAPI.git
    cd PaymentLaterAPI
  2. Set up environment variables

    export MONGODB_URI="mongodb://localhost:27017"
    export MONGODB_DATABASE="paymentlater"
    export JWT_SECRET_BASE64="your-base64-encoded-jwt-secret"
    export MAIL_SERVER_EMAIL="your-email@gmail.com"
    export MAIL_SERVER_PASSWORD="your-app-password"
  3. Run the application

    ./gradlew bootRun
  4. Access the API

    • API Base URL: http://localhost:1010
    • Swagger UI: http://localhost:1010/swagger-ui.html
    • API Documentation: http://localhost:1010/api-docs

πŸ“š API Documentation

Authentication

Admin Authentication (JWT)

# Register Admin
POST /api/v1/admin/auth/register
Content-Type: application/json

{
  "username": "admin",
  "email": "admin@example.com",
  "password": "securepassword"
}

# Login
POST /api/v1/admin/auth/login
Content-Type: application/json

{
  "username": "admin",
  "password": "securepassword"
}

Merchant Authentication (API Key)

# Register Merchant
POST /api/v1/merchant/auth/register
Content-Type: application/json

{
  "name": "My Business",
  "email": "merchant@example.com",
  "webhookUrl": "https://mybusiness.com/webhook"
}

# Use API Key in requests
GET /api/v1/merchant/auth/me
X-API-KEY: your-64-character-api-key

Payment Processing

Create Payment Intent

POST /api/v1/payments
X-API-KEY: your-api-key
Content-Type: application/json

{
  "items": [
    {
      "name": "Electricity & Water",
      "description": "Monthly bills",
      "unitAmount": 20,
      "quantity": 2
    }
  ],
  "currency": "EUR",
  "metadata": {
    "referenceId": "123XXX",
    "userId": "123",
    "phone": "949784925244606",
    "email": "customer@example.com",
    "description": "Paying for bills"
  }
}

Confirm Payment Intent

POST /api/v1/payments/{paymentIntentId}/confirm
X-API-KEY: your-api-key
Content-Type: application/json

{
  "paymentMethod": "MOBILE_MONEY",
  "metadata": {
    "customerEmail": "alice@example.com",
    "customerPhone": "+250788123456",
    "customerName": "Alice Johnson",
    "referenceId": "REF-1001",
    "description": "Payment for order #1024",
    "failureReason": null,
    "refundReason": null,
    "gatewayResponseCode": "00",
    "extra": {
      "network": "MTN Rwanda",
      "transactionId": "MTN-TXN-78901",
      "paymentSession": "SESSION-ABC123"
    }
  }
}

Webhook Configuration

POST /api/v1/merchant/auth/set-webhook
X-API-KEY: your-api-key
Content-Type: application/json

{
  "webhookUrl": "https://mybusiness.com/webhook1"
}

πŸ”Œ Integration Examples

Kotlin/Android

// Add to your build.gradle.kts
dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")
}

// API Client
interface PaymentLaterApiService {
    @POST("payments")
    suspend fun createPaymentIntent(
        @Header("X-API-KEY") apiKey: String,
        @Body request: PaymentIntentRequest
    ): PaymentIntentResponse
}

// Usage
class PaymentRepository {
    private val api = // ... retrofit instance
    
    suspend fun processPayment(amount: Long): PaymentIntentResponse {
        val metadata = mapOf<String, Any>(...)
        val items = listOf<Map<String, Any>>(...)
        
        return api.createPaymentIntent(
            apiKey = "your-api-key",
            request = PaymentIntentRequest(
                items = items,
                metadata = metadata,
                currency = "RWF"
            )
        )
    }
}

JavaScript/React

// Payment service
class PaymentLaterService {
    constructor(apiKey) {
        this.apiKey = apiKey;
        this.baseUrl = 'http://localhost:1010/api/v1';
    }
    
    async createPaymentIntent(paymentData) {
        const response = await fetch(`${this.baseUrl}/payments/`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'X-API-KEY': this.apiKey
            },
            body: JSON.stringify(paymentData)
        });
        return response.json();
    }
}

// React component
function CheckoutForm() {
    const paymentService = new PaymentLaterService('your-api-key');
    
    const handlePayment = async (amount) => {
        const metadata = {...}
        const items = [...]
        
        const intent = await paymentService.createPaymentIntent({
            items: items,
            metadata: metadata,
            currency: 'RWF'
        });
        
        // Handle payment confirmation
        console.log('Payment Intent:', intent);
    };
}

🎯 Use Cases

πŸ“± Mobile App Development

  • Prototype e-commerce checkout flows
  • Test payment integration in development
  • Demo payment features to stakeholders

πŸŽ“ Educational Projects

  • University assignments requiring payment features
  • Bootcamp projects demonstrating full-stack skills
  • Teaching payment system architecture

πŸ† Hackathons & MVPs

  • Quick payment integration for hackathon projects
  • MVP development without payment provider delays
  • Proof of concept demonstrations

πŸ§ͺ Testing & Development

  • Frontend payment flow testing
  • API integration testing
  • Webhook handling development

πŸ“Š Monitoring & Analytics

Health Check

GET /actuator/health

System Analytics (Admin)

GET /api/v1/admin/analytics/system-health
Authorization: Bearer jwt-token

Merchant Analytics

GET /api/v1/merchant/analytics/overview
X-API-KEY: your-api-key

πŸ›‘οΈ Security Features

  • JWT Authentication with 15-hour access tokens and 30-day refresh tokens
  • API Key Authentication with SHA-256 hashing
  • BCrypt Password Hashing for admin accounts
  • Role-Based Access Control (RBAC)
  • Request Rate Limiting (planned)
  • HTTPS Support (configure with SSL certificates)

πŸ§ͺ Testing

# Run all tests
./gradlew test

# Run with coverage
./gradlew test jacocoTestReport

🀝 Contributing

We welcome contributions from developers who want to:

  • πŸ”§ Add new features or endpoints
  • πŸ“± Build SDKs for other platforms (JavaScript, Flutter, Python)
  • πŸ“ Improve documentation and examples
  • πŸ§ͺ Write tests and improve code quality
  • πŸ› Fix bugs and performance issues
  • πŸ’‘ Suggest new use cases and improvements

Contribution Guidelines

  1. Fork the repository
  2. Create a feature branch (git checkout -b fea/amazing-feature)
  3. Follow coding standards (Kotlin conventions, comprehensive documentation)
  4. Add tests for new functionality
  5. Update documentation as needed
  6. Commit changes (git commit -m 'fea(amazing-feature): Add amazing feature')
  7. Push to branch (git push origin fea/amazing-feature)
  8. Open a Pull Request

Development Setup

# Clone your fork
git clone https://github.com/yourusername/PaymentLaterAPI.git

# Add upstream remote
git remote add upstream https://github.com/original/PaymentLaterAPI.git

# Create development branch
git checkout -b develop

# Install dependencies and run
./gradlew bootRun

πŸ“‹ Roadmap

βœ… Completed

  • Core REST API implementation
  • JWT and API Key authentication
  • Payment intent and confirmation flow
  • Webhook system
  • Email notifications
  • MongoDB integration
  • Comprehensive documentation
  • Swagger UI integration

🚧 In Progress

  • Kotlin SDK
  • Enhanced analytics and reporting
  • Rate limiting and throttling
  • Comprehensive testing suite

πŸ“… Planned

  • SDK Development
    • Kotlin/Android SDK
    • JavaScript/TypeScript SDK
    • Flutter/Dart SDK
    • Python SDK
  • Additional Features
    • Subscription billing simulation
    • Wallet Integration
    • Multi-tenant support
    • Payment method expansion
    • Advanced fraud detection simulation
  • DevOps & Deployment
    • Docker containerization
    • Kubernetes deployment configs
    • CI/CD pipeline setup
    • Monitoring and observability

⚠️ Important Disclaimers

  • 🚫 Not for Production: This is a mock service for testing and development only
  • πŸ’° No Real Money: All transactions are simulated - no actual funds are processed
  • πŸ”’ Educational Security: Security implementations are practical but not enterprise-grade
  • πŸ“œ No Legal Compliance: Not intended for PCI-DSS, AML, or KYC compliance

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Spring Boot Team for the excellent framework
  • Kotlin Team for the amazing language
  • MongoDB for reliable data persistence
  • OpenAPI Initiative for standardized API documentation
  • Contributors who make this project better

πŸ“ž Support & Community


⭐ If you find PaymentLater API helpful, please star this repository to support the project!

Made with ❀️ by developers, for developers

About

A simulated payment API designed to replicate real-world payment systems (e.g., IremboPay, Stripe, or mobile money APIs)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 96.6%
  • HTML 3.4%