Ejemplo n.º 1
0
 public function mpnotificationAction()
 {
     try {
         $this->_helper->layout->disableLayout();
         $this->_helper->viewRenderer->setNoRender(TRUE);
         $user_id = 0;
         if (isset($_GET['id']) && $_GET['topic'] == 'payment') {
             $notification_id = $_GET['id'];
         } else {
             throw new Exception("Se ha llamado al método mpnotification pero no se encontró el parámetro id", 10001);
         }
         //$pendigPayments = PAP_Model_Payment::getPendigPaymentsMP($user_id);
         $config = new PAP_Helper_Config();
         $MPConfig = $config->getMPConfig();
         $MPObject = new PAP_MP($MPConfig['mp_client_id'], $MPConfig['mp_client_secret']);
         $payment_info = $MPObject->get_payment_info($notification_id);
         if ($payment_info["status"] == 200) {
             $jsonPayment = json_decode($payment_info["response"]);
             $payment = new PAP_Model_Payment();
             $payment->loadByControl($jsonPayment->{'id'}, 'MP');
             $payment->setStatus($jsonPayment->{'status'});
             $charge = new PAP_Model_Charge();
             $charge->loadById($payment->getChargeId());
             $charge->setStatus($payment->getStatus());
             $payment->save();
             $charge->save();
         } else {
             throw new Exception("MP Error (" . $payment_info["status"] . ")" . $payment_info["error"] . ": " . $payment_info["message"] . " CAUSE:" . $payment_info["cause"]);
         }
     } catch (Exception $ex) {
         //TODO 4: Logear error en llamada mpnotification.
     }
 }