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
- Pasargad
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.