public ActionResult Charge(string stripeEmail, string stripeToken) { // TODO Make less dependent on Stripe // Gets the total price var totalPrice = GetTotalPriceFromCookieCart(); int priceInCents = (int)(totalPrice * 100); // Gets the information about the customers from Stripe var customers = new StripeCustomerService(); var customer = customers.Create(new StripeCustomerCreateOptions { Email = stripeEmail, SourceToken = stripeToken }); // Gets the information about the charges made from Stripe var charges = new StripeChargeService(); var charge = charges.Create(new StripeChargeCreateOptions { Amount = priceInCents,//charge in cents Description = "Sample Charge", Currency = "eur", CustomerId = customer.Id }); if (charge.Paid) { // TODO ERROR // Gets the deliveryOption from the cookie Delivery deliveryOption = Newtonsoft.Json.JsonConvert.DeserializeObject <Delivery>(Request.Cookies[ConstVal.cookieDeliverOptionName].Value); IncomingOrder order; if (deliveryOption.OtherAddress) { // If the client wants to use another address // Get the client ID int clientID = int.Parse(RudycommerceLib.Security.Encryption.DecryptString(Request.Cookies[ConstVal.cookieClientIDName].Value)); // Pass the inserted deliveryOption to the incoming order order = new IncomingOrder(deliveryOption) { ClientID = clientID }; } else { // If the client wants to use his home address for delivery // Gets the client var client = _client; // Adds the client with his address to the incoming order order = new IncomingOrder(client) { ClientID = client.ID }; } // Gives a status code 0 ( = Ordered, but not yet picked) order.StatusCode = 0; // Adds a paymentComplete, paymentOption and totalprice order.PaymentComplete = true; order.PaymentOption = charge.Source.Card.Brand; order.TotalPrice = totalPrice; // Gets the products from the cart cookie and adds them as order lines) var cart = GetCartFromCookie(); foreach (var item in cart.ProductList) { order.IncomingOrderLines.Add(new IncomingOrderLines { ProductID = item.ID, ProductQuantity = item.Quantity, ProductUnitPrice = item.Price / 100 }); } // Creates the order and saves it _incOrderRepo.Add(order); _incOrderRepo.SaveChangesAsync(); try { string productsString = ""; foreach (var prod in cart.ProductList) { productsString += prod.Quantity.ToString() + " x " + prod.Name + "\r\n"; } string title = Resources.Checkout.OrderEmailTitle; string content = string.Format(Resources.Checkout.OrderEmailContent, _client.FullName, productsString, deliveryOption.StreetAndNumber, deliveryOption.MailBox, deliveryOption.PostalCode, deliveryOption.City); GmailNotifier gmail = new GmailNotifier(); gmail.Notify(new System.Net.Mail.MailAddress(_client.Email), title, content); } catch (EmailSentFailed) { } catch (Exception) { throw; } // Redirects to the Thank you page return(RedirectToAction("OrderFinished", "Orders", null)); } else { // If the payment failed, send back to the payment page return(Payment()); } }
private void SendMailToNewUser() { // Builds the mail to the new user DesktopUser user = NewDesktopUser; string adminEmail = _userRepo.GetAllQueryable().SingleOrDefault(du => du.IsAdmin == true).Email; string title = "TODO Title"; string content = "TODO Content"; if (_preferredLanguage != null) { switch (_preferredLanguage.LocalName) { case "Nederlands": title = $"Account aangemaakt bij Rudycommerce"; content = $"Beste {user.ToString()}, \r\n" + "\r\n" + $"Uw account (met gebruikersnaam '{user.Username}' is aangemaakt, maar nu moet u afwachten tot de beheerder van de applicatie u de toegansgrechten zal toekennen.\r\n" + $"Gelieve de applicatiebeheerder ({adminEmail}) te contacteren indien u te lang moet wachten.\r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; break; case "English": title = $"Account created for Rudycommerce"; content = $"Dear {user.ToString()}, \r\n" + "\r\n" + $"Your account (with username '{user.Username}' has been created, but now you will have to wait till the administrator gives you access rights to the application.\r\n" + $"Please contact the administrator ({adminEmail}) in case you have to wait too long.\r\n" + "\r\n" + "With kind regards, \r\n" + "Rudycommerce"; break; default: title = $"Account aangemaakt bij Rudycommerce"; content = $"Beste {user.ToString()}, \r\n" + "\r\n" + $"Uw account (met gebruikersnaam '{user.Username}' is aangemaakt, maar nu moet u afwachten tot de beheerder van de applicatie u de toegansgrechten zal toekennen.\r\n" + $"Gelieve de applicatiebeheerder ({adminEmail}) te contacteren indien u te lang moet wachten.\r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; break; } } else { title = $"Account aangemaakt bij Rudycommerce"; content = $"Beste {user.ToString()}, \r\n" + "\r\n" + $"Uw account (met gebruikersnaam '{user.Username}' is aangemaakt, maar nu moet u afwachten tot de beheerder van de applicatie u de toegansgrechten zal toekennen.\r\n" + $"Gelieve de applicatiebeheerder ({adminEmail}) te contacteren indien u te lang moet wachten.\r\n" + "\r\n" + "Met vriendelijke groeten, \r\n" + "Rudycommerce"; } _notifier.Notify(new MailAddress(user.Email, user.ToString()), title, content); }