感謝您對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™ 做出貢獻!齊心協力,我們可以創造出令人驚嘆的東西。
快樂編碼!