Не нравятся результаты поиска? Попробуйте другой поиск!
DLE FAQ » Все вопросы » Модули » Как исправить ошибку UnitPay в модуле DLE-Billing?

Как исправить ошибку UnitPay в модуле DLE-Billing?


     24.01.2020    Все вопросы » Модули    1655

вопрос
Установлен модуль DLE-Billing. К нему подключен плагин UnitPay, статус проекта в UnitPay активен/
Проблема в обработчике платежей, ссылка на обработчик платежей, которая дается в модули не работает (??) в UnitPay пишет ошибку "неверный формат". Кто нибудь сталкивался с данной проблемой ?

Ответа пока нет


5 комментариев

dj-avtosh
PHP-developer

dj-avtosh - 24 января 2020 14:14 -

Здравствуйте. Есть ли код?

https://elkhan.ru
По заказам пишем сюда: @Rud00y

ЯД: 41001679231462
Заказы в telegram (ремонт модулей, оптимизация нагрузок и т.п.):
В телегу писать сразу задачу и бюджет.

nobodylovesyou
Юзер

nobodylovesyou - 24 января 2020 14:23 -

<?php
/**
 * UnitPay Payment Module
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is available through the world-wide-web at this URL:
 * [leech=http://opensource.org/licenses/osl-3.0.php]http://opensource.org/licenses/osl-3.0.php[/leech]
 *
 * @category        UnitPay
 * @package         unitpay/unitpay
 * @version         1.0.0
 * @author          UnitPay
 * @copyright       Copyright (c) 2015 UnitPay
 * @license         [leech=http://opensource.org/licenses/osl-3.0.php]http://opensource.org/licenses/osl-3.0.php[/leech] Open Software License (OSL 3.0)
 *
 * EXTENSION INFORMATION
 *
 * UNITPAY API       [leech=https://unitpay.ru/doc]https://unitpay.ru/doc[/leech]
 *
 */

/**
 * Payment method UnitPay process
 *
 * @author      UnitPay <support@unitpay.ru>
 */
class UnitPay
{
    private $supportedCurrencies = array('EUR','UAH', 'BYR', 'USD','RUB');
    private $supportedUnitpayMethods = array('initPayment', 'getPayment');
    private $requiredUnitpayMethodsParams = array(
        'initPayment' => array('desc', 'account', 'sum'),
        'getPayment' => array('paymentId')
    );
    private $supportedPartnerMethods = array('check', 'pay', 'error');
    private $supportedUnitpayIp = array(
        '31.186.100.49',
        '178.132.203.105',
        '52.29.152.23',
        '52.19.56.234',
        '127.0.0.1' // for debug
    );
    private $apiUrl = 'https://unitpay.ru/api';
    private $formUrl = 'https://unitpay.ru/pay/';
    private $secretKey;

    public function __construct($secretKey = null)
    {
        $this->secretKey = $secretKey;
    }

    /**
     * Create SHA-256 digital signature
     *
     * @param array $params
     * @param $method
     *
     * @return string
     */
    function getSignature(array $params, $method = null)
    {
        ksort($params);
        unset($params['sign']);
        unset($params['signature']);
        array_push($params, $this->secretKey);
        if ($method) {
            array_unshift($params, $method);
        }

        return hash('sha256', join('{up}', $params));
    }

    /**
     * Get URL for pay through the form
     *
     * @param $publicKey
     * @param $sum
     * @param $account
     * @param $desc
     * @param string $currency
     * @param string $locale
     *
     * @return string
     */
    public function form($publicKey, $sum, $account, $desc, $currency = 'RUB', $locale = 'ru')
    {
        $params = [
            'account' => $account,
            'currency' => $currency,
            'desc' => $desc,
            'sum' => $sum,
        ];
        if ($this->secretKey) {
            $params['signature'] = $this->getSignature($params);
        }
        $params['locale'] = $locale;

        return $this->formUrl.$publicKey.'?'.http_build_query($params);
    }

