private KlarnaCheckoutEntity GetKcoOrderRequest(global::Nop.Core.Domain.Customers.Customer currentCustomer, Uri resourceUri)
 {
     return(new KlarnaCheckoutEntity
     {
         CustomerId = currentCustomer.Id,
         OrderGuid = Guid.NewGuid(),
         KlarnaResourceUri = resourceUri.ToString(),
         Status = KlarnaCheckoutStatus.Pending,
         IpAddress = _webHelper.GetCurrentIpAddress(),
         AffiliateId = currentCustomer.AffiliateId,
         StoreId = _storeContext.CurrentStore.Id,
         CreatedOnUtc = DateTime.UtcNow
     });
 }
        public void CancelPayment(string reservation, global::Nop.Core.Domain.Customers.Customer customer)
        {
            try
            {
                var configuration = new Configuration(Country.Code.SE, Language.Code.SV, Currency.Code.SEK, Encoding.Sweden)
                {
                    Eid        = _klarnaSettings.EId,
                    Secret     = _klarnaSettings.SharedSecret,
                    IsLiveMode = !_klarnaSettings.TestMode
                };

                var api = new Api(configuration);
                api.CancelReservation(reservation);

                _logger.Information("KlarnaCheckout: Reservation cancelled: " + reservation, customer: customer);
            }
            catch (Exception ex)
            {
                _logger.Error("KlarnaCheckout: Error cancelling reservation: " + reservation, exception: ex, customer: customer);
            }
        }
        public void SyncBillingAndShippingAddress(global::Nop.Core.Domain.Customers.Customer customer, KlarnaCheckoutOrder klarnaCheckoutOrder)
        {
            try
            {
                var billingAddress  = klarnaCheckoutOrder.BillingAddress;
                var shippingAddress = klarnaCheckoutOrder.ShippingAddress;

                var nopBillingAddress = customer.Addresses.FirstOrDefault(billingAddress.RepresentsAddress);
                if (nopBillingAddress == null)
                {
                    nopBillingAddress = new global::Nop.Core.Domain.Common.Address {
                        CreatedOnUtc = DateTime.UtcNow
                    };
                    customer.Addresses.Add(nopBillingAddress);
                }

                customer.BillingAddress = nopBillingAddress;
                billingAddress.CopyTo(nopBillingAddress);

                var nopShippingAddress = customer.Addresses.FirstOrDefault(shippingAddress.RepresentsAddress);
                if (nopShippingAddress == null)
                {
                    nopShippingAddress = new global::Nop.Core.Domain.Common.Address {
                        CreatedOnUtc = DateTime.UtcNow
                    };
                    customer.Addresses.Add(nopShippingAddress);
                }

                customer.ShippingAddress = nopShippingAddress;
                shippingAddress.CopyTo(nopShippingAddress);

                _customerService.UpdateCustomer(customer);
            }
            catch (Exception ex)
            {
                var billing  = JsonConvert.SerializeObject(klarnaCheckoutOrder.BillingAddress);
                var shipping = JsonConvert.SerializeObject(klarnaCheckoutOrder.ShippingAddress);
                throw new KlarnaCheckoutException(string.Format(CultureInfo.CurrentCulture, "Error syncing addresses. Billing: {0}, Shipping: {1}", billing, shipping), ex);
            }
        }