Gracias por su interés en el paquete C# de Chargily Pay™, un proyecto de código abierto de Chargily, una empresa de tecnología financiera líder en Argelia que se especializa en soluciones de pago y facilitación del comercio electrónico. Este paquete proporciona la forma más fácil y gratuita de integrar el pago electrónico. API a través de métodos de pago generalizados en Argelia, como EDAHABIA (Algerie Post) y CIB (SATIM) en sus proyectos C#/ASP.NET.
Este paquete fue desarrollado por Ahmed Chakhoum (rainxh11) y está abierto a contribuciones de desarrolladores como usted.
Paquete Nuget | Descargas |
---|---|
Cargamente.Pagar: | |
Chargily.Pay.AspNet: |
Solo se admiten .NET6.0
y versiones más recientes.
NOTA: La capacidad de recibir el estado de pago con el punto final de Webhook solo es posible con tipos de proyectos que pueden alojar un servidor HTTP.
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 ) ;
NOTA: El pago se puede crear con una lista de precios o usando un monto + moneda.
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 ( ) ;
En el ejemplo anterior, Chargily.Pay.AspNet
proporciona un middleware de validación de firmas de webhook integrado; puede registrarlo con builder.Services.AddChargilyPayWebhookValidationMiddleware()
y luego usarlo con app.UseChargilyPayWebhookValidation()
.
Validará cualquier solicitud POST
que tenga un nombre de encabezado: signature
. Puede anular el nombre del encabezado con app.UseChargilyPayWebhookValidation("another_name")
.
También incorporó un punto final webapi mínimo que se puede registrar con app.MapChargilyPayWebhookEndpoint()
y usarlo para acceder al cuerpo del webhook sin manejar manualmente la validación.
Chargily.Pay
como Chargily.Pay.AspNet
se pueden generar usando este comando: docker build . -- output = . / output
.nupkg
se guardarán en la carpeta ./output
Los paquetes/complementos de Chargily Pay™ son una colección de proyectos de código abierto publicados por Chargily para facilitar la integración de nuestra pasarela de pago en diferentes lenguajes y marcos de programación. Nuestro objetivo es empoderar a los desarrolladores y las empresas brindándoles herramientas fáciles de usar para aceptar pagos sin problemas.
Para obtener instrucciones detalladas sobre cómo integrarse con nuestra API y utilizar Chargily Pay™ en sus proyectos, consulte nuestra documentación de API.
Únase a nuestra comunidad de desarrolladores en Telegram para conectarse con otros desarrolladores, hacer preguntas y mantenerse actualizado sobre las últimas noticias y desarrollos relacionados con Chargily Pay™: Comunidad de Telegram
Agradecemos contribuciones de todo tipo, ya sean correcciones de errores, mejoras de funciones, mejoras de documentación o desarrollos de nuevos complementos/paquetes. Así es como puede comenzar:
Bifurcar el repositorio: haga clic en el botón "Bifurcar" en la esquina superior derecha de esta página para crear su propia copia del repositorio.
Clona el repositorio: clona tu repositorio bifurcado en tu máquina local usando el siguiente comando:
git clone https://github.com/Chargily/chargily-pay-csharp.git
Realizar cambios: realice los cambios o adiciones que desee al código base. Asegúrese de seguir nuestros estándares y pautas de codificación.
Pruebe sus cambios: pruebe sus cambios minuciosamente para asegurarse de que funcionen como se espera.
Envíe una solicitud de extracción: una vez que esté satisfecho con los cambios, envíe una solicitud de extracción al repositorio principal. Nuestro equipo revisará sus contribuciones y brindará comentarios si es necesario.
¿Tiene preguntas o necesita ayuda? Únase a nuestra comunidad de desarrolladores en Telegram y conéctese con otros desarrolladores y nuestro equipo.
¡Apreciamos su interés en contribuir a Chargily Pay™! Juntos podemos construir algo increíble.
¡Feliz codificación!