    /**
     * Call API
     *
     * @param $method
     * @param array $params
     *
     * @return object
     *
     * @throws InvalidArgumentException
     * @throws UnexpectedValueException
     */
    public function api($method, $params = array())
    {
        if (!in_array($method, $this->supportedUnitpayMethods)) {
            throw new UnexpectedValueException('Method is not supported');
        }
        if (isset($this->requiredUnitpayMethodsParams[$method])) {
            foreach ($this->requiredUnitpayMethodsParams[$method] as $rParam) {
                if (!isset($params[$rParam])) {
                    throw new InvalidArgumentException('Param '.$rParam.' is null');
                }
            }
        }
        $params['secretKey'] = $this->secretKey;
        if (empty($params['secretKey'])) {
            throw new InvalidArgumentException('SecretKey is null');
        }

        $requestUrl = $this->apiUrl.'?'.http_build_query([
            'method' => $method,
            'params' => $params
        ], null, '&', PHP_QUERY_RFC3986);

        $response = json_decode(file_get_contents($requestUrl));
        if (!is_object($response)) {
            throw new InvalidArgumentException('Temporary server error. Please try again later.');
        }

        return $response;
    }

    /**
     * Check request on handler from UnitPay
     *
     * @return bool
     *
     * @throws InvalidArgumentException
     * @throws UnexpectedValueException
     */
    public function checkHandlerRequest()
    {
        $ip = $_SERVER['REMOTE_ADDR'];
        if (!isset($_GET['method'])) {
            throw new InvalidArgumentException('Method is null');
        }
        if (!isset($_GET['params'])) {
            throw new InvalidArgumentException('Params is null');
        }
        list($method, $params) = array($_GET['method'], $_GET['params']);

        if (!in_array($method, $this->supportedPartnerMethods)) {
            throw new UnexpectedValueException('Method is not supported');
        }

        if ($params['signature'] != $this->getSignature($params, $method)) {
            throw new InvalidArgumentException('Wrong signature');
        }

        /**
         * IP address check
         * @link [leech=http://help.unitpay.ru/article/67-ip-addresses]http://help.unitpay.ru/article/67-ip-addresses[/leech]
         */
        if (!in_array($ip, $this->supportedUnitpayIp)) {
            throw new InvalidArgumentException('IP address Error');
        }

        return true;
    }

    /**
     * Response for UnitPay if handle success
     *
     * @param $message
     *
     * @return string
     */
    public function getSuccessHandlerResponse($message)
    {
        return json_encode(array(
            "result" => array(
                "message" => $message
            )
        ));
    }

    /**
     * Response for UnitPay if handle error
     *
     * @param $message
     *
     * @return string
     */
    public function getErrorHandlerResponse($message)
    {
        return json_encode(array(
            "error" => array(
                "message" => $message
            )
        ));
    }
}

dj-avtosh
PHP-developer

dj-avtosh - 24 января 2020 14:37 -

какая ссылка получается и какая должна быть по сути?

https://elkhan.ru
По заказам пишем сюда: @Rud00y

ЯД: 41001679231462
Заказы в telegram (ремонт модулей, оптимизация нагрузок и т.п.):
В телегу писать сразу задачу и бюджет.

nobodylovesyou
Юзер

nobodylovesyou - 24 января 2020 14:40 -

site.ru/billing.html/pay/handler/payment/unitpay/key/11111111/ , на другом ресурсе подключена robokassa работает без проблем

dj-avtosh
PHP-developer

dj-avtosh - 24 января 2020 14:40 -

внимательно прочтите что я написал

https://elkhan.ru
По заказам пишем сюда: @Rud00y

ЯД: 41001679231462
Заказы в telegram (ремонт модулей, оптимизация нагрузок и т.п.):
В телегу писать сразу задачу и бюджет.

Чтобы комментировать - войдите или зарегистрируйтесь на сайте

Похожие вопросы

наверх