XRPService is a microservice that enables XRP Ledger (XRPL) integration for EV charging payments. It provides functionality for:
- Processing real-time micropayments for EV charging sessions
- Managing XRP wallets for payment processing
- Interacting with the XRP Ledger
- Tracking payment transactions on the blockchain
- Payment Processing: Process micropayments in XRP for ongoing charging sessions
- Wallet Management: Create and manage XRP wallets for users and stations
- Blockchain Integration: Connect with the XRP Ledger for transaction processing
- Transaction History: Track and retrieve payment history for users
- Distributed Tracing: OpenTelemetry integration for monitoring payment flows
- Event-Based Messaging: MassTransit integration for asynchronous processing
- Dockerization: Containerized deployment with Ubuntu-based image
The service follows the same architectural patterns as other microservices in the system:
- OpenTelemetry: End-to-end tracing and metrics
- MassTransit: Event-based messaging
- Minimal API: Modern ASP.NET Core endpoints
- Clean Architecture: Separation of concerns into services, features, and models
This diagram illustrates the typical payment session lifecycle involving XRPService and other components:
- .NET 9.0 SDK
- Azure Service Bus (or local equivalent)
- XRP Ledger node access (testnet/devnet for development)
The main configuration is in appsettings.json
:
{
"XRPLedger": {
"DefaultNetwork": "testnet",
"Endpoints": {
"Mainnet": "https://xrplcluster.com",
"Testnet": "https://s.altnet.rippletest.net:51234",
"Devnet": "https://s.devnet.rippletest.net:51234"
}
}
}
dotnet run --project XRPService
- POST /api/payments/sessions: Initialize a payment session
- POST /api/payments/micropayments: Process a micropayment
- POST /api/payments/sessions/{id}/finalize: Finalize a payment session
- GET /api/payments/history/{userId}: Get payment history for a user
- GET /api/payments/wallets/{address}: Get wallet information
- POST /api/wallets: Create a new XRP wallet
- GET /api/wallets/{address}: Get wallet information
- POST /api/wallets/{address}/fund: Fund a test wallet (testnet/devnet only)
This service integrates with:
- EVSEService: For charging session management
- XRP Ledger: For blockchain transactions
- Monitoring: OpenTelemetry for tracing payments
-
Services:
- IXRPLService: Interface for XRP Ledger interactions
- IWalletService: Interface for wallet management
- IPaymentService: Interface for payment processing
-
API Endpoints:
- PaymentsEndpoints: API endpoints for payment operations
- WalletEndpoints: API endpoints for wallet management
-
Event System:
- EnergyUpdateEvent: Triggered when energy consumption is updated
- PaymentConfirmedEvent: Triggered when a payment is confirmed
- PaymentFailedEvent: Triggered when a payment fails
- SessionFinalizedEvent: Triggered when a charging session is completed
-
Consumers:
- EnergyUpdateConsumer: Handles energy updates and triggers micropayments
Test projects are organized to mirror the service structure, focusing on:
- Unit tests for service implementations
- Integration tests for API endpoints
- Mock tests for blockchain interactions
The service is deployed as a Docker container in Kubernetes, similar to other services in the system.
Build and run the Docker container:
# Build the Docker image
docker build -t xrpservice:latest .
# Run the container
docker run -d -p 8080:80 --name xrpservice xrpservice:latest
The service uses an Ubuntu-based container with .NET 9.0 runtime.