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?
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Hellopaulfeakins wrote: ↑Mon Apr 03, 2023 7:13 pmAs 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.
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);
Anyway, your code won't work because the variable $order_id is undefined.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Dev. wrote: ↑Mon Apr 03, 2023 8:35 pmHellopaulfeakins wrote: ↑Mon Apr 03, 2023 7:13 pmAs 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.
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
This is what I try to do. I hope this enoughCode: 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);
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.
HelloADD Creative wrote: ↑Tue Apr 04, 2023 2:54 amAnything 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.
I didn't find any things in the logs file. But Order History in the admin panel didn't add any update from webhook
Attachments
Screenshot 1444-09-12 at 10.53.56 PM.png (72.26 KiB) Viewed 2992 times
why didn't called?ADD Creative wrote: ↑Tue Apr 04, 2023 6:56 amIf there is nothing in the web access log, maybe it's not being 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?ADD Creative wrote: ↑Wed Apr 05, 2023 7:05 amDid 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.
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
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);
}
DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.
https://www.youtube.com/watch?v=zXIxDoCRc84
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).Dev. wrote: ↑Wed Apr 05, 2023 11:22 amweb 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
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.
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.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Code: Select all
$setting = array_replace_recursive((array)$config_setting, (array)$this->config->get('setting'));
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
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.ADD Creative wrote: ↑Sat May 06, 2023 5:41 pmCould 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.
You're right.
My issue was caused by the event about mail sending.
Users browsing this forum: No registered users and 325 guests