Подключение эквайринг банка тинькофф v2

433
27 августа 2017, 05:28

Ребят всем привет, столкнулся с проблемой подключения эквайринга от тиньков банка, а именно 2 версии, в документации у них висит 1 версия через cURL, просят отправлять запросы на https://securepay.tinkoff.ru/v2/Init с помощью json, в ответ должна приходить ссылка на которую человек переходит чтобы делать оплату, но ничего не приходит, тех поддержка динамит и говорит что нужно ознакомиться с документацией... перерыл всю документацию и перепроверил массивы, толку 0... бьюсь с этим 3 день, в бэкенде опыт у меня не большой, но вроде все в порядке... может кто чем подсказать, буду очень благодарен... есть документация https://oplata.tinkoff.ru/landing/develop/documentation/Init, в ней указано какой массив должен приходить на адрес, собственно он вроде как такой и идет, но что то все равно не так... собственно есть 3 файла, два испольнительных(debug.php и TinkoffMerchantAPI.php) и один куда ты вбиваешь массив и данные своего магазина (index.php)

вот собственно файлы

index.php

      <?php
     /**
      * File index.php. Demo for using TinkoffMerchantAPI library.
      *
      * PHP version 5.3
      *
      * @category Tinkoff
      * @package  Tinkoff
      * @author   Shuyskiy Sergey <s.shuyskiy@tinkoff.ru>
      * @license  http://opensource.org/licenses/MIT MIT license
      * @link     http://tinkoff.ru
      */
     function __autoload($className)
     {
         include $className.'.php';
     }
     //spl_autoload('TinkoffMerchantAPI');
     $api = new TinkoffMerchantAPI(
         '1502455205939DEMO',//'Test',
         'k2gk471x6g61qflb',//'password',
         'https://securepay.tinkoff.ru/v2/Init'
     );
     ?>
     <!doctype html>
     <html lang="en">
     <head>
         <meta charset="UTF-8">
         <link rel="stylesheet" href="main.css"/>
         <title>Testing Merchant API</title>
     </head>
     <body>
     <h1 align="center">Тестирование MerchantAPI</h1>
     <?php if (true) : ?>
         <div class="card">
             <h2>Метод Init:</h2>
             <div class="article">
                 <?php
                 $params = array(
                     'TerminalKey' => '1502455205939DEMO',
                     'Amount' => 100,
                     'OrderId' => '66239',//'669',
                     'Description' => '123',
                     'Language' => 'ru',
                     'DATA' => array('Email' => '@test.ru', 'Phone' => '         +78985643434'),
                     'Receipt' => array('Email' => '@test.ru', 'Phone' => '         +78985643434','Taxation' => 'usn_income',
                     'Items' => [array(
                      'Name' => 'tov1',
                      'Price' => 10000,
                      'Quantity' => 1.00,
                      'Amount' => 10000,
                      'Tax' => 'none'
                      )])
                 );
                 $params1 = json_encode($params);
                 echo $params1;
                 $api->init($params1);
                 echo 'Params:';
     //                Debug::trace($params);
                 ?>
                 <p><span class="highlight">Response</span>: <?php echo $api->         response ?></p>
                 <?php if ($api->error) : ?>
                     <span class="error"><?php echo $api->error ?></span>
                 <?php else: ?>
                     <p><span class="highlight">Status</span>: <?php echo $api->         status ?></p>
                     <p>
                         <span class="highlight">PaymentUrl</span>:
                         <a href="<?php echo $api->paymentUrl ?>" target="_blank"         ><?php echo $api->paymentUrl ?></a>
                     </p>
                     <p><span class="highlight">PaymentId</span>: <?php echo $api         ->paymentId ?></p>
                 <?php endif; ?>
             </div>
         </div>
     <?php endif; ?>
     <?php if (false) : ?>
         <div class="card">
             <h2>Метод GetState:</h2>
             <div class="article">
                 <?php
                 $params = array(
                     'PaymentId' => '147161',
                 );
                 $api->getState($params);
                 ?>
                 <p><span class="highlight">Response</span>: <?php echo $api->         response ?></p>
                 <?php if ($api->error) : ?>
                     <p><span class="error"><?php echo $api->error ?></span></p>
                 <?php else: ?>
                     <p><span class="highlight">Status</span>: <?php echo $api->         status ?></p>
                     <p><span class="highlight">PaymentId</span>: <?php echo $api         ->paymentId ?></p>
                     <p><span class="highlight">OrderId</span>: <?php echo $api->         orderId ?></p>
                 <?php endif; ?>
             </div>
         </div>
     <?php endif; ?>
     <?php if (false) : ?>
         <div class="card">
             <h2>Метод Confirm:</h2>
             <div class="article">
                 <?php
                 $params = array(
                     'PaymentId' => '147161',
                 );
                 $api->confirm($params);
                 //    echo 'Params:';
                 //    Debug::trace($params);
                 ?>
                 <p><span class="highlight">Response</span>: <?php echo $api->         response ?></p>
                 <?php if ($api->error) : ?>
                     <span class="error"><?php echo $api->error ?></span>
                 <?php else: ?>
                     <p><span class="highlight">Status</span>: <?php echo $api->         status ?></p>
                     <p><span class="highlight">PaymentId</span>: <?php echo $api         ->paymentId ?></p>
                 <?php endif; ?>
             </div>
         </div>
     <?php endif; ?>
     <?php if (false) : ?>
         <div class="card">
             <h2>Метод Resend</h2>
             <div class="article">
                 <p><span class="highlight">Response</span>: <?php echo $api->         resend() ?></p>
                 <p><span class="highlight">Count</span>: <?php echo $api->Count          ?></p>
             </div>
         </div>
     <?php endif; ?>
     <?php if (false) : ?>
         <div class="card">
             <h2>Метод AddCustomer</h2>
             <div class="article">
                 <?php
                 $params = array(
                     'CustomerKey' => '4',
                 );
                 $api->addCustomer($params);
                 ?>
                 <p><span class="highlight">Response</span>: <?php echo $api->         response ?></p>
                 <?php if ($api->error) : ?>
                     <p><span class="error"><?php echo $api->error ?></span></p>
                 <?php else: ?>
                     <p><span class="highlight">CustomerKey</span>: <?php echo $         api->customerKey ?></p>
                 <?php endif; ?>
             </div>
         </div>
     <?php endif; ?>
     <?php if (false) : ?>
         <div class="card">
             <h2>Метод GetCustomer</h2>
             <div class="article">
                 <?php
                 $params = array(
                     'CustomerKey' => '4',
                 );
                 $api->getCustomer($params);
                 ?>
                 <p><span class="highlight">Response</span>: <?php echo $api->         response ?></p>
                 <?php if ($api->error) : ?>
                     <p><span class="error"><?php echo $api->error ?></span></p>
                 <?php else: ?>
                     <p><span class="highlight">CustomerKey</span>: <?php echo $         api->customerKey ?></p>
                 <?php endif; ?>
             </div>
         </div>
     <?php endif; ?>
     <?php if (false) : ?>
         <div class="card">
             <h2>Метод RemoveCustomer</h2>
             <div class="article">
                 <?php
                 $params = array(
                     'CustomerKey' => '4',
                 );
                 $api->removeCustomer($params);
                 ?>
                 <p><span class="highlight">Response</span>: <?php echo $api->         response ?></p>
                 <?php if ($api->error) : ?>
                     <p><span class="error"><?php echo $api->error ?></span></p>
                 <?php else: ?>
                     <p><span class="highlight">CustomerKey</span>: <?php echo $         api->customerKey ?></p>
                 <?php endif; ?>
             </div>
         </div>
     <?php endif; ?>
     <?php if (true) : ?>
         <div class="card">
             <h2>Метод GetCardList</h2>
             <div class="article">
                 <?php
                 $params = array(
                     'CustomerKey' => '5',
                 );
                 $api->getCardList($params);
                 ?>
                 <p><span class="highlight">Response</span>: <?php echo $api->         response ?></p>
                 <?php if ($api->error) : ?>
                     <p><span class="error"><?php echo $api->error ?></span></p>
                 <?php else: ?>
                     <p><span class="highlight">CustomerKey</span>: <?php echo $         api->customerKey ?></p>
                 <?php endif; ?>
             </div>
         </div>
     <?php endif; ?>
     <?php if (true) : ?>
         <div class="card">
             <h2>Метод RemoveCard</h2>
             <div class="article">
                 <?php
                 $params = array(
                     'CardId' => '10804',
                     'CustomerKey' => '5',
                 );
                 $api->removeCard($params);
                 ?>
                 <p><span class="highlight">Response</span>: <?php echo $api->         response ?></p>
                 <?php if ($api->error) : ?>
                     <p><span class="error"><?php echo $api->error ?></span></p>
                 <?php else: ?>
                     <p><span class="highlight">CustomerKey</span>: <?php echo $         api->customerKey ?></p>
                 <?php endif; ?>
             </div>
         </div>
     <?php endif; ?>
     </body>
     </html>         

