public ActionResult CardPurchase(BuyGiftCardModel model, ShoppingCart cart) { TempData["EmailSentMsg"] = ""; TempData["CardCode"] = ""; ViewBag.result = 0; if (ModelState.IsValid) { try { if (DoDirectPaymentSuccess(model)) { ViewBag.result = 1; if (DoCheckoutCompleted(model)) { ViewBag.result = 2; } } } catch { ViewBag.result = 3; } // test = TempData["EmailSentMsg"] //test only } ViewBag.bagitems = GetCartItems(cart); return(View(model)); }
public CreditCard AddCreditCardToDB(BuyGiftCardModel model) { CreditCard cc = new CreditCard(); cc = CreditCardRepository.InsertCreditCard(0, UserName, int.Parse(model.CardType), model.BillFirstName, model.BillLastName, model.CardNumber, int.Parse(model.ExpirationMonth), int.Parse(model.ExpirationYear), int.Parse(model.SecurityCode), model.Phone, model.BuyerEmail, DateTime.Now, UserName, DateTime.Now, UserName, true); return(cc); }
public ActionResult CardPurchase(ShoppingCart cart) { ViewBag.result = 0; BuyGiftCardModel gcb = new BuyGiftCardModel(); if (User.Identity.IsAuthenticated) { AspNetUser up = new AspNetUser(); up = UserRepository.GetUserByUserName(User.Identity.Name); gcb.BuyerEmail = up.UserDetails.Count > 0 ? up.UserDetails.FirstOrDefault(e => e.UserId == up.Id).ContactInfo.Email : ""; } ViewBag.bagitems = GetCartItems(cart); return(View(gcb)); }
public string BuildGiftCardEmailHtmlBody(BuyGiftCardModel model) { string pagepath = "~/Content/HTMLPages/BuyGiftCardEmail.htm"; string msgbody = string.Empty; using (StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath(pagepath))) { msgbody = sr.ReadToEnd(); } msgbody = msgbody.Replace("+sitephone+", WebConfigurationManager.AppSettings["ServicePhone"].ToString()); msgbody = msgbody.Replace("+sitefax+", WebConfigurationManager.AppSettings["ServiceFax"].ToString()); msgbody = msgbody.Replace("+buyeremail+", model.BuyerEmail); msgbody = msgbody.Replace("+phone+", model.Phone); msgbody = msgbody.Replace("+message+", model.Message); msgbody = msgbody.Replace("+code+", OrderNumber); return(msgbody); }
public bool DoDirectPaymentSuccess(BuyGiftCardModel model) { bool success = false; com.paypal.sdk.services.NVPCallerServices caller = PayPalAPI.PayPalAPIInitialize(); NVPCodec encoder = new NVPCodec(); encoder["METHOD"] = "DoDirectPayment"; encoder["PAYMENTACTION"] = "Sale"; encoder["IPADDRESS"] = Helper.CurrentUserIP; encoder["AMT"] = Helper.FormatPriceToPayPalStringFormat(model.Amount); encoder["CREDITCARDTYPE"] = CreditCardTypeRepository.GetCreditCardTypeById(int.Parse(model.CardType)).Title; encoder["ACCT"] = model.CardNumber; encoder["EXPDATE"] = int.Parse(model.ExpirationMonth).ToString() + int.Parse(model.ExpirationYear).ToString(); encoder["CVV2"] = int.Parse(model.SecurityCode).ToString(); encoder["FIRSTNAME"] = model.BillFirstName; encoder["LASTNAME"] = model.BillLastName; encoder["CURRENCYCODE"] = "USD"; string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = caller.Call(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); string strAck = decoder["ACK"]; if (strAck != null && (strAck == "Success" || strAck == "SuccessWithWarning")) { Session["result"] = decoder; // string pStrResQue = "API=" + "DoDirect Payment "; success = true; } else { Session["errorresult"] = decoder; } return(success); }
public bool DoCheckoutCompleted(BuyGiftCardModel model) { bool completed = false; NVPCodec decoderResults = new NVPCodec(); decoderResults = (NVPCodec)Session["result"]; TempData["OrderSummaryTitle"] = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); // string res = Util.BuildResponse(Session["result"], Request.QueryString.Get("API"), "Thank you for your payment!"); int cardid = CreditCardRepository.GetCreditCardId(UserName, int.Parse(model.CardType), model.CardNumber, int.Parse(model.ExpirationMonth), int.Parse(model.ExpirationYear), int.Parse(model.SecurityCode)); if (cardid == 0) { cardid = AddCreditCardToDB(model).CreditCardId; } CreditCard cc = CreditCardRepository.GetCreditCardById(cardid); //Order od = AddOrderToDB(cart, decoderResults["TRANSACTIONID"].ToString(), false, 0, 0.0m); string code = Guid.NewGuid().ToString(); TempData["CardCode"] = code; DateTime dt = DateTime.Now; GiftCard gc = GiftCardRepository.AddGiftCard(0, code, CurrentUserID, cardid, 0, model.BuyerEmail, model.RecipientEmail, model.Amount, dt, model.Amount, 0.0m, 0.0m, dt, UserName, dt, UserName, true); EmailManager em = new EmailManager(); EmailContents ec = new EmailContents(); em.OrderTime = dt.ToShortTimeString() + " " + dt.ToShortDateString(); TempData["DeliveryAddress"] = ""; em.OrderType = "Buy Gift Card"; em.PaymentType = "Credit Card"; em.OrderNumber = code; //gift card code em.Name = UserName; em.Phone = model.Phone; em.IpAddress = base.CurrentUserIP; em.CreditCardType = cc.CreditCardType.Title; em.CreditCardNumber = "xxxx-xxxx-xxxx-" + cc.CreditCardNumber.Substring(cc.CreditCardNumber.Length - 4); em.ExpirationDate = cc.ExpirationMonth.ToString() + "/" + cc.ExpirationYear.ToString(); em.SecurityCode = "xx" + cc.SecurityCode.ToString().Substring(cc.SecurityCode.ToString().Length - 1); em.Instruction = model.Message; em.Total = Helper.FormatPriceWithDollar(decoderResults["AMT"].ToString()); // ToUSD(cart.Total().ToString("N2")); ec.FromEmailAddress = Globals.Settings.ContactForm.MailFrom; ec.FromName = "foodready.net"; ec.Subject = "New online order"; ec.To = model.RecipientEmail; ec.Body = em.BuildGiftCardEmailHtmlBody(model); //em.FaxBody = em.BuildGiftCardFaxHtmlBody(model); //em.SendFax(WebConfigurationManager.AppSettings["OnlineFaxNumber"].ToString()); em.Send(ec); ec.To = Globals.Settings.ContactForm.MailTo; em.Send(ec); if (em.IsSent == false) { completed = false; TempData["EmailSentMsg"] = ec.Body; // TempData["paymentResult"] = "SendEmail failed"; } else { completed = true; TempData["EmailSentMsg"] = ec.Body; //TempData["paymentResult"] = string.Empty; } return(completed); }
public string BuildGiftCardFaxHtmlBody(BuyGiftCardModel model) { return(BuildGiftCardEmailHtmlBody(model)); }