Skip to content

Payment processing service handling transactions and gateways

Notifications You must be signed in to change notification settings

minisource/payment

Minisource Payment Service

Multi-tenant payment processing microservice built with .NET 10. Handles payment gateways, transactions, and billing operations.

Features

  • πŸ’³ Multi-Gateway Support - ZarinPal, Stripe, PayPal integration ready
  • 🏒 Multi-Tenant - Complete tenant isolation for payments
  • πŸ“Š Transaction Management - Track and manage all transactions
  • πŸ”„ Webhook Handling - Process payment provider callbacks
  • πŸ“ Audit Trail - Complete payment history logging
  • πŸ” OAuth2 Authentication - Secure service-to-service auth

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                Payment Service (:4005)                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚  β”‚   Application  β”‚  β”‚    Domain      β”‚                 β”‚
β”‚  β”‚    Services    β”‚  β”‚    Entities    β”‚                 β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β”‚          β”‚                   β”‚                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚  β”‚         Infrastructure             β”‚                 β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚                 β”‚
β”‚  β”‚  β”‚ Payment β”‚  β”‚    Database     β”‚  β”‚                 β”‚
β”‚  β”‚  β”‚ Gateway β”‚  β”‚   Repository    β”‚  β”‚                 β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚                 β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Prerequisites

  • .NET 10 SDK
  • PostgreSQL 15+
  • Docker & Docker Compose (optional)

Development

# Clone repository
git clone https://github.com/minisource/payment.git
cd payment

# Copy environment file
cp .env.example .env

# Restore dependencies
dotnet restore

# Run migrations
dotnet ef database update --project Infrastructure

# Run the service
dotnet run --project payment

Docker

# Build and run with Docker Compose
docker-compose -f docker-compose.dev.yml up --build

# Or use the scripts
./docker.sh up     # Linux/Mac
docker.bat up      # Windows

Configuration

Variable Description Default
PORT Service port 4005
DATABASE_URL PostgreSQL connection Required
AUTH_SERVICE_URL Auth service URL http://auth:9001
CLIENT_ID OAuth client ID Required
CLIENT_SECRET OAuth client secret Required
ZARINPAL_MERCHANT_ID ZarinPal merchant Optional
STRIPE_SECRET_KEY Stripe API key Optional

API Endpoints

Payment Operations

Method Path Description
POST /api/v1/payments Create payment
GET /api/v1/payments/{id} Get payment
GET /api/v1/payments List payments
POST /api/v1/payments/{id}/verify Verify payment
POST /api/v1/payments/{id}/refund Refund payment

Webhooks

Method Path Description
POST /api/v1/webhooks/zarinpal ZarinPal callback
POST /api/v1/webhooks/stripe Stripe webhook

Admin Operations

Method Path Description
GET /api/v1/admin/transactions List all transactions
GET /api/v1/admin/stats Payment statistics

Project Structure

payment/
β”œβ”€β”€ Application/
β”‚   β”œβ”€β”€ DTOs/              # Data transfer objects
β”‚   β”œβ”€β”€ Options/           # Configuration options
β”‚   └── Services/          # Business logic
β”œβ”€β”€ Domain/
β”‚   β”œβ”€β”€ Entities/          # Domain entities
β”‚   β”œβ”€β”€ Enums/             # Enumerations
β”‚   └── Interfaces/        # Contracts
β”œβ”€β”€ Infrastructure/
β”‚   β”œβ”€β”€ Data/              # EF Core context
β”‚   β”œβ”€β”€ Repositories/      # Data access
β”‚   └── Services/          # External integrations
β”œβ”€β”€ payment/
β”‚   β”œβ”€β”€ Controllers/       # API controllers
β”‚   └── Program.cs         # Entry point
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ docker-compose.dev.yml
└── Dockerfile

Payment Flow

1. Client creates payment request
         β”‚
         β–Ό
2. Payment service generates gateway URL
         β”‚
         β–Ό
3. User redirected to payment gateway
         β”‚
         β–Ό
4. Gateway processes payment
         β”‚
         β–Ό
5. Gateway calls webhook with result
         β”‚
         β–Ό
6. Payment service verifies and updates status
         β”‚
         β–Ό
7. Client receives confirmation

Adding Payment Gateways

  1. Create gateway service in Infrastructure/Services/
  2. Implement IPaymentGateway interface
  3. Register in dependency injection
  4. Add configuration options

Build Commands

# Build
dotnet build

# Test
dotnet test

# Publish
dotnet publish -c Release -o ./publish

# Docker build
docker build -t minisource/payment .

Environment Files

  • .env.example - Template configuration
  • .env - Local development (git ignored)

Dependencies

  • ASP.NET Core 10 - Web framework
  • Entity Framework Core - ORM
  • Minisource.Common - Shared utilities
  • Minisource.Sdk - Service clients

License

MIT

About

Payment processing service handling transactions and gateways

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published