示例#1
0
 public function save($return = 0)
 {
     $pp = new PaymentProcessor();
     if (!empty($_POST['id'])) {
         $pp->loadId($_POST['id']);
         if (empty($pp->id)) {
             $this->cancel();
         }
         $procname = $pp->processor_name;
     } elseif (isset($_POST['processor'])) {
         $pp->loadName($_POST['processor']);
         $procname = $_POST['processor'];
     }
     $pp->fullInit(true);
     $active = $procname . '_active';
     $longname = $procname . '_info_longname';
     $description = $procname . '_info_description';
     if (isset($_POST[$longname])) {
         $pp->info['longname'] = $_POST[$longname];
         unset($_POST[$longname]);
     }
     if (isset($_POST[$description])) {
         $pp->info['description'] = $_POST[$description];
         unset($_POST[$description]);
     }
     if (isset($_POST[$active])) {
         $pp->processor->active = $_POST[$active];
         unset($_POST[$active]);
     }
     $settings = $pp->getBackendSettings();
     if (is_int($pp->is_recurring())) {
         $settings['recurring'] = 2;
     }
     foreach ($settings as $name => $value) {
         if ($name == 'lists') {
             continue;
         }
         $postname = $procname . '_' . $name;
         if (isset($_POST[$postname])) {
             $val = $_POST[$postname];
             if (empty($val)) {
                 switch ($name) {
                     case 'currency':
                         $val = 'USD';
                         break;
                     default:
                         break;
                 }
             }
             $pp->settings[$name] = $val;
         }
     }
     $pp->storeload();
     $this->setMessage(JText::_('AEC_CONFIG_SAVED'));
 }
 public function explodePlanList($recurring)
 {
     global $aecConfig;
     $groups = array();
     $plans = array();
     $gs = array();
     $ps = array();
     // Break apart groups and items, make sure we have no duplicates
     foreach ($this->list as $litem) {
         if ($litem['type'] == 'group') {
             if (!in_array($litem['id'], $gs)) {
                 $gs[] = $litem['id'];
                 $groups[] = $litem;
             }
         } else {
             if (!in_array($litem['id'], $ps)) {
                 if (ItemGroupHandler::checkParentRestrictions($litem['plan'], 'item', $this->metaUser)) {
                     $ps[] = $litem['id'];
                     $plans[] = $litem;
                 }
             }
         }
     }
     foreach ($plans as $pid => $plan) {
         if (!isset($plan['plan']->params['cart_behavior'])) {
             $plan['plan']->params['cart_behavior'] = 0;
         }
         if ($this->metaUser->userid && !$this->expired && ($aecConfig->cfg['enable_shoppingcart'] || $plan['plan']->params['cart_behavior'] == 1) && $plan['plan']->params['cart_behavior'] != 2) {
             // We have a shopping cart situation, care about processors later
             if ($plan['plan']->params['processors'] == '' || is_null($plan['plan']->params['processors'])) {
                 if (!$plan['plan']->params['full_free']) {
                     continue;
                 }
             }
             $plans[$pid]['gw'][0] = new stdClass();
             $plans[$pid]['gw'][0]->processor_name = 'add_to_cart';
             $plans[$pid]['gw'][0]->info['statement'] = '';
             $plans[$pid]['gw'][0]->recurring = 0;
             continue;
         }
         if (empty($plan['select_mode'])) {
             $select_mode = '0';
         } else {
             $select_mode = $plan['select_mode'];
         }
         if ($select_mode == 1) {
             // We want to only select the processors on confirmation
             if ($plan['plan']->params['processors'] == '' || is_null($plan['plan']->params['processors'])) {
                 if (!$plan['plan']->params['full_free']) {
                     continue;
                 }
             }
             $plans[$pid]['gw'][0] = new stdClass();
             $plans[$pid]['gw'][0]->processor_name = 'select';
             $plans[$pid]['gw'][0]->info['statement'] = '';
             $plans[$pid]['gw'][0]->recurring = 0;
             continue;
         }
         if ($plan['plan']->params['full_free']) {
             $plans[$pid]['gw'][0] = new stdClass();
             $plans[$pid]['gw'][0]->processor_name = 'free';
             $plans[$pid]['gw'][0]->info['statement'] = '';
             $plans[$pid]['gw'][0]->recurring = 0;
         } else {
             if ($plan['plan']->params['processors'] != '' && !is_null($plan['plan']->params['processors'])) {
                 $processors = array_reverse($plan['plan']->params['processors']);
                 // Restrict to pre-chosen processor (if set)
                 if (!empty($this->processor)) {
                     $processorid = PaymentProcessorHandler::getProcessorIdfromName($this->processor);
                     if (in_array($processorid, $processors)) {
                         $processors = array($processorid);
                     }
                 }
                 $plan_gw = array();
                 if (count($processors)) {
                     foreach ($processors as $n) {
                         if (empty($n)) {
                             continue;
                         }
                         $pp = new PaymentProcessor();
                         if (!$pp->loadId($n)) {
                             continue;
                         }
                         if (!$pp->processor->active) {
                             continue;
                         }
                         $pp->init();
                         $pp->getInfo();
                         $pp->exchangeSettingsByPlan($plan['plan']);
                         $recurring = $pp->is_recurring($recurring, true);
                         if ($recurring > 1) {
                             $pp->recurring = 0;
                             $plan_gw[] = $pp;
                             if (!$plan['plan']->params['lifetime']) {
                                 $pp = new PaymentProcessor();
                                 $pp->loadId($n);
                                 $pp->init();
                                 $pp->getInfo();
                                 $pp->exchangeSettingsByPlan($plan['plan']);
                                 $pp->recurring = 1;
                                 $plan_gw[] = $pp;
                             }
                         } elseif (!($plan['plan']->params['lifetime'] && $recurring)) {
                             if (is_int($recurring)) {
                                 $pp->recurring = $recurring;
                             }
                             $plan_gw[] = $pp;
                         }
                     }
                 }
                 if (!empty($plan_gw)) {
                     $plans[$pid]['gw'] = $plan_gw;
                 } else {
                     unset($plans[$pid]);
                 }
             }
         }
     }
     $this->list = array_merge($groups, $plans);
 }
示例#3
0
 public function confirm()
 {
     global $aecConfig;
     if (empty($this->passthrough)) {
         if (!$this->checkAuth()) {
             return false;
         }
     }
     if (empty($aecConfig->cfg['skip_registration'])) {
         if (!$this->reCaptchaCheck()) {
             return false;
         }
     }
     $this->puffer();
     $this->coupons = array();
     $this->coupons['active'] = !empty($aecConfig->cfg['confirmation_coupons']);
     if (empty($this->mi_error)) {
         $this->mi_error = array();
     }
     if (!empty($this->plan)) {
         $this->mi_form = $this->plan->getMIforms($this->metaUser, $this->mi_error, $this->passthrough);
     }
     $this->jsvalidation = array();
     $this->formatting = array();
     if (!empty($this->mi_form) && is_array($this->passthrough)) {
         $params = $this->plan->getMIformParams($this->metaUser);
         foreach ($params as $mik => $miv) {
             if ($mik == 'lists') {
                 continue;
             } elseif ($mik == 'validation') {
                 if (!empty($miv)) {
                     $this->jsvalidation = array_merge($this->jsvalidation, $miv);
                 }
                 continue;
             } elseif ($mik == 'formatting') {
                 if (!empty($miv)) {
                     $this->formatting = array_merge($this->formatting, $miv);
                 }
                 continue;
             }
             foreach ($this->passthrough as $pid => $pk) {
                 if (!is_array($pk)) {
                     continue;
                 }
                 if (!empty($pk[0])) {
                     if ($pk[0] == $mik || $pk[0] == $mik . '[]') {
                         unset($this->passthrough[$pid]);
                     }
                 }
             }
         }
     }
     if ($aecConfig->cfg['skip_confirmation'] && empty($this->mi_form)) {
         $this->getPassthrough();
         return $this->save();
     }
     $this->userdetails = "";
     foreach (array('name', 'username', 'email') as $k) {
         if (!empty($this->metaUser->cmsUser->{$k})) {
             $this->userdetails .= '<p>' . JText::_('CONFIRM_ROW_' . strtoupper($k)) . "&nbsp;" . $this->metaUser->cmsUser->{$k} . '</p>';
         }
     }
     $this->processorSelect = false;
     if ($this->processor == 'select' && !empty($this->plan->params['processor_selectmode']) && $this->plan->params['processor_selectmode'] == 1 || !empty($this->plan->params['processor_selectmode']) && $this->plan->params['processor_selectmode'] == 2) {
         $this->processorSelect = array();
         $processors = array_reverse($this->plan->params['processors']);
         foreach ($processors as $kn => $n) {
             $pp = new PaymentProcessor();
             if (!$pp->loadId($n)) {
                 continue;
             }
             if (!$pp->processor->active) {
                 continue;
             }
             $pp->init();
             $pp->getInfo();
             if ($this->processor == 'select') {
                 $selected = $kn == 0;
             } else {
                 $selected = $this->processor == $pp->info['name'];
             }
             $this->processorSelect[] = (object) array('id' => $pp->processor->id, 'handle' => $pp->info['name'], 'name' => $pp->info['longname'], 'selected' => $selected);
         }
     }
     return getView('confirmation', array('InvoiceFactory' => $this, 'passthrough' => $this->getPassthrough()));
 }
示例#4
0
 static function getCartProcessorGroups($cart, $recurring = false)
 {
     $pgroups = array();
     foreach ($cart->content as $cid => $c) {
         $cartitem = aecCartHelper::getCartItemObject($cart, $cid);
         $pplist = array();
         $pplist_names = array();
         if (!empty($cartitem->params['processors'])) {
             foreach ($cartitem->params['processors'] as $n) {
                 $pp = new PaymentProcessor();
                 if (!$pp->loadId($n)) {
                     continue;
                 }
                 $pp->init();
                 $pp->getInfo();
                 $pp->exchangeSettingsByPlan($cartitem);
                 if (isset($recurring)) {
                     $recurring = $pp->is_recurring($recurring);
                 } else {
                     $recurring = $pp->is_recurring();
                 }
                 if ($recurring > 1) {
                     $pplist[] = $pp->id;
                     $pplist_names[] = $pp->info['longname'];
                     if (!$cartitem->params['lifetime']) {
                         $pplist[] = $pp->id . '_recurring';
                         $pplist_names[] = $pp->info['longname'];
                     }
                 } elseif (!$cartitem->params['lifetime'] && $recurring) {
                     $pplist[] = $pp->id . '_recurring';
                     $pplist_names[] = $pp->info['longname'];
                 } else {
                     $pplist[] = $pp->id;
                     $pplist_names[] = $pp->info['longname'];
                 }
             }
         }
         if (empty($pplist)) {
             continue;
         }
         if (empty($pgroups)) {
             $pg = array();
             $pg['members'] = array($cid);
             $pg['processors'] = $pplist;
             $pg['processor_names'] = $pplist_names;
             $pgroups[] = $pg;
         } else {
             $create = true;
             foreach ($pgroups as $pgid => $pgroup) {
                 $pg = array();
                 if (count($pplist) == count($pgroup['processors'])) {
                     $a = true;
                     foreach ($pplist as $k => $v) {
                         if ($pgroup['processors'][$k] != $v) {
                             $a = false;
                         }
                     }
                     if ($a) {
                         $pgroups[$pgid]['members'][] = $cid;
                         $create = false;
                     }
                 }
             }
             if ($create) {
                 $pg['members'] = array($cid);
                 $pg['processors'] = $pplist;
                 $pg['processor_names'] = $pplist_names;
                 $pgroups[] = $pg;
             }
         }
     }
     return $pgroups;
 }