Giter Site home page Giter Site logo

chargily / chargily-epay-csharp Goto Github PK

View Code? Open in Web Editor NEW
7.0 0.0 3.0 17.18 MB

C# Library for Chargily ePay Gateway

Home Page: https://dev.chargily.com/docs/#/epay-csharp

License: MIT License

C# 100.00%
api c-sharp chargily cib cibweb csharp csharp-library edahabia epay gateway integration library package payment plugin satim

chargily-epay-csharp's Introduction

Nuget Pacakge Downloads
Latest version Downloads

Chargily ePay Gateway C# Package

This package supports the following frameowrks and platforms:

Framework Support Platform
Console Windows, Linux, macOS
ASP.NET Core Windows, Linux, macOS
Blazor WASM Windows, Linux, macOS
Blazor Server Windows, Linux, macOS
.NET MAUI Windows, Linux, macOS, Android, iOS, Tizen
Xamarin Android, iOS
ASP.NET Windows
WPF Windows
AvaloniaUI Windows, Linux, macOS
UWP Windows, Xbox OS
WinForms Windows

Any C# application that uses Microsoft.Extensions.DependencyInjection can use this package

Chargily ePay Gateway

Integrate ePayment gateway with Chargily easily.

  • Currently support payment by CIB / EDAHABIA cards and soon by Visa / Mastercard
  • This is a C#.NET Nuget Package, If you are using another programing language Browse here or look to API documentation

Installation

First, install the chargily.epay.csharp NuGet package into your app

Using DotNet CLI :

dotnet add chargily.epay.csharp

Using Visual Studio Dev Console:

Install-Package chargily.epay.csharp

Using Visual Studio IDE:

tutorial_adding_nuget_package.mp4

Requirements

  1. Get your API Key/Secret from ePay by Chargily dashboard for free

How to use

Installation & Project Creation Video Guide

tutorial_create_console_project.mp4

Implemention of the code below:

tutorial_generic_project.mp4

Usage with any generic C# Project:

this package provide ChargilyEpayClient client, to create payment request use:

using Chargily.Epay;

var client = ChargilyEpay.CreateClient("[API_KEY]");

var payment = new EpayPaymentRequest()
{
    InvoiceNumber = "[INVOICE_NUMBER]",
    Name = "Ahmed",
    Email = "[email protected]",
    Amount = 1500,
    DiscountPercentage = 5.0,
    PaymentMethod = PaymentMethod.EDAHABIA,
    BackUrl = "https://yourapp.com/",
    WebhookUrl = "https://api.yourbackend.com/webhook-validator",
    ExtraInfo = "Product Purchase"
};

var response = await client.CreatePayment(payment);

Usage with ASP.NET Core

Video Guide how to use with Minimal API

tutorial_backend_aspnetcore_minimalapi.mp4

Video Guide how to use with ASP.NET Core WebAPI

Soon

this applies to:

  • ASP.NET Core WebAPI
  • ASP.NET Core Minimal WebAPI
  • Blazor Server
  • Blazor WASM
  • ASP.NET Core MVC
using Chargily.Epay;
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddChargilyEpayGateway("[API_KEY]");

var app = builder.Build();

app.MapPost("/invoice",
    async ([FromBody] EpayPaymentRequest request,
        [FromServices] IChargilyEpayClient<EpayPaymentResponse, EpayPaymentRequest> chargilyClient) =>
    {
        return await chargilyClient.CreatePayment(request);
    });

app.Run();

Request:

{
    "invoice_number" : "321616",
    "client" : "Ahmed",
    "client_email" : "[email protected]",
    "amount" : 1500,
    "discount" : 5.0,
    "mode" : "EDAHABIA",
    "back_url" : "https://example.com/",
    "webhook_url" : "https://shop.com/purchase",
    "comment" : "Product Purchase"
}

Response:

{
    "httpStatusCode": 201,
    "responseMessage": {
        "Message": "Success"
    },
    "isSuccessful": true,
    "isRequestValid": true,
    "body": {
        "checkout_url": "https://epay.chargily.com.dz/checkout/d00c1e652200798bbc35f688b2910fa9bc6c4c30d38b51e3f4142e407fa7c141"
    },
    "createdOn": "2022-05-06T03:55:49.6527862+01:00"
}

WebHook Validation:

using Chargily.Epay;
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddChargilyWebHookValidator("[APP_SECRET]");

