FahdCloud.ThirdParty.PaymentIntegrations 1.0.0

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FahdCloud.ThirdParty.PaymentIntegrations" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FahdCloud.ThirdParty.PaymentIntegrations" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FahdCloud.ThirdParty.PaymentIntegrations" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FahdCloud.ThirdParty.PaymentIntegrations --version 1.0.0
                    
#r "nuget: FahdCloud.ThirdParty.PaymentIntegrations, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=FahdCloud.ThirdParty.PaymentIntegrations&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FahdCloud.ThirdParty.PaymentIntegrations&version=1.0.0
                    
Install as a Cake Tool

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

  • 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

  1. 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
    
  2. 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" />
    
  3. Build Requirements

    • .NET 8.0 or later
    • Visual Studio 2022 or compatible IDE

Configuration

  1. 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();
    
  2. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 18 6/21/2025
1.0.4 110 6/19/2025
1.0.3 136 5/29/2025
1.0.2 137 5/29/2025
1.0.1 141 5/29/2025
1.0.0 135 5/29/2025