Coder Social home page Coder Social logo

jashdev74 / bankpayment Goto Github PK

View Code? Open in Web Editor NEW

This project forked from soghandi/bankpayment

0.0 0.0 0.0 2.11 MB

Persian Bank Payment Server

License: GNU Lesser General Public License v2.1

JavaScript 0.06% C# 96.79% CSS 0.23% HTML 2.77% Dockerfile 0.15%

bankpayment's Introduction

BankPayment

Persian Bank Payment Gateway

Easily connect to Iranian bank gateways without getting involved with their contractual protocol.

Supported Banks:

  • Saman
  • Mellat (behpardakht)
  • Efarda (Ertebat Farda - efarda.ir)
  • Parsian

How to setup server:
clone project, build and run Adin.BankPayment in your server (Windows, Linux, Mac)
build command:
dotnet build Adin.BankPayment

add connectionstring to appsettings in Adin.Bankpayment project
{
"ConnectionString": "Server=SERVERNAME;Database=DATABASENAME;User Id=DATABASEUSER;Password=PASSWORD;MultipleActiveResultSets=True"
}

run below command to create tables with default values:
dotnet ef database update -p .\Adin.BankPayment.Domain\Adin.BankPayment.Domain.csproj -s .\Adin.BankPayment\Adin.BankPayment.csproj

publish command:
dotnet publish .\Adin.BankPayment\Adin.BankPayment.csproj

run command:
dotnet .\Adin.BankPayment\bin\Debug\netcoreapp2.1\publish\Adin.BankPayment.dll

after project started successfully you can easily add various applications with multiple bank gateways from swagger url: http://localhost:5000/api-docs/index.html
server configuration finish!


How to setup client:

First add connector dll to client project

Install-Package Adin.BankPayment.Connector

use it in your project (like sample project)

send request:

 public async Task<IActionResult> GotoBankPage()
 {
   var currentBaseUrl = string.Format("{0}://{1}", Request.Scheme, Request.Host);
   var model = new Connector.Model.PayInfoModel
   {
       Amount = 1000,
       BankCode = BankCodeEnum.Saman,
       CallbackUrl = currentBaseUrl + "/Home/Callback",
       Mobile = 989354762696,
       PriceUnit = Connector.Enum.PriceUnitEnum.Rial,
       TrackCode = DateTime.Now.ToString("hhmmssfff")
   };
   var response = await client.RequestPay(model);
   if (response.Status == Connector.Enum.ApiStatusCodeEnum.Success)
   {
     return Redirect(response.Body.Url);
   }
   else
   {
       throw new Exception(response.Status + ":" + response.Body);
   }
 }

callback:

  public async Task<IActionResult> CallBack()
  {
    Guid payId = Guid.Parse(Request.Query["id"]);
    string trackCode = Request.Query["trackCode"];
    bool status = bool.Parse(Request.Query["status"]);
    string message = Request.Query["message"];
    if (status == false)
    {
        int errorCode = int.Parse(Request.Query["errorCode"]);
        BankErrorCodeEnum errCode = (BankErrorCodeEnum)errorCode;
        ViewBag.Result = message;
    }
    else
    {
        try
        {
            //Todo: deliver product to customer here


            var res = await client.Verify(payId);
            if (res.Status == Connector.Enum.ApiStatusCodeEnum.Success && res.Body.Status)
            {
                //Transaction Done
                ViewBag.Result = res.Body.Message;
            }
            else
            {
                //Transaction Failed
                ViewBag.Result = res.Body.Message + "<br/>" + "تا 24 ساعت دیگر مبلغ به حساب شما بازگردانده خواهد شد";
            }
        }
        catch
        {            
            //Reverse Transaction
        }
    }
    return View();
  }



enjoy it.

bankpayment's People

Contributors

soghandi avatar mohsen2hasani avatar morbitpool avatar dependabot[bot] avatar alty-ir avatar

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.