var app = builder.Build();
app.MapPost("/webhook_endpoint",
            ([FromServices] IWebHookValidator validator, HttpRequest request, [FromBody] ChargilyWebhookRequest body) =>
            {
                var signature = request.Headers["Signature"].First();
                var isValid   = validator.Validate(signature, request.Body);
                if (isValid) return Results.Ok(body.Invoice);
                return Results.Unauthorized();
            });

app.Run();

Configuration:

API_KEY & APP_SECRET can be added directly in code or from appsettings.json configuration file

builder.Services.AddChargilyWebHookValidator("[APP_SECRET]");
builder.Services.AddChargilyEpayGateway("[API_KEY]");

// OR

builder.Services.AddChargilyWebHookValidator(builder.Configuration["CHARGILY_APP_SECRET"]);
builder.Services.AddChargilyEpayGateway(builder.Configuration["CHARGILY_API_KEY"]);

// OR
// Same as previous but it will be loaded automatically from appsettings.json
builder.Services.AddChargilyWebHookValidator());
builder.Services.AddChargilyEpayGateway();

appsettings.json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "CHARGILY_APP_SECRET": "[APP_SECRET]", // <-- APP SECRET
  "CHARGILY_API_KEY": "[API_KEY]" // <-- API KEY
}

ASP.NET Core Middleware

This package provide WebHookValidatorMiddleware ASP.NET Core Middleware, when registered every POST request that have a Signature Http Header will be validated automatically. How to register the Middleware:

using Chargily.Epay;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddChargilyEpayGateway("[API_KEY]");

builder.Services
    .AddChargilyValidatorMiddleware("[APP_SECRET]"); // WebHookValidatorMiddleware have to be registered

var app = builder.Build();

app.UseChargilyValidatorMiddleware();

app.Run();

Usage with .NET MAUI

using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Controls.Compatibility;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Chargily.Epay;

namespace MyApp
{
  public static class MauiProgram
  {
    public static MauiApp CreateMauiApp()
    {
      var builder = MauiApp.CreateBuilder();
      builder.UseMauiApp<App>();
      builder.Services.AddChargilyEpayGateway("[API_KEY]");
      return builder.Build();
    }
  }
}

then you can add in ViewModels:

public class MainViewModel : ViewModelBase  
{  
    private ChargilyEpayClient _chargilyClient;  
    private IWebHookValidator _webhookValidator;

    public MainViewModel(ChargilyEpayClient chargilyClient)  
    {  
        _chargilyClient = chargilyClient;  
    }  
    // With Validator
    public MainViewModel(ChargilyEpayClient chargilyClient, IWebHookValidator webhookValidator)  
    {  
        _chargilyClient = chargilyClient;  
        _webhookValidator = webhookValidator;
    }  
}

Note when using .NET MAUI / Xamarin:

storing sensitive APP_SECRET in a frontend app is not a recommended approach, you'd be better off calling a backend api to handle payment, but it's doable. if you decide to use it in the frontend, consider storing APP_SECRET with Akavache BlobCache.Secure

This package is using Microsoft.Extensions.DependencyInjection dependancy injection, so it can be used with application or framework using it.

chargily-epay-csharp's People

Contributors

chargilydev avatar rainxh11 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chargily-epay-csharp's Issues

problem de epay c sharp

Project Sdk="Microsoft.NET.Sdk">

Exe net6.0 enable enable

problem execustion en consol test
problem version chargily 1.0.2 na pas compatible
chargily epaygetway problem monque de dll

Gravité Code Description Projet Fichier Ligne État de la suppression
Avertissement NETSDK1182 le ciblage de .NET 6.0 dans Visual Studio 2019 n’est pas pris en charge. Chargily.Epay.CSharp.AspNetCore.MinimalAPIExample C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets 134



Gravité Code Description Projet Fichier Ligne État de la suppression
Erreur NU1104 Projet 'C:\Users\DEMDZ\Desktop\chargily-epay-csharp-1.0.2\Chargily.EpayGateway.NET\Chargily.EpayGateway.NET.csproj' introuvable. Vérifiez que la référence de projet est valide et que le fichier projet existe. ConsoleTest C:\Users\DEMDZ\Desktop\chargily-epay-csharp-1.0.2\ConsoleTest\ConsoleTest.csproj 1

problem de epay

le programme sa marche pas verifier svp

quelle est la version de vb.net qui sa marche avec cette programme
maittre toi un video qui dirige l'instalation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.