TinkoffMerchantAPI.php - внизу идет отправка через cURL

     <?php
     /**
      * File TinkoffMerchantAPI
      *
      * PHP version 5.3
      *
      * @category Tinkoff
      * @package  Tinkoff
      * @author   Shuyskiy Sergey <s.shuyskiy@tinkoff.ru>
      * @license  http://opensource.org/licenses/MIT MIT license
      * @link     http://tinkoff.ru
      */
     //namespace Tinkoff;
     //use HttpException;
     /**
      * Class TinkoffMerchantAPI
      *
      * @category Tinkoff
      * @package  Tinkoff
      * @author   Shuyskiy Sergey <s.shuyskiy@tinkoff.ru>
      * @license  http://opensource.org/licenses/MIT MIT license
      * @link     http://tinkoff.ru
      * @property integer     orderId
      * @property integer     Count
      * @property bool|string error
      * @property bool|string response
      * @property bool|string customerKey
      * @property bool|string status
      * @property bool|string paymentUrl
      * @property bool|string paymentId
      */
     class TinkoffMerchantAPI
     {
         private $_api_url;
         private $_terminalKey;
         private $_secretKey;
         private $_paymentId;
         private $_status;
         private $_error;
         private $_response;
         private $_paymentUrl;
         /**
          * Constructor
          *
          * @param string $terminalKey Your Terminal name
          * @param string $secretKey   Secret key for terminal
          * @param string $api_url     Url for API
          */
         public function __construct($terminalKey, $secretKey, $api_url)
         {
             $this->_api_url = $api_url;
             $this->_terminalKey = $terminalKey;
             $this->_secretKey = $secretKey;
         }
         /**
          * Get class property or json key value
          *
          * @param mixed $name Name for property or json key
          *
          * @return bool|string
          */
         public function __get($name)
         {
             switch ($name) {
             case 'paymentId':
                 return $this->_paymentId;
             case 'status':
                 return $this->_status;
             case 'error':
                 return $this->_error;
             case 'paymentUrl':
                 return $this->_paymentUrl;
             case 'response':
                 return htmlentities($this->_response);
             default:
                 if ($this->_response) {
                     if ($json = json_decode($this->_response, true)) {
                         foreach ($json as $key => $value) {
                             if (strtolower($name) == strtolower($key)) {
                                 return $json[$key];
                             }
                         }
                     }
                 }
                 return false;
             }
         }
         /**
          * Initialize the payment
          *
          * @param mixed $args mixed You could use associative array or url          params string
          *
          * @return bool
          */
         public function init($args)
         {
             return $this->buildQuery('Init', $args);
         }
         /**
          * Get state of payment
          *
          * @param mixed $args Can be associative array or string
          *
          * @return mixed
          */
         public function getState($args)
         {
             return $this->buildQuery('GetState', $args);
         }
         /**
          * Confirm 2-staged payment
          *
          * @param mixed $args Can be associative array or string
          *
          * @return mixed
          */
         public function confirm($args)
         {
             return $this->buildQuery('Confirm', $args);
         }
         /**
          * Performs recursive (re) payment - direct debiting of funds from the
          * account of the Buyer's credit card.
          *
          * @param mixed $args Can be associative array or string
          *
          * @return mixed
          */
         public function charge($args)
         {
             return $this->buildQuery('Charge', $args);
         }
         /**
          * Registers in the terminal buyer Seller. (Init do it automatically)
          *
          * @param mixed $args Can be associative array or string
          *
          * @return mixed
          */
         public function addCustomer($args)
         {
             return $this->buildQuery('AddCustomer', $args);
         }
         /**
          * Returns the data stored for the terminal buyer Seller.
          *
          * @param mixed $args Can be associative array or string
          *
          * @return mixed
          */
         public function getCustomer($args)
         {
             return $this->buildQuery('GetCustomer', $args);
         }
         /**
          * Deletes the data of the buyer.
          *
          * @param mixed $args Can be associative array or string
          *
          * @return mixed
          */
         public function removeCustomer($args)
         {
             return $this->buildQuery('RemoveCustomer', $args);
         }
         /**
          * Returns a list of bounded card from the buyer.
          *
          * @param mixed $args Can be associative array or string
          *
          * @return mixed
          */
         public function getCardList($args)
         {
             return $this->buildQuery('GetCardList', $args);
         }
         /**
          * Removes the customer's bounded card.
          *
          * @param mixed $args Can be associative array or string
          *
          * @return mixed
          */
         public function removeCard($args)
         {
             return $this->buildQuery('RemoveCard', $args);
         }
         /**
          * The method is designed to send all unsent notification
          *
          * @return mixed
          */
         public function resend()
         {
             return $this->buildQuery('Resend', array());
         }
         /**
          * Builds a query string and call sendRequest method.
          * Could be used to custom API call method.
          *
          * @param string $path API method name
          * @param mixed  $args query params
          *
          * @return mixed
          * @throws HttpException
          */
         public function buildQuery($path, $args)
         {
             $url = $this->_api_url;
             if (is_array($args)) {
                 if (! array_key_exists('TerminalKey', $args)) {
                     $args['TerminalKey'] = $this->_terminalKey;
                 }
                 if (! array_key_exists('Token', $args)) {
                     $args['Token'] = $this->_genToken($args);
                 }
             }
             $url = $this->_combineUrl($url, $path);

             return $this->_sendRequest($url, $args);
         }
         /**
          * Generates token
          *
          * @param array $args array of query params
          *
          * @return string
          */
         private function _genToken($args)
         {
             $token = '';
             $args['Password'] = $this->_secretKey;
             ksort($args);
             foreach ($args as $arg) {
                 $token .= $arg;
             }
             $token = hash('sha256', $token);
             return $token;
         }
         /**
          * Combines parts of URL. Simply gets all parameters and puts '/'          between
          *
          * @return string
          */
         private function _combineUrl()
         {
             $args = func_get_args();
             $url = '';
             foreach ($args as $arg) {
                 if (is_string($arg)) {
                     if ($arg[strlen($arg) - 1] !== '/') {
                         $arg .= '/';
                     }
                     $url .= $arg;
                 } else {
                     continue;
                 }
             }
             return $url;
         }
         /**
          * Main method. Call API with params
          *
          * @param string $api_url API Url
          * @param array  $args    API params
          *
          * @return mixed
          * @throws HttpException
          */
         private function _sendRequest($api_url, $args)
         {
             $this->_error = '';
             //todo add string $args support
             //$proxy = 'http://192.168.5.22:8080';
             //$proxyAuth = '';
             if (is_array($args)) {
                 $args = http_build_query($args);
             }
             Debug::trace($args);

             if ($curl = curl_init()) {
                 curl_setopt($curl, CURLOPT_URL, $api_url);
                 curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type:          application/json; charset=UTF-8"));
                 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                 curl_setopt($curl, CURLOPT_POST, 1);  
                 curl_setopt($curl, CURLOPT_POSTFIELDS, $args);
                 $out = curl_exec($curl);
                 var_dump($out);
                 $this->_response = $out;
                 $json = json_decode($out);
                 if ($json) {
                     if (@$json->ErrorCode !== "0") {
                         $this->_error = @$json->Details;
                     } else {
                         $this->_paymentUrl = @$json->PaymentURL;
                         $this->_paymentId = @$json->PaymentId;
                         $this->_status = @$json->Status;
                     }
                 }
                 curl_close($curl);
                 return $out;
             } else {
                 throw new HttpException(
                     'Can not create connection to ' . $api_url . ' with args '
                     . $args, 404
                 );
             }
         }
     }

