Post by Dev. » Mon Apr 03, 2023 12:23 pm

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?

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by thekrotek » Mon Apr 03, 2023 4:32 pm

No, because you provided zero info.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by paulfeakins » 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.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by Dev. » 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'));
		
		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
Last edited by Dev. on Mon Apr 03, 2023 10:09 pm, edited 1 time in total.

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by JNeuhoff » 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.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Dev. » Mon Apr 03, 2023 10:13 pm

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

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by Dev. » Mon Apr 03, 2023 10:14 pm

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.

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by ADD Creative » 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.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Dev. » Tue Apr 04, 2023 3:54 am

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

Attachments

Screenshot 1444-09-12 at 10.53.56 PM.png

Screenshot 1444-09-12 at 10.53.56 PM.png (72.26 KiB) Viewed 2958 times


New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by ADD Creative » Tue Apr 04, 2023 6:56 am

If there is nothing in the web access log, maybe it's not being called.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Dev. » Wed Apr 05, 2023 12:38 am

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,

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by ADD Creative » 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.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Dev. » Wed Apr 05, 2023 11:22 am

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

New member

Posts

Joined
Sun Jul 17, 2022 10:02 pm

Post by by mona » Wed Apr 05, 2023 12:09 pm

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);
}

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


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by ADD Creative » Wed Apr 05, 2023 4:48 pm

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.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Gpli » 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.

New member

Posts

Joined
Thu Dec 01, 2016 7:31 am

Post by straightlight » Sat May 06, 2023 7:40 am

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.
Last edited by straightlight on Sat May 06, 2023 9:09 am, edited 1 time in total.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sat May 06, 2023 7:59 am

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by ADD Creative » 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.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Gpli » Sat Jun 03, 2023 3:56 pm

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.

New member

Posts

Joined
Thu Dec 01, 2016 7:31 am
Who is online

Users browsing this forum: sidclel and 82 guests