public function execute($params = null)
 {
     $result = array();
     // from payment callback
     if (is_array($params)) {
         $order_id = $params['order_id'];
         $result['text'] = $params['plugin'] . ' (' . $params['view_data'] . ' - ' . $params['amount'] . ' ' . $params['currency_id'] . ')';
         $result['update']['params'] = array('payment_transaction_id' => $params['id']);
     } else {
         $order_id = $params;
         $result['text'] = waRequest::post('text', '');
     }
     $order_model = new shopOrderModel();
     $order = $order_model->getById($order_id);
     $log_model = new waLogModel();
     if (wa()->getEnv() == 'backend') {
         $log_model->add('order_pay', $order_id);
     } else {
         $log_model->add('order_pay_callback', $order_id, $order['contact_id']);
     }
     if (!$order['paid_year']) {
         shopAffiliate::applyBonus($order_id);
         if (wa('shop')->getConfig()->getOption('order_paid_date') == 'create') {
             $time = strtotime($order['create_datetime']);
         } else {
             $time = time();
         }
         $result['update'] = array('paid_year' => date('Y', $time), 'paid_quarter' => floor((date('n', $time) - 1) / 3) + 1, 'paid_month' => date('n', $time), 'paid_date' => date('Y-m-d', $time));
         if (!$order_model->where("contact_id = ? AND paid_date IS NOT NULL", $order['contact_id'])->limit(1)->fetch()) {
             $result['update']['is_first'] = 1;
         }
     }
     return $result;
 }
 public function postExecute($order_id = null, $result = null)
 {
     $data = parent::postExecute($order_id, $result);
     if ($order_id != null) {
         $log_model = new waLogModel();
         $log_model->add('order_restore', $order_id);
         $order_model = new shopOrderModel();
         $app_settings_model = new waAppSettingsModel();
         if ($this->state_id != 'refunded') {
             // for logging changes in stocks
             shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_ORDER, 'Order %s was restored', array('order_id' => $order_id));
             $update_on_create = $app_settings_model->get('shop', 'update_stock_count_on_create_order');
             if ($update_on_create) {
                 $order_model->reduceProductsFromStocks($order_id);
             } else {
                 if (!$update_on_create && $this->state_id != 'new') {
                     $order_model->reduceProductsFromStocks($order_id);
                 }
             }
             shopProductStocksLogModel::clearContext();
         }
         $order = $order_model->getById($order_id);
         if ($order && $order['paid_date']) {
             shopAffiliate::applyBonus($order_id);
             shopCustomers::recalculateTotalSpent($order['contact_id']);
         }
     }
     return $data;
 }
 public function execute($order_id = null)
 {
     $order_model = new shopOrderModel();
     $order = $order_model->getById($order_id);
     if ($order['paid_year']) {
         return true;
     } else {
         if (wa('shop')->getConfig()->getOption('order_paid_date') == 'create') {
             $time = strtotime($order['create_datetime']);
         } else {
             $time = time();
         }
         shopAffiliate::applyBonus($order_id);
         $result = array('update' => array('paid_year' => date('Y', $time), 'paid_quarter' => floor((date('n', $time) - 1) / 3) + 1, 'paid_month' => date('n', $time), 'paid_date' => date('Y-m-d', $time)));
         if (!$order_model->where("contact_id = ? AND paid_date IS NOT NULL", $order['contact_id'])->limit(1)->fetch()) {
             $result['update']['is_first'] = 1;
         }
         return $result;
     }
 }