Skip to content

Commit

Permalink
Fix for KCO UpdateOrder not prefilling address
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikvig committed Dec 19, 2020
1 parent e62a609 commit f876a45
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/Klarna.Checkout/KlarnaCheckoutService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,7 @@ public virtual async Task<CheckoutOrder> CreateOrder(ICart cart)
var checkout = CreateCheckoutOrder(market);
var orderData = GetCheckoutOrderData(cart, market, PaymentMethodDto);
var checkoutConfiguration = GetCheckoutConfiguration(market);

if (checkoutConfiguration.PrefillAddress)
{
// KCO_4: In case of signed in user the email address and default address details will be prepopulated by data from Merchant system.
var customerContact = CustomerContext.Current.GetContactById(cart.CustomerId);
if (customerContact?.PreferredBillingAddress != null)
{
orderData.BillingCheckoutAddress = customerContact.PreferredBillingAddress.ToAddress();
}

if (orderData.CheckoutOptions.AllowSeparateShippingAddress)
{
var shipment = cart.GetFirstShipment();
if (shipment.ShippingAddress != null)
{
orderData.ShippingCheckoutAddress = shipment.ShippingAddress.ToCheckoutAddress();
}
}
}

try
{
if (ServiceLocator.Current.TryGetExistingInstance(out ICheckoutOrderDataBuilder checkoutOrderDataBuilder))
Expand Down Expand Up @@ -277,6 +259,30 @@ protected virtual CheckoutOrder GetCheckoutOrderData(
{
orderData.CheckoutOptions = GetOptions(cart.MarketId);
}

if (checkoutConfiguration.PrefillAddress)
{
// KCO_4: In case of signed in user the email address and default address details will be prepopulated by data from Merchant system.
var customerContact = CustomerContext.Current.GetContactById(cart.CustomerId);
if (customerContact?.PreferredBillingAddress != null)
{
orderData.BillingCheckoutAddress = customerContact.PreferredBillingAddress.ToAddress();
}

if (orderData.CheckoutOptions.AllowSeparateShippingAddress)
{
if (customerContact?.PreferredShippingAddress != null)
{
orderData.ShippingCheckoutAddress = customerContact.PreferredShippingAddress.ToAddress();
}

if (shipment?.ShippingAddress != null)
{
orderData.ShippingCheckoutAddress = shipment.ShippingAddress.ToCheckoutAddress();
}
}
}

return orderData;
}

Expand Down

0 comments on commit f876a45

Please sign in to comment.