Example #1
0
 function deleteAction()
 {
     /* This is from profilegateways
     		$id = AF::get($_POST, 'id', 0);
     		$ids = explode('_', $id);
             $errors = FALSE;
     		$model = new ProfileGateway();
     		$model->profile_id = $ids[0];
     		$model->method_id = $ids[1];
     		$model->gateway_id = $ids[2];
     		$model->delete();
             unset($model);
     		Message::echoJsonSuccess(__('gateway_removed'));
             $this->redirect();
     		*/
     $id = AF::get($_POST, 'id', 0);
     $errors = FALSE;
     $model = new GatewayLimit();
     $model->model_uset_id = $this->user->user_id;
     if ($model->findByPk($id)) {
         $model->delete();
     } else {
         $errors = TRUE;
     }
     if ($model->getErrors()) {
         $errors = TRUE;
     }
     unset($model);
     Message::echoJsonSuccess(__('limit_removed'));
     $this->redirect();
 }
Example #2
0
 function getgatewaylimitAction()
 {
     $this->checkLogin();
     AF::setJsonHeaders('json');
     $limit_id = AF::get($_POST, 'limit_id', false);
     if (!$limit_id) {
         Message::echoJsonError(__('incorrect_limit_id'));
     }
     $model = new GatewayLimit();
     $limit = $model->getLimitById($limit_id);
     echo json_encode($limit);
     exit;
 }
Example #3
0
 protected function afterPay()
 {
     // add gateway limit
     if ($this->_paymetnResponse->attemptModel->status == Attempt::SUCCESS_STATUS) {
         GatewayLimit::add($this->_paymetnResponse->attemptModel->gateway_id, $this->paymentMethod->method_id, $this->_paymetnResponse->attemptModel->amount);
     }
     return true;
 }
Example #4
0
 public function afterClone()
 {
     //get gateway limits
     $sql = 'SELECT `method_id`,
                 `limit_type`,
                 `orders_max`,
                 `orders_count`,
                 `amount_max`,
                 `amount_count`
         FROM `gateway_limits`
         WHERE `gateway_id`=?i';
     $result = self::$_msql->getAll($sql, (int) $this->cloneId);
     if ($result) {
         foreach ($result as $array) {
             $gatewayLimitModel = new GatewayLimit();
             $gatewayLimitModel->fillFromArray($array);
             $gatewayLimitModel->gateway_id = $this->gateway_id;
             $gatewayLimitModel->save();
             unset($gatewayLimitModel);
         }
     }
     return true;
 }
Example #5
0
 public function processGatewayRoutingByOrder($order)
 {
     if (!$order) {
         return false;
     }
     // action flags
     $switchedAlready = false;
     $nextGateway = false;
     $turnOffGateway = false;
     $hasLimit = true;
     // have to load the AFActiveDataProvider->models result into a public variable
     $allGateways = $this->getProfileGatewayByIds($order->campaign->profile_id, $order->payment->method_id);
     foreach ($allGateways as $g) {
         // build private gateways array with pk as array key
         $this->gateways[$g->profiles_gateways_id] = $g;
         // order gateway.  set pk and build limit object
         if ($g->gateway_id == $order->gateway_id) {
             if (isset($g->limit_id) && $g->limit_id) {
                 $this->limit = GatewayLimit::model()->fillFromDbPk($g->limit_id);
             }
             $this->orderGateway = $g->profiles_gateways_id;
         }
         // set realtime current gateway
         if ($g->flags == 'cur') {
             $this->currentGateway = $g->profiles_gateways_id;
         }
     }
     unset($allGateways);
     /*fb($this->gateways);
     		fb($this->currentGateway);
     		fb($this->orderGateway . ' = ' . $order->gateway_id);*/
     // make sure the 'cur' gateway is the same as what was used for the order.
     // if it was switched already for some reason, then we'll only update the limit record
     if ($this->currentGateway != $this->orderGateway) {
         $switchedAlready = true;
     }
     //fb($switchedAlready);
     // check limits.  if no limits present then set the flag
     if (!$this->limit) {
         $hasLimit = false;
     } else {
         // update limit count/amount
         // not using $order->payment_total since it is only set when payment has actually gone through.
         $this->limit->orders_count++;
         $this->limit->amount_count += $order->amount_product + $order->amount_shipping;
         if (!$this->limit->save()) {
             // this should never happen
             //fb($this->limit->getErrors());
         }
     }
     // gateway already switched?  return out of function
     if ($switchedAlready) {
         //fb('gateway already switched');
         return;
     } else {
         if ($hasLimit) {
             // check limits.  what limit type?  if limit is reached then the next gateway must be selected
             if ($this->limit->orders_max > 0 && $this->limit->amount_max > 0) {
                 // both limits apply
                 if ($this->limit->orders_count >= $this->limit->orders_max || $this->limit->amount_count >= $this->limit->amount_max) {
                     $nextGateway = true;
                     $turnOffGateway = true;
                     //fb('one');
                     //fb($this->limit->orders_count . ' >= ' . $this->limit->orders_max. ' || ' . $this->limit->amount_count . ' >= ' . $this->limit->amount_max);
                 }
             } else {
                 if ($this->limit->orders_max > 0) {
                     // order number limit
                     if ($this->limit->orders_count >= $this->limit->orders_max) {
                         $nextGateway = true;
                         $turnOffGateway = true;
                         //fb('two');
                     }
                 } else {
                     if ($this->limit->amount_max > 0) {
                         // order amount limit
                         if ($this->limit->amount_count >= $this->limit->amount_max) {
                             $nextGateway = true;
                             $turnOffGateway = true;
                             //fb('three');
                         }
                     } else {
                         // no limits set in limit record
                         $hasLimit = false;
                     }
                 }
             }
         }
     }
     // grab load balance type from profiles_methods by profile_id and method_id
     $pm = ProfileMethod::model()->findByPk(array('profile_id' => $order->campaign->profile_id, 'method_id' => $order->payment->method_id));
     // what type is it? rotation.  grab the next gateway according to rank no matter what the limits are
     if ($pm->load_balance == 'rot') {
         $nextGateway = true;
     }
     unset($pm);
     // enable next gateway?
     if ($nextGateway) {
         // if we don't need to turn off the gateway then this is a rotating profile.  we need to set the flag to blank
         if (!$turnOffGateway) {
             $this->gateways[$this->orderGateway]->flags = '';
             if (!$this->gateways[$this->orderGateway]->save()) {
                 fb($this->gateways[$this->orderGateway]->getErrors());
             }
         }
         // what's the next gateway
         $pgNext = $this->nextActiveGateway();
         // is this equal to our current gateway?  if so, something's wrong.  disable $turnOffGateway
         if (!$pgNext || $pgNext == $this->orderGateway) {
             $turnOffGateway = false;
         } else {
             $this->gateways[$pgNext]->flags = 'cur';
             if (!$this->gateways[$pgNext]->save()) {
                 fb($this->gateways[$pgNext]->getErrors());
             }
         }
     }
     // disable the gateway?
     if ($turnOffGateway) {
         $this->gateways[$this->orderGateway]->flags = 'off';
         if (!$this->gateways[$this->orderGateway]->save()) {
             fb($this->gateways[$this->orderGateway]->getErrors());
         }
     }
     return true;
 }