Chargily.Pay.V2
1.0.0
dotnet add package Chargily.Pay.V2 --version 1.0.0
NuGet\Install-Package Chargily.Pay.V2 -Version 1.0.0
<PackageReference Include="Chargily.Pay.V2" Version="1.0.0" />
paket add Chargily.Pay.V2 --version 1.0.0
#r "nuget: Chargily.Pay.V2, 1.0.0"
// Install Chargily.Pay.V2 as a Cake Addin #addin nuget:?package=Chargily.Pay.V2&version=1.0.0 // Install Chargily.Pay.V2 as a Cake Tool #tool nuget:?package=Chargily.Pay.V2&version=1.0.0
<img src="https://raw.githubusercontent.com/rainxh11/chargily-pay-csharp/main/Assets/chargily_wide.svg" width="300"/>
Nuget Pacakge | Downloads |
---|---|
Chargily Pay V2 .NET Client Library
A fully-featured client library to work with Chargily Pay API version 2 Online Payment Platform. The easiest and free way to integrate e-payment API through EDAHABIA of Algerie Poste and CIB of SATIM
Support with the various .NET Project-types:
Only .NET6.0
and newer versions are supported.
NOTE: Ability to receive checkout status with Webhook endpoint is only possible with project types that can host an HTTP Server.
Documentations Summary:.gitignore
Installation:
Using DotNet CLI :
dotnet add Chargily.Pay.V2
Getting Started:
- First create & configure a client:
using Chargily.Pay.V2;
var chargilyClient = ChargilyPay.CreateResilientClient(config =>
{
// toggle live mode
config.IsLiveMode = false;
// your chargily dev account api-secret key
config.ApiSecretKey = "YOUR API SECRET";
});
- Create a Product:
var createProduct = new CreateProduct()
{
Name = "Product Name",
ImagesUrls = new List<Uri>()
{
new Uri("https://domain.com/image.png")
},
Description = "Product Description",
};
var product = await _chargilyPayClient.AddProduct(createProduct);
- Add Price for the Product:
var createPrice = new CreatePrice()
{
Amount = 3000,
Currency = Currency.DZD,
ProductId = product.Value.Id,
};
var productPrice = await chargilyClient.AddPrice(createPrice);
- Create a checkout:
var checkoutItems = new List<CheckoutPriceItem>()
{
new CheckoutPriceItem()
{
Quantity = 1,
PriceId = productPrice.Value.Id
}
};
var createCheckout = new Checkout(checkoutItems)
{
Description = "Checkout Description",
Language = LocaleType.Arabic,
PaymentMethod = PaymentMethod.EDAHABIA,
PassFeesToCustomer = true,
WebhookEndpointUrl = new Uri("https://domain.com/webhook/endpoint"),
OnFailureRedirectUrl = new Uri("https://webapp.com/checkout/fail"),
OnSuccessRedirectUrl = new Uri("https://webapp.com/checkout/success"),
CollectShippingAddress = false,
};
var checkout = await chargilyClient.CreateCheckout(createCheckout);
Create a checkout without Product & Price:
var createCheckout = new Checkout(amount: 3000, Currency.DZD)
{
Description = "Checkout Description",
Language = LocaleType.Arabic,
PaymentMethod = PaymentMethod.EDAHABIA,
PassFeesToCustomer = true,
WebhookEndpointUrl = new Uri("https://domain.com/webhook/endpoint"),
OnFailureRedirectUrl = new Uri("https://webapp.com/checkout/fail"),
OnSuccessRedirectUrl = new Uri("https://webapp.com/checkout/success"),
CollectShippingAddress = false,
};
var fastCheckout = await chargilyClient.CreateCheckout(createCheckout);
NOTE: Checkout can be created with list of prices or using an amount + currency.
Create a Payment Link for a product:
var createProduct = new CreateProduct()
{
/* ... */
};
var product = await _chargilyPayClient.AddProduct(createProduct);
var createPrice = new CreatePrice()
{
/* ... */
};
var productPrice = await chargilyClient.AddPrice(createPrice);
// above steps are similar to how to create a checkout
var paymentLinkItems = new List<PaymentLinkPriceItem>()
{
new PaymentLinkPriceItem()
{
AdjustableQuantity = true,
PriceId = productPrice.Value.Id,
Quantity = 2
}
};
var createPaymentLink = new CreatePaymentLink(paymentLinkItems)
{
Language = LocaleType.Arabic,
PassFeesToCustomer = true,
CollectShippingAddress = false,
Name = "Name",
CompletionMessage = "completion message",
IsActive = true
};
Create a Customer:
- Support for Customers also added in V2, and can be added to checkout also:
var createCustomer = new CreateCustomer()
{
Name = "Customer Name",
Address = new CustomerAddress()
{
Address = "Address",
Country = Country.Algeria,
State = "Alger"
},
Email = "user@email.com",
Phone = "+2130601010101"
};
var customer = await chargilyClient.AddCustomer(createCustomer);
var createCheckout = new Checkout(amount: 3000, Currency.DZD)
{
CustomerId = customer.Value.Id,
/* .... */
};
var fastCheckout = await chargilyClient.CreateCheckout(createCheckout);
Retrieve Balance Wallets:
- Balance Wallets are refreshed automatically, to check current balance:
foreach (var wallet in chargilyClient.Balance)
{
/* ... */
}
- Configuring how often balance wallets are refreshed:
using Chargily.Pay.V2;
var chargilyClient = ChargilyPay.CreateResilientClient(config =>
{
/* ... */
// refresh balance every 30 seconds
config.BalanceRefreshInterval = TimeSpan.FromSeconds(30);
});
- Or get balance manually:
var balance = await chargilyClient.GetBalance();
How to Retrieve Data:
Products:
// by id
var byId = await chargilyClient.GetProduct("id");
// by page number & page size
var products = await chargilyClient.GetProducts(page: 1, pageSize: 50);
// or iterate through all items using `Async Enumerable async foreach`
await foreach(var product in chargilyClient.Products())
{
/* ... */
}
Prices:
// by id
var byId = await chargilyClient.GetPrice("id");
// by page number & page size
var prices = await chargilyClient.GetPrices(page: 1, pageSize: 50);
// or iterate through all items using `IAsyncEnumerable async foreach`
await foreach(var price in chargilyClient.Prices())
{
/* ... */
}
Customers:
// by id
var byId = await chargilyClient.GetCustomer("id");
// by page number & page size
var customers = await chargilyClient.GetCustomers(page: 1, pageSize: 50);
// or iterate through all items using `IAsyncEnumerable async foreach`
await foreach(var customer in chargilyClient.Customers())
{
/* ... */
}
Checkouts:
// by id
var byId = await chargilyClient.GetCheckout("id");
// by page number & page size
var checkouts = await chargilyClient.GetCheckouts(page: 1, pageSize: 50);
// or iterate through all items using `IAsyncEnumerable async foreach`
await foreach(var checkout in chargilyClient.Checkouts())
{
/* ... */
}
Checkout Items:
var checkoutItems = await chargilyClient.GetCheckoutItems("checkoutId");
Payment Links:
// by id
var byId = await chargilyClient.GetPaymentLink("id");
// by page number & page size
var paymentLinks = await chargilyClient.GetPaymentLinks(page: 1, pageSize: 50);
// or iterate through all items using `IAsyncEnumerable async foreach`
await foreach(var paymentLink in chargilyClient.PaymentLinks())
{
/* ... */
}
Payment Links Items:
var paymentLinksItems = await chargilyClient.GetPaymentLinkItems("paymentLinkId");
Usage with ASP.NET WebApi:
Install Chargily.Pay.V2.AspNet
Nuget Package:
dotnet add Chargily.Pay.V2.AspNet
Example Usage:
using Chargily.Pay.V2;
using Chargily.Pay.V2.AspNet;
var builder = WebApplication.CreateBuilder(args);
builder.Services
// Register Chargily Pay Client
.AddGlobalChargilyPayClient(config =>
{
// toggle live mode
config.IsLiveMode = false;
// your chargily dev account api-secret key
config.ApiSecretKey = "YOUR API SECRET";
})
// Register Chargily Pay Webhook Signature Validator
.AddChargilyPayWebhookValidationMiddleware();
var app = builder.Build();
// User Chargily Pay Webhook Signature Validator Middleware
app.UseChargilyPayWebhookValidation();
// Map Webhook Endpoint to `both POST & GET /api/checkout-webhook`
app.MapChargilyPayWebhookEndpoint(endpointPath: "/api/checkout-webhook");
app.Run();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- AutoMapper (>= 13.0.1)
- FluentValidation (>= 11.9.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.9.0)
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Debug (>= 8.0.0)
- Polly (>= 8.3.0)
- Refit (>= 7.0.0)
- Refit.HttpClientFactory (>= 7.0.0)
- System.Reactive (>= 6.0.0)
-
net8.0
- AutoMapper (>= 13.0.1)
- FluentValidation (>= 11.9.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.9.0)
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Debug (>= 8.0.0)
- Polly (>= 8.3.0)
- Refit (>= 7.0.0)
- Refit.HttpClientFactory (>= 7.0.0)
- System.Reactive (>= 6.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Chargily.Pay.V2:
Package | Downloads |
---|---|
Chargily.Pay.V2.AspNet
AspNet WebApi Extension Library for C#.NET Library for Chargily Pay™ Gateway - V2 |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 152 | 3/12/2024 |