public string Purchase(FormCollection form) { int GameID = Convert.ToInt32((form["GameID"])); AspNetUser user = db.AspNetUsers.Where(x => x.UserName == User.Identity.Name).First(); Member member = db.Members.Where(m => m.ASPUserId == user.Id).First(); MemberInGame mib = db.MemberInGames.Where(c => c.MemberID == member.MemberID && c.GameID == GameID).First(); trackingTransactionManager.PausePaymentTrackingTransaction(GameID, member.MemberID); //Address billingAddress = db.Addresses.Where(a => a.MemberID == member.MemberID && a.AddressType.ToLower() == "billing").First(); pig = mib.Game.ProductInGames.FirstOrDefault(); /* Setcom Purchase */ SetcomPaymentTransactionManager PayMan = new SetcomPaymentTransactionManager(); PurchaseTransactionRequest purchaseTransactionRequest = new PurchaseTransactionRequest(); purchaseTransactionRequest.CCNumber = form["PaymentsModel.CardNumber"]; //"4444444444444444"; purchaseTransactionRequest.CCCVV = form["PaymentsModel.CVCNumber"]; purchaseTransactionRequest.ExYear = (form["PaymentsModel.ExpiryDateY"].ToString().Trim().Length > 2) ? form["PaymentsModel.ExpiryDateY"] : "20" + form["PaymentsModel.ExpiryDateY"]; purchaseTransactionRequest.ExMonth = form["PaymentsModel.ExpiryDateM"]; purchaseTransactionRequest.CCName = form["PaymentsModel.NameOnCard"]; purchaseTransactionRequest.MemberInGameID = mib.MemberInGameID; purchaseTransactionRequest.EmailAddress = mib.Member.EmailAddress; purchaseTransactionRequest.CC_Amount = pig.PriceInGame.ToString(); purchaseTransactionRequest.ip_address = Request.ServerVariables["REMOTE_ADDR"]; purchaseTransactionRequest.transactionDateTime = DateTime.Now; /* Additional Non-mandatory fields */ purchaseTransactionRequest.bill_first_name = mib.Member.FirstName; purchaseTransactionRequest.bill_last_name = mib.Member.LastName; purchaseTransactionRequest.bill_street1 = ""; purchaseTransactionRequest.bill_street2 = ""; purchaseTransactionRequest.bill_city = ""; purchaseTransactionRequest.bill_state = ""; purchaseTransactionRequest.bill_country = mib.Member.Country.CountryName;; purchaseTransactionRequest.bill_zip = ""; purchaseTransactionRequest.bill_phone = ""; purchaseTransactionRequest.bill_title = ""; PurchaseTransactionResponse ptRes = PayMan.PerformPaymentTransaction(purchaseTransactionRequest); ptRes.outcome = ptRes.outcome.ToUpper(); if (ptRes.outcome.ToUpper() != "APPROVED") // Setcom change ends here { trackingTransactionManager.ResumePaymentTrackingTransaction(GameID, member.MemberID); ptRes.timeRemaining = trackingTransactionManager.GetTimeRemaining(GameID, member.MemberID).ToString(); } else { trackingTransactionManager.CompletePaymentTrackingTransaction(GameID, member.MemberID); //Update paymentIndicator mib.PaymentIndicator = true; try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } // get winner address Address deliveryAddress = db.Addresses.FirstOrDefault(x => x.MemberID == member.MemberID && x.AddressType.ToLower() == "postal"); // get quantity won - divide quantity from pig by number of winners ??? really??? ok then..... Game qtyGame = db.Games.Find(GameID); int winQuantity = 1; //pig.Quantity / qtyGame.NumberOfWinners; // send winner email this.sendWinnermail(member.FirstName + ' ' + member.LastName, member.EmailAddress, deliveryAddress, winQuantity); } JsonResult json = new JsonResult { Data = ptRes }; string son = new JavaScriptSerializer().Serialize(json.Data); return(son); }