и Debug.php

    <?php
    class Debug {
        private static $logfile = 'log.txt';
        public static function trace($arg = null, $die = false){
            if (!$arg) $arg = '';
            $arg = print_r($arg, true);
            echo '<pre>' . $arg . '</pre>';
            if ($die) die();
        }
        public static function log($arg = null, $die = false)
        {
            if (!$arg) return false;
            if ( ! is_string($arg)) {
                $arg = print_r($arg, true);
            }
            file_put_contents(self::$logfile, $arg);
            if ($die) die();
            return true;
        }
    }        
READ ALSO
Как реализовать отправку таблицы на php? Работа с тегами

Как реализовать отправку таблицы на php? Работа с тегами

Возможно ли в PHP работать с тегом <tabel> также как и с тегом <form>? То есть делать формы регистрации, менять значения в БД и тд

266
Хитрый SQL запрос

Хитрый SQL запрос

Есть две таблицы users и ticketВ users хранится информация о пользователях

253
wordpress не работают checkbox&#39;ы

wordpress не работают checkbox'ы

Пишу плагин под впВ каждом посте есть метабокс и чекбоксами (пока сделал только один чекбокс)

222
Неправильная кодировка в БД

Неправильная кодировка в БД

Записывал данные в бд, русские символы как обычно превращались в "кракозябру"Дописал строчку

183