I'm trying to figure out why my order balance isn't directly updated after I've created a payment. I'm debugging it with xDebug. This is my OnNotify function
$this->order = Order::load($orderId);
//isPaid = false
if ($this->order !== NULL) {
//create the payment, assign it to the order
$payment = $this->createPayment($this->order, $mt);
if ($this->order->isPaid()) { //isPaid still false instead of true
This is how the payment is created
protected function createPayment(OrderInterface $order, $mt){
$payment_storage = $this->entityTypeManager->getStorage('commerce_payment');
/** @var \Drupal\commerce_payment\Entity\Payment $payment */
$payments = $payment_storage->loadByProperties(['order_id' => $this->order->id()]);
$price = new Price(((int)$mt)/100, 'EUR');
if (count($payments) == 0) {
$payment = $payment_storage->create([
'state' => 'completed',
'amount' => $price,
'payment_gateway' => $this->entityId,
'order_id' => $this->order->id(),
'remote_id' => null,
'remote_state' => null,
'completed' => time()
]);
$payment->save();
$this->order->save();
return $payment;
}
So if i put breakpoint, the isPaid is always false. However, if I don't use the debugger, the order balance works correctly (without the process beeing executed twice or anything...). Any ideas ?