public function onAfterPayment(&$PaymentResponse, $IDPaymentMethod) { // Registrando la clase de Place To Pay para la encriptacion JLoader::register('PlacetoPay', JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_p2p' . DS . 'library' . DS . 'EGM' . DS . 'PlacetoPay.php'); switch ($IDPaymentMethod) { case 'P2P': $params = JComponentHelper::getParams('com_p2p'); if (!$PaymentResponse instanceof PlacetoPay) { $p2p = new PlacetoPay(); $p2p->setGPGProgramPath($params->get('gpg_path', '/usr/bin/gpg')); $p2p->setGPGHomeDirectory($params->get('gpg_dir', '')); $KeyID = $params->get('cust_keyid', ''); $Passprhase = $params->get('passprhase', ''); $RecipientKeyID = $params->get('p2p_keyid', ''); $rc = $p2p->getPaymentResponse($RecipientKeyID, $Passprhase, $PaymentResponse); } else { $p2p = $PaymentResponse; $rc = $p2p->_rc; } $recloc = $p2p->getReference(); //if(!$model->savePayment($order->order->id, $PaymentResponse, $p2p->getAuthorization())) //throw new Exception($model->getError()); $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $status = ''; switch ($rc) { case PlacetoPay::P2P_ERROR: $data = array('status' => $params->get('st_failed', '')); $status = JText::_('AOM_P2P_ERROR'); $note = $p2p->getErrorCode() . ' - ' . $p2p->getErrorMessage() . ' ' . ($ip != '' ? '/ IP ' . $ip : ''); break; case PlacetoPay::P2P_DECLINED: $data = array('status' => $params->get('st_rejected', '')); $status = JText::_('AOM_P2P_DECLINED'); $note = $p2p->getErrorCode() . ' - ' . $p2p->getErrorMessage() . ' ' . ($ip != '' ? '/ IP ' . $ip : ''); break; case PlacetoPay::P2P_APPROVED: case PlacetoPay::P2P_DUPLICATE: case PlacetoPay::P2P_PENDING: if (PlacetoPay::P2P_PENDING == $rc) { $data = array('status' => $params->get('st_pendent', '')); $status = JText::_('AOM_P2P_PENDING'); // Si se ejecuta mediante el cron, no guarda ordenes pendinetes if (php_sapi_name() == 'cli') { return true; } } else { $data = array('status' => $params->get('st_paid', '')); $status = JText::_('AOM_P2P_APPROVED'); } if ($p2p->getCreditCardNumber() == '') { $note = $p2p->getBankName() . ' - ' . $p2p->getReceipt(); } else { $note = $p2p->getFranchise() . '-' . $p2p->getFranchiseName() . ' / Auth. ' . $p2p->getAuthorization() . ' / CCard. ***' . substr($p2p->getCreditCardNumber(), -4); } $note .= ' / ' . $p2p->getShopperName() . '<' . $p2p->getShopperEmail() . '> ' . ($ip != '' ? '/ IP ' . $ip : ''); break; } // Directorio que contiene la libreria que consta de interfaces y clases para // integrarse con el AmadeuS Order Manager $library = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_asom' . DS . 'library'; // Se registra el directorio, para que dinamicamente cargue las clases necesarias. JLoader::registerPrefix('Asom', $library); $order = new AsomClassOrder(array('recloc' => $recloc)); // Se envia la informacion del pago, para que se guarde $extra = $p2p->getExtraData(); $extra = explode('|', $extra); $extra = count($extra) == 2 ? $extra : array(0, 0); $paymentInfo = array('id' => 0, 'company' => $params->get('name', ''), 'nit' => $params->get('nit', ''), 'reason' => $p2p->getErrorCode() . ' - ' . $p2p->getErrorMessage(), 'fare' => $p2p->getTotalAmount(), 'airportfare' => (double) $extra[1], 'fee' => (double) $extra[0], 'currency' => $p2p->getCurrency(), 'franchise' => $p2p->getFranchise(), 'franchiseName' => $p2p->getFranchiseName(), 'creditCardNumber' => substr($p2p->getCreditCardNumber(), -4), 'bank' => $p2p->getBankName(), 'cus' => $p2p->getAuthorization(), 'receipt' => $p2p->getReceipt(), 'reference' => $p2p->getReference(), 'description' => $params->get('name', '') . ' - ' . $params->get('website', '') . ' - ' . $p2p->getReference(), 'ip' => $ip, 'customer' => $p2p->getShopperName(), 'customerEmail' => $p2p->getShopperEmail(), 'status' => $status, 'statusCode' => $rc, 'fectrans' => $p2p->getTransactionDate()); $order->savePayment($paymentInfo); if (!$order->updateOrder($data, $note, -1)) { return false; } $issue = $this->params->get('issue', 0); if ($issue && (PlacetoPay::P2P_APPROVED || PlacetoPay::P2P_DUPLICATE)) { $ok = $this->params->get('st_succesful', 1); $error = $this->params->get('st_error', 1); $issue = new AsomClassIssue(); if ($p2p->getCreditCardNumber() == '') { $issue->setPaymentMethod('CA', 0); } else { $cards = array('CR_VS' => 'VI', 'CR_AM' => 'AX', 'RM_MC' => 'CA'); $issue->setPaymentMethod('CC', 0, array('card' => $p2p->getCreditCardNumber(), 'code' => $cards[$p2p->getFranchise()], 'approval' => $p2p->getAuthorization())); } if (!$issue->issue($recloc, array('card' => $p2p->getCreditCardNumber(), 'code' => $cards[$p2p->getFranchise()], 'approval' => $p2p->getAuthorization()))) { $data = array('status' => $error); $note = JText::_('AOM_ISSUE_ERROR') . $issue->getMessage(); } else { $data = array('status' => $ok); $tickets = $issue->getTickets(); $note = JText::_('AOM_ISSUE_OK') . $tickets; } if (!$order->updateOrder($data, $note, -1)) { return false; } } // Si se ejecuta mediante el cron, no redirecciona a ningun lado if (php_sapi_name() == 'cli') { return true; } $config = JFactory::getConfig(); $app = JFactory::getApplication(); $id = $order->getOrder()->id; $code = sha1($id . $config->getValue('config.secret')); $link = JRoute::_('index.php?option=com_asom&task=orders.resume&order=' . $id, false); if ($app->setUserState('asom.code', $code) == null) { // Fallback si no se puede guardar el dato en el registro $_SESSION['asom'] = array('code' => $code); } $app->redirect($link); break; } return true; }
public function retry() { $order = (int) JRequest::getVar('order', '', 'post'); //Se valida que exista un hash con la orden generada, para mostrar asi el resultado, y evitar //que otros usuarios vean otras ordenes $code = JFactory::getApplication()->getUserState('asom.code', ''); $config = new JConfig(); $secret = sha1($order . $config->secret); if ($order != 0 && $secret == $code) { // Directorio que contiene la libreria que consta de interfaces y clases para // integrarse con el AmadeuS Order Manager $library = JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_asom' . DS . 'library'; // Se registra el directorio, para que dinamicamente cargue las clases necesarias. JLoader::registerPrefix('Asom', $library); $order = new AsomClassOrder($order); // Se obtiene la informacion relevante para el pago // de la orden $data = $order->getOrder(); $paymentInfo = $order->getPaymentValues(); // Se termina de completar el objeto $paymentInfo->Reference = $data->recloc; $paymentInfo->AirlineCode = $data->provider; // Se indica si el vuelo es nacional o internacional $paymentInfo->isNational = $order->isNational(); // Se llaman todos los plugins que se tengan instalados para // el validaciones antes del pago JPluginHelper::importPlugin('amadeus'); $dispatcher = JDispatcher::getInstance(); $paymentMethod = JRequest::getVar('payment', '', 'post'); $answer = $dispatcher->trigger('onBeforePayment', array($paymentInfo, $paymentMethod)); $app = JFactory::getApplication(); if (!count($answer)) { $app->redirect('index.php', JText::_('ORDER_SAVE')); } elseif (in_array(false, $answer, true)) { $app->redirect('index.php', JText::_('PAYMENT ERROR'), 'error'); } return true; } else { JFactory::getApplication()->redirect('index.php', JText::_('ORDER IS NOT VALID, TRY AGAIN'), 'error'); } }
/** * La funcion valida que existan plugins para realizar el pago * y organiza la información para enviarsela al plugin */ private function _afterSave() { // Se obtiene el objeto que representa la orden $order = new AsomClassOrder($this->_order); // Se obtiene la informacion relevante para el pago // de la orden $data = $order->getOrder(); $paymentInfo = $order->getPaymentValues(); // Se termina de completar el objeto $paymentInfo->Reference = $data->recloc; $paymentInfo->AirlineCode = $data->provider; // Se indica si el vuelo es nacional o internacional $paymentInfo->isNational = $order->isNational(); // Se llaman todos los plugins que se tengan instalados para // el validaciones antes del pago JPluginHelper::importPlugin('amadeus'); $dispatcher = JDispatcher::getInstance(); $answer = $dispatcher->trigger('onBeforePayment', array($paymentInfo, $this->_delegate->getIDPaymentMethod())); $app = JFactory::getApplication(); if (!count($answer)) { $app->redirect('index.php', JText::_('ORDER_SAVE')); } elseif (in_array(false, $answer, true)) { $app->redirect('index.php', JText::_('PAYMENT ERROR'), 'error'); } return true; }
public function status() { try { $order = JRequest::getVar('cid', array(), 'array', 'post'); if (!is_array($order) || !isset($order[0]) || !is_numeric($order[0])) { throw new Exception(JText::_('AOM_DATA_MISTAKE')); } $order = $order[0]; $note = JRequest::getVar('note', '', 'string', 'post'); if ($note == '') { throw new Exception(JText::_('AOM_DATA_MISTAKE')); } $status = JRequest::getVar('status', 0, 'int', 'post'); if ($status == 0) { throw new Exception(JText::_('AOM_DATA_MISTAKE')); } $library = JPATH_COMPONENT . DS . 'library'; // Se registra el directorio, para que dinamicamente cargue las clases necesarias. JLoader::registerPrefix('Asom', $library); $order = new AsomClassOrder($order); $data = array('status' => $status); if (!$order->updateOrder($data, $note)) { throw new Exception(JText::_('AOM_ERROR_UPDATE_PROCESS')); } $type = ''; $message = JText::_('AOM_STATUS_CHANGED'); } catch (Exception $e) { $type = 'error'; $message = $e->getMessage(); } $model = $this->getModel('orders'); $link = JRoute::_($model->getUrl(), false); $this->setRedirect($link, $message, $type); }