public void Acknowledge(global::Nop.Core.Domain.Orders.Order order)
        {
            try
            {
                var entity = _klarnaRepository.Table.First(x => x.OrderGuid == order.OrderGuid);
                var resourceUri = new Uri(entity.KlarnaResourceUri);
                var apiOrder = Fetch(resourceUri);
                var klarnaOrder = KlarnaCheckoutOrder.FromApiOrder(apiOrder);

                if (klarnaOrder.Status == KlarnaCheckoutOrder.StatusCheckoutComplete)
                {
                    var updateData = new KlarnaCheckoutOrder
                    {
                        Status = KlarnaCheckoutOrder.StatusCreated,
                        MerchantReference = new MerchantReference
                        {
                            OrderId1 = order.Id.ToString(CultureInfo.InvariantCulture),
                            OrderId2 = order.OrderGuid.ToString()
                        }
                    };

                    var dictData = updateData.ToDictionary();

                    apiOrder.Update(dictData);

                    order.AuthorizationTransactionId = klarnaOrder.Reservation;
                    _orderService.UpdateOrder(order);
                }
            }
            catch (Exception ex)
            {
                throw new KlarnaCheckoutException("Error acknowledging Klarna order. Order Id: " + order.Id, ex);
            }
        }
        public Uri Create()
        {
            var cart = _klarnaCheckoutUtils.GetCart();
            var merchant = _klarnaCheckoutUtils.GetMerchant();
            var supportedLocale = _klarnaCheckoutUtils.GetSupportedLocale();
            var gui = _klarnaCheckoutUtils.GetGui();
            var options = _klarnaCheckoutUtils.GetOptions();
            var shippingAddress = _klarnaCheckoutUtils.GetShippingAddress();

            var klarnaOrder = new KlarnaCheckoutOrder
            {
                Cart = cart,
                Merchant = merchant,
                Gui = gui,
                Options = options,
                ShippingAddress = shippingAddress,
                Locale = supportedLocale.Locale,
                PurchaseCountry = supportedLocale.PurchaseCountry,
                PurchaseCurrency = supportedLocale.PurchaseCurrency
            };

            var dictData = klarnaOrder.ToDictionary();
            var connector = Connector.Create(_klarnaSettings.SharedSecret, BaseUri);
            var order = new Klarna.Checkout.Order(connector);

            order.Create(dictData);

            var location = order.Location;

            var kcoOrderRequest = GetKcoOrderRequest(_workContext.CurrentCustomer, location);
            _klarnaRepository.Insert(kcoOrderRequest);

            return location;
        }
        public bool Update(Uri resourceUri)
        {
            try
            {
                var klarnaOrderId = _klarnaCheckoutUtils.GetOrderIdFromUri(resourceUri);
                var cart = _klarnaCheckoutUtils.GetCart();
                var options = _klarnaCheckoutUtils.GetOptions();
                var connector = Connector.Create(_klarnaSettings.SharedSecret, BaseUri);
                var supportedLocale = _klarnaCheckoutUtils.GetSupportedLocale();

                var klarnaOrder = new KlarnaCheckoutOrder
                {
                    Cart = cart,
                    Options = options,
                    Locale = supportedLocale.Locale,
                    PurchaseCountry = supportedLocale.PurchaseCountry,
                    PurchaseCurrency = supportedLocale.PurchaseCurrency
                };

                var order = new Order(connector, klarnaOrderId);
                var dictData = klarnaOrder.ToDictionary();

                order.Update(dictData);

                return true;
            }
            catch (Exception ex)
            {
                var exceptionJson = JsonConvert.SerializeObject(ex.Data);

                _logger.Warning(string.Format(CultureInfo.CurrentCulture, "KlarnaCheckout: Error updating Klarna order. Will try to create a new one. ResourceURI: {0}, Data: {1}",
                    resourceUri, exceptionJson), exception: ex);
            }

            return false;
        }