public function addFilter($filterName, $filterClass, $filterElementName = '') { if (!isset($this->_filters[$filterName]) && class_exists($filterClass)) { $this->_filters[$filterName] = new $filterClass($this->_pixie); $elementName = empty($filterElementName) ? $this->_filters[$filterName]->getFieldName() : $filterElementName; $postData = $this->_request->post($elementName); $value = !empty($postData) ? $postData : $this->_request->get($elementName); $this->_filters[$filterName]->setValue($value); } }
/** * @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; }