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

                  
                }
            }