public ActionResult IndexPost() { gHelper = new GenaralHelpers(Session); try { ViewBag.Message = "Your application description page."; PostingVM vm = new PostingVM(); string sAmount = "10.00"; string Mer_ref = GenaralHelpers.GetRandomNumber().ToString(); Session["ipay_in__mer_ref_id"] = Mer_ref; //Set session Data vm.TxnAmount = sAmount; vm.Action = SalesTransactionType; vm.CurrencyCode = "LKR"; vm.LanguageCode = "eng"; vm.MerRefID = Mer_ref; vm.ItemList = ""; vm.ReturnURL = Return_Url; vm.MerVar1 = ""; vm.MerVar2 = ""; vm.MerVar3 = ""; vm.MerVar4 = ""; string autoHtml = ""; switch (SalesTransactionType) { case "SaleTxn": autoHtml = gHelper.DoApiSaleTransaction(SalesTransactionType, vm, API_URL_Pay); break; case "saleTxnGroup": autoHtml = gHelper.DoApiSaleTransaction(SalesTransactionType, vm, API_URL_Pay); break; } return(Content(autoHtml)); } catch (Exception ex) { //Need to include your error handling code here. just for demostration purpose we direct the full error message to view var errorMessage = ex.Message; ViewBag.Error = errorMessage; return(View()); } }
public ActionResult IndexPost(IndexViewModel Model) { string UUID = ""; string autoHtml = ""; var _Configuration = System.Configuration.ConfigurationManager.AppSettings; var SalesTransactionType = (_Configuration["SalesFunction"] != null) ? _Configuration["SalesFunction"] : "SaleTxn"; string Return_Url = (_Configuration["ipay_in__ret_url"] != null) ? _Configuration["ipay_in__ret_url"] : ""; string API_URL_Pay = (_Configuration["API_URL_Pay"] != null) ? _Configuration["API_URL_Pay"] : ""; //Set session Data Session["ipay_in__txn_amt"] = GenaralHelpers.GetRoundWithDecimalPrecision(Model.ToSu1.ToString()).ToString() + ".00"; Session["ipay_in__action"] = SalesTransactionType; Session["ipay_in__cur"] = "LKR"; Session["ipay_in__lang"] = "eng"; Session["ipay_in__mer_ref_id"] = GenaralHelpers.GetRandomNumber().ToString(); Session["ipay_in__item_list"] = ""; Session["ipay_in__ret_url"] = Return_Url; Session["ipay_in__mer_var1"] = ""; Session["ipay_in__mer_var2"] = ""; Session["ipay_in__mer_var3"] = ""; Session["ipay_in__mer_var4"] = ""; //Create Api Helper Instance. Don't use static methods inside ApiHelper or use them anywhere ApiHelper apiCaller = new ApiHelper(Session); switch (SalesTransactionType) { case "SaleTxn": //Calling the api caller Sale Transaction initiate with data var returnData = apiCaller.saleTxn(); if (returnData.ContainsKey("ERROR_CODE")) { //**************************THIS MEAN AN ERROR ON RESPONSE********************* //NEED TO HANDLE THIS ********************************************************* } else { UUID = returnData["txn_uuid"]; //Add the UUID to the session so it can be used when trns verifying Session["ipay_out__txn_uuid"] = UUID; //Commence AutoRedirect autoHtml = GenaralHelpers.GenarateBrowserRedirectionHTML(API_URL_Pay, UUID); } break; case "saleTxnGroup": //Calling the api caller Sale Transaction initiate with data var returnDataVerify = apiCaller.saleTxn(); if (returnDataVerify.ContainsKey("ERROR_CODE")) { //**************************THIS MEAN AN ERROR ON RESPONSE********************* //NEED TO HANDLE THIS ********************************************************* } else { //Get UUID from the Return data UUID = returnDataVerify["ipay_out__txn_uuid"]; //Add the UUID to the session so it can be used when trns verifying Session["ipay_out__txn_uuid"] = UUID; //Commence AutoRedirect autoHtml = GenaralHelpers.GenarateBrowserRedirectionHTML(API_URL_Pay, UUID); } break; } return(Content(autoHtml)); }