Exemple #1
0
        public ActionResult CheckoutPaymentPage(ContentModel model)
        {
            var currentCart = CurrentCart.Create(SnuffoSettings.STORE_NAME);
            var order       = currentCart.GetOrder();

            if (order.HasOrderProductDetails() && !order.ShippingMethodId.HasValue)
            {
                return(Redirect(string.Concat("/", CurrentUser.LanguageCode, "/cart/checkout-shipping")));
            }

            var cpm = new CheckoutPaymentModel(model.Content);

            cpm.PaymentMethods = UvendiaContext.PaymentMethods.All().Where(p => p.Enabled).ToList();

            cpm.SelectedPaymentMethodId = order.PaymentMethodId;
            cpm.iDealIssuerId           = order.MetaData;

            try
            {
                var ideal = cpm.PaymentMethods.Single(x => x.Name.Equals("ideal", StringComparison.InvariantCultureIgnoreCase));
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;

                Connector connector = new Connector();
                connector.MerchantId        = ideal["MerchantID"];
                connector.SubId             = ideal["SubID"];
                connector.ExpirationPeriod  = ideal["ExpirationPeriod"];
                connector.MerchantReturnUrl = new Uri(string.Format(ideal["MerchantReturnURL"], CurrentUser.LanguageCode));

                ING.iDealAdvanced.Data.Issuers issuers = connector.GetIssuerList();

                foreach (var country in issuers.Countries)
                {
                    foreach (var issuer in country.Issuers)
                    {
                        cpm.iDealIssuerList.Add(new SelectListItem()
                        {
                            Text = issuer.Name, Value = issuer.Id.ToString()
                        });
                    }
                }
            }
            catch (ING.iDealAdvanced.Data.IDealException iex)
            {
                // request consumerMessage
                MailController.Instance(Request, model.Content, CurrentUser.LanguageCode).MailError(new HandleErrorInfo(iex, "CheckoutPaymentPage", "LoadIssueList")).SendAsync();
            }
            catch (Exception ex)
            {
                MailController.Instance(Request, model.Content, CurrentUser.LanguageCode).MailError(new HandleErrorInfo(ex, "CheckoutPaymentPage", "LoadIssueList")).SendAsync();
                //throw;
            }

            return(CurrentTemplate(cpm));
        }
Exemple #2
0
        public ActionResult InvoicePayment(string k)
        {
            if (string.IsNullOrEmpty(k))
            {
                return(InvokeHttp400());
            }

            string encodedKey = k.ToLower();

            var emailInvoice = _orderService.GetEmailInvoiceByEncodedKey(encodedKey);

            // Not found
            // Expired
            if (emailInvoice == null || emailInvoice.EndDate.CompareTo(DateTime.Now) < 0)
            {
                return(InvokeHttp400());
            }

            // Paid
            if (emailInvoice.Paid)
            {
                return(InvokeHttp410());
            }

            var paymentModel = new CheckoutPaymentModel
            {
                CardTypes    = PrepareCardTypes(),
                ExpireYears  = PrepareCardYears(),
                ExpireMonths = PrepareCardMonths(),
                OrderTotal   = _priceFormatter.FormatValue(emailInvoice.Amount * emailInvoice.ExchangeRate, emailInvoice.CurrencyCode)
            };

            if (string.IsNullOrEmpty(_session["PaymentErrorMessage"] as string) == false)
            {
                ViewBag.ErrorMessage            = _session["PaymentErrorMessage"].ToString();
                _session["PaymentErrorMessage"] = null;
            }

            var model = new InvoicePaymentModel
            {
                EmailInvoiceId = emailInvoice.Id,
                Payment        = paymentModel
            };

            // countries and states
            var countries = _shippingService.GetActiveCountries();
            var states    = _shippingService.GetUSStates();

            model.BillingAddress.AvailableCountries = countries.PrepareCountries();
            model.BillingAddress.AvailableStates    = states.PrepareStates();

            return(View(model));
        }
Exemple #3
0
        public ActionResult UpdateOrderCheckoutPayment(CheckoutPaymentModel model)
        {
            PaymentMethod paymentMethod = null;

            if (model.SelectedPaymentMethodId.HasValue)
            {
                paymentMethod = UvendiaContext.PaymentMethods.Single(model.SelectedPaymentMethodId.Value);
                if (model.SelectedPaymentMethodId.HasValue)
                {
                    if (string.Equals(paymentMethod.Name, "ideal", StringComparison.InvariantCultureIgnoreCase) &&
                        model.iDealIssuerId.IsNullOrEmpty())
                    {
                        ModelState.AddModelError("", "Please select your bank");
                    }
                }
            }

            if (ModelState.IsValid)
            {
                var currentCart = CurrentCart.Create(SnuffoSettings.STORE_NAME);
                var order       = currentCart.GetOrder();

                order.PaymentMethod   = paymentMethod;
                order.PaymentMethodId = model.SelectedPaymentMethodId.Value;
                order.MetaData        = model.iDealIssuerId;

                if (currentCart.SaveOrder(order, true, out List <string> errors))
                {
                    return(Redirect($"/{CurrentUser.LanguageCode}/cart/checkout-review"));
                }
                else
                {
                    errors.ForEach(err => ModelState.AddModelError("", err));
                }
            }
            return(CurrentUmbracoPage());
        }
