In this post you will learn where to hook into the module to Indicate an invoice/refund reference when sending a Klarna capture and refund reuqest in settlement reports for Klarna Checkout orders.
Magento itself does not provide by default the respective IDs before the the invoice or refund was created. But this is not the case for settlement reports (ERP). For this case you need to hook into the module and indicate the respective reference.
Checkout where to hook:
1. The Klarna Checkout module provides two methods to hook into. For the invoice its the method \Klarna\Backend\Model\Api\Ordermanagement::getInvoiceId() and for the refund its the method \Klarna\Backend\Model\Api\Ordermanagement::getRefundId(). These methods are just returning a null value since the IDs are just created after the invoice/refund was generated (vanilla Magento). For settlement reports a plugin must be created around them where the own logic will be added.
2. Create a plugin to return the ID:In the following just an example for the invoice id will be shown. This solution works similiar for the refund id. At first you need to create the plugin entry in your module A\B\etc\di.xml:
After that you need to create the plugin class:
3. Run the Magento cli commands so that Magento knows about this new entry.
After these steps you can now indicate the invoice/refund it when the respective Klarna capture/refund API request will be send.