/** * Notification action. */ public function indexAction() { if (!$this->_validateRequest()) { $this->_redirect(''); return; } $token = $this->getRequest()->getParam('token'); $reference = $this->getRequest()->getParam('reference'); $status = $this->getRequest()->getParam('status'); $amount = $this->getRequest()->getParam('amount'); $transactionId = $this->getRequest()->getParam('transactionId'); $this->_logger()->notificationLog($this->getRequest()->getParams()); if (!$status || !$reference || !$token) { $this->_redirect(''); return; } $this->_logger()->setFilename('RedeClickPag_Notification_Params'); $this->_logger()->startTransactionLog($reference); $this->_logger()->log($this->getRequest()->getParams()); $this->_logger()->finishTransactionLog($reference); $statuses = Rede_ClickPag_Model_Api::getAllowedStatuses(); $configToken = $this->_helper()->getConfigNotificationToken(); if ($token != $configToken || !in_array($status, $statuses)) { $this->_redirect(''); return; } /** @var Mage_Sales_Model_Order $order */ $order = Mage::getModel('sales/order')->loadByIncrementId(trim($reference)); if (!$reference || !$order->getId()) { $this->_redirect(''); return; } /** @var Rede_ClickPag_Model_Payments $payments */ $payments = Mage::getModel('rede_clickpag/payments'); $payments->loadByOrderId($order->getId())->setTransactionId($transactionId)->save(); $this->getApi()->consult($transactionId, $order); $body = is_array($this->getApi()->getBody()) ? $this->getApi()->getBody() : array(); $processType = Rede_ClickPag_Model_Processor_Order::PROCESS_TYPE_NOTIFICATION; $this->_helper()->processOrderConsultStatus($order, $status, $body, $processType); }
/** * @param Rede_ClickPag_Model_Api $api * * @return $this */ protected function _validateRefundResult(Rede_ClickPag_Model_Api $api) { /** * If request was not authorized in ClickPag. */ if ($api->getResult()->getStatus() === 401) { $message = $this->_helper()->__('This request was Unauthorized by Clickpag.'); Mage::throwException($message); } /** * If order was not found in ClickPag. */ if ($api->getResult()->getStatus() === 404) { $message = $this->_helper()->__('This order was not found in ClickPag.'); Mage::throwException($message); } /** * Any other error. */ $status = (int) $api->getResult()->getStatus(); $okCodes = array(200, 201, 202, 204); if (!in_array($status, $okCodes) && Mage::app()->getStore()->isAdmin()) { $message = $this->_helper()->__('Some error has occurred when trying to refund the order.'); if (is_array($api->getBody())) { foreach ($api->getBody() as $error) { $this->_getAdminSession()->addError($error['message']); } } Mage::throwException($message); } return $this; }