Exemple #4
0
        public ActionResult ConfirmPayment(CheckoutPaymentModel model)
        {
            if (_workContext.CurrentProfile.IsAnonymous)
            {
                return(new HttpUnauthorizedResult());
            }

            var profileId   = _workContext.CurrentProfile.Id;
            var orderTotals = _cartService.CalculateOrderTotals(profileId);

            if (orderTotals == null || orderTotals.Total <= 0M)
            {
                _session["PaymentErrorMessage"] = "Failed to submit payment as basket value is zero.";
                RedirectToAction("Payment", "Checkout");
            }

            var card = new Card
            {
                CardType     = model.CardType,
                CardNumber   = model.CardNumber,
                HolderName   = model.CardHolderName,
                SecurityCode = model.CardCode,
                ExpiryMonth  = model.ExpireMonth,
                ExpiryYear   = model.ExpireYear,
                StartMonth   = string.Empty,
                StartYear    = string.Empty,
                IssueNumber  = string.Empty
            };

            var account = _accountService.GetAccountByProfileId(profileId);

            var output = _paymentService.ProcessPaymentFromCart(
                profileId,
                model.CardType,
                account.Email,
                account.ContactNumber,
                _httpContext.Request.UserAgent,
                _httpContext.Request.UserHostAddress == "::1" ? "45.1.1.1" : _httpContext.Request.UserHostAddress,
                card,
                sendEmailFlag: true);

            if (output == null)
            {
                _session["PaymentErrorMessage"] = "Failed to submit payment. Please refresh the page and try one more time.";
                return(RedirectToAction("Payment", "Checkout"));
            }

            if (output.Status == false)
            {
                _session["PaymentErrorMessage"] = output.Message;
                return(RedirectToAction("Payment", "Checkout"));
            }

            // 3D Secure redirect?
            if (output.Has3DSecure)
            {
                RedirectToSecuredCardPage(output.RedirectUrl, output.PaReq, output.MD);
            }
            else
            {
                return(RedirectToRoute("Checkout Completed", new { orderid = output.OrderId, emailinvoiceid = 0, hasnhs = output.HasNHSPrescription ? 1 : 0 }));
            }

            return(Content(string.Empty));
        }
Exemple #5
0
        /// <summary>
        /// If cart has only NHS Prescription item, we can just create an order without displaying payment page.
        /// </summary>
        /// <returns></returns>
        public ActionResult Payment()
        {
            if (_workContext.CurrentProfile.IsAnonymous)
            {
                return(new HttpUnauthorizedResult());
            }

            var profileId = _workContext.CurrentProfile.Id;
            var hasOnlyFreeNHSPrescriptionItem = _cartService.HasOnlyFreeNHSPrescriptionItem(profileId);

            if (hasOnlyFreeNHSPrescriptionItem)
            {
                return(CreatePrescriptionOrder(profileId, _httpContext.Request.UserHostAddress));
            }

            var totalQuantity = _cartService.GetTotalQuantityCartItemByProfileId(profileId);
            var orderTotals   = _cartService.CalculateOrderTotals(profileId);
            var orderTotal    = 0M;

            if (orderTotals != null)
            {
                orderTotal = orderTotals.Total;
            }

            if (orderTotal <= 0M && totalQuantity > 0)
            {
                return(CreateFOCOrder(profileId, _httpContext.Request.UserHostAddress));
            }

            var model = new CheckoutPaymentModel
            {
                CardTypes      = PrepareCardTypes(),
                ExpireYears    = PrepareCardYears(),
                ExpireMonths   = PrepareCardMonths(),
                OrderTotal     = _priceFormatter.FormatPrice(orderTotal),
                DisableProceed = orderTotal <= 0M
            };

            // Check for any error from payment service
            if (string.IsNullOrEmpty(_session["PaymentErrorMessage"] as string) == false)
            {
                ViewBag.ErrorMessage            = _session["PaymentErrorMessage"].ToString();
                _session["PaymentErrorMessage"] = null;
            }

            // Check for postal restriction rule
            var messages = _cartService.ProcessPostalRestrictionRules(profileId, _workContext.CurrentCountry.ISO3166Code);

            if (messages.Length > 0)
            {
                model.DisableProceed = true;

                if (string.IsNullOrEmpty(ViewBag.ErrorMessage as string))
                {
                    ViewBag.ErrorMessage = string.Join("<br/>", messages);
                }
                else
                {
                    ViewBag.ErrorMessage += "<br/>" + string.Join("<br/>", messages);
                }
            }

            return(View(model));
        }