예제 #1
0
파일: paypal.php 프로젝트: ramsam5/paypal
 public function hookAdminOrder($params)
 {
     if (Tools::isSubmit('submitPayPalCapture')) {
         if ($capture_amount = Tools::getValue('totalCaptureMoney')) {
             if ($capture_amount = PaypalCapture::parsePrice($capture_amount)) {
                 if (Validate::isFloat($capture_amount)) {
                     $capture_amount = Tools::ps_round($capture_amount, '6');
                     $ord = new Order((int) $params['id_order']);
                     $cpt = new PaypalCapture();
                     if ($capture_amount > Tools::ps_round(0, '6') && Tools::ps_round($cpt->getRestToPaid($ord), '6') >= $capture_amount) {
                         $complete = false;
                         if ($capture_amount > Tools::ps_round((double) $ord->total_paid, '6')) {
                             $capture_amount = Tools::ps_round((double) $ord->total_paid, '6');
                             $complete = true;
                         }
                         if ($capture_amount == Tools::ps_round($cpt->getRestToPaid($ord), '6')) {
                             $complete = true;
                         }
                         $this->_doCapture($params['id_order'], $capture_amount, $complete);
                     }
                 }
             }
         }
     } elseif (Tools::isSubmit('submitPayPalRefund')) {
         $this->_doTotalRefund($params['id_order']);
     }
     $admin_templates = array();
     if ($this->isPayPalAPIAvailable()) {
         if ($this->_needValidation((int) $params['id_order'])) {
             $admin_templates[] = 'validation';
         }
         if ($this->_needCapture((int) $params['id_order'])) {
             $admin_templates[] = 'capture';
         }
         if ($this->_canRefund((int) $params['id_order'])) {
             $admin_templates[] = 'refund';
         }
     }
     if (count($admin_templates) > 0) {
         $order = new Order((int) $params['id_order']);
         $currency = new Currency($order->id_currency);
         $cpt = new PaypalCapture();
         $cpt->id_order = (int) $order->id;
         if (version_compare(_PS_VERSION_, '1.5', '>=')) {
             $order_state = $order->current_state;
         } else {
             $order_state = OrderHistory::getLastOrderState($order->id);
         }
         $this->context->smarty->assign(array('authorization' => (int) Configuration::get('PAYPAL_OS_AUTHORIZATION'), 'base_url' => _PS_BASE_URL_ . __PS_BASE_URI__, 'module_name' => $this->name, 'order_state' => $order_state, 'params' => $params, 'id_currency' => $currency->getSign(), 'rest_to_capture' => Tools::ps_round($cpt->getRestToPaid($order), '6'), 'list_captures' => $cpt->getListCaptured(), 'ps_version' => _PS_VERSION_));
         foreach ($admin_templates as $admin_template) {
             $this->_html .= $this->fetchTemplate('/views/templates/admin/admin_order/' . $admin_template . '.tpl');
             $this->_postProcess();
             $this->_html .= '</fieldset>';
         }
     }
     return $this->_html;
 }