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); } } }
private Payment CreatePayment(APIContext apiContext, string redirectUrl, Class_Passes cp) { Promotion p; p = db.getPromotionByPassId(cp.Pass_Id); decimal price = decimal.Round(cp.Pass_Price, 2); decimal dis = 0; decimal t; var amount = new Amount(); var itemList = new ItemList() { items = new List <Item>() }; var payer = new Payer() { payment_method = "paypal" }; var redirUrls = new RedirectUrls() { cancel_url = redirectUrl + "&Cancel=true", return_url = redirectUrl }; var details = new Details(); string desc = ""; try { if (p.Promo_End.Date > DateTime.Today && p.Num_Classes == 0) { decimal discount = (decimal)p.Discount; dis = (price * discount * -1); dis = decimal.Round(dis, 2); t = ((price + dis) * (decimal).15); t = decimal.Round(t, 2); //create itemlist and add item objects to it //Adding Item Details like name, currency, price etc itemList.items.Add(new Item() { name = cp.Pass_Name, currency = "CAD", price = price.ToString("F"), quantity = "1" }); itemList.items.Add(new Item() { name = p.Promo_Desc + " " + (int)(discount * 100) + "% Off", currency = "CAD", price = dis.ToString("F"), quantity = "1", }); // Adding Tax, shipping and Subtotal details details.tax = t.ToString("F"); details.subtotal = (price + dis).ToString("F"); //Final amount with details amount.currency = "CAD"; amount.total = ((price + dis) + t).ToString("F"); amount.details = details; } else if (p.Promo_End.Date > DateTime.Today) { t = ((price) * (decimal).15); //create itemlist and add item objects to it //Adding Item Details like name, currency, price etc itemList.items.Add(new Item() { name = cp.Pass_Name + " + " + p.Num_Classes + " Classes", currency = "CAD", price = price.ToString("F"), quantity = "1" }); details.tax = t.ToString("F"); details.subtotal = (price).ToString("F"); //Final amount with details amount.currency = "CAD"; amount.total = ((price) + t).ToString("F"); amount.details = details; } else { t = ((price) * (decimal).15); //create itemlist and add item objects to it //Adding Item Details like name, currency, price etc itemList.items.Add(new Item() { name = cp.Pass_Name, currency = "CAD", price = price.ToString("F"), quantity = "1" }); details.tax = t.ToString("F"); details.subtotal = (price).ToString("F"); //Final amount with details amount.currency = "CAD"; amount.total = ((price) + t).ToString("F"); amount.details = details; } } catch { t = ((price) * (decimal).15); //create itemlist and add item objects to it //Adding Item Details like name, currency, price etc itemList.items.Add(new Item() { name = cp.Pass_Name, currency = "CAD", price = price.ToString("F"), quantity = "1" }); details.tax = t.ToString("F"); details.subtotal = (price).ToString("F"); //Final amount with details amount.currency = "CAD"; amount.total = ((price) + t).ToString("F"); amount.details = details; } // Configure Redirect Urls here with RedirectUrls object // Adding Tax, shipping and Subtotal details var transactionList = new List <Transaction>(); // Adding description about the transaction transactionList.Add(new Transaction() { description = desc, amount = amount, item_list = itemList }); payment = new Payment() { intent = "sale", payer = payer, transactions = transactionList, redirect_urls = redirUrls }; // Create a payment using a APIContext return(payment.Create(apiContext)); }