Changing order status to Completed fails with API error
-
We use your plugin version 1.6.5, which I believe is the latest one, and noticed that changing order status to Completed stopped working for Klarna orders recently. Instead, the orders get the “On Hold” status with this error reported:
Could not capture Klarna order. ‘order_lines[0].type’ must not be null.
We conducted a research on that and found the following:
1. “‘order_lines[0].type’ must not be null.” error is actually coming from a Klarna API response to an order capture request.
2. Order capture API actually requires the “type” parameter for an order item: https://developers.klarna.com/api/#order-management-api__create-capture__order_lines__type.
3. Your plugin doesn’t provide the “type” parameter for product items in \WC_Klarna_Order_Management_Order_Lines::process_order_item_product method at includes/class-wc-klarna-order-management-order-lines.php:168.
public function process_order_item_product( $order_item, $order ) { return array( 'reference' => $this->get_item_reference( $order_item ), 'name' => $this->get_item_name( $order_item ), 'quantity' => $this->get_item_quantity( $order_item ), 'unit_price' => $this->get_item_unit_price( $order_item ), 'tax_rate' => $this->get_item_tax_rate( $order, $order_item ), 'total_amount' => $this->get_item_total_amount( $order_item ), 'total_discount_amount' => $this->get_item_discount_amount( $order_item ), 'total_tax_amount' => $this->get_item_tax_amount( $order_item ), ); }
Though the “type” parameter is provided for other item types like shipping fee, item fee, coupon, etc.
4. Adding type parameter fixes the issue:
public function process_order_item_product( $order_item, $order ) { return array( 'reference' => $this->get_item_reference( $order_item ), 'type' => 'physical', 'name' => $this->get_item_name( $order_item ), 'quantity' => $this->get_item_quantity( $order_item ), 'unit_price' => $this->get_item_unit_price( $order_item ), 'tax_rate' => $this->get_item_tax_rate( $order, $order_item ), 'total_amount' => $this->get_item_total_amount( $order_item ), 'total_discount_amount' => $this->get_item_discount_amount( $order_item ), 'total_tax_amount' => $this->get_item_tax_amount( $order_item ), ); }
So, I believe that until the recent times, Klarna API accepted missing “type” parameter for order items. I found successful capture requests logged in our store with missing “type” parameter for product items. Either they changed the API specification recently or just enforced a validation of the parameter.
Since we sell only physical goods, hardcoding “physical” type is OK for us. Though for a permanent fix, it would likely need to check the product type as there is a “digital” value supported, which seems matching virtual product type in WooCommerce product type system.
Could you please incorporate the fix into the next update?
- The topic ‘Changing order status to Completed fails with API error’ is closed to new replies.