/**
  * @brief The merchant can cancel the order or refund the customer
  */
 public function hookadminOrder($params)
 {
     if (!$this->active) {
         return false;
     }
     $order = new Order($params['id_order']);
     $cart = new Cart($order->id_cart);
     $tokenTransaction = new TokenTransaction($cart->id);
     $token = $tokenTransaction->getToken();
     if ($token == null) {
         return false;
     }
     if ($order->getCurrentState() == Configuration::get('PS_OS_CANCELED') && $tokenTransaction->getStatus() != 'CANCEL') {
         $call = new Call();
         try {
             $result = $call->voidTransaction($token);
         } catch (Exception $e) {
             $this->context->smarty->assign('error', Tools::safeOutput($e->getMessage()));
         }
         if (isset($result->VoidResult->ApprovalStatus) && strrpos($result->VoidResult->ApprovalStatus, 'APPROVED') !== false) {
             $tokenTransaction->setStatus('CANCEL');
             $this->context->smarty->assign('message', $this->l('Action succeded.'));
         } else {
             $this->context->smarty->assign('error', isset($result->VoidResult->ApprovalStatus) ? Tools::safeOutput($result->VoidResult->ApprovalStatus) : $this->l('ERROR, please contact MerchantWare for Support assistance.'));
         }
     }
     if ($order->getCurrentState() == Configuration::get('PS_OS_REFUND') && $tokenTransaction->getStatus() != 'REFUND') {
         $call = new Call();
         try {
             $result = $call->refundTransaction($token, $order->total_paid_real);
         } catch (Exception $e) {
             $this->context->smarty->assign('error', Tools::safeOutput($e->getMessage()));
         }
         if (isset($result->RefundResult->ApprovalStatus) && strrpos($result->RefundResult->ApprovalStatus, 'APPROVED') !== false) {
             $tokenTransaction->setStatus('REFUND');
             $this->context->smarty->assign('message', $this->l('Action succeded.'));
         } else {
             $this->context->smarty->assign('error', isset($result->RefundResult->ApprovalStatus) ? Tools::safeOutput($result->RefundResult->ApprovalStatus) : $this->l('ERROR, please contact Merchant Warehouse for Support assistance.'));
         }
     }
     return $this->display(__FILE__, 'tpl/adminOrder.tpl');
 }