Fib.Payment
2.0.0
dotnet add package Fib.Payment --version 2.0.0
NuGet\Install-Package Fib.Payment -Version 2.0.0
<PackageReference Include="Fib.Payment" Version="2.0.0" />
<PackageVersion Include="Fib.Payment" Version="2.0.0" />
<PackageReference Include="Fib.Payment" />
paket add Fib.Payment --version 2.0.0
#r "nuget: Fib.Payment, 2.0.0"
#:package Fib.Payment@2.0.0
#addin nuget:?package=Fib.Payment&version=2.0.0
#tool nuget:?package=Fib.Payment&version=2.0.0
Fib.NET - First Iraqi Bank Payment Gateway SDK
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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
๐ Links
๐จโ๐ป Author
Dersalik
| Product | Versions 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. |
-
net8.0
- EnumExtensions.System.Text.Json (>= 1.3.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- System.Text.Json (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.