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.IPG
package from nugetInstall-Package AsanPardakht.IPG
-
If you are using asp.net core just install latest version of
AsanPardakht.IPG.AspNetCore
package from nugetInstall-Package AsanPardakht.IPG.AspNetCore
-
Enter your MerchantConfiguraion in
appsettings.json
{ "AsanPardakhtIPGConfig": { "MerchantUser": "myUsername", "MerchantPassword": "myPassword", "MerchantConfigurationId": 1234 } }
-
Call
AddAsanPardakhtIpg
method with an instance ofIConfiguration
to register default services inStartup.cs
filepublic IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddAsanPardakhtIpg(Configuration); ,... }
-
If you need your own implementation of
AsanPardakht.IPG.Abstractions.ILocalInvoiceIdGenerator
register it as a service. -
Now you can inject
AsanPardakht.IPG.Abstractions.IServices
in your classes.
- First you need to get a
Payment RefId (Token)
fromGenerateToken
method. You can use one of the following methods:- Use
IServices.GenerateBuyToken
method to get a token for a simple buy payment. - Use
IServices.GenerateBillToken
method to get a token for paying an existing Bill. - Use
IServices.GenerateTelecomeChargeToken
method to get a token for buying a Telecom Sim Charge. - Use
IServices.GenerateTelecomeBoltonToken
method to get a token for buying a Telecom Package. - Use
IServices.GenerateToken
method to get a token for a custom implementation. - For more information about
Token
method refer to the Online Swagger Doc.
- Use
- After getting a
RefId
fromToken
method, 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.GetTranResult
method. - After receiving successful result from
IServices.GetTranResult
method, you have to verify the payment usingIServices.Verify
method. - 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.Settle
method to complete the payment process else callIServices.Reverse
method 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 - [email protected]
Project Link: https://github.com/mrdaghestani/AsanPardakht.IPG