Setting Delivery state to Processing after KCO payment confirmation to move whole order to Processing

After Klarna Checkout payment confirmation, we need to export order and customer data to ERP for further processing. We’ve been advised to set the Delivery state of the order to Processing, since this will indicate the correct Delivery state and also move the whole order to Processing, which is also correct.

However, when we try to change the Delivery state in the KCO payment confirmation callback we get a “state was invalid” exception and we don’t even know if we’re going about it the correct way:

// KlarnaPaymentController.Confirmation
var order = _moduleECommerce.Orders.GetOrder(orderId.Value, _moduleECommerce.AdminToken);
order.SetDeliveryStatus((short)OrderState.Processing, _moduleECommerce.AdminToken);

Litium version: 7.6.2

You don’t need to touch the Order status. When you set the Delivery to Processing it automatically sets the Order status to processing and if you have done that before the delivery is set to Processing then the state will be invalid.
Just handle everything with Delivery states and the rest will follow.

So, how do I set the Delivery to Processing? The code we have in place currently is the one that raises the state-invalid exception:

order.SetDeliveryStatus((short)OrderState.Processing, _moduleECommerce.AdminToken);

order.SetDeliveryStatus(DeliveryState.Processing, token);

I still get the “state was invalid” exception. This is immediately after KCO confirmation, so we haven’t touched the Delivery before this.

order.SetDeliveryStatus((short)DeliveryState.Processing, _moduleECommerce.AdminToken);

Make sure you do it after
_paymentWidgetService.PlaceOrder(new PaymentWidgetOrder(klarnaCheckout, checkoutOrder), true);
otherwise the payment wont be reserved/charged and the order Confirmed.

Correct! Payment states must be set correct before you can do this.

You can also try this:
delivery.SetDeliveryStatus((short)DeliveryState.Processing, _moduleECommerce.AdminToken);
I’m using the delivery to set the status, not the order. But i guess it should not matter.

This is at the very end of KlarnaPaymentController.Confirmation, so well after PlaceOrder.

How do I get the delivery for delivery.SetDeliveryStatus?

It’s the delivery on the order
order.Deliveries.FirstOrDefault().SetDeliveryStatus

You have Deliveries object array inside the order that you can look at but setting deliveries to Processing is usually done by ERP call to Litium that Delivery has started or Admins can also do it from the BO. Those are handled in

Litium.Accelerator.StateTransitions

folder. Take a look at the StateBuilder files there.

Thank you. I already have code in the entry for Processing for an order, and that is what I want to trigger by moving the order from Confirmed to Processing at the end of the KCO confirmation.

In our case, there is no callback from ERP to Litium to signal delivery processing start, so we assume delivery processing starts after exporting the order to ERP by setting the Order and the Delivery to Processing.

Thank you, this works!

Nice!
Might be a Litium bug on order then…

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.