Programatically get Klarna Account config
This article give sample code to get the Klarna Account configuration specified in the addon config file, programatically if you have the payment method name.
The first 'word' in the payment method name is the payment account identifier.
Therefore, if you know the payment method name, then you can get the whole payment account configuration using following code fragment. Following code assumes you are in the checkout page code behind.
var paymentInfoCarrier = CurrentState.Current.ShoppingCart.OrderCarrier.PaymentInfo.FirstOrDefault();
if (paymentInfoCarrier != null && !string.IsNullOrWhiteSpace(paymentInfoCarrier.PaymentMethod))
{
if (paymentInfoCarrier.PaymentProvider == "Klarna")
{
var methodParts = paymentInfoCarrier.PaymentMethod.Split(' ');
if (methodParts.Length > 0)
{
var paymentAccountConfig =
Litium.Studio.AddOns.Klarna.Configuration.PluginSettings.Instance.Configuration.PaymentAccounts[
methodParts[0]];
//now we have the payment account configuration, it can be used for example to get storeId, etc.
var storeId = paymentAccountConfig.StoreName;
}
}
}