Fib.Payment 2.0.0

dotnet add package Fib.Payment --version 2.0.0
                    
NuGet\Install-Package Fib.Payment -Version 2.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="Fib.Payment" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fib.Payment" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Fib.Payment" />
                    
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 Fib.Payment --version 2.0.0
                    
#r "nuget: Fib.Payment, 2.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.
#:package Fib.Payment@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Fib.Payment&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Fib.Payment&version=2.0.0
                    
Install as a Cake Tool

Fib.NET - First Iraqi Bank Payment Gateway SDK

CI NuGet License: MIT

A modern, type-safe .NET SDK for integrating with the First Iraqi Bank (FIB) Online Payment Gateway. Built with .NET 8.0, this library provides a simple and intuitive API for processing payments in Iraq.

๐Ÿ“ฆ Installation

Install the package via NuGet Package Manager:

dotnet add package Fib.Payment

Or via Package Manager Console:

Install-Package Fib.Payment

๐Ÿš€ Quick Start

1. Configure Services

Add FIB Payment services to your dependency injection container:

Using appsettings.json:

{
  "Fib": {
    "ClientId": "your-client-id",
    "ClientSecret": "your-client-secret",
    "BaseUrl": "https://fib.iq",
    "TokenRefreshBufferSeconds": 60
  }
}
// Program.cs or Startup.cs
using Fib.Payment;

builder.Services.AddFibPayment(builder.Configuration);

Using inline configuration:

builder.Services.AddFibPayment(options =>
{
    options.ClientId = "your-client-id";
    options.ClientSecret = "your-client-secret";
    options.BaseUrl = "https://fib.iq";
    options.TokenRefreshBufferSeconds = 60;
});

2. Inject and Use the Service

public class PaymentController : ControllerBase
{
    private readonly FibPaymentService _paymentService;

    public PaymentController(FibPaymentService paymentService)
    {
        _paymentService = paymentService;
    }

    [HttpPost("create-payment")]
    public async Task<IActionResult> CreatePayment()
    {
        var payment = await _paymentService.CreatePaymentAsync(
            amount: 50000,
            currency: Currency.IQD,
            callbackUrl: "https://yoursite.com/payment-callback"
        );

        return Ok(new
        {
            payment.PaymentId,
            payment.ReadableCode,
            payment.QrCode,
            payment.ValidUntil,
            payment.PersonalAppLink
        });
    }
}

๐Ÿ“– Usage Examples

Creating a Payment

Basic Payment:

var payment = await _paymentService.CreatePaymentAsync(
    amount: 100000,
    currency: Currency.IQD,
    callbackUrl: "https://yoursite.com/callback"
);

Payment with Options:

var options = new PaymentOptions
{
    Amount = 100000,
    Currency = Currency.IQD,
    StatusCallbackUrl = "https://yoursite.com/callback",
    Description = "Order #12345 - Premium Subscription",
    ExpiresIn = "PT1H" // ISO 8601 duration: 1 hour
};

var payment = await _paymentService.CreatePaymentAsync(options);

Checking Payment Status

var status = await _paymentService.CheckPaymentAsync(paymentId);

switch (status.Status)
{
    case PaymentStatus.Paid:
        Console.WriteLine($"Payment completed at: {status.PaidAt}");
        Console.WriteLine($"Paid by: {status.PaidBy?.Name}");
        break;
    case PaymentStatus.Unpaid:
        Console.WriteLine("Payment is still pending");
        break;
    case PaymentStatus.Declined:
        Console.WriteLine($"Payment declined: {status.DecliningReason}");
        break;
    case PaymentStatus.Refunded:
        Console.WriteLine("Payment has been refunded");
        break;
}

Canceling a Payment

try
{
    var cancelled = await _paymentService.CancelPaymentAsync(paymentId);
    if (cancelled)
    {
        Console.WriteLine("Payment cancelled successfully");
    }
}
catch (FibPaymentException ex)
{
    Console.WriteLine($"Cancellation failed: {ex.Message}");
}

Refunding a Payment

try
{
    var refunded = await _paymentService.RefundPaymentAsync(paymentId);
    if (refunded)
    {
        Console.WriteLine("Refund requested successfully");
    }
}
catch (FibPaymentException ex)
{
    Console.WriteLine($"Refund failed: {ex.Message}");
}

๐Ÿ”ง Configuration Options

Option Type Default Description
ClientId string - Client ID provided by FIB (required)
ClientSecret string - Client Secret provided by FIB (required)
BaseUrl string - FIB API base URL (required)
TokenRefreshBufferSeconds int 30 Seconds before token expiration to refresh

๐ŸŒ Supported Currencies

  • IQD - Iraqi Dinar
  • USD - United States Dollar
  • EUR - Euro

๐Ÿ“Š Payment Status

Status Description
Paid Payment completed successfully
Unpaid Payment is pending
Declined Payment was declined
RefundRequested Refund has been requested
Refunded Payment has been refunded

๐Ÿšซ Declining Reasons

Reason Description
ServerFailure Payment declined due to server error
PaymentExpiration Payment expired before completion
PaymentCancellation Payment was cancelled

๐Ÿ›ก๏ธ Error Handling

The SDK throws two types of exceptions:

FibAuthenticationException

Thrown when authentication with FIB fails:

try
{
    var payment = await _paymentService.CreatePaymentAsync(options);
}
catch (FibAuthenticationException ex)
{
    Console.WriteLine($"Auth Error: {ex.Error}");
    Console.WriteLine($"Description: {ex.ErrorDescription}");
}

FibPaymentException

Thrown when payment operations fail:

try
{
    var payment = await _paymentService.CreatePaymentAsync(options);
}
catch (FibPaymentException ex)
{
    Console.WriteLine($"Status Code: {ex.StatusCode}");
    Console.WriteLine($"Error: {ex.Message}");
    
    if (ex.ErrorBody != null)
    {
        Console.WriteLine($"Trace ID: {ex.ErrorBody.TraceId}");
        foreach (var error in ex.ErrorBody.Errors)
        {
            Console.WriteLine($"- {error.Code}: {error.Title}");
            Console.WriteLine($"  {error.Detail}");
        }
    }
}

๐Ÿงช Testing

The project includes comprehensive unit tests using xUnit, FluentAssertions, and Moq.

Run tests:

dotnet test

Run tests with coverage:

dotnet test --collect:"XPlat Code Coverage"

๐Ÿ—๏ธ Project Structure

Fib.NET/
โ”œโ”€โ”€ Fib.Payment/              # Main SDK library
โ”‚   โ”œโ”€โ”€ Configuration/        # Configuration classes
โ”‚   โ”œโ”€โ”€ Exceptions/          # Custom exceptions
โ”‚   โ”œโ”€โ”€ Models/              # Request/response models
โ”‚   โ”œโ”€โ”€ FibAuthenticationHandler.cs
โ”‚   โ”œโ”€โ”€ FibPaymentService.cs
โ”‚   โ””โ”€โ”€ ServiceCollectionExtensions.cs
โ”œโ”€โ”€ Fib.Payment.Tests/       # Unit tests
โ””โ”€โ”€ .github/workflows/       # CI/CD workflows

๐Ÿ“ Requirements

  • .NET 8.0 or later
  • FIB merchant account with API credentials

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Dersalik

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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
2.0.0 154 12/29/2025
1.0.0 217 11/26/2025