%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 18.117.229.33
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/sale/lib/cashbox/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/sale/lib/cashbox/cashboxrest.php
<?php

namespace Bitrix\Sale\Cashbox;

use Bitrix\Main;
use Bitrix\Main\Localization\Loc;
use Bitrix\Sale;
use Bitrix\Sale\Result;

/**
 * Class CashboxRest
 * @package Bitrix\Sale\Cashbox
 */
class CashboxRest extends Cashbox implements IPrintImmediately, ICheckable
{
	/**
	 * @return mixed
	 */
	public function getHandlerCode()
	{
		$settings = $this->getField("SETTINGS");
		return $settings["REST"]["REST_CODE"];
	}

	/**
	 * @param $handlerCode
	 * @return mixed
	 * @throws Main\ArgumentException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	public static function getHandlerParams($handlerCode)
	{
		$handlerList = Manager::getRestHandlersList();
		return $handlerList[$handlerCode];
	}

	/**
	 * @param $handlerCode
	 * @return mixed
	 * @throws Main\ArgumentException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	public static function getConfigStructure($handlerCode)
	{
		$handlerParams = self::getHandlerParams($handlerCode);

		$result = $handlerParams["SETTINGS"]["CONFIG"];
		$result["REST"] = [
			"REQUIRED" => "Y",
			"ITEMS" => [
				"REST_CODE" => [
					"TYPE" => "STRING",
					"LABEL" => Loc::getMessage("SALE_CASHBOX_REST_HANDLER_CODE"),
					"READONLY" => true,
					"VALUE" => $handlerCode,
				]
			]
		];

		return $result;
	}

	/**
	 * @return array
	 */
	protected static function getCheckTypeMap(): array
	{
		return array(
			SellCheck::getType() => 'full_payment',
			SellReturnCashCheck::getType() => 'full_payment',
			SellReturnCheck::getType() => 'full_payment',
			AdvancePaymentCheck::getType() => 'advance',
			AdvanceReturnCashCheck::getType() => 'advance',
			AdvanceReturnCheck::getType() => 'advance',
			PrepaymentCheck::getType() => 'prepayment',
			PrepaymentReturnCheck::getType() => 'prepayment',
			PrepaymentReturnCashCheck::getType() => 'prepayment',
			FullPrepaymentCheck::getType() => 'full_prepayment',
			FullPrepaymentReturnCheck::getType() => 'full_prepayment',
			FullPrepaymentReturnCashCheck::getType() => 'full_prepayment',
			CreditCheck::getType() => 'credit',
			CreditReturnCheck::getType() => 'credit',
			CreditPaymentCheck::getType() => 'credit_payment',
		);
	}

	/**
	 * @return mixed
	 * @throws Main\ArgumentException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	private function getPrintUrl()
	{
		$handlerCode = $this->getHandlerCode();
		$handlerParams = self::getHandlerParams($handlerCode);
		return $handlerParams["SETTINGS"]["PRINT_URL"];
	}

	/**
	 * @return mixed
	 * @throws Main\ArgumentException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	private function getCheckUrl()
	{
		$handlerCode = $this->getHandlerCode();
		$handlerParams = self::getHandlerParams($handlerCode);
		return $handlerParams["SETTINGS"]["CHECK_URL"];
	}

	/**
	 * @param Check $check
	 * @return array
	 * @throws Main\ArgumentException
	 * @throws Main\ArgumentNullException
	 * @throws Main\ArgumentOutOfRangeException
	 * @throws Main\ArgumentTypeException
	 * @throws Main\LoaderException
	 * @throws Main\NotImplementedException
	 * @throws Main\ObjectException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	public function buildCheckQuery(Check $check): array
	{
		$data = $check->getDataForCheck();

		$data["uuid"] = static::buildUuid(static::UUID_TYPE_CHECK, $data['unique_id']);

		/** @var Main\Type\DateTime $dateTime */
		$dateTime = $data["date_create"];
		$dateTimestamp = $dateTime->getTimestamp();
		$data["date_create"] = $dateTimestamp;

		$data["operation"] = $check::getCalculatedSign();

		$checkTypeMap = self::getCheckTypeMap();
		if (is_array($data["items"])) {
			foreach ($data["items"] as $index => $item) {
				$data["items"][$index]['payment_method'] = $checkTypeMap[$check::getType()];
			}
		}

		$data["number_kkm"] = $this->getField('NUMBER_KKM');
		$data["service_email"] = $this->getField('EMAIL');
		$cashboxParams = $this->getField("SETTINGS");

		// there's no need to pass our REST configuration (i.e. the handler code) to the application
		unset($cashboxParams["REST"]);
		$data["cashbox_params"] = $cashboxParams;

		return $data;
	}

	/**
	 * @param $id
	 * @return array
	 */
	public function buildZReportQuery($id): array
	{
		return [];
	}


	/**
	 * @param array $data
	 * @return array
	 * @throws Main\ArgumentException
	 * @throws Main\NotImplementedException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	protected static function extractCheckData(array $data): array
	{
		$result = [];

		if (!$data['UUID'])
		{
			return $result;
		}

		$checkInfo = CheckManager::getCheckInfoByExternalUuid($data['UUID']);

		if ($data['STATUS'] === 'ERROR')
		{
			$result['ERROR'] = [
				'TYPE' => Errors\Error::TYPE,
				'MESSAGE' => $data['ERROR'],
			];
		}

		$result['ID'] = $checkInfo['ID'];
		$result['CHECK_TYPE'] = $checkInfo['TYPE'];

		$check = CheckManager::getObjectById($checkInfo['ID']);
		$dateTime = Main\Type\DateTime::createFromTimestamp($data["PRINT_END_TIME"]);
		$result['LINK_PARAMS'] = [
			Check::PARAM_REG_NUMBER_KKT => $data['REG_NUMBER_KKT'],
			Check::PARAM_FISCAL_DOC_ATTR => $data['FISCAL_DOC_ATTR'],
			Check::PARAM_FISCAL_DOC_NUMBER => $data['FISCAL_DOC_NUMBER'],
			Check::PARAM_FISCAL_RECEIPT_NUMBER => $data['FISCAL_RECEIPT_NUMBER'],
			Check::PARAM_FN_NUMBER => $data['FN_NUMBER'],
			Check::PARAM_SHIFT_NUMBER => $data['SHIFT_NUMBER'],
			Check::PARAM_DOC_SUM => (float)$checkInfo['SUM'],
			Check::PARAM_DOC_TIME => $dateTime->getTimestamp(),
			Check::PARAM_CALCULATION_ATTR => $check::getCalculatedSign()
		];

		return $result;
	}

	/**
	 * @param Check $check
	 * @return Result
	 * @throws Main\ArgumentException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	public function check(Check $check): Result
	{
		$result = new Result();
		$url = $this->getCheckUrl();
		$checkUUID = $check->getField('EXTERNAL_UUID');
		$queryResult = Sale\Helpers\Rest\Http::sendRequest($url, ["uuid" => $checkUUID]);
		$response = $queryResult->getData();

		if ($response === false)
		{
			return $result->addError(new Errors\Error(Loc::getMessage("SALE_CASHBOX_REST_DATA_ERROR_CHECK_CHECK")));
		}

		$response['UUID'] = $checkUUID;

		if ($response['STATUS'] === 'WAIT')
		{
			$result = $result->addError(new Main\Error(Loc::getMessage('SALE_CASHBOX_REST_PRINT_IN_PROGRESS')));

			return $result;
		}

		return static::applyCheckResult($response);
	}

	/**
	 * @param Check $check
	 * @return Result
	 * @throws Main\ArgumentException
	 * @throws Main\ArgumentNullException
	 * @throws Main\ArgumentOutOfRangeException
	 * @throws Main\ArgumentTypeException
	 * @throws Main\LoaderException
	 * @throws Main\NotImplementedException
	 * @throws Main\ObjectException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	public function printImmediately(Check $check): Result
	{
		$url = $this->getPrintUrl();
		$printResult = Sale\Helpers\Rest\Http::sendRequest($url, $this->buildCheckQuery($check));

		if (!$printResult->isSuccess())
		{
			return $printResult;
		}

		$printData = $printResult->getData();
		if (isset($printData['ERRORS']) && is_array($printData['ERRORS']))
		{
			foreach ($printData['ERRORS'] as $errorMessage)
			{
				$printResult->addError(new Errors\Error($errorMessage));
			}
		}

		return $printResult;
	}

	/**
	 * @return Result
	 * @throws Main\ArgumentException
	 * @throws Main\ObjectPropertyException
	 * @throws Main\SystemException
	 */
	public function validate(): Result
	{
		$result = parent::validate();

		// check whether the specified handler actually exists
		$handlerCode = $this->getHandlerCode();
		$handlerList = Manager::getRestHandlersList();
		if (!isset($handlerList[$handlerCode]))
		{
			$result->addError(
				new Main\Error(
					Loc::getMessage(
						"SALE_CASHBOX_REST_HANDLER_NOT_FOUND",
						["#HANDLER_CODE#" => $handlerCode]
					)
				)
			);
		}

		return $result;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit