Skip to content

xshopai/payment-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

89 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’³ Payment Service

Multi-provider payment processing microservice for the xshopai e-commerce platform

.NET C# SQL Server Dapr License

Getting Started β€’ Documentation β€’ API Reference β€’ Contributing


🎯 Overview

The Payment Service handles payment transactions, refunds, and payment method management across multiple providers (Stripe, PayPal, Square). Built with a provider abstraction layer, it supports multi-currency operations, PCI compliance considerations, and idempotent payment processing with full audit trails.


✨ Key Features

πŸ’³ Multi-Provider Payments

  • Stripe, PayPal, and Square integration
  • Provider abstraction layer
  • Multi-currency support (USD, EUR, GBP, CAD)
  • Idempotent payment processing

πŸ”„ Refund Management

  • Full and partial refunds
  • Refund reason tracking
  • Provider-specific refund handling
  • Refund status monitoring

πŸ’Ύ Payment Methods

  • Secure payment method storage
  • Customer payment profiles
  • Default method selection
  • Provider tokenization

πŸ›‘οΈ Security & Compliance

  • PCI compliance considerations
  • JWT Bearer authentication
  • Provider credential security
  • Complete transaction audit trails

πŸš€ Getting Started

Prerequisites

  • .NET 8 SDK
  • SQL Server 2019+
  • Docker & Docker Compose (optional)
  • Dapr CLI (for production-like setup)

Quick Start with Docker Compose

# Clone the repository
git clone https://github.com/xshopai/payment-service.git
cd payment-service

# Start SQL Server + service
docker-compose up -d

# Verify the service is healthy
curl http://localhost:8009/health

Local Development Setup

πŸ”§ Without Dapr (Simple Setup)
# Restore dependencies
dotnet restore

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration

# Start SQL Server (Docker)
docker-compose -f docker-compose.db.yml up -d

# Apply migrations
dotnet ef database update --project PaymentService

# Run the service
dotnet run --project PaymentService

πŸ“– See Local Development Guide for detailed instructions.

⚑ With Dapr (Production-like)
# Ensure Dapr is initialized
dapr init

# Start with Dapr sidecar
./run.sh       # Linux/Mac
.\run.ps1      # Windows

# Or manually
dapr run \
  --app-id payment-service \
  --app-port 8009 \
  --dapr-http-port 3500 \
  --dapr-grpc-port 50001 \
  --resources-path .dapr/components \
  --config .dapr/config.yaml \
  -- dotnet run --project PaymentService

Note: All services now use the standard Dapr ports (3500 for HTTP, 50001 for gRPC).


πŸ“š Documentation

Document Description
πŸ“˜ Local Development Step-by-step local setup and development workflows
πŸ“˜ Technical Reference Architecture, security, monitoring
☁️ Azure Container Apps Deploy to serverless containers with built-in Dapr

API Documentation: Swagger UI available at /swagger endpoint.


πŸ”Œ API Reference

Payments

Method Endpoint Description
POST /api/payments Process a payment
GET /api/payments Get payments (filtered)
GET /api/payments/{id} Get specific payment
POST /api/payments/{id}/refund Process refund
GET /api/payments/order/{orderId} Get payment by order

Payment Methods

Method Endpoint Description
POST /api/paymentmethods Save payment method
GET /api/paymentmethods/customer/{customerId} Customer's methods
DELETE /api/paymentmethods/{id} Delete payment method
GET /api/paymentmethods/supported-methods Supported methods
GET /api/paymentmethods/providers Available providers
GET /api/paymentmethods/providers/{name}/status Provider status

πŸ§ͺ Testing

# Run all tests
dotnet test

# Build without tests
dotnet build

# Run with specific configuration
dotnet test --configuration Release

# Apply migration
dotnet ef database update --project PaymentService

Provider Testing

Provider Test Mode
Stripe Test card: 4242424242424242
PayPal Sandbox environment
Square Sandbox environment

πŸ—οΈ Project Structure

payment-service/
β”œβ”€β”€ πŸ“ PaymentService/               # Main application project
β”‚   β”œβ”€β”€ πŸ“ Controllers/              # REST API endpoints
β”‚   β”œβ”€β”€ πŸ“ Services/                 # Business logic + provider adapters
β”‚   β”œβ”€β”€ πŸ“ Models/
β”‚   β”‚   β”œβ”€β”€ πŸ“ Entities/             # Domain entities (Payment, Refund)
β”‚   β”‚   └── πŸ“ DTOs/                 # Data transfer objects
β”‚   β”œβ”€β”€ πŸ“ Data/                     # EF Core context + migrations
β”‚   β”œβ”€β”€ πŸ“ Configuration/            # Settings classes
β”‚   └── πŸ“„ Program.cs                # Application entry point
β”œβ”€β”€ πŸ“ PaymentService.Tests/         # Unit tests
β”œβ”€β”€ πŸ“ docs/                         # Documentation
β”œβ”€β”€ πŸ“ .dapr/                        # Dapr configuration
β”‚   β”œβ”€β”€ πŸ“ components/               # Pub/sub, state stores
β”‚   └── πŸ“„ config.yaml               # Dapr runtime configuration
β”œβ”€β”€ πŸ“„ docker-compose.yml            # Full service stack
β”œβ”€β”€ πŸ“„ docker-compose.db.yml         # SQL Server only
β”œβ”€β”€ πŸ“„ Dockerfile                    # Production container image
└── πŸ“„ PaymentService.sln            # Solution file

πŸ”§ Technology Stack

Category Technology
🟣 Runtime .NET 8 / C# 12
🌐 Framework ASP.NET Core 8
πŸ—„οΈ Database SQL Server 2022 with Entity Framework Core
πŸ’³ Providers Stripe, PayPal, Square (pluggable)
πŸ“¨ Messaging Dapr Pub/Sub (RabbitMQ backend)
πŸ” Authentication JWT Bearer Tokens
πŸ“– API Docs Swagger / OpenAPI (Swashbuckle)
πŸ§ͺ Testing xUnit
πŸ“Š Observability Structured logging + correlation IDs

⚑ Quick Reference

# 🐳 Docker Compose
docker-compose up -d              # Start all services
docker-compose down               # Stop all services
docker-compose -f docker-compose.db.yml up -d  # SQL Server only

# 🟣 Local Development
dotnet run --project PaymentService  # Run service
dotnet watch --project PaymentService  # Hot reload

# ⚑ Dapr Development
./run.sh                          # Linux/Mac
.\run.ps1                         # Windows

# πŸ§ͺ Testing
dotnet test                       # Run all tests
dotnet build                      # Build solution

# πŸ” Health Check
curl http://localhost:8009/health
curl http://localhost:8009/swagger

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Write tests for your changes
  4. Run the test suite
    dotnet test
  5. Commit your changes
    git commit -m 'feat: add amazing feature'
  6. Push to your branch
    git push origin feature/amazing-feature
  7. Open a Pull Request

Please ensure your PR:

  • βœ… Passes all existing tests
  • βœ… Includes tests for new functionality
  • βœ… Follows PCI compliance considerations
  • βœ… Updates documentation as needed

πŸ†˜ Support

Resource Link
πŸ› Bug Reports GitHub Issues
πŸ“– Documentation docs/
πŸ’¬ Discussions GitHub Discussions

πŸ“„ License

This project is part of the xshopai e-commerce platform. Licensed under the MIT License - see LICENSE for details.


⬆ Back to Top

Made with ❀️ by the xshopai team

About

Integrates with external payment gateways (Stripe, PayPal, etc.)

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors