public ActionResult StorePurchase(int passId, int userId) { Pass_Log pl = db.processPurchase(db.getClassPasse(passId), userId, "IN-STORE"); Yoga_User u = db.getUserById(userId); EmailSender.sendPurchaseConfirmation(u, pl, "In-Store"); return(RedirectToAction("SuccessView")); }
public ActionResult Purchases(string Cancel = null) { int passId = Int32.Parse(Request.QueryString["passId"]); var pass = db.getClassPasse(passId); // veryfy paypal successfull before //getting the apiContext APIContext apiContext = Paypal.GetAPIContext(); try { string payerId = Request.Params["PayerID"]; var guid = Request.Params["guid"]; var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string); if (executedPayment.state.ToLower() != "approved") { return(View("FailureView")); } } catch (Exception e) { Debug.WriteLine(e); return(View("FailureView")); } int userId = Int32.Parse(Session["Uid"].ToString()); //todo update all field correctly later on // create purchase log Pass_Log pl = db.processPurchase(pass, userId, "ONLINE"); Yoga_User u = db.getUserById(userId); EmailSender.sendPurchaseConfirmation(u, pl, "Online"); // todo success message with receipt etc. return(View("SuccessView")); }
public static void sendPurchaseConfirmation(Yoga_User user, Pass_Log pl, string purchaseType) { DBMaster db = new DBMaster(); Class_Passes pass = db.getClassPasse(pl.Pass_Id); Promotion p = db.getPromotionByPassId(pl.Pass_Id); SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "xkcd1701"); MailMessage msobj = new MailMessage(); msobj.To.Add(user.U_Email); msobj.From = new MailAddress("*****@*****.**"); msobj.Subject = "Confirmation of " + purchaseType + " Purchase from Samsara Yoga"; msobj.IsBodyHtml = true; if (p == null || p.Promo_End < DateTime.Now.Date) { decimal tax = ((pass.Pass_Price) * (decimal).15); msobj.Body = "<h1 style='color:#557ee6;'>Saṃsāra Yoga</h1><p>Thank you for your recent " + purchaseType.ToLower() + " purchase from Samsara Yoga. Details of this transaction are below:</p><br/>Transaction ID: " + pl.Invoice_Number + "<br/>Transaction Date: " + pl.Date_Purchased + "<br/><br/>Purchased Item: " + pass.Pass_Name + "<br/><br/>‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑<br/><br/>Unit Price: " + pass.Pass_Price.ToString("F") + "<br/>Tax: " + tax.ToString("F") + "<br>Total: " + (tax + pass.Pass_Price).ToString("F") + "$"; client.Send(msobj); } else { if (p.Promo_End.Date > DateTime.Today && p.Num_Classes == 0) { decimal discount = decimal.Round((pass.Pass_Price * (decimal)p.Discount * -1), 2); decimal tax = ((pass.Pass_Price + discount) * (decimal).15); msobj.Body = "<h1 style='color:#557ee6;'>Saṃsāra Yoga</h1>" + "<p>Thank you for your recent " + purchaseType.ToLowerInvariant() + " purchase from Samsara Yoga. Details of this transaction are below:</p><br/>Transaction ID: " + pl.Invoice_Number + "<br/>Transaction Date: " + pl.Date_Purchased + "<br/><br/>Purchased Item: " + pass.Pass_Name + "<br/>Promotion: " + p.Promo_Desc + " " + (int)(p.Discount * 100) + "% Off<br/><br>‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑<br/><br/>Unit Price: " + pass.Pass_Price.ToString("F") + "<br/>Discount: " + discount.ToString("F") + "<br/><br/>Subtotal: " + (discount + pass.Pass_Price).ToString("F") + "<br/>Total: " + (tax + pass.Pass_Price + discount).ToString("F") + "$"; client.Send(msobj); } else { decimal tax = ((pass.Pass_Price) * (decimal).15); msobj.Body = "<h1 style='color:#557ee6;'>Saṃsāra Yoga</h1><p>Thank you for your recent " + purchaseType.ToLowerInvariant() + " purchase from Samsara Yoga. Details of this transaction are below:</p><br/>Transaction ID: " + pl.Invoice_Number + "<br/>Transaction Date: " + pl.Date_Purchased + "<br/><br/>Purchased Item: " + pass.Pass_Name + "<br/>Promotion: " + p.Promo_Desc + " +" + p.Num_Classes + " Passes<br/><br/>‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑<br/><br/>Unit Price: " + pass.Pass_Price.ToString("F") + "<br/>Tax: " + tax.ToString("F") + "<br>Total: " + (tax + pass.Pass_Price).ToString("F") + "$"; client.Send(msobj); } } }