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);
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.
Make sure you do it after
_paymentWidgetService.PlaceOrder(new PaymentWidgetOrder(klarnaCheckout, checkoutOrder), true);
otherwise the payment wont be reserved/charged and the order Confirmed.
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.
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.