We are exporting orders to a dispatch warehouse using the Xtento Order Export module. It is set up to happen automatically on order confirmation. The warehouse sends back a response of "received" and a transaction code. On receipt of this response we change the order status to a custom status of "Received".
This works when we manually export an order after the fact. However when an order gets placed and the export happens on the fly, the status gets changed but then Opayo/Sagepay changes it back to "Processing". So in the comments you can see the status getting changed to Received and then, in the same second, Opayo changing it back to Processing. I can't see anything in the Opayo set up to stop the status change.
Code is as follows, in vendor\xtento\orderexport\model\destination\Http.php:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order') ->loadByIncrementId($orderId);
// $order->setState($statuschange);
$order->setStatus($statuschange);
$order->addStatusToHistory($statuschange, "Sent to XX {$txref}", false);
$order->setData('export_log', "Received by XX");
$order->save($order);
Not sure this is a coding question though so much as a "how to get around this" question. My first thought was to put a slight delay on the save, a second or 2 to let Opayo do its thing, and then sneak in there afterwards, but I don't like time delays. Maybe keep checking if there is a message from Opayo and don't save until there is? We will probably also have Paypal set up there too so I'm assuming that's going to do similar. Any other suggestions or pitfalls to watch out for? Thanks