403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/grain.iiko/tools/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/grain.iiko/tools/webhook.php
<?php
define("NO_KEEP_STATISTIC", "Y");
define("NO_AGENT_STATISTIC","Y");
define("NOT_CHECK_PERMISSIONS", true);
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");

use Bitrix\Main\Web\Json;
use Bitrix\Main\Loader;
use Bitrix\Main\Config\Option;
use Bitrix\Sale\Order;
use Bitrix\Sale\Internals\OrderTable;
use Grain\Iiko\Restaurants;

if(!Loader::includeModule('sale') || !Loader::includeModule('grain.iiko'))
	return;

$request = \Bitrix\Main\HttpApplication::getInstance()->getContext()->getRequest();
$headers = getallheaders();

try {
	$webhooks = Json::decode($request->getInput());
} catch (\Bitrix\Main\SystemException $e) {
	$webhooks = array();
}

foreach($webhooks as $webhook)
{
	$event = new \Bitrix\Main\Event("grain.iiko", "OnGetWebhook", array(
		'WEBHOOK' => $webhook,
	));
	$event->send();
	foreach ($event->getResults() as $eventResult)
	{
		if($eventResult->getType() == \Bitrix\Main\EventResult::ERROR)
			continue;
		if($eventResult->getParameters())
			$webhook = $eventResult->getParameters();
	}

	if(
		!is_array($webhook) 
		|| !isset($webhook['eventType']) 
		|| !isset($webhook['organizationId'])
		|| !is_array($webhook['eventInfo'])
	)
		continue;
	
	if(!$restaurant=Restaurants::getRestaurantByXmlId($webhook['organizationId']))
		continue;
	
	$token = Option::get('grain.iiko','webhook_token_'.$restaurant['ID']);
	if($headers['Authorization']!='Bearer '.$token)
		continue;
	
	switch($webhook['eventType'])
	{
		case 'DeliveryOrderUpdate':
			
			if(!isset($webhook['eventInfo']['id']) || !isset($webhook['eventInfo']['order']['status']))
				continue;
			
			$orderStatus = $webhook['eventInfo']['order']['status'];
			if(!$statusId=Option::get('grain.iiko','status_'.$restaurant['ID'].'_'.$orderStatus))
				continue;

			$orderXmlId = 'grain-iiko-'.$webhook['eventInfo']['id'];
			$resultOrder = OrderTable::getList(array(
				'filter' => array('=XML_ID'=>$orderXmlId),
				'limit' => 1,
				'select' => array('ID','XML_ID'),
			));
			if(!$orderRow=$resultOrder->fetch())
				continue;
			
			if(!$order=Order::load($orderRow['ID']))
				continue;
			
			$order->setField("STATUS_ID",$statusId);
			$order->save();
			
			break;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit