Exemple #1
0
 protected function beforePay()
 {
     $profileMethod = ProfileMethod::model()->findByPk(array('profile_id' => $this->campaignModel->profile->profile_id, 'method_id' => $this->paymentMethod->method_id));
     if ($profileMethod && $profileMethod->isFlag(ProfileMethod::FLAG_FILTER) && $this->paymentModel->cc_number) {
         if (!Bin::verificationCreditCard($this->paymentModel->cc_number)) {
             Attempt::setAttemptStatus($this->attemptModel, Attempt::FRAUD_STATUS);
             $this->_paymetnResponse->addError('error_processing_request');
             $this->_paymetnResponse->addAlert('please_use_a_different_card');
             $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS;
             // log prepaid card attempt
             OrderLog::createLog(0, $this->orderModel->order_id, 28, 'Prepaid Card');
             return false;
         }
     }
     return true;
 }
Exemple #2
0
 function deleteAction()
 {
     $id = AF::get($_POST, 'id', 0);
     $ids = explode('_', $id);
     $errors = FALSE;
     $model = new ProfileMethod();
     $model->profile_id = $ids[0];
     $model->method_id = $ids[1];
     $model->load_balance = $ids[2];
     $model->delete();
     unset($model);
     Message::echoJsonRedirect("/lj3/profiles/update/id=" . $ids[0]);
     $this->redirect();
 }
Exemple #3
0
 function updateAction()
 {
     $model = new Profile();
     if (isset($_POST['ajax'])) {
         // Add method to profile
         if (isset($_POST['model']) && $_POST['model'] == 'profiles_methods') {
             $profileMethod = new ProfileMethod();
             @$this->performAjaxValidation($profileMethod);
             // Uncomment the line if AJAX validation is needed
             if ($_POST['action'] == 'create') {
                 $profileMethod->fillFromArray($_POST, TRUE);
             } elseif ($_POST['action'] == 'update') {
                 $methodID = (int) AF::get($_POST, 'method_id');
                 $profileID = (int) AF::get($_POST, 'profile_id');
                 $profileMethod = ProfileMethod::model()->findByPk(array('method_id' => $methodID, 'profile_id' => $profileID));
                 $profileMethod->fillFromArray($_POST);
             }
             if ($profileMethod->method_id == Method::METHOD_CC) {
                 if (isset($_POST['flags']['filter']) && $_POST['flags']['filter']) {
                     if (!$profileMethod->flags) {
                         $profileMethod->flags = '';
                     }
                     @$profileMethod->addFlags('filter');
                 } else {
                     $profileMethod->removeFlags('filter');
                 }
             }
             if (!$profileMethod->flags) {
                 $profileMethod->flags = '';
             }
             if ($profileMethod->save()) {
                 $link = AF::link(array('profiles' => 'update'), array('id' => $profileMethod->profile_id));
                 Message::echoJson('success', array('redirect' => $link));
             } else {
                 Message::echoJsonError(__('profile_method_not_' . $_POST['action'] . 'd') . '. ' . $profileMethod->errors2string);
             }
         }
         if (isset($_POST['getprofilemethodinfo'])) {
             $methodID = (int) AF::get($_POST, 'method_id');
             $profileID = (int) AF::get($_POST, 'profile_id');
             $methods = Method::model()->cache()->findAllInArray();
             //$model = ProfileMethod::model()->find("profiles_methods_id=:profiles_methods_id", array(':profiles_methods_id'=>$id));
             $model = ProfileMethod::model()->findByPk(array('method_id' => $methodID, 'profile_id' => $profileID));
             echo $this->view->includeFile('_methods_form', array('application', 'views', 'profiles'), array('action' => 'update', 'ajax' => TRUE, 'popup' => TRUE, 'methodModel' => $model, 'methods' => $methods));
             die;
         }
     }
     if (isset($_POST['model'])) {
         // Change profile_name
         if ($_POST['model'] == 'profile') {
             if (isset($_POST['ajax'])) {
                 $this->performAjaxValidation($model);
                 // Uncomment the line if AJAX validation is needed
                 $model->fillFromArray($_POST, FALSE);
                 $model->user_id_updated = $this->user->user_id;
                 $model->updated = 'NOW():sql';
                 $model->model_uset_id = $this->user->user_id;
                 if ($model->save()) {
                     $link = AF::link(array('profiles' => 'update'), array('id' => $model->PkValue));
                     Message::echoJson('success', array('redirect' => $link));
                 } else {
                     Message::echoJsonError(__('profile_no_updated'));
                 }
                 die;
             }
             $this->redirect();
             die;
         }
         // Add gateway to profile
         if ($_POST['model'] == 'profiles_gateways') {
             $profileGateway = new ProfileGateway();
             $this->performAjaxValidation($profileGateway);
             // Uncomment the line if AJAX validation is needed
             $profileGateway->fillFromArray($_POST, TRUE);
             $profileGateway->addGateway();
         }
     }
     $id = AF::get($this->params, 'id', FALSE);
     $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params));
     $models = AFActiveDataProvider::models('ProfileGateway', $this->params, $pagination);
     $profile_methods = ProfileMethod::model()->getProfileMethodsByProfile($id);
     //$method_ids = '0';
     if ($profile_methods) {
         foreach ($profile_methods as $key => $value) {
             $method_id_array[] = $value['method_id'];
         }
         $method_ids = implode(',', $method_id_array);
     }
     $methods = Method::model()->cache()->findAllInArray();
     $gateways = Gateway::model()->getGateways();
     if (!$id) {
         throw new AFHttpException(0, 'no_id');
     }
     if (!$model->findByPk($id)) {
         throw new AFHttpException(0, 'incorrect_id');
     }
     //for create profile method
     $modelProfileMethod = new ProfileMethod();
     $modelProfileMethod->profile_id = $model->profile_id;
     Assets::js('jquery.form');
     $this->addToPageTitle('Edit Profile');
     $this->render('update', array('model' => $model, 'gateways' => $gateways, 'models' => $models, 'methods' => $methods, 'profile_methods' => $profile_methods, 'modelProfileMethod' => $modelProfileMethod));
 }
Exemple #4
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;
 }