Closed jeandanyel closed 3 years ago
What I got today, I still don't know why 😔
[2021-03-05T13:44:27.340188-05:00] paypal.ERROR: POST request to "https://api.paypal.com/v2/checkout/orders" failed with debug ID a4ddc9911946b [] [] [2021-03-05T13:44:28.250741-05:00] paypal.ERROR: Error: Expected an order id to be passed [] [] [2021-03-05T13:44:36.278537-05:00] paypal.ERROR: Error: Unexpected token < in JSON at position 0 [] [] [2021-03-05T13:44:47.289368-05:00] paypal.ERROR: Error: Unexpected token < in JSON at position 0 [] []
I am finally able to reproduce the bug!
When we complete the order, we are redirected to a page where we find two PayPal buttons. When we click the pay button, a window open to process the payment.
But if we go back to Sylius (without closing the PayPal window) and then we refresh the page, we got an error message.
Video here: https://youtu.be/TkR1Sj1W0hw
Logs: [2021-03-01T11:52:04.059566-05:00] paypal.ERROR: POST request to "https://api.sandbox.paypal.com/v2/checkout/orders" failed with debug ID 6734d2ed6fc0a [] [] [2021-03-01T11:52:05.079994-05:00] paypal.ERROR: Error: Unexpected token < in JSON at position 0 [] []
Thanks!
Thank you for the report! We will take a look at it and see how it can be fixed 🖖
I found something that might help to fix the issue...
When the problem occurs, we can see these logs in the profiler:
If we take a look to the CreatePayPalOrderAction class, at the line 65, the function getLastPayment(PaymentInterface::STATE_NEW)
return null because the current payent has PROCESSING
as state.
I tried to replace the line 65 with these lines and it works... but it's a temporary fix!
$payment = $order->getLastPayment();
if($payment->getState() !== PaymentInterface::STATE_NEW) {
$payment->setState(PaymentInterface::STATE_NEW);
}
Hello @jeandanyel, it's been a while 🖖 I'd dug deeper into the issue and I believe I've found the problem. When going to PayPal, the payment is already set as "processing". Once you normally close the Paypal window, the payment is cancelled (with a proper onCancel callback). However, when we just refresh the page, the payment is not cancelled so no new one with a "new" state is created. And it results in such an error.
What we should probably do, we should listen to page refreshing (probably with a listener to beforeunload
event?) and cancel the payment as well.
I hope we will be able to fix it soon, thanks again for the report 🎉
Hi 🙂
Sometimes I get this error and it is not possible to pay and complete the order. I'll try to find out why this is happening to give you more details...
Thank you!
[2021-02-27T09:04:31.884693-05:00] paypal.ERROR: POST request to "https://api.paypal.com/v2/checkout/orders" failed with debug ID 1e418bc543e0d [] [] [2021-02-27T09:04:32.000958-05:00] paypal.ERROR: Error: Expected an order id to be passed [] [] [2021-02-27T09:04:36.553244-05:00] paypal.ERROR: Error: Unexpected token < in JSON at position 0 [] []