Exemplo n.º 1
0
        private IPurchaseOrder GetOrCreatePurchaseOrder(int orderGroupId, string klarnaOrderId)
        {
            // Check if the order has been created already
            var purchaseOrder = _klarnaCheckoutService.GetPurchaseOrderByKlarnaOrderId(klarnaOrderId);

            if (purchaseOrder != null)
            {
                return(purchaseOrder);
            }

            // Check if we still have a cart and can create an order
            var cart = _orderRepository.Load <ICart>(orderGroupId);
            var cartKlarnaOrderId = cart.Properties[Constants.KlarnaCheckoutOrderIdCartField]?.ToString();

            if (cartKlarnaOrderId == null || !cartKlarnaOrderId.Equals(klarnaOrderId))
            {
                return(null);
            }

            var order = _klarnaCheckoutService.GetOrder(klarnaOrderId, cart.Market);

            if (!order.Status.Equals("checkout_complete"))
            {
                // Won't create order, Klarna checkout not complete
                return(null);
            }
            purchaseOrder = _checkoutService.CreatePurchaseOrderForKlarna(klarnaOrderId, order, cart);
            return(purchaseOrder);
        }
Exemplo n.º 2
0
        public ActionResult KlarnaCheckoutConfirmation(int orderGroupId, string klarna_order_id)
        {
            var cart = _klarnaCheckoutService.GetCartByKlarnaOrderId(orderGroupId, klarna_order_id);

            if (cart != null)
            {
                var market = _marketService.GetMarket(cart.MarketId);
                var order  = _klarnaCheckoutService.GetOrder(klarna_order_id, market);
                if (order.Status == "checkout_complete")
                {
                    var purchaseOrder = _checkoutService.CreatePurchaseOrderForKlarna(klarna_order_id, order, cart);
                    if (purchaseOrder == null)
                    {
                        ModelState.AddModelError("", "Error occurred while creating a purchase order");

                        return(RedirectToAction("Index"));
                    }

                    _checkoutService.SendConfirmation(new CheckoutViewModel
                    {
                        CurrentPage    = _contentLoader.Get <CheckoutPage>(_contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage),
                        BillingAddress = new Shared.Models.AddressModel {
                            Email = purchaseOrder.GetFirstForm().Payments.FirstOrDefault()?.BillingAddress.Email
                        }
                    }, purchaseOrder);

                    return(Redirect(_checkoutService.BuildRedirectionUrl(purchaseOrder)));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(HttpNotFound());
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Index(OrderConfirmationPage currentPage, string notificationMessage, string orderNumber, string trackingNumber)
        {
            int orderId;

            trackingNumber = string.IsNullOrEmpty(trackingNumber) ? orderNumber : trackingNumber;

            IPurchaseOrder order = null;

            if (PageEditing.PageIsInEditMode)
            {
                order = ConfirmationService.CreateFakePurchaseOrder();
            }
            else if (int.TryParse(orderNumber, out orderId))
            {
                order = ConfirmationService.GetOrder(orderId);

                if (order != null)
                {
                    await _recommendationService.TrackOrderAsync(HttpContext, order);
                }
            }
            else if (!string.IsNullOrEmpty(trackingNumber))
            {
                order = ConfirmationService.GetByTrackingNumber(trackingNumber);

                if (order != null)
                {
                    await _recommendationService.TrackOrderAsync(HttpContext, order);
                }
            }

            if (order != null && order.CustomerId == CustomerContext.CurrentContactId)
            {
                var viewModel = CreateViewModel(currentPage, order);
                viewModel.NotificationMessage = notificationMessage;

                var paymentMethod = PaymentManager
                                    .GetPaymentMethodBySystemName(Constants.KlarnaCheckoutSystemKeyword,
                                                                  ContentLanguage.PreferredCulture.Name)
                                    .PaymentMethod.FirstOrDefault();

                if (paymentMethod != null &&
                    order.GetFirstForm().Payments.Any(x => x.PaymentMethodId == paymentMethod.PaymentMethodId &&
                                                      !string.IsNullOrEmpty(order.Properties[Klarna.Common.Constants.KlarnaOrderIdField]?.ToString())))
                {
                    var market      = _marketService.GetMarket(order.MarketId);
                    var klarnaOrder = await _klarnaCheckoutService.GetOrder(
                        order.Properties[Klarna.Common.Constants.KlarnaOrderIdField].ToString(), market).ConfigureAwait(false);

                    viewModel.KlarnaCheckoutHtmlSnippet = klarnaOrder.HtmlSnippet;
                    viewModel.IsKlarnaCheckout          = true;
                }

                return(View(viewModel));
            }

            return(Redirect(Url.ContentUrl(ContentReference.StartPage)));
        }
Exemplo n.º 4
0
        public ActionResult Index(OrderConfirmationPage currentPage, string notificationMessage, int?orderNumber, string trackingNumber)
        {
            IPurchaseOrder order = null;

            if (PageEditing.PageIsInEditMode)
            {
                order = _confirmationService.CreateFakePurchaseOrder();
            }
            else if (orderNumber.HasValue)
            {
                order = _confirmationService.GetOrder(orderNumber.Value);
            }
            else if (!string.IsNullOrEmpty(trackingNumber))
            {
                order = _confirmationService.GetByTrackingNumber(trackingNumber);
            }

            if (order != null /* && order.CustomerId == _customerContext.CurrentContactId*/)
            {
                var viewModel = CreateViewModel(currentPage, order);
                viewModel.NotificationMessage = notificationMessage;

                var paymentMethod = PaymentManager
                                    .GetPaymentMethodBySystemName(Constants.KlarnaCheckoutSystemKeyword,
                                                                  ContentLanguage.PreferredCulture.Name)
                                    .PaymentMethod.FirstOrDefault();

                if (paymentMethod != null &&
                    order.GetFirstForm().Payments.Any(x => x.PaymentMethodId == paymentMethod.PaymentMethodId &&
                                                      !string.IsNullOrEmpty(order.Properties[Klarna.Common.Constants.KlarnaOrderIdField]?.ToString())))
                {
                    var klarnaOrder =
                        _klarnaCheckoutService.GetOrder(
                            order.Properties[Klarna.Common.Constants.KlarnaOrderIdField].ToString(), order.Market);
                    viewModel.KlarnaCheckoutHtmlSnippet = klarnaOrder.HtmlSnippet;
                    viewModel.IsKlarnaCheckout          = true;
                }

                return(View(viewModel));
            }

            return(Redirect(Url.ContentUrl(ContentReference.StartPage)));
        }