Tuesday, 13 September 2016

Eazypay Payment Gateway Integration in ASP.NET

This is to send request to payment gateway server

   ASEKEY  & merchantid will be provided by BANK after submitting return URL to bank

string redirecturl = "";  // this is to check what url is coming before encryption
            string encryptredirecturl = "";

            string ASEKEY = "xxxxxxxxxxxxxxxxxxxx";

            string Reference_no, sub_merchant_id, pgamount, Mobile_No, city, name;

            Reference_no ="your value";
            sub_merchant_id ="your value";
            pgamount = 000;
            Mobile_No = "your value";;
            city ="your value";
            name = "your value";


            redirecturl += "https://eazypay.icicibank.com/EazyPG?";
            redirecturl += "merchantid=xxxxx";
            redirecturl += "&mandatory fields=" + Reference_no + "|" + sub_merchant_id + "|" + pgamount + "|" + Mobile_No + "|456";
            redirecturl += "&optional fields=" + city + "|" + name;
            redirecturl += "&returnurl=http://yourwebsite.com/eazypayreturn.aspx";
            redirecturl += "&Reference No=" + Reference_no;
            redirecturl += "&submerchantid=" + sub_merchant_id;
            redirecturl += "&transaction amount=" + pgamount;
            redirecturl += "&paymode=9";


            encryptredirecturl += "https://eazypay.icicibank.com/EazyPG?";
            encryptredirecturl += "merchantid=xxxxx";
            encryptredirecturl += "&mandatory fields=" + encryptFile(Reference_no + "|" + sub_merchant_id + "|" + pgamount + "|" + Mobile_No + "|456", ASEKEY);
            encryptredirecturl += "&optional fields=" + encryptFile(city + "|" + name, ASEKEY);
            encryptredirecturl += "&returnurl=" + encryptFile("http://yourwebsite.com/eazypayreturn.aspx", ASEKEY);
            encryptredirecturl += "&Reference No=" + encryptFile(Reference_no, ASEKEY);
            encryptredirecturl += "&submerchantid=" + encryptFile(sub_merchant_id, ASEKEY);
            encryptredirecturl += "&transaction amount=" + encryptFile(pgamount, ASEKEY);
            encryptredirecturl += "&paymode=" + encryptFile("9", ASEKEY);


            Response.Redirect(encryptredirecturl);

-----------------------------------------------------------------------------------------
 public static string encryptFile(string textToEncrypt, string key)
        {
            RijndaelManaged rijndaelCipher = new RijndaelManaged();
            rijndaelCipher.Mode = CipherMode.ECB;
            rijndaelCipher.Padding = PaddingMode.PKCS7;
            rijndaelCipher.KeySize = 0x80;
            rijndaelCipher.BlockSize = 0x80;
            byte[] pwdBytes = Encoding.UTF8.GetBytes(key);
            byte[] keyBytes = new byte[0x10];
            int len = pwdBytes.Length;
            if (len > keyBytes.Length)
            {
                len = keyBytes.Length;
            }
            Array.Copy(pwdBytes, keyBytes, len);
            rijndaelCipher.Key = keyBytes;
            rijndaelCipher.IV = keyBytes;
            ICryptoTransform transform = rijndaelCipher.CreateEncryptor();
            byte[] plainText = Encoding.UTF8.GetBytes(textToEncrypt);
            return Convert.ToBase64String(transform.TransformFinalBlock(plainText,
            0, plainText.Length));
        }

************************************************************

After coming back to return url , get response parameters and their vales 

 foreach (string key in HttpContext.Current.Request.Form.AllKeys)
            {
                string value = HttpContext.Current.Request.Form[key];

               

                if (value == "E000")
                {
                    //Success
 

                }
                else
                {
                    //Error

                  
                }
            }

16 comments:

  1. very helpful code! Thanks for sharing information.
    Payment Gateway Integration

    ReplyDelete
  2. Thank you Israr for the very helpful code. its working. Can you please help how to validate the response in the payment confirmation page? Thanks in advance.

    ReplyDelete
  3. Im getting session time out exception in https://eazypay.icicibank.com/ClickOnNextToAcctAction page after click on proceed button in eazypay,if I go back from this error page its returning back to my application and showing transaction already paid error message.It is returning E006 error and sometimes it is returning E0038 response code

    ReplyDelete
  4. Can you please help me to fix this E006 error

    ReplyDelete
  5. can you please help me its redirecting to return url not the payment gateway

    ReplyDelete
    Replies
    1. i am also having the same issue

      Delete
    2. I am also get same issue.....Please any one help me...

      Delete
  6. How to test my payment getway url, any test api is there

    ReplyDelete
  7. how to use their verify status api

    ReplyDelete
  8. This blog is so informative for providing a valuable information about send c# sms gateway integration. Get ready to use integrated Bulk SMS API and easily integrate it into your software to Send SMS in a single click.

    ReplyDelete
  9. i have implement the eazypay paymentgetway but it's return the "Your Session has expired"
    , i have implement the your given above code using asp.net mvc4

    please provide me suggestion what to do

    ReplyDelete
  10. Is there any api to verfiy broken payment has been done.

    ReplyDelete
  11. please provide a integration source code for asp.net mvc 4

    ReplyDelete
  12. For all those who get a session expired error - do not copy paste the URL in the browser; rather create a page that redirects to this URL; I think the system checks for referrer variable.

    ReplyDelete