Page 1 of 1
addOrderHistory didn't work with webhook
Posted: Mon Apr 03, 2023 12:23 pm
by Dev.
Hell
I'm working with webhook with a custom plugin. I need to send an updated order into webhook and then add it to the order history in the admin panel
I was use $this->model_checkout_order->addOrderHistory($order_id, $order_status); . But didn't get anything in the admin.
Is there any suggestion for that?
Re: addOrderHistory didn't work with webhook
Posted: Mon Apr 03, 2023 4:32 pm
by thekrotek
No, because you provided zero info.
Re: addOrderHistory didn't work with webhook
Posted: Mon Apr 03, 2023 7:13 pm
by paulfeakins
As above it's very hard to work out what's going on without a bit more info about what you're trying to do and how you've done it.
Re: addOrderHistory didn't work with webhook
Posted: Mon Apr 03, 2023 8:35 pm
by Dev.
paulfeakins wrote: ↑Mon Apr 03, 2023 7:13 pm
As above it's very hard to work out what's going on without a bit more info about what you're trying to do and how you've done it.
Hello
After a customer places an order webhook will work and the below simple function will get information from the getaway.
when trying to use
$this->log->write($data['orser_id']); will get info in logs. But I need to add this info in
order history
Code: Select all
public function webhook() {
$this->load->model('extension/payment/extension-name');
$webhook_data = json_decode(html_entity_decode(file_get_contents('php://input')), true);
$setting = array_replace_recursive((array)$config_setting, (array)$this->config->get('setting'));
if ($webhook_data['event_type'] == 'PAYMENT.AUTHORIZATION.CREATED') {
$order_status_id = $setting['order_status']['pending']['id'];
}
$this->load->model('checkout/order');
$this->model_checkout_order->addOrderHistory($order_id, $order_status_id, '', true);
This is what I try to do. I hope this enough
Re: addOrderHistory didn't work with webhook
Posted: Mon Apr 03, 2023 9:53 pm
by JNeuhoff
No need to post it twice here.
Anyway, your code won't work because the variable $order_id is undefined.
Re: addOrderHistory didn't work with webhook
Posted: Mon Apr 03, 2023 10:13 pm
by Dev.
Dev. wrote: ↑Mon Apr 03, 2023 8:35 pm
paulfeakins wrote: ↑Mon Apr 03, 2023 7:13 pm
As above it's very hard to work out what's going on without a bit more info about what you're trying to do and how you've done it.
Hello
After a customer places an order webhook will work and the below simple function will get information from the getaway.
when trying to use
$this->log->write($data['orser_id']); will get info in logs. But I need to add this info in
order history
Code: Select all
public function webhook() {
$this->load->model('extension/payment/extension-name');
$webhook_data = json_decode(html_entity_decode(file_get_contents('php://input')), true);
$setting = array_replace_recursive((array)$config_setting, (array)$this->config->get('setting'));
$order_id = $webhook_data['id'];
if ($webhook_data['event_type'] == 'PAYMENT.AUTHORIZATION.CREATED') {
$order_status_id = $setting['order_status']['pending']['id'];
}
$this->load->model('checkout/order');
$this->model_checkout_order->addOrderHistory($order_id, $order_status_id, '', true);
This is what I try to do. I hope this enough
Re: addOrderHistory didn't work with webhook
Posted: Mon Apr 03, 2023 10:14 pm
by Dev.
JNeuhoff wrote: ↑Mon Apr 03, 2023 9:53 pm
No need to post it twice here.
Anyway, your code won't work because the variable
$order_id is undefined.
Hello
I was defined all veritable But still didn't get any update in order history.
Re: addOrderHistory didn't work with webhook
Posted: Tue Apr 04, 2023 2:54 am
by ADD Creative
Anything else in your error log or the PHP error log. Also check the web access log to see the status code.
You may already have it, but it's a common mistake for payment extensions. You would also need some sort or authentication, otherwise anyone could call your webhook and change the status of an order.
Re: addOrderHistory didn't work with webhook
Posted: Tue Apr 04, 2023 3:54 am
by Dev.
ADD Creative wrote: ↑Tue Apr 04, 2023 2:54 am
Anything else in your error log or the PHP error log. Also check the web access log to see the status code.
You may already have it, but it's a common mistake for payment extensions. You would also need some sort or authentication, otherwise anyone could call your webhook and change the status of an order.
Hello
I didn't find any things in the logs file. But Order History in the admin panel didn't add any
update from webhook
Re: addOrderHistory didn't work with webhook
Posted: Tue Apr 04, 2023 6:56 am
by ADD Creative
If there is nothing in the web access log, maybe it's not being called.
Re: addOrderHistory didn't work with webhook
Posted: Wed Apr 05, 2023 12:38 am
by Dev.
ADD Creative wrote: ↑Tue Apr 04, 2023 6:56 am
If there is nothing in the web access log, maybe it's not being called.
why didn't called?
Could you please provide me the suggested reason?
And if didn't work what's the best solution to adding a webhook updated?
Thank you,
Re: addOrderHistory didn't work with webhook
Posted: Wed Apr 05, 2023 7:05 am
by ADD Creative
Dev. wrote: ↑Wed Apr 05, 2023 12:38 am
why didn't called?
Could you please provide me the suggested reason?
And if didn't work what's the best solution to adding a webhook updated?
Thank you,
Did you check for your callback URL in your web access log. If it not there then it could be that the URL is wrong or the request is being blocked for some reason.
Re: addOrderHistory didn't work with webhook
Posted: Wed Apr 05, 2023 11:22 am
by Dev.
ADD Creative wrote: ↑Wed Apr 05, 2023 7:05 am
Dev. wrote: ↑Wed Apr 05, 2023 12:38 am
why didn't called?
Could you please provide me the suggested reason?
And if didn't work what's the best solution to adding a webhook updated?
Thank you,
Did you check for your callback URL in your web access log. If it not there then it could be that the URL is wrong or the request is being blocked for some reason.
web access log you mean /system/storage/logs/error.log?
if yes, didn't show any error a bout that.
$this->model_checkout_order->addOrderHistory() It's working when placing an order the first time. But didn't work in the Webhook function
when I try to use
$this->log->write() I can see all webhook updated in the logs file. But didn't get any update in admin (Order History) when use
addOrderHistory()..
Thank you so much for your reply
Re: addOrderHistory didn't work with webhook
Posted: Wed Apr 05, 2023 12:09 pm
by by mona
Rather than speculating, just trace what is happening.
Code: Select all
$webhook_data = json_decode(html_entity_decode(file_get_contents('php://input')), true);
$this->log->write('webhook data received: '.print_r(webhook_data,true));
$this->log->write('webhook send to order history: '.$order_id.' - '.$order_status_id);
$result = $this->model_checkout_order->addOrderHistory($order_id, $order_status_id, '', true);
if ($result) {
$this->log->write('webhook order history result order_id: '.$result);
}
Re: addOrderHistory didn't work with webhook
Posted: Wed Apr 05, 2023 4:48 pm
by ADD Creative
Dev. wrote: ↑Wed Apr 05, 2023 11:22 am
web access log you mean /system/storage/logs/error.log?
if yes, didn't show any error a bout that.
$this->model_checkout_order->addOrderHistory() It's working when placing an order the first time. But didn't work in the Webhook function
when I try to use
$this->log->write() I can see all webhook updated in the logs file. But didn't get any update in admin (Order History) when use
addOrderHistory()..
Thank you so much for your reply
No, the web access log if a log of all the requests made to the server. In cPanel it's called Raw Access under Metrics. If you are not using cPanel ask your host. Find your callback URL and check the status code is 200 (usually the first number after the URL).
They other log you need to also look in is your PHP or server error log, again different to /system/storage/logs/error.log. You can use phpinfo() to find the PHP error_log or ask your host.
Re: addOrderHistory didn't work with webhook
Posted: Sat May 06, 2023 7:32 am
by Gpli
Maybe it's the same weird issue with mine.
After changing the function addOrderHistory to another name, it worked.
Re: addOrderHistory didn't work with webhook
Posted: Sat May 06, 2023 7:40 am
by straightlight
Gpli wrote: ↑Sat May 06, 2023 7:32 am
Maybe it's the same weird issue with mine.
After changing the function addOrderHistory to another name, it worked.
OC version. Looking at your code, it is possible that $webhook_data['id'] cannot be identical to the $order_id for the addOrderHistory() method since the $webhook_data['id'] will not match with the OC's created order ID from your local database. The $order_id must then be compared with the database table, or from the webhook array (if the OC's order ID is indeed stored in there) where your $webhook_data['id'] or it may also be stored on the database and able to be repulled prior to add the order history.
Re: addOrderHistory didn't work with webhook
Posted: Sat May 06, 2023 7:59 am
by straightlight
Furthermore, this line is also wrong:
Code: Select all
$setting = array_replace_recursive((array)$config_setting, (array)$this->config->get('setting'));
$config_setting is not set anywhere in the code and $this->config->get('setting') does not exist in the setting table or it may exist but would not be used with $this->config->get object without a prefix since the latest OC versions.
Re: addOrderHistory didn't work with webhook
Posted: Sat May 06, 2023 5:41 pm
by ADD Creative
Gpli wrote: ↑Sat May 06, 2023 7:32 am
Maybe it's the same weird issue with mine.
After changing the function addOrderHistory to another name, it worked.
Could of been an issue with an event on catalog/model/checkout/order/addOrderHistory/before. Such as mail_order_add, mail_order_alert or another event added by an extension. Did you check both your OpenCart and PHP error logs, assuming they are both enabled.
Re: addOrderHistory didn't work with webhook
Posted: Sat Jun 03, 2023 3:56 pm
by Gpli
ADD Creative wrote: ↑Sat May 06, 2023 5:41 pm
Gpli wrote: ↑Sat May 06, 2023 7:32 am
Maybe it's the same weird issue with mine.
After changing the function addOrderHistory to another name, it worked.
Could of been an issue with an event on catalog/model/checkout/order/addOrderHistory/before. Such as mail_order_add, mail_order_alert or another event added by an extension. Did you check both your OpenCart and PHP error logs, assuming they are both enabled.
Thank you for your reply.
You're right.
My issue was caused by the event about mail sending.