I am trying to update order status and payment status depending upon the value we get in a variable called $payment_status. I am able to update order status but I am unable to update payment status inside that order. I am getting an error "The website encountered an unexpected error. Please try again later. Error: Class 'Drupal\commerce_order\Payment\Payment' not found" The code I used is as follows:-
//update order status based on payment status
$order = \Drupal\commerce_order\Entity\Order::load($order_id);
// dpm($order);
if($payment_status === 'payment.captured' ){
$order->set('state', 'completed' );
$order->save();
$payments = \Drupal\commerce_order\Payment\Payment::loadByProperties(['order_id' => $order_id]);
foreach ($payments as $payment)
{
$payment->setState('completed')->save();
}
}
else{
$order->set('state', 'pending' );
$order->save();
}
How to solve this?