За последние 24 часа нас посетили 17674 программиста и 1723 робота. Сейчас ищут 896 программистов ...

подключить платежную систему liqpay php

Тема в разделе "Сделайте за меня", создана пользователем valeriiphpjs, 1 ноя 2017.

  1. valeriiphpjs

    valeriiphpjs Новичок

    С нами с:
    1 ноя 2017
    Сообщения:
    4
    Симпатии:
    1
    Доброго времени суток, подскажите как реализовать оплату на сайте файл freekassa работает и нормально передает все параметры файл в спойлере не работает его надо как то подружить с переменными первого файла, файл wallet проводит оплату внутренне валютой, сори за так заданный вопрос может не совсем понятный, сильно не пинайте новичка, заранее спасибо за ответ.
    PHP:
    1. <?php
    2. /**
    3. * Liqpay Payment Module
    4. *
    5. * NOTICE OF LICENSE
    6. *
    7. * This source file is subject to the Open Software License (OSL 3.0)
    8. * that is available through the world-wide-web at this URL:
    9. * http://opensource.org/licenses/osl-3.0.php
    10. *
    11. * @category        LiqPay
    12. * @package         liqpay/liqpay
    13. * @version         3.0
    14. * @author          Liqpay
    15. * @copyright       Copyright (c) 2014 Liqpay
    16. * @license         http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
    17. *
    18. * EXTENSION INFORMATION
    19. *
    20. * LIQPAY API       https://www.liqpay.ua/documentation/en
    21. *
    22. */
    23. /**
    24. * Payment method liqpay process
    25. *
    26. * @author      Liqpay <support@liqpay.ua>
    27. */
    28. class LiqPay
    29. {
    30.     const CURRENCY_EUR = 'EUR';
    31.     const CURRENCY_USD = 'USD';
    32.     const CURRENCY_UAH = 'UAH';
    33.     const CURRENCY_RUB = 'RUB';
    34.     const CURRENCY_RUR = 'RUR';
    35.     private $_api_url = 'https://www.liqpay.ua/api/';
    36.     private $_checkout_url = 'https://www.liqpay.ua/api/3/checkout';
    37.     protected $_supportedCurrencies = array(
    38.         self::CURRENCY_EUR,
    39.         self::CURRENCY_USD,
    40.         self::CURRENCY_UAH,
    41.         self::CURRENCY_RUB,
    42.         self::CURRENCY_RUR,
    43.     );
    44.     private $_public_key;
    45.     private $_private_key;
    46.     private $_server_response_code = null;
    47.     /**
    48.      * Constructor.
    49.      *
    50.      * @param string $public_key
    51.      * @param string $private_key
    52.      *
    53.      * @throws InvalidArgumentException
    54.      */
    55.     public function __construct($public_key, $private_key)
    56.     {
    57.         if (empty($public_key)) {
    58.             throw new InvalidArgumentException('public_key is empty');
    59.         }
    60.         if (empty($private_key)) {
    61.             throw new InvalidArgumentException('private_key is empty');
    62.         }
    63.         $this->_public_key = $public_key;
    64.         $this->_private_key = $private_key;
    65.     }
    66.     /**
    67.      * Call API
    68.      *
    69.      * @param string $path
    70.      * @param array $params
    71.      * @param int $timeout
    72.      *
    73.      * @return string
    74.      */
    75.     public function api($path, $params = array(), $timeout = 5)
    76.     {
    77.         if (!isset($params['version'])) {
    78.             throw new InvalidArgumentException('version is null');
    79.         }
    80.         $url         = $this->_api_url . $path;
    81.         $public_key  = $this->_public_key;
    82.         $private_key = $this->_private_key;
    83.         $data        = $this->encode_params(array_merge(compact('public_key'), $params));
    84.         $signature   = $this->str_to_sign($private_key.$data.$private_key);
    85.         $postfields  = http_build_query(array(
    86.            'data'  => $data,
    87.            'signature' => $signature
    88.         ));
    89.         $ch = curl_init();
    90.         curl_setopt($ch, CURLOPT_URL, $url);
    91.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // Avoid MITM vulnerability http://phpsecurity.readthedocs.io/en/latest/Input-Validation.html#validation-of-input-sources
    92.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);    // Check the existence of a common name and also verify that it matches the hostname provided
    93.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,$timeout);   // The number of seconds to wait while trying to connect
    94.         curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);          // The maximum number of seconds to allow cURL functions to execute
    95.         curl_setopt($ch, CURLOPT_POST, true);
    96.         curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    97.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    98.         $server_output = curl_exec($ch);
    99.         $this->_server_response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    100.         curl_close($ch);
    101.         return json_decode($server_output);
    102.     }
    103.     /**
    104.      * Return last api response http code
    105.      *
    106.      * @return string|null
    107.      */
    108.     public function get_response_code()
    109.     {
    110.         return $this->_server_response_code;
    111.     }
    112.     /**
    113.      * cnb_form
    114.      *
    115.      * @param array $params
    116.      *
    117.      * @return string
    118.      *
    119.      * @throws InvalidArgumentException
    120.      */
    121.     public function cnb_form($params)
    122.     {
    123.         $language = 'ru';
    124.         if (isset($params['language']) && $params['language'] == 'en') {
    125.             $language = 'en';
    126.         }
    127.         $params    = $this->cnb_params($params);
    128.         $data      = $this->encode_params($params);
    129.         $signature = $this->cnb_signature($params);
    130.        
    131.         return sprintf('
    132.            <form method="POST" action="%s" accept-charset="utf-8">
    133.                %s
    134.                %s
    135.                <input type="image" src="//static.liqpay.ua/buttons/p1%s.radius.png" name="btn_text" />
    136.            </form>
    137.            ',
    138.             $this->_checkout_url,
    139.             sprintf('<input type="hidden" name="%s" value="%s" />', 'data', $data),
    140.             sprintf('<input type="hidden" name="%s" value="%s" />', 'signature', $signature),
    141.             $language
    142.         );
    143.     }
    144.     /**
    145.      * cnb_signature
    146.      *
    147.      * @param array $params
    148.      *
    149.      * @return string
    150.      */
    151.     public function cnb_signature($params)
    152.     {
    153.         $params      = $this->cnb_params($params);
    154.         $private_key = $this->_private_key;
    155.         $json      = $this->encode_params($params);
    156.         $signature = $this->str_to_sign($private_key . $json . $private_key);
    157.         return $signature;
    158.     }
    159.     /**
    160.      * cnb_params
    161.      *
    162.      * @param array $params
    163.      *
    164.      * @return array $params
    165.      */
    166.     private function cnb_params($params)
    167.     {
    168.         $params['public_key'] = $this->_public_key;
    169.         if (!isset($params['version'])) {
    170.             throw new InvalidArgumentException('version is null');
    171.         }
    172.         if (!isset($params['amount'])) {
    173.             throw new InvalidArgumentException('amount is null');
    174.         }
    175.         if (!isset($params['currency'])) {
    176.             throw new InvalidArgumentException('currency is null');
    177.         }
    178.         if (!in_array($params['currency'], $this->_supportedCurrencies)) {
    179.             throw new InvalidArgumentException('currency is not supported');
    180.         }
    181.         if ($params['currency'] == self::CURRENCY_RUR) {
    182.             $params['currency'] = self::CURRENCY_RUB;
    183.         }
    184.         if (!isset($params['description'])) {
    185.             throw new InvalidArgumentException('description is null');
    186.         }
    187.         return $params;
    188.     }
    189.     /**
    190.      * encode_params
    191.      *
    192.      * @param array $params
    193.      * @return string
    194.      */
    195.     private function encode_params($params)
    196.     {
    197.         return base64_encode(json_encode($params));
    198.     }
    199.     /**
    200.      * decode_params
    201.      *
    202.      * @param string $params
    203.      * @return array
    204.      */
    205.     public function decode_params($params)
    206.     {
    207.         return json_decode(base64_decode($params), true);
    208.     }
    209.     /**
    210.      * str_to_sign
    211.      *
    212.      * @param string $str
    213.      *
    214.      * @return string
    215.      */
    216.     public function str_to_sign($str)
    217.     {
    218.         $signature = base64_encode(sha1($str, 1));
    219.         return $signature;
    220.     }
    221. }
     

    Вложения: