public ActionResult RedirectFromPaypal(int id) { ServiceReference1.ClientAPIServiceSoapClient s = new ServiceReference1.ClientAPIServiceSoapClient(); string clientId = ConfigurationManager.AppSettings["ClientId"]; string clientPwd = ConfigurationManager.AppSettings["ClientPwd"]; string responseid = ""; string status = ""; string balances = ""; TB_Transaction tx = entities.TB_Transaction.Where(x => x.TransactionId == id).FirstOrDefault(); bool result = s.RequestInput(clientId, clientPwd, tx.TransactionNumber, tx.ProductId.ToString(), Convert.ToDecimal(tx.Denomination), tx.Phone, ref responseid, ref status, ref balances); RechargeModel model = new RechargeModel(); model.phone = tx.Phone; model.amount = tx.Denomination; model.Operator = entities.TB_Product.Where(x => x.ProductId == tx.ProductId).FirstOrDefault().Product_Name; tx.Status = status; tx.ResponseId = responseid; repo.updateTrasnaction(tx); if (status == "SUBMIT_SUCCESS") { repo.DeductMoneyFromWallet(tx.UserId ?? 0, Convert.ToDecimal(tx.Denomination)); ViewBag.Message = "Recharge Succesful ! Transaction Number is :" + tx.TransactionNumber; ViewBag.MessageDesc = ""; } else { ViewBag.Message = "Recharge was UnSuccesful ! Transaction Number is :" + tx.TransactionNumber + ""; ViewBag.MessageDesc = "Some issue occured in the backend. We haven't deducted money from your wallet. Please try again later. Please note down transaction number for refund process."; } return(View(model)); }
public ActionResult PayUsingWallet() { RechargeModel model = (RechargeModel)Session["recharge"]; EWallet wallet = null; if (Session["user"] != null) { TB_User user = (TB_User)Session["user"]; wallet = user.EWallets.FirstOrDefault(); if (Convert.ToDecimal(model.amount) < wallet.Amount) { ServiceReference1.ClientAPIServiceSoapClient s = new ServiceReference1.ClientAPIServiceSoapClient(); string clientId = ConfigurationManager.AppSettings["ClientId"]; string clientPwd = ConfigurationManager.AppSettings["ClientPwd"]; string responseid = ""; string status = ""; string balances = ""; string number = Guid.NewGuid().ToString().Substring(0, 6); TB_Transaction tx = repo.createTransaction(number, model.amount, wallet.UserID ?? 0, Convert.ToInt32(model.ProductId), model.phone); bool result = s.RequestInput(clientId, clientPwd, number, model.Operators, Convert.ToDecimal(model.amount), model.phone, ref responseid, ref status, ref balances); tx.Status = status; tx.ResponseId = responseid; repo.updateTrasnaction(tx); if (status == "SUBMIT_SUCCESS") { TB_Transaction txu = entities.TB_Transaction.Where(x => x.TransactionId == tx.TransactionId).FirstOrDefault(); txu.PaymentStatus = "Payment Recieved."; entities.SaveChanges(); repo.DeductMoneyFromWallet(((TB_User)Session["user"]).UserId, Convert.ToDecimal(model.amount)); TB_Paypal paypal = new TB_Paypal(); paypal.Amount = Convert.ToDecimal(model.amount); paypal.date = DateTime.Now; paypal.EWalletID = wallet.EWalletID; paypal.Type = "Mobile Recharge"; paypal.UserID = user.UserId; paypal.TransactionID = txu.TransactionId; entities.TB_Paypal.Add(paypal); entities.SaveChanges(); ViewBag.Message = "Recharge Succesful !"; } else { ViewBag.Message = "Recharge was UnSuccesful !"; ViewBag.MessageDesc = "Some issue occured in the backend. We haven't deducted money from your wallet. Please try again later"; } } } return(View(model)); }