感谢您对 Chargily Pay™ 的 C# 软件包感兴趣,该软件包是阿尔及利亚领先的金融科技公司 Chargily 的开源项目,专门从事支付解决方案和电子商务促进,该软件包提供了集成电子支付的最简单且免费的方式通过阿尔及利亚广泛的支付方式(例如 EDAHABIA(阿尔及利亚邮政)和 CIB (SATIM))将 API 集成到您的 C#/ASP.NET 项目中。
该软件包由Ahmed Chakhoum (rainxh11)开发,欢迎像您这样的开发人员做出贡献。
努盖特·帕卡格 | 下载 |
---|---|
收费: | |
Chargily.Pay.AspNet: |
仅支持.NET6.0
及更高版本。
注意:只有能够托管 HTTP 服务器的项目类型才能使用 Webhook 端点接收结账状态。
dotnet add Chargily.Pay
using Chargily . Pay ;
var chargilyClient = ChargilyPay . CreateResilientClient ( config =>
{
// toggle live mode
config . IsLiveMode = false ;
// your chargily dev account api-secret key
config . ApiSecretKey = "YOUR API SECRET" ;
} ) ;
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 ) ;
var createPrice = new CreatePrice ( )
{
Amount = 3000 ,
Currency = Currency . DZD ,
ProductId = product . Value . Id ,
} ;
var productPrice = await chargilyClient . AddPrice ( createPrice ) ;
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 ) ;
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 ) ;
注意:可以使用价格列表或使用金额 + 货币来创建结帐。
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
} ;
var createCustomer = new CreateCustomer ( )
{
Name = "Customer Name" ,
Address = new CustomerAddress ( )
{
Address = "Address" ,
Country = Country . Algeria ,
State = "Alger"
} ,
Email = "[email protected]" ,
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 ) ;
foreach ( var wallet in chargilyClient . Balance )
{
/* ... */
}
using Chargily . Pay ;
var chargilyClient = ChargilyPay . CreateResilientClient ( config =>
{
/* ... */
// refresh balance every 30 seconds
config . BalanceRefreshInterval = TimeSpan . FromSeconds ( 30 ) ;
} ) ;
var balance = await chargilyClient . GetBalance ( ) ;
// 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 ( ) )
{
/* ... */
}
await chargilyClient . DeleteProduct ( "01hrtc39vq463jhnemv0q33mcq" ) ;
// 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 ( ) )
{
/* ... */
}
// 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 ( ) )
{
/* ... */
}
await chargilyClient . DeleteCustomer ( "01hrsfjgvfvv1007y54y8fph1v" ) ;
// 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 ( ) )
{
/* ... */
}
var checkoutItems = await chargilyClient . GetCheckoutItems ( "checkoutId" ) ;
// 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 ( ) )
{
/* ... */
}
var paymentLinksItems = await chargilyClient . GetPaymentLinkItems ( "paymentLinkId" ) ;
Chargily.Pay.AspNet
Nuget 包: dotnet add Chargily.Pay.AspNet
using Chargily . Pay ;
using Chargily . Pay . 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 ( "/chargily/webhook" , async ( webhookContext ) =>
{
// you can access the webhook body, http context, validation result
if ( webhookContext . SignatureIsValid )
{
var body = webhookContext . Request ;
/* do something with the webhook request body */
}
} ) ;
app . Run ( ) ;
在上面的示例中, Chargily.Pay.AspNet
提供了内置的 webhook 签名验证器中间件,您可以使用builder.Services.AddChargilyPayWebhookValidationMiddleware()
注册它,然后将其与app.UseChargilyPayWebhookValidation()
一起使用。
它将验证任何具有标头名称的POST
请求: signature
。您可以使用app.UseChargilyPayWebhookValidation("another_name")
覆盖标头名称。
还内置了一个最小的 webapi 端点,可以使用app.MapChargilyPayWebhookEndpoint()
注册,并使用它来访问 webhook 主体,而无需手动处理验证。
Chargily.Pay
和Chargily.Pay.AspNet
nuget 包都可以使用以下命令生成: docker build . -- output = . / output
.nupkg
工件将保存到./output
文件夹Chargily Pay™ 包/插件是 Chargily 发布的开源项目的集合,旨在促进我们的支付网关集成到不同的编程语言和框架中。我们的目标是通过提供易于使用的工具来无缝接受付款,从而为开发人员和企业提供支持。
有关如何与我们的 API 集成并在您的项目中使用 Chargily Pay™ 的详细说明,请参阅我们的 API 文档。
加入我们的 Telegram 开发者社区,与其他开发者联系、提出问题并随时了解与 Chargily Pay™ 相关的最新新闻和动态:Telegram 社区
我们欢迎各种贡献,无论是错误修复、功能增强、文档改进还是新插件/包开发。您可以通过以下方式开始:
分叉存储库:单击此页面右上角的“分叉”按钮以创建您自己的存储库副本。
克隆存储库:使用以下命令将分叉存储库克隆到本地计算机:
git clone https://github.com/Chargily/chargily-pay-csharp.git
进行更改:对代码库进行所需的更改或添加。请务必遵循我们的编码标准和指南。
测试您的更改:彻底测试您的更改以确保它们按预期工作。
提交拉取请求:对更改感到满意后,将拉取请求提交回主存储库。我们的团队将审核您的贡献并在需要时提供反馈。
有疑问或需要帮助吗?加入我们的 Telegram 开发者社区,与其他开发者和我们的团队联系。
我们感谢您有兴趣为 Chargily Pay™ 做出贡献!齐心协力,我们可以创造出令人惊叹的东西。
快乐编码!