Esempio n. 1
0
 /**
  * платеж по токену (рекарринг)
  *
  * @param $order_id
  * @param $token
  * @param $amount
  * @param $number
  *
  * @param string $key
  *
  * @return object
  */
 public function payByToken($order_id, $token, $amount, $number, $key = null)
 {
     $user = $this->ContrInfo($key);
     $url = Config::get('cloud.url');
     $post = ['Amount' => $amount, 'Currency' => 'RUB', 'InvoiceId' => $order_id, 'Description' => 'Оплата в dryharder.me заказа №' . $number, 'AccountId' => $user['id'], 'Email' => $user['email'], 'Token' => $token];
     Reporter::payTokenRequest($user['id'], $order_id, $url, $post);
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
     curl_setopt($ch, CURLOPT_USERPWD, Config::get('cloud.PublicId') . ':' . Config::get('cloud.SecretKey'));
     $result = curl_exec($ch);
     $error = curl_error($ch);
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     $response = @json_decode($result);
     $model = null;
     $paySuccess = false;
     Reporter::payTokenResponse($user['id'], $order_id, $result, $response, $error);
     // есть нормальный ответ
     if (!$error && !empty($response) && is_object($response)) {
         // информация о транзакции
         if (!empty($response->Model)) {
             $model = $response->Model;
         }
         // ошибка
         if ($response->Success) {
             $paySuccess = true;
         } else {
             $message = $response->Model->CardHolderMessage;
             $error = $message > '' ? $message : 'Ошибка операции в платежной системе';
         }
     }
     if ($paySuccess) {
         Reporter::payTokenSuccess($user['id'], $order_id, $model);
         return (object) ['success' => true, 'message' => 'Успешная оплата'];
     }
     if ($code != 200) {
         $error = trim($error . ' [code=' . $code . ']');
     }
     Reporter::payTokenError($user['id'], $order_id, $error, $model);
     return (object) ['success' => false, 'message' => $error];
 }