*/ /** * Klasa stPlatnosciPlFrontendActions * * @package stPlatnosciPlPlugin * @subpackage actions */ class stPlatnosciPlFrontendActions extends stActions { /** * Pozytywny powrót z płatności */ public function executeReturnSuccess() { if ($this->hasRequestParameter('error')) { return $this->redirect('@stPlatnosciPlPlugin?action=returnFail'); } $this->smarty = new stSmarty($this->getModuleName()); } /** * Negatywny powrót z płatności */ public function executeReturnFail() { $this->smarty = new stSmarty($this->getModuleName()); $webpage = WebpagePeer::retrieveByState('CONTACT'); if ($webpage) { sfLoader::loadHelpers(array('Helper', 'stUrl')); $this->smarty->assign('contact_url', st_url_for('stWebpageFrontend/index?url='.$webpage->getFriendlyUrl())); } } public function executeProcessPayment() { $this->smarty = new stSmarty('stPlatnosciPlFrontend'); $api = new stPlatnosciPl(); $order = OrderPeer::retrieveByIdAndHashCode($this->getRequestParameter('id'), $this->getRequestParameter('hash')); try { $url = $api->getOrderFormUrl($order); if ($url) { return $this->renderJSON(array('redirect' => $url)); } } catch (OpenPayU_Exception $e) { stPlatnosciPl::log("Process Payment - Exception: in file ".$e->getFile().' on line '.$e->getLine().' with message'.$e->getMessage()); } sfLoader::loadHelpers(array('Helper', 'stUrl')); return $this->renderJSON(array('redirect' => st_url_for('stPlatnosciPlFrontend/returnFail?type=process'))); } /** * Odbieranie statusu transakcji */ public function executeStatusReport() { $body = file_get_contents('php://input'); $data = trim($body); stPlatnosciPl::log("Status Report Request: ".$data); $api = new stPlatnosciPl(); try { $order = $api->getOrderNotify($data); } catch (OpenPayU_Exception $e) { stPlatnosciPl::log("Process Payment - Exception: in file ".$e->getFile().' on line '.$e->getLine().' with message'.$e->getMessage()); throw $e; } if ($order && $order->status == 'COMPLETED') { $payment_id = null; if ($this->hasRequestParameter('id')) { $order = OrderPeer::retrieveByIdAndHashCode($this->getRequestParameter('id'), $this->getRequestParameter('hash')); if (null !== $order) { $payment = $order->getOrderPayment(); if (!$payment) { stPlatnosciPl::log("Status Report: Payment for order id {$this->getRequestParameter('id')} does not exist"); } } else { stPlatnosciPl::log("Status Report: Order with id {$this->getRequestParameter('id')} does not exist"); } } else { list($id) = explode(':', $order->extOrderId); $payment = PaymentPeer::retrieveByPK($id); if (!$payment) { stPlatnosciPl::log("Status Report: Payment with id $id does not exist"); } } if ($payment) { $payment->setStatus(true); $payment->save(); stPlatnosciPl::log("Status Report: Payment with id {$payment->getId()} paid successfully"); } } return $this->renderText('OK'); } }