Advertisement
mr_therabbit

Untitled

Dec 1st, 2014
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.90 KB | None | 0 0
  1. <?php
  2.  
  3. class Payment_Controller extends Base_Controller {
  4.  
  5.     public function action_index() {
  6.         // Получим список разделов
  7.         $VL = IoC::resolve('VL');
  8.         $arrList = $VL->getRootGroups();
  9.         // Разложим на строки по 6 элементов
  10.         $arrT = array();
  11.         $intC = 0;
  12.         $intR = 1;
  13.         foreach ($arrList as $arrI) {
  14.             $intC++;
  15.             $arrT[$intR][] = $arrI;
  16.             if ($intC == 6) {
  17.                 $intC = 0;
  18.                 $intR++;
  19.             }//\\ if
  20.         }//\\ foreach
  21.        
  22.         return View::make('sd.payment')->with('arrList', $arrT);
  23.     }//\\ action_index
  24.  
  25.  
  26.     public function action_vendors($intGroupID) {
  27.         // Получим список вендоров из этого раздела
  28.         $VL = IoC::resolve('VL');
  29.         $arrList = $VL->getListVendors($intGroupID);
  30.         // Разложим на строки по 6 элементов
  31.         $arrT = array();
  32.         $intC = 0;
  33.         $intR = 1;
  34.         foreach ($arrList as $arrI) {
  35.             $intC++;
  36.             $arrT[$intR][] = $arrI;
  37.             if ($intC == 6) {
  38.                 $intC = 0;
  39.                 $intR++;
  40.             }//\\ if
  41.         }//\\ foreach
  42.        
  43.         return View::make('sd.payment_vendors')->with('arrList', $arrT);
  44.     }//\\ action_index
  45.  
  46.     public function action_pay($intAcct) {
  47.         // Получим инфу о вендоре
  48.         $VL = IoC::resolve('VL');
  49.         $arrVendor = $VL->getVendor($intAcct);
  50.        
  51.         // Получим счета и карты
  52.         $arrA = Accts::getAcctsAndCards();
  53.         if (count($arrA['accts'])) {
  54.             foreach ($arrA['accts'] as $arrT) {
  55.                 if ($arrT['Type'] == 1)
  56.                     $arrVendor['accts'][] = array(
  57.                         'Acct' => $arrT['Acct'],
  58.                         'AcctNum' => $arrT['AcctNum'],
  59.                         'Available' => Utils::getMoney($arrT['Available']),
  60.                         'Currency' => $arrT['Currency'],
  61.                         'CurrencyCode' => MessagesVtbi::getCurrencyCode($arrT['Currency']),
  62.                     );
  63.             }//\\ foreach
  64.         }//\\ if
  65.        
  66.         return View::make('sd.payment_pay')->with('arrVendor', $arrVendor);
  67.     }//\\ action_index
  68.    
  69.     public function action_schedule() {
  70.         $arrResult = array();
  71.        
  72.         $strFromAcct = Input::get('OperationAcctSelect');
  73.         $intToAcct = intval(Input::get('ToAcct'));
  74.         $strAmount = floatval(Input::get('Amount'));
  75.         $strCurrency = intval(Input::get('Currency'));
  76.         $strComment = Input::get('Comment');
  77.        
  78.         $strSEQ = '';
  79.         // Получим поля от вендора
  80.         $VL = IoC::resolve('VL');
  81.         $arrVendor = $VL->getVendor($intToAcct);
  82.         if (count($arrVendor['fields'])) {
  83.             $intNum = 1;
  84.             foreach($arrVendor['fields'] as $arrField) {
  85.                 $strSEQ .= '
  86.     <Row>
  87.         <SEQ>'.$intNum.'</SEQ>
  88.         <ID>'.$arrField->name.'</ID>
  89.         <VAL>'.Input::get('FF_'.$arrField->name).'</VAL>
  90.     </Row>';
  91.                 $intNum++;
  92.             }//\\ foreach
  93.         }//\\ if
  94.        
  95.        
  96.         $strXML = '
  97. <FromAcct>'.$strFromAcct.'</FromAcct>
  98. <ToAcct>'.$intToAcct.'</ToAcct>
  99. <CustAcct>'.$strSEQ.'
  100. </CustAcct>
  101. <Amount>'.$strAmount.'</Amount>
  102. <Currency>'.$strCurrency.'</Currency>
  103. <Comment>'.$strComment.'</Comment>
  104. <Date/>
  105. <Period>0</Period>
  106. <Count>1</Count>';
  107.  
  108.         // Сделаем запрос
  109.         $TB = IoC::resolve('TWO');
  110.  
  111.         // Разберемся с SMS кодом
  112.         if (Input::has('SmsCode')) {
  113.             // Установим динамический пароль
  114.             $TB->setDynamicPassword(Input::get('SmsCode'));
  115.         }//\\ if
  116.        
  117.         try {
  118.             $objXml = $TB->exec('Schedule', $strXML);
  119.         } catch (Exception $e) {
  120.             $arrResult['responseCode'] = $e->getCode();
  121.             $arrResult['responseMessage'] = $e->getMessage();
  122.             // требуется динамическая авторизация
  123.             if ($e->getCode() == 18) {
  124.                 // Запросим список получателей динамической аунтификации
  125.                 $arrList = $TB->getDynAuthAddressList();
  126.                 $arrAuthAddress = array();
  127.                
  128.                 // Найдем активного
  129.                 if (count($arrList)) {
  130.                     foreach ($arrList as $arrItem) {
  131.                         if ($arrItem['Default'] == true)
  132.                             $arrAuthAddress = $arrItem;
  133.                     }//\\ foreach
  134.                 }//\\ if
  135.                
  136.                 if (isset($arrAuthAddress['Channel'])) {
  137.                     // Сгенерируем пароль
  138.                     $objXml = $TB->exec('GenerateDynPassword', '<Channel>'.$arrAuthAddress['Channel'].'</Channel><Address>'.$arrAuthAddress['Address'].'</Address>');
  139.                     // Получим номер SMS
  140.                     $objResult = $objXml->xpath('//PasswordCount');
  141.                     if (count($objResult)) {
  142.                         $intNumSMS = (integer)$objResult[0];
  143.                     }//\\ if
  144.                    
  145.                     $arrResult['smsNum'] = $intNumSMS;
  146.                     //return Response::make(json_encode($arrResult), 200, array('Content-type' => 'application/json'));
  147. /*                  $intCount = 3;
  148.                     if ($intCount > 99) $intCount = 99;
  149.                     $strXML = '<?xml version="1.0" encoding="utf-8" ?>
  150.                     <badge value="'.($intCount > 0 ? $intCount : 'none').'"/>';
  151.                     return Response::make($strXML, 200, array('Content-type' => 'application/xml'));*/                 
  152.                    
  153.                    
  154.                 }//\\ if
  155.             } else {
  156.                 //throw $e;
  157.             }//\\ if
  158.         }//\\ try
  159.        
  160.         return Response::make(json_encode($arrResult), 200, array('Content-type' => 'application/json'));
  161.     }
  162.  
  163.  
  164. }//\\ Payment_Controller
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement