Source: Spinfoweb Blog

Spinfoweb Blog CCAvenue Integration in MVC

Dear Friends,From last few days i am struggling to integrate CCAvenue in MVC. Finally i got the solution. May be you can get idea to get the source code from CCAvenue website. But the things need to be considered as below.1) MerchandID3) AccessCode3) Working Keys4)Website URL. (Registered URL)Now as we know which are the most imp things we need to consider we need to follow the steps.1) We have Index.cshtmlChange working key and merchant_id(hidden Field) @using CCA.Util; @using System.Collections.Specialized; @{ Random randomValue = new Random(); var randomId = randomValue.Next().ToString(); var tid = "WE16-" + randomId; } @{ if (IsPost) { string workingKey = "";//put in the 32bit alpha numeric key in the quotes provided here CCACrypto ccaCrypto = new CCACrypto(); string encResponse = ccaCrypto.Decrypt(Request.Form["encResp"], workingKey); NameValueCollection Params = new NameValueCollection(); string[] segments = encResponse.Split('&'); foreach (string seg in segments) { string[] parts = seg.Split('='); if (parts.Length > 0) { string Key = parts[0].Trim(); string Value = parts[1].Trim(); Params.Add(Key, Value); } } for (int i = 0; i < Params.Count; i++) { //Response.Write(Params.Keys[i] + " = " + Params[i] + "<br>"); } <div> <div class="row"> <div class="small-12 large-12 columns"> <div class="panel" id="payment-confirmation"> <h2 class="text-center">Payment received successfully</h2> <div> <table align="center"> <tbody> <tr><td>Payment Status</td><td>@Params.Get("order_status")</td></tr> <tr><td>Total Amount</td><td>₹ @Params.Get("amount")</td></tr> <tr><td>Email Address</td><td>@Params.Get("billing_email")</td></tr> <tr><td>Order ID</td><td>@Params.Get("order_id")</td></tr> <tr><td>Payment ID</td><td>@Params.Get("tracking_id")</td></tr> <tr><td>Bank Reference</td><td>@Params.Get("bank_ref_no")</td></tr> <tr><td>Transaction Date</td><td>@DateTime.Now</td></tr> <tr><td>Address</td><td>@Params.Get("billing_address")</td></tr> <tr><td>City</td><td>@Params.Get("billing_city")</td></tr> <tr><td>State</td><td>@Params.Get("billing_state") - @Params.Get("billing_zip")</td></tr> </tbody> </table> </div> </div> </div> </div> <div> </div> </div> } else { <div id="container1"> <div class="row"> <div class="small-12 large-12 columns"> <h2>Confirm your details</h2> </div> </div> <form id="payment" name="payment" method="post" action="~/Order/processor"> <div class="row"> <div class="small-12 large-12 columns"> <label> Full Name* <input type="text" name="billing_name" id="billing_name" placeholder="Full Name" required /> </label> </div> </div> <div class="row"> <div class="small-12 large-6 columns"> <label> Email Address* <input type="email" name="billing_email" id="billing_email" placeholder="Email Address" required /> </label> </div> <div class="small-12 large-6 columns"> <label> Mobile Number <input type="number" name="billing_tel" id="billing_tel" placeholder="Mobile Number" /> </label> </div> </div> <div class="row"> <div class="small-12 large-12 columns"> <label> Address <textarea placeholder="billing_address" name="billing_address" id="address"></textarea> </label> </div> </div> <div class="row"> <div class="small-12 large-3 columns"> <label>City <input type="text" name="billing_city" id="billing_city" placeholder="City" /> </label> </div> <div class="small-12 large-3 columns"> <label>Pin/Zip code <input type="text" name="billing_zip" id="billing_zip" placeholder="pincode or zipcode" /> </label> </div> <div class="small-12 large-3 columns"> <label>State <input type="text" name="billing_state" id="billing_state" placeholder="State" /> </label> </div> <div class="small-12 large-3 columns"> <label>Country <input type="text" name="billing_country" id="billing_country" placeholder="country" /> </label> </div> </div> <div class="row"> <div class="small-12 large-12 columns"> <label> Notes: <textarea placeholder="Note (if any)" name="notes" id="notes"></textarea> </label> </div> </div> <! -- to checkout --> <div> <input type="hidden" id="merchant_id" name="merchant_id" value="" /> <!-- pass this merchant id from any secure way--> <input type="hidden" id="order_id" name="order_id" value="@tid" /> <input type="hidden" id="currency" name="currency" value="INR" /> <input type="hidden" id="language" name="language" value="en" /> <input type="hidden" id="amount" name="amount" value="1" /> <input type="hidden" id="redirect_url" name="redirect_url" value="/"/> <input type="hidden" id="cancel_url" name="cancel_url" value="/" /> <input type="hidden" id="merchant_param1" name="merchant_param1" value="We support Credit Card/ Debit Card/ Net Banking/ Wallets..." /> <input type="hidden" id="tid" name="tid" value="@randomId" /> </div> <div class="row"> <div class="small-12 large-12 columns"> <button type="submit" class="button success expand right"> Proceed to checkout <i class="fi-lock"></i></button> </div> </div> </form> </div> } } 2) We have Processor.cshtmlChange workingKey and strAccessCode @using CCA.Util; @using System.Collections.Specialized; @{ if (IsPost) { var workingKey = "";//put in the 32bit alpha numeric key in the quotes provided here var ccaRequest = ""; var strEncRequest = ""; var strAccessCode = "";// put the access key in the quotes provided here. //var strAccessCode = "AVVK63DB84AD40KVDA"; CCACrypto ccaCrypto = new CCACrypto(); foreach (var name in Request.Form) { if (name != null) { if (!name.ToString().StartsWith("_")) { ccaRequest = ccaRequest + name + "=" + Request.Form[name.ToString()] + "&"; //Response.Write(name + "=" + Request.Form[name.ToString()]); //Response.Write("</br>"); } } } strEncRequest = ccaCrypto.Encrypt(ccaRequest, workingKey); <div> <form method="post" id="payment_processor" action="https://test.ccavenue.com/transaction/transaction.do?command=initiateTransaction" > <input type="hidden" id="encRequest" name="encRequest" value="@strEncRequest" /> <input type="hidden" id="access_code" name="access_code" value="@strAccessCode" /> </form> </div> <div class="row" style="text-align:center"> <div class="small-12 large-12"> <h2 class="text-center" >Processing...</h2> </div> </div> <script src="~/Scripts/jquery-1.10.2.min.js"></script> <script> $("#payment_processor").submit(); </script> } } 3) OrderController public ActionResult Index() { return View(); } public ActionResult processor() { return View(); } Now may be you have a question from where i can get the DLL for CCA.Util namespace.When you download the source code from CCAvenue website you can find in IFRAME_KIT /libs/MCPG.CCA.Util.dllSo give reference to your project.Thats it. Now you can run the project but it won't execute, it wont take you to the CCAvenue website why because in your CCAvenue account you have registered the different website URL so it always gives you error "10002 - Invalid Marchant Authentication" .Now what is the solution to run local website . Go to IIS and give same host name as you have mentioned in CCAvenue Account.Run this URL and you will get success.That's it.HAVE FUN.

Read full article »
Est. Annual Revenue
$100K-5.0M
Est. Employees
1-25
CEO Avatar

Founder & CEO

Samir Mistry

CEO Approval Rating

65/100

Read more