View Demo
·
Report Bug
·
Request Feature
Table of Contents
The goal of this project is to make it easier to work with the AsanPardakht internet payment gateway (IPG). This project includes packages that can be installed to make it easier to implement the internet payment gateway.
A list of commonly used resources that I find helpful are listed in the acknowledgements.
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
-
Register your merchant & get a MerchantConfiguraion with following AsanPardakht website instruction
-
Install latest version of
AsanPardakht.IPGpackage from nugetInstall-Package AsanPardakht.IPG -
If you are using asp.net core just install latest version of
AsanPardakht.IPG.AspNetCorepackage from nugetInstall-Package AsanPardakht.IPG.AspNetCore -
Enter your MerchantConfiguraion in
appsettings.json{ "AsanPardakhtIPGConfig": { "MerchantUser": "myUsername", "MerchantPassword": "myPassword", "MerchantConfigurationId": 1234 } } -
Call
AddAsanPardakhtIpgmethod with an instance ofIConfigurationto register default services inStartup.csfilepublic IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddAsanPardakhtIpg(Configuration); ,... }
-
If you need your own implementation of
AsanPardakht.IPG.Abstractions.ILocalInvoiceIdGeneratorregister it as a service. -
Now you can inject
AsanPardakht.IPG.Abstractions.IServicesin your classes.
- First you need to get a
Payment RefId (Token)fromGenerateTokenmethod. You can use one of the following methods:- Use
IServices.GenerateBuyTokenmethod to get a token for a simple buy payment. - Use
IServices.GenerateBillTokenmethod to get a token for paying an existing Bill. - Use
IServices.GenerateTelecomeChargeTokenmethod to get a token for buying a Telecom Sim Charge. - Use
IServices.GenerateTelecomeBoltonTokenmethod to get a token for buying a Telecom Package. - Use
IServices.GenerateTokenmethod to get a token for a custom implementation. - For more information about
Tokenmethod refer to the Online Swagger Doc.
- Use
- After getting a
RefIdfromTokenmethod, send user to the Payment Gateway usingPOST HTTP METHOD-
You can use the following javascript code to send user to the Payment Gateway
function postRefId(gatewayUrl, refId, mobileap) { var form = document.createElement("form"); form.setAttribute("method", "POST"); form.setAttribute("action", gatewayUrl); form.setAttribute("target", "_self"); var refIdField = document.createElement("input"); refIdField.setAttribute("name", "RefId"); refIdField.setAttribute("value", refId); form.appendChild(refIdField); if (mobileap) { var mobileField = document.createElement("input"); mobileField.setAttribute("name", "Mobileap"); mobileField.setAttribute("value", mobileap); form.appendChild(mobileField); } document.body.appendChild(form); form.submit(); document.body.removeChild(form); } postRefId(tokenResponse.GatewayUrl, tokenResponse.RefId, tokenResponse.Mobileap);
-
- After payment your callback url will called with some parameters, you can ignore those parameters and use
IServices.GetTranResultmethod. - After receiving successful result from
IServices.GetTranResultmethod, you have to verify the payment usingIServices.Verifymethod. - Now it's time to do whatever you like with your site order, for example check the payment amount with order amount and change its status to Saccessful Payment.
- If your operations were successful call
IServices.Settlemethod to complete the payment process else callIServices.Reversemethod to cancel payment and return money back to user.
For exploring a working example, please refer to the HomeController file
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated. 😏
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
MohammadReza Daghestani - @mrdaghestani - MRDaghestani@gmail.com
Project Link: https://github.com/mrdaghestani/AsanPardakht.IPG