Skip to content

mrdaghestani/AsanPardakht.IPG

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

AsanPardakht IPG Sample



View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

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.

Built With

Getting Started

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.

Installation

  1. Register your merchant & get a MerchantConfiguraion with following AsanPardakht website instruction

  2. Install latest version of AsanPardakht.IPG package from nuget

    Install-Package AsanPardakht.IPG
    
  3. If you are using asp.net core just install latest version of AsanPardakht.IPG.AspNetCore package from nuget

    Install-Package AsanPardakht.IPG.AspNetCore
    
  4. Enter your MerchantConfiguraion in appsettings.json

    {
       "AsanPardakhtIPGConfig": {
         "MerchantUser": "myUsername",
         "MerchantPassword": "myPassword",
         "MerchantConfigurationId": 1234
       }
    }
  5. Call AddAsanPardakhtIpg method with an instance of IConfiguration to register default services in Startup.cs file

    public IConfiguration Configuration { get; }
    
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAsanPardakhtIpg(Configuration);
    
        ,...
    }
  6. If you need your own implementation of AsanPardakht.IPG.Abstractions.ILocalInvoiceIdGenerator register it as a service.

  7. Now you can inject AsanPardakht.IPG.Abstractions.IServices in your classes.

Usage

  1. First you need to get a Payment RefId (Token) from GenerateToken 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.
  2. After getting a RefId from Token method, send user to the Payment Gateway using POST 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);
  3. After payment your callback url will called with some parameters, you can ignore those parameters and use IServices.GetTranResult method.
  4. After receiving successful result from IServices.GetTranResult method, you have to verify the payment using IServices.Verify method.
  5. 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.
  6. If your operations were successful call IServices.Settle method to complete the payment process else call IServices.Reverse method to cancel payment and return money back to user.

For exploring a working example, please refer to the HomeController file

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

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

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

MohammadReza Daghestani - @mrdaghestani - [email protected]

Project Link: https://github.com/mrdaghestani/AsanPardakht.IPG

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published