Your IP : 18.191.135.39


Current Path : /home/bitrix/ext_www/dev.easy-comfort.com.ua/local/php_interface/
Upload File :
Current File : /home/bitrix/ext_www/dev.easy-comfort.com.ua/local/php_interface/BankController.php

<?
class BankController
{

    /**
     * Ответ банка
     * @var null
     */
    private $bankResponse = null;

    /**
     * Урл от банка
     * @var
     */
    public $formUrl;

    /**
     * this .parameters.php
     * @var array|bool
     */
    private $config = array();

    /**
     * BankController constructor.
     */
    public function __construct()
    {
        $this->config = CComponentUtil::GetComponentProps('online_paid:fsk')['PARAMETERS'];
    }

    /**
     * @param $SID
     * @param $orderData
     * @param $bankConfig
     * @return bool
     */
    public function sendData($SID, $orderData, $bankConfig)
    {
        if ($this->config['BANK']['API_2STAGE'] == true) {
            $url = $bankConfig['url'] .
                'registerPreAuth.do?amount=' . $orderData['basketAmount'] . '&currency=' . $bankConfig['money'] . '&language=ru&orderNumber=' . $SID . '&password=' . urlencode($bankConfig['password']) . '&returnUrl='
                . urlencode($this->config['BANK']['BACK_HOST'] . $this->config['BANK']['BACK_URL'] . $SID) . '&userName=' . $bankConfig['login'] .
                '&jsonParams={"orderNumber":"' . $SID . '","description":"' . $SID . '"}&orderBundle=' . urlencode($orderData['orderBundle']);
        } else {
            $url = $bankConfig['url'] .
                'register.do?amount=' . $orderData['basketAmount'] . '&currency=' . $bankConfig['money'] . '&language=ru&orderNumber=' . $SID . '&password=' . urlencode($bankConfig['password']) . '&returnUrl='
                . urlencode($this->config['BANK']['BACK_HOST'] . $this->config['BANK']['BACK_URL'] . $SID) . '&userName=' . $bankConfig['login'] .
                '&jsonParams={"orderNumber":"' . $SID . '","description":"' . $SID . '"}&orderBundle=' . urlencode($orderData['orderBundle']);
        }

        $return = $this->curl($url);

        $this->bankResponse = json_decode($return);

		\Bitrix\Main\Diag\Debug::writeToFile(date("Y-m-d H:i:s").' - '.$SID.' - '.$url, '', "local/log/sale.order.bank.log");
		\Bitrix\Main\Diag\Debug::writeToFile(date("Y-m-d H:i:s").' - '.$SID.' - '.$return, '', "local/log/sale.order.bank.log");

        //банк ответил, что все ок, отдаем инфо обратно
        if (isset($this->bankResponse->formUrl) && isset($this->bankResponse->orderId)) {
            return $this->bankResponse;
        };

        return FALSE;
    }

    /**
     * Проверяем прошла ли оплата
     * @param $BID
     * @param $bankConfig
     * @return mixed|null
     */
    public function checkData($BID, $bankConfig)
    {
        $url = $this->config['BANK']['API_URL'] . 'getOrderStatus.do?language=ru&orderId=' . $BID . '&password=' . urlencode($bankConfig['password']) . '&userName=' . $bankConfig['login'];

        // пуляем урлы в курл, ждем ответ
        $return = $this->curl($url);

        $this->bankResponse = json_decode($return);

        return $this->bankResponse;

    }

    /**
     * @param $url
     * @return mixed
     */
    private function curl($url)
    {

        $ch = \curl_init($url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 20);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_STDERR, $this->CLog->flog);

        // TEMP!!!!!!
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


        $return = curl_exec($ch);

        curl_close($ch);

        return $return;
    }
}