Seamlessly integrate multiple payment gateways into your ASP.NET Core applications.
Features • Getting Started • Usage • Sample Payloads & Responses • Contributing • License
git clone https://github.com/teesofttech/PayBridge.git cd PayBridge⚙️ Configure the Database
Edit appsettings.json
:
"DatabaseProvider": "MSSQL", "ConnectionStrings": { "PayBridgeDbContext": "Data Source=BABATUNDE;Initial Catalog=PayBridgeDB;Integrated Security=True;TrustServerCertificate=true;" }
dotnet ef database update💳 Sample Payment Controller
[Route("api/[controller]")] [ApiController] public class PaymentController : ControllerBase { private readonly IPaymentService _paymentService; private readonly ILogger<PaymentController> _logger; public PaymentController( IPaymentService paymentService, ILogger<PaymentController> logger) { _paymentService = paymentService ?? throw new ArgumentNullException(nameof(paymentService)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); } [HttpPost] public async Task<IActionResult> CreatePayment([FromBody] CreatePaymentRequest request) { try { _logger.LogInformation("Creating payment for {Amount} {Currency}", request.Amount, request.Currency); var paymentRequest = PaymentRequestMapper.MapToPaymentRequest(request); var paymentGateway = request.Gateway ?? PaymentGatewayType.Automatic; var response = await _paymentService.CreatePaymentAsync(paymentRequest, paymentGateway); if (response.Success) { _logger.LogInformation("Payment created successfully: {Reference}", response.TransactionReference); return Ok(response); } else { _logger.LogWarning("Payment creation failed: {Message}", response.Message); return BadRequest(new ErrorResponse { Message = response.Message, ErrorCode = "PAYMENT_FAILED" }); } } catch (Exception ex) { _logger.LogError(ex, "Error creating payment"); return StatusCode(500, new ErrorResponse { Message = "An error occurred while processing your payment", ErrorCode = "INTERNAL_ERROR" }); } } [HttpGet("verify-transaction")] public async Task<IActionResult> VerifyTransaction() { try { var queryParams = HttpContext.Request.Query; var allParams = new Dictionary<string, string>(); foreach (var param in queryParams) { if (param.Key.Contains("reference", StringComparison.OrdinalIgnoreCase) || param.Key.Contains("tx_ref", StringComparison.OrdinalIgnoreCase)) { allParams["reference"] = param.Value!; } } PaymentGatewayType gateway = GatewayExtractor.DetectGatewayFromWebhook(allParams.Values); string reference = allParams.Values.FirstOrDefault()!.ToString()!; if (string.IsNullOrEmpty(reference)) { _logger.LogWarning("Could not extract transaction reference from Query"); return BadRequest(new ErrorResponse { Message = "Could not extract transaction reference from Query", ErrorCode = "INVALID_REQUEST" }); } var response = await _paymentService.VerifyPaymentAsync(reference, gateway); if (response.Success) { _logger.LogInformation("Query verification successful: {Reference}, Status: {Status}", reference, response.Status); return Ok(new { success = true, response }); } else { _logger.LogWarning("Query verification failed: {Message}", response.Message); return BadRequest(new ErrorResponse { Message = response.Message, ErrorCode = "QUERY_VERIFICATION_FAILED" }); } } catch (Exception ex) { _logger.LogError(ex, "Error processing Query"); return StatusCode(500, new ErrorResponse { Message = "An error occurred while processing the Query", ErrorCode = "INTERNAL_ERROR" }); } } }📦 Sample Payloads & Responses 🔼 Sample Payment Request Payload
{ "amount": 1000, "currency": "NGN", "description": "est", "customerEmail": "tunde@yopmail.com", "customerName": "string", "customerPhone": "string", "redirectUrl": "https://localhost:7252/api/payment/verify-transaction", "webhookUrl": "https://localhost:7252/api/payment/verify-transaction", "metadata": { "additionalProp1": "string", "additionalProp2": "string", "additionalProp3": "string" }, "paymentMethodType": 0, "savedPaymentMethodId": "string", "gateway": 1 }🔽 Sample Payment Response
{ "success": true, "transactionReference": "FLW_dc324e96d52b4bd48c401ff9194c15e8", "message": "Hosted Link", "checkoutUrl": "https://checkout-v2.dev-flutterwave.com/v3/hosted/pay/207b10ab0a05ddf19746", "status": 0, "gatewayResponse": { "link": "https://checkout-v2.dev-flutterwave.com/v3/hosted/pay/207b10ab0a05ddf19746" } }
We welcome your ideas, improvements, and fixes!
git clone https://github.com/teesofttech/PayBridge.git
git checkout -b feature/your-feature-name
git commit -m "feat: add new feature" git push origin feature/your-feature-name
🙌 Your support helps make PayBridge better for everyone!
PayBridge is released under the MIT License.
You're free to use, modify, and distribute this software as long as the original license is included.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4