FahdCloud.ThirdParty.PaymentIntegrations
1.0.0
See the version list below for details.
dotnet add package FahdCloud.ThirdParty.PaymentIntegrations --version 1.0.0
NuGet\Install-Package FahdCloud.ThirdParty.PaymentIntegrations -Version 1.0.0
<PackageReference Include="FahdCloud.ThirdParty.PaymentIntegrations" Version="1.0.0" />
<PackageVersion Include="FahdCloud.ThirdParty.PaymentIntegrations" Version="1.0.0" />
<PackageReference Include="FahdCloud.ThirdParty.PaymentIntegrations" />
paket add FahdCloud.ThirdParty.PaymentIntegrations --version 1.0.0
#r "nuget: FahdCloud.ThirdParty.PaymentIntegrations, 1.0.0"
#addin nuget:?package=FahdCloud.ThirdParty.PaymentIntegrations&version=1.0.0
#tool nuget:?package=FahdCloud.ThirdParty.PaymentIntegrations&version=1.0.0
FahdCloud.ThirdParty.PaymentIntegrations
A .NET C# library for integrating multiple third-party payment gateways into your application. This library provides a unified interface to interact with payment services such as Paymob, Stripe, Taps, MyFatoorah, Fawaterak, and Moyasar, enabling seamless payment processing, invoice detail retrieval, and connection health checks.
Table of Contents
- Features
- Supported Payment Gateways
- Installation
- Configuration
- Usage
- Dependencies
- Contributing
- License
Features
- Unified Interface: Consistent methods across all supported payment gateways for creating checkout URLs, retrieving payment details, and checking API connectivity.
- Dependency Injection: Easy integration with ASP.NET Core applications using built-in service collection extensions.
- Validation and Error Handling: Input validation and null checks to ensure robust payment processing.
- Caching Support: Optimized authentication for Paymob using in-memory caching.
- Asynchronous Operations: Full support for asynchronous programming with cancellation tokens.
Supported Payment Gateways
The library supports the following payment gateways:
- Paymob: Handles payment intentions and transaction inquiries with authentication token caching.
- Stripe: Integrates with Stripe's checkout sessions for payment processing.
- Taps: Supports invoice creation and details retrieval for the Taps payment gateway.
- MyFatoorah: Provides region-specific API endpoints (e.g., Kuwait, UAE, Egypt) for flexible payment processing.
- Fawaterak: Enables invoice initialization and payment status checks.
- Moyasar: Supports invoice creation and payment status verification.
Each gateway implements the following core functionalities:
- Create a checkout URL for payment initiation.
- Retrieve payment or invoice details to check transaction status.
- Verify API connectivity with a health check.
Installation
Install the NuGet Package Install the
FahdCloud.ThirdParty.PaymentIntegrations
NuGet package in your project using one of the following methods:Using Package Manager Console:
Install-Package FahdCloud.ThirdParty.PaymentIntegrations
Using .NET CLI:
dotnet add package FahdCloud.ThirdParty.PaymentIntegrations
Install Dependencies Ensure the following NuGet packages are installed in your project:
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Stripe.net" Version="45.0.0" />
Build Requirements
- .NET 8.0 or later
- Visual Studio 2022 or compatible IDE
Configuration
Set Up Dependency Injection Register the payment integration services in your ASP.NET Core application by adding the following to your
Program.cs
or service configuration:using FahdCloud.ThirdParty.PaymentIntegrations.Extensions; var builder = WebApplication.CreateBuilder(args); // Register payment integration services builder.Services.AddPaymentIntegration(); var app = builder.Build();
Configure Payment Gateway Settings Provide configuration settings for each payment gateway via dependency injection, configuration files (e.g.,
appsettings.json
), or environment variables. Example configuration:{ "PaymobSettings": { "ApiKey": "your-paymob-api-key", "SecretKey": "your-paymob-secret-key", "PublicKey": "your-paymob-public-key" }, "StripeSettings": { "ApiKey": "your-stripe-api-key" }, "TapsSettings": { "ApiKey": "your-taps-api-key" }, "MyFatoorahSettings": { "ApiKey": "your-myfatoorah-api-key", "IsLiveMode": true, "MyFatoorahApiRegion": "KuwaitUAEJordanBahrainOman" }, "FawaterakSettings": { "ApiKey": "your-fawaterak-api-key", "IsLiveMode": false }, "MoyasarSettings": { "ApiKey": "your-moyasar-api-key" } }
Inject these settings into your services using dependency injection.
Usage
Registering Services
Add the payment integration services to your service collection as shown in the Configuration section.
Creating a Checkout URL
Use the respective service to create a checkout URL for initiating a payment. Example for Paymob:
using FahdCloud.ThirdParty.PaymentIntegrations.Interfaces.Paymob;
using FahdCloud.ThirdParty.PaymentIntegrations.Models.Paymob.Requests;
using FahdCloud.ThirdParty.PaymentIntegrations.PaymentGatewaysSettings.Gateways.Paymob;
public class PaymentController
{
private readonly IPaymobService _paymobService;
public PaymentController(IPaymobService paymobService)
{
_paymobService = paymobService;
}
public async Task<string> CreatePaymobCheckout()
{
var request = new PaymobTransactionRequest
{
amount = 10000, // Amount in cents
currency = "EGP",
redirection_url = "https://your-redirect-url.com"
};
var settings = new PaymobSetting
{
ApiKey = "your-api-key",
SecretKey = "your-secret-key",
PublicKey = "your-public-key"
};
var response = await _paymobService.CreateCheckoutUrlAsync(request, settings);
return response.checkOutUrl;
}
}
Retrieving Payment Details
Retrieve payment or invoice details to check the transaction status. Example for Stripe:
using FahdCloud.ThirdParty.PaymentIntegrations.Interfaces.Stripe;
using FahdCloud.ThirdParty.PaymentIntegrations.Models.Stripe.Request;
using FahdCloud.ThirdParty.PaymentIntegrations.PaymentGatewaysSettings.Gateways.Stripe;
using Stripe.Checkout;
public class PaymentController
{
private readonly IStripeService _stripeService;
public PaymentController(IStripeService stripeService)
{
_stripeService = stripeService;
}
public async Task<bool> GetStripePaymentStatus(string sessionId)
{
var request = new StripeSessionDetailsRequest { session_id = sessionId };
var settings = new StripeSetting { ApiKey = "your-api-key" };
var response = await _stripeService.GetSessionDetails(request, settings);
return response.successStatus;
}
}
Checking Connection Status
Verify the connectivity to a payment gateway's API. Example for Taps:
using FahdCloud.ThirdParty.PaymentIntegrations.Interfaces.Taps;
using FahdCloud.ThirdParty.PaymentIntegrations.PaymentGatewaysSettings.Gateways.Taps;
public class PaymentController
{
private readonly ITapsService _tapsService;
public PaymentController(ITapsService tapsService)
{
_tapsService = tapsService;
}
public async Task<bool> CheckTapsConnection()
{
var settings = new TapsSetting { ApiKey = "your-api-key" };
return await _tapsService.CheckConnection(settings);
}
}
Dependencies
- Microsoft.Extensions.DependencyInjection: For dependency injection.
- Microsoft.Extensions.Http: For HTTP client factory.
- Microsoft.Extensions.Caching.Memory: For caching Paymob authentication tokens.
- Newtonsoft.Json: For JSON serialization/deserialization.
- Stripe.net: For Stripe API interactions.
- System.ComponentModel.DataAnnotations: For request validation.
Contributing
Contributions are welcome! Please submit a pull request or open an issue on the repository for bug reports, feature requests, or improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.Extensions.Caching.Memory (>= 9.0.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Http (>= 9.0.5)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.5)
- Stripe.net (>= 48.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.