- Issue created by @nicolas bouteille
- π«π·France nicolas bouteille
In this piece of code, we also retrieve the order's payment_method
$payment_method = $this->order->get('payment_method')->entity;
but we forget to check if the $payment_method is not null before using it
$payment_method->getRemoteId();
the only thing we check is if
!$this->order->get('payment_method')->isEmpty()
but the entity_reference field can have a target_id that references the id of a payment_method that has been deleted since. Leading to $payment_method object being null.
if I'm not mistaken
assert($payment_method instanceof PaymentMethodInterface);
is only here to help for code autocomplete, but does not stop the code execution.
So$payment_method->getRemoteId();
throws an Exception or a PHP error "trying to call ->getRemoteId() on null..."
Here is what the if statement looks like on our website now to solve this :if ( !$this->order->get('payment_method')->isEmpty() && $payment_method = $this->order->get('payment_method')->entity ) {
- πΊπΈUnited States TomTech
Marking this as a duplicate of π Payment taken from the wrong card Fixed , as the root cause is the same...if a payment method is changed, we need to minimally update the paymentIntent, and possibly create a new one.
This is performed at a lower level, (whenever the order is updated, if the payment method is changed), which should prevent it from cropping up in other scenarios.
We could try and be more surgical in determining if we need to update the paymentIntent vs creating a new one, but since it is unlikely someone would continually swap between methods (more likely during development/qa), creating a new one when the method is changed is likely sufficient.
- Assigned to TomTech
- Status changed to Closed: duplicate
about 1 year ago 6:50pm 8 July 2024