public ActionResult DonateProcess(StripeModel model) { try { model.Description = Dictionary.Donation; _stripeService.Charge(model); _donationService.CreateDonation(new Donation { Currency = model.LocalisedCurrencyThreeLetters, Customer = model.StripeBillingName, CustomerEmail = model.StripeEmail, DonationDescription = model.Description, DonatedOn = DateTime.Now, DonationAmount = model.AmountToDonate }); return(RedirectToAction("DonationSuccess")); } catch (Exception ex) { _logger.Error($"SupportController => Donate => Donation failed: {ex.Message}"); ModelState.AddModelError("", ex.Message); } return(View("Donate", model)); }
public ActionResult <ItemResponse <int> > Insert(CheckoutOrderAddRequest model) { ObjectResult result = null; int user = _authService.GetCurrentUserId(); try { int userId = _authService.GetCurrentUserId(); string chargeId = _stripe.Charge(model.Payment.Token, model.Payment.Total, model.Shipping.EmailAddress); model.ShoppingCartItems = _cartService.GetByCurrent(user); int id = _service.Insert(model, userId, chargeId); ItemResponse <int> response = new ItemResponse <int>() { Item = id }; result = Created201(response); } catch (Exception ex) { Logger.LogError(ex.ToString()); ErrorResponse response = new ErrorResponse(ex.Message); result = StatusCode(500, response); } return(result); }
public ActionResult Pay(StripeCheckoutViewModel stripeData, string stripeToken, string next, string back) { var checkoutData = GetCheckoutData(stripeData); if (!String.IsNullOrWhiteSpace(back)) { return(RedirectToAction(checkoutData.Amount >= 0 ? "SendMoney" : "Ship")); } var subTotal = 0.0; var total = checkoutData.Amount; var isProductOrder = checkoutData.CheckoutItems.Any(); if (isProductOrder) { var taxes = checkoutData.Taxes == null ? 0 : checkoutData.Taxes.Amount; subTotal = checkoutData.CheckoutItems.Sum(i => i.Price * i.Quantity + i.LinePriceAdjustment); total = subTotal + taxes + checkoutData.ShippingOption.Price; } // Call Stripe to charge card var stripeCharge = _stripeService.Charge(stripeToken, total); if (stripeCharge.Error != null) { Logger.Error(stripeCharge.Error.Type + ": " + stripeCharge.Error.Message); _workflowManager.TriggerEvent("OrderError", null, () => new Dictionary <string, object> { { "CheckoutError", stripeCharge.Error } }); if (stripeCharge.Error.Type == "card_error") { return(Pay(stripeCharge.Error.Message)); } throw new InvalidOperationException(stripeCharge.Error.Type + ": " + stripeCharge.Error.Message); } var userId = -1; var currentUser = _wca.GetContext().CurrentUser; if (currentUser != null) { userId = currentUser.Id; } var order = _orderService.CreateOrder( stripeCharge, checkoutData.CheckoutItems, subTotal, total, checkoutData.Taxes, checkoutData.ShippingOption, checkoutData.ShippingAddress, checkoutData.BillingAddress, checkoutData.Email, checkoutData.Phone, checkoutData.SpecialInstructions, OrderPart.Pending, null, _stripeService.IsInTestMode(), userId, total, checkoutData.PurchaseOrder); TempData["OrderId"] = order.Id; _workflowManager.TriggerEvent( isProductOrder ? "NewOrder" : "NewPayment", order, () => new Dictionary <string, object> { { "Content", order }, { "Order", order } }); order.LogActivity(OrderPart.Event, T("Order created.").Text); // Clear checkout info from temp data TempData.Remove(NwazetStripeCheckout); return(RedirectToAction("Confirmation", "OrderSsl")); }