No order will be created when using klarna co

We have currently upgraded the accelerator to version 7.2.0 and it has caused some problems with Klarna.

For now I get an NullReferenceException from this method:

private ILitiumKcoApi CreateKlarnaCheckoutApi(string merchantId)
{
return KlarnaV2.StudioKlarnaCheckoutApi.CreateFrom(
_paymentConfigv2.UpdateDataSentToKlarna)
?? LitiumKcoApi.CreateFrom(merchantId, _paymentConfigv3.UpdateDataSentToKlarna);
}

Stacktrace:
[ERROR] Litium.IWebLog - IWebLog exception ‘Objektreferensen har inte angetts till en instans av ett objekt.’: b2161dc3-5424-477a-a1da-d113911a3711 System.NullReferenceException: Objektreferensen har inte angetts till en instans av ett objekt.
vid Litium.Studio.AddOns.Klarna.Configuration.PluginSettings…ctor()
vid Litium.Studio.AddOns.Klarna.Configuration.PluginSettings.get_Instance()
vid Litium.Studio.AddOns.Klarna.StudioKlarnaCheckoutApi.CreateFrom(String paymentAccId, Action`2 updateDataSentToKlarnaAction)
vid Litium.Accelerator.Mvc.Controllers.Checkout.KlarnaPaymentController.CreateKlarnaCheckoutApi(String merchantId) i …\Src\Litium.Accelerator.Mvc\Controllers\Checkout\KlarnaPaymentController.cs:rad 168
vid Litium.Accelerator.Mvc.Controllers.Checkout.KlarnaPaymentController.Confirmation(String accountId, String transactionNumber) i …\Src\Litium.Accelerator.Mvc\Controllers\Checkout\KlarnaPaymentController.cs:rad 56

which the result is that no order will be placed.

What am I missing? What is causing this exception? I have double chacked the config file and everything seems good. Is there anything specific that I should look at?

We are using kco V3.
Litium version: 7.2.0

Upgrade your Klarna AddOn to 4.7.103 to begin with:
https://docs.litium.com/documentation/add-ons/payments/klarna

Upgraded and changed to use Klarna.Rest.Core library according to: https://docs.litium.com/documentation/add-ons/payments/klarna/upgrade

One thing that they not mention to in the this link is this part of code in: AddCashOnDeliveryExternalPaymentMethod`

var cashOnDeliveryExternalPayment = new ExternalPaymentMethod
        {
            Name = "Cash on delivery",
            RedirectUri = new Uri(urlHelper.Action("ChangePaymentMethod", "KlarnaPayment", routeValues, Uri.UriSchemeHttps)),
            Fee = 0
        };

        klarnaCheckoutOrder.ExternalPaymentMethods = new List<ExternalPaymentMethod>
        {
            cashOnDeliveryExternalPayment
        };

It doesn’t seem to get List<ExternalPaymentMethod> anymore so I tried to change it to List<PaymentProvider> I get error. How should this code sniippet looks like?

Check the page again please, I updated it just now since some examples were not present there.

Now is everything changed according to the guide. But I still get the same error:

[ERROR] Litium.Studio.AddOns.Klarna.KlarnaProvider payment provider initialization failed. Please check whether config file contain correct information. - Objektreferensen har inte angetts till en instans av ett objekt. System.NullReferenceException: Objektreferensen har inte angetts till en instans av ett objekt. vid Litium.Studio.AddOns.Klarna.Configuration.PluginSettings..ctor() vid Litium.Studio.AddOns.Klarna.Configuration.PluginSettings.get_Instance() vid Litium.Studio.AddOns.Klarna.KlarnaProvider.GetPaymentMethodsSupported() vid Litium.Foundation.Modules.ECommerce.Plugins.Payments.PaymentProviderFactory..ctor() [ERROR] Litium.IWebLog - IWebLog exception 'Objektreferensen har inte angetts till en instans av ett objekt.': c1eb917d-7d9a-4a4b-ae69-8754e766c083 System.NullReferenceException: Objektreferensen har inte angetts till en instans av ett objekt. vid Litium.Studio.AddOns.Klarna.Configuration.PluginSettings..ctor() vid Litium.Studio.AddOns.Klarna.Configuration.PluginSettings.get_Instance() vid Litium.Studio.AddOns.Klarna.StudioKlarnaCheckoutApi.CreateFrom(String paymentAccId, Action2 updateDataSentToKlarnaAction)
vid Litium.Accelerator.Mvc.Controllers.Checkout.KlarnaPaymentController.CreateKlarnaCheckoutApi(String merchantId) i …\Src\Litium.Accelerator.Mvc\Controllers\Checkout\KlarnaPaymentController.cs:rad 168
vid Litium.Accelerator.Mvc.Controllers.Checkout.KlarnaPaymentController.Confirmation(String accountId, String transactionNumber) i …\Src\Litium.Accelerator.Mvc\Controllers\Checkout\KlarnaPaymentController.cs:rad 56`

Check the V2 config since it is complaining on Litium.Studio.AddOns.Klarna namespace and not the Litium.AddOns.Klarna.

Try a workaround by changing these lines:

Before:
private ILitiumKcoApi CreateKlarnaCheckoutApi(string merchantId) { return KlarnaV2.StudioKlarnaCheckoutApi.CreateFrom(merchantId, _paymentConfigv2.UpdateDataSentToKlarna) ?? LitiumKcoApi.CreateFrom(merchantId, _paymentConfigv3.UpdateDataSentToKlarna); }

After:
private ILitiumKcoApi CreateKlarnaCheckoutApi(string merchantId) { LitiumKcoApi.CreateFrom(merchantId, _paymentConfigv3.UpdateDataSentToKlarna); }

The thing is that I didn’t have any config for V2… :confused:

I was missing Litium.Studio.AddOns.Klarna.UI and the config was gone which caused this problem. I added it and it works now.

But It seems to work if I remove KlarnaV2.StudioKlarnaCheckoutApi.CreateFrom(merchantId, _paymentConfigv2.UpdateDataSentToKlarna) as well.

Thank you for helping Steve!

1 Like