Example #1
0
 /**
  * @param Request $request
  * @return ProcessResult
  * @throws HttpException
  * @throws NotFoundException
  * @throws \Exception
  */
 public function processResponse(Request $request)
 {
     if ($request->method != 'POST') {
         throw new HttpException("Должен использоваться POST-запрос");
     }
     $data = $request->post();
     $orderUid = trim($data['ORDER']);
     $transactionType = (int) trim($data['TRTYPE']);
     if (!$orderUid) {
         throw new HttpException("Отсутствует идентификатор заказа.");
     }
     if (!is_numeric(trim($data['RESULT'])) || !is_numeric(trim($data['RC'])) || !trim($data['RRN']) || !trim($data['INT_REF'])) {
         throw new HttpException("Некорректный запрос.");
     }
     /** @var Order $orderModel */
     $orderModel = $this->pixie->orm->get('Order');
     $order = $orderModel->getByUid($orderUid);
     if (!$order || !$order->payment || !$order->payment->loaded()) {
         throw new NotFoundException("Заказ или платёж отсутствует.");
     }
     if (!in_array($transactionType, PaymentOperation::getTypes())) {
         throw new HttpException("Некорректный тип операции: {$transactionType}");
     }
     $operation = $order->payment->payment_operation;
     //var_dump($operation->as_array(), $order->payment->as_array()); exit;
     if (!$operation || !$operation->loaded()) {
         throw new HttpException("Отсутствует операция оплаты для платежа {$order->payment->id}");
     }
     if (!$this->checkFieldsMatch($order, $order->payment, $operation, $data)) {
         $message = 'Ошибка при проверке полей запроса.';
         if ($this->pixie->config->get('parameters.display_errors')) {
             $message = "Поля не совпадают. Указанные поля: " . var_export($data, true) . "\nОжидаемые: " . implode(', ', [$order->amount, $order->payment->currency, $operation->merchant_name, $operation->terminal]);
         }
         throw new HttpException($message);
     }
     $this->validateOperationState($operation, $data);
     $result = (trim($data['RESULT']) == '0' || trim($data['RESULT']) == '1') && trim($data['RC']) == '00';
     $processResult = new ProcessResult();
     $processResult->setOrder($order);
     $processResult->setOperation($operation);
     $processResult->setResult($result);
     return $processResult;
 }
Example #2
0
 /**
  * @param Request $request
  * @return ProcessResult
  * @throws HttpException
  * @throws NotFoundException
  * @throws \Exception
  */
 public function processResponse(Request $request)
 {
     $user = $this->pixie->auth->user();
     if (!$user) {
         throw new ForbiddenException();
     }
     $orderUid = $request->get('order_id');
     if (!$orderUid) {
         throw new ForbiddenException();
     }
     /** @var Order $orderModel */
     $orderModel = $this->pixie->orm->get('order');
     $order = $orderModel->getByUid($orderUid);
     if (!$order) {
         throw new NotFoundException("Заказа с таким ID не существует.");
     }
     if ($order->customer->id() != $user->id()) {
         throw new NotFoundException("Заказа с таким ID не существует.");
     }
     if (!$order->isPayable()) {
         throw new ForbiddenException("Заказ №" . $orderUid . " не может быть оплачен.");
     }
     $operation = $order->payment->payment_operation;
     //var_dump($operation->as_array(), $order->payment->as_array()); exit;
     if (!$operation || !$operation->loaded()) {
         throw new HttpException("Отсутствует операция оплаты для платежа {$order->payment->id}");
     }
     $info = $this->checkOrderStatus($order);
     $this->validateOperationState($operation, $info);
     $processResult = new ProcessResult();
     $processResult->setOrder($order);
     $processResult->setOperation($operation);
     $processResult->setTransactionType($operation->getTransactionType());
     $processResult->setResult(true);
     return $processResult;
 }