Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.67 KB | None | 0 0
  1. <?php
  2. /**
  3.  * PagSeguro Transparente Magento
  4.  * Test Controller responsible for diagnostics, usually when you ask for support
  5.  * It helps our team to detect misconfiguration and other problems when you ask for help
  6.  *
  7.  * @category    RicardoMartins
  8.  * @package     RicardoMartins_PagSeguro
  9.  * @author      Ricardo Martins
  10.  * @copyright   Copyright (c) 2017 Ricardo Martins (http://r-martins.github.io/PagSeguro-Magento-Transparente/)
  11.  * @license     https://opensource.org/licenses/MIT MIT License
  12.  */
  13. class RicardoMartins_PagSeguro_TestController extends Mage_Core_Controller_Front_Action
  14. {
  15.     /**
  16.      * Bring us some information about the module configuration and version info.
  17.      * You can remove it, but can make our team to misjudge your configuration or problem.
  18.      */
  19.     public function getConfigAction()
  20.     {
  21.         $info = array();
  22.         $helper = Mage::helper('ricardomartins_pagseguro');
  23.         $pretty = ($this->getRequest()->getParam('pretty', true) && version_compare(PHP_VERSION, '5.4', '>='))?128:0;
  24.  
  25.         $info['RicardoMartins_PagSeguro']['version'] = (string)Mage::getConfig()
  26.                                                         ->getModuleConfig('RicardoMartins_PagSeguro')->version;
  27.         $info['RicardoMartins_PagSeguro']['debug'] = Mage::getStoreConfigFlag('payment/rm_pagseguro/debug');
  28.         $info['RicardoMartins_PagSeguro']['sandbox'] = Mage::getStoreConfigFlag('payment/rm_pagseguro/sandbox');
  29.         $info['configJs'] = json_decode($helper->getConfigJs());
  30.  
  31.         if (Mage::getConfig()->getModuleConfig('RicardoMartins_PagSeguroPro')) {
  32.             $info['RicardoMartins_PagSeguroPro']['version'] = (string)Mage::getConfig()
  33.                                                         ->getModuleConfig('RicardoMartins_PagSeguroPro')->version;
  34.  
  35.             $keyType = $helper->getLicenseType();
  36.             $info['RicardoMartins_PagSeguroPro']['key_type'] = ($keyType)==''?'assinatura':$keyType;
  37.             $info['RicardoMartins_PagSeguroPro']['key_validation'] = $this->_validateKey();
  38.  
  39.         }
  40.  
  41.         $info['compilation'] = $this->_getCompilerState();
  42.  
  43.         $info['token_consistency'] = $this->_getTokenConsistency();
  44.         $info['session_id'] = $helper->getSessionId();
  45.         $info['retry_active'] = $helper->isRetryActive();
  46.  
  47.         $modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
  48.         $coreHelper = Mage::helper('core');
  49.         foreach ($modules as $module) {
  50.             if (false !== strpos(strtolower($module), 'pagseguro') && $coreHelper->isModuleEnabled($module)) {
  51.                 $info['pagseguro_modules'][] = $module;
  52.             }
  53.         }
  54.         $this->getResponse()->setHeader('Content-type', 'application/json');
  55.         $this->getResponse()->setBody(json_encode($info, $pretty));
  56.  
  57.     }
  58.  
  59.     /**
  60.      * Validates your PRO key. Only for tests purposes.
  61.      * @return mixed|string
  62.      */
  63.     private function _validateKey()
  64.     {
  65.         $key = Mage::getStoreConfig('payment/pagseguropro/key');
  66.         if (empty($key)) {
  67.             return 'KEY IS EMPTY';
  68.         }
  69.             $url = 'http://ws.ricardomartins.net.br/pspro/v6/auth/' . $key;
  70.  
  71.         $ch = curl_init();
  72.         curl_setopt($ch, CURLOPT_URL, $url);
  73.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  74.         curl_setopt($ch, CURLOPT_TIMEOUT, 45);
  75.         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  76.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  77.         libxml_use_internal_errors(true);
  78.  
  79.         return curl_exec($ch);
  80.     }
  81.  
  82.     /**
  83.      * Get compilation config details
  84.      * @return array
  85.      */
  86.     private function _getCompilerState()
  87.     {
  88.         $compiler = Mage::getModel('compiler/process');
  89.         $compilerConfig = MAGENTO_ROOT . '/includes/config.php';
  90.  
  91.         if (file_exists($compilerConfig) && !(defined('COMPILER_INCLUDE_PATH') || defined('COMPILER_COLLECT_PATH'))) {
  92.             include $compilerConfig;
  93.         }
  94.         $status = defined('COMPILER_INCLUDE_PATH') ? 'Enabled' : 'Disabled';
  95.         $state  = $compiler->getCollectedFilesCount() > 0 ? 'Compiled' : 'Not Compiled';
  96.         return array(
  97.           'status' => $status,
  98.           'state'  => $state,
  99.           'files_count' => $compiler->getCollectedFilesCount(),
  100.           'scopes_count' => $compiler->getCompiledFilesCount()
  101.         );
  102.     }
  103.  
  104.     /**
  105.      * @return string
  106.      */
  107.     private function _getTokenConsistency()
  108.     {
  109.         $token = Mage::helper('ricardomartins_pagseguro')->getToken();
  110.         return (strlen($token)!=32)?'Wrong size':'Good';
  111.     }
  112.  
  113.     public function testSenderHashAction()
  114.     {
  115. //        $paymentPost = $this->getRequest()->getPost('payment');
  116. //        $isAdmin = isset($paymentPost['is_admin']) && $paymentPost['is_admin']=="true";
  117. //        $session = 'checkout/session';
  118. //        if ($isAdmin) {
  119. //            $session = 'core/cookie';
  120. //            Mage::getSingleton($session)->set('PsPayment', serialize($paymentPost));
  121. //        } else {
  122. //            Mage::getSingleton($session)->setData('PsPayment', serialize($paymentPost));
  123. //        }
  124. //        Mage::log(var_export($paymentPost, true), null, 'martins.log', true);
  125. //
  126. //
  127. //        $this->getResponse()->setHttpResponseCode(200);
  128.  
  129.  
  130.  
  131.         // pegando sender hash
  132.         $isAdmin = Mage::app()->getStore()->isAdmin();
  133.         $session = ($isAdmin)?'core/cookie':'checkout/session';
  134.         $registry = Mage::getSingleton($session);
  135.  
  136.         $registry = ($isAdmin)?$registry->get('PsPayment'):$registry->getData('PsPayment');
  137.  
  138.         $registry = unserialize($registry);
  139.  
  140.         Mage::log('Registry:' . var_export($registry, true), null, 'martins.log', true);
  141.  
  142.  
  143.  
  144.     }
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement