public function getmpinitpointAction() { $this->_helper->layout->setLayout('json'); $callback = $this->getRequest()->getParam('jsoncallback'); if ($callback != "") { // strip all non alphanumeric elements from callback $callback = preg_replace('/[^a-zA-Z0-9_]/', '', $callback); } $this->view->callback = $callback; $json_preference = $this->_getParam('data'); $json_preference['items']['0']['quantity'] = (int) $json_preference['items']['0']['quantity']; $json_preference['items']['0']['unit_price'] = (double) $json_preference['items']['0']['unit_price']; $json_preference['payment_methods']['installments'] = (int) $json_preference['payment_methods']['installments']; $mp = new PAP_MP($this->_MP_client_id, $this->_MP_client_secret); $preferenceResult = $mp->create_preference($json_preference); $json = json_encode(array('status' => 'OK', 'body' => $preferenceResult["response"]["sandbox_init_point"])); $response = $this->getFrontController()->getResponse(); $response->appendBody($callback . '(' . $json . ')'); $this->getFrontController()->setResponse($response); }
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. } }