Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module doesn't change statut with hook #353

Open
BenTen opened this issue Jul 22, 2024 · 7 comments · Fixed by #383
Open

Module doesn't change statut with hook #353

BenTen opened this issue Jul 22, 2024 · 7 comments · Fixed by #383
Assignees

Comments

@BenTen
Copy link

BenTen commented Jul 22, 2024

Describe the bug and add screenshots

When a customer make an order by paying with Paypal, the module add the statut "awaiting PayPal payment" with the hook
hookActionOrderStatusPostUpdate.

But when the module receive the information of the paypal's webhook, the statut "payment accepted" is not add by using this hook.

So if another module read this hook, it can't be able to know the new statut.

Expected behavior

The PayPal module need to change each statut by using the hook hookActionOrderStatusPostUpdate.

Steps to reproduce

  • be able to read hookActionOrderStatusPostUpdate
  • Make an order and select Paypal as payment method
  • See the first state "awaiting paypal payment"
  • wait info of the webook
  • you won't see the new statut ("error" or "accepted") via hookActionOrderStatusPostUpdate

PrestaShop version(s) where the bug happened

1.7.5

PHP version(s) where the bug happened

7.2

Module version(s) where the bug happened

6.4.1 (addon version)

@bogdan202
Copy link
Collaborator

Hello @BenTen,
The module 'paypal' uses Order::setCurrentState() to change an order state.
https://github.com/202ecommerce/paypal/blob/6.4.0/classes/Webhook/WebhookEventHandler.php#L147
Hook 'actionOrderStatusPostUpdate' is triggered in the method OrderHistory::changeIdOrderState() that is performed inside the method Order::setCurrentState().
https://github.com/PrestaShop/PrestaShop/blob/1.7.5.0/classes/order/OrderHistory.php#L411
https://github.com/PrestaShop/PrestaShop/blob/1.7.5.0/classes/order/Order.php#L1668
Given all above, your problem seems to be not in the module 'paypal'.
Perhaps, you have an overrides for Order or OrderHistory

@BenTen
Copy link
Author

BenTen commented Jul 23, 2024

Thank you @bogdan202 to clarify the process

But when the module receive the information of the paypal's webhook, the statut "payment accepted" is not add by using this hook.

Maybe this sentence was not clear.

I mean, the statut seems not add by using this hook BUT the statut is adding

I don't have override for this files but modification has been made to apply 4 years ago:

who was trouble with Werbservice of PS 1.7.5 in our case.
But It seems not related with this actual issue we are facing on PayPal module.

Here the statut is updated but can't see it on the hookActionOrderStatusPostUpdate

@mgtalles
Copy link

mgtalles commented Dec 3, 2024

Hi!
I have experienced the same problem. All the process looks ok but the order doesn't change state and remains in "awaiting PayPal payment". Let me explain my case. First some data:

Prestashop 8.2.0
PHP 8.1
Paypal Module 6.4.2

I found in Apache's access.log the following lines with 500 errors (shown only relevant part)

/es/module/paypal/webhookhandler HTTP/1.1" 500

and in error.log the following error and trace:

PHP Fatal error: Uncaught Error: Call to a member function getPaypalOrderByPaymentId() on null in
/var/www/html/agroquimes/modules/paypal/controllers/front/webhookhandler.php:196
Stack trace:
#0 /var/www/html/agroquimes/modules/paypal/controllers/front/webhookhandler.php(114): PaypalWebhookhandlerModuleFrontController->initPaypalOrder()
#1 /var/www/html/agroquimes/classes/Dispatcher.php(510): PaypalWebhookhandlerModuleFrontController->run()
#2 /var/www/html/agroquimes/index.php(28): DispatcherCore->dispatch()
#3 {main}\n thrown in /var/www/html/agroquimes/modules/paypal/controllers/front/webhookhandler.php on line 196

webhookhandler.php in line 114 is trying to report a catched exception

Looking the source at line 196 I found that the property servicePaypalOrder

return $this->servicePaypalOrder->getPaypalOrderByPaymentId($paymentId);

is null, so commenting this line and returning an empty PaypalOrder object the catched exception was shown in the log.

imagen

This non-existen service is from one of my modules and is called from symfony container in the hook hookActionPaymentConfirmation only if we are in Backoffice context. So the question here is, which is the execution context of the webhook.

But returning to the subject. I think the bug is that if there is an error executing the method Order::setCurrentState() the exception is captured but not written because servicePaypalOrder is NULL.

Hope this helps.

@clotairer
Copy link
Collaborator

@mgtalles we propose the PR #383 to fix your issue. Can you make test with it ?

@BenTen
Copy link
Author

BenTen commented Dec 4, 2024

Is the PR related to the issue I opened or to the last comment?

@mgtalles
Copy link

mgtalles commented Dec 4, 2024

@clotairer

PR #383 worked OK for me. Thanks!

@BenTen Maybe is useful for you too, because unblocks logging and if there is an error in your shop, it will be traced.

@Niji-Bemani
Copy link

@mgtalles

Maybe is useful for you too, because unblocks logging and if there is an error in your shop, it will be traced.

Hello, where can I see this trace ? Is there a log file somewhere ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants