public function touchProcessors() { // Make sure settings & info are updated $pplist = PaymentProcessorHandler::getInstalledNameList(); foreach ($pplist as $ppname) { $pp = new PaymentProcessor(); if (!$pp->loadName($ppname)) { continue; } $pp->copyAssets(); $pp->fullInit(); // Infos often change, so we protect the name and description and so on, but replace everything else $original = $pp->processor->info(); $protect = array('name', 'longname', 'statement', 'description'); foreach ($original as $name => $var) { if (!in_array($name, $protect)) { $pp->info[$name] = $var; } } $pp->processor->storeload(); } }
public function computeAmount($InvoiceFactory = null, $save = true, $recurring_choice = null) { if (!empty($InvoiceFactory->metaUser)) { $metaUser = $InvoiceFactory->metaUser; } else { $metaUser = new metaUser($this->userid ? $this->userid : 0); } $pp = null; $madefree = false; if (is_null($recurring_choice) && isset($this->params['userselect_recurring'])) { $recurring_choice = $this->params['userselect_recurring']; } if (empty($this->usage)) { return null; } $recurring = 0; if (InvoiceFactory::isActualProcessorName($this->method)) { if (empty($InvoiceFactory->pp)) { $pp = new PaymentProcessor(); if (!$pp->loadName($this->method)) { $short = 'processor loading failure'; $event = 'When computing invoice amount, tried to load processor: ' . $this->method; $tags = 'processor,loading,error'; $params = array(); $eventlog = new eventLog(); $eventlog->issue($short, $tags, $event, 128, $params); return; } $pp->fullInit(); } else { $pp = $InvoiceFactory->pp; } if ($pp->is_recurring($recurring_choice)) { $recurring = $pp->is_recurring($recurring_choice); } if (empty($this->currency)) { $this->currency = isset($pp->settings['currency']) ? $pp->settings['currency'] : ''; } } $usage = explode('.', $this->usage); // Update old notation if (!isset($usage[1])) { $temp = $usage[0]; $usage[0] = 'p'; $usage[1] = $temp; } $allfree = false; switch (strtolower($usage[0])) { case 'c': case 'cart': $cart = $this->getObjUsage(); if ($cart->id) { if (!empty($this->coupons)) { foreach ($this->coupons as $coupon) { if (!$cart->hasCoupon($coupon)) { $cart->addCoupon($coupon); } } } $return = $cart->getAmount($metaUser, $this->counter, $this); $allfree = $cart->checkAllFree($metaUser, $this->counter, $this); $this->amount = $return; } elseif (isset($this->params['cart'])) { // Cart has been deleted, use copied data $vars = get_object_vars($this->params['cart']); foreach ($vars as $v => $c) { // Make extra sure we don't put through any _properties if (strpos($v, '_') !== 0) { $cart->{$v} = $c; } } $return = $cart->getAmount($metaUser, $this->counter, $this); $this->amount = $return; } else { $this->amount = '0.00'; } break; case 'p': case 'plan': default: $plan = $this->getObjUsage(); if (is_object($pp)) { $pp->exchangeSettingsByPlan($plan); if ($this->currency != $pp->settings['currency'] && !empty($pp->settings['currency'])) { $this->currency = $pp->settings['currency']; } if ($pp->is_recurring($recurring_choice)) { $recurring = $pp->is_recurring($recurring_choice); } else { $recurring = 0; } } $terms = $plan->getTermsForUser($recurring, $metaUser); $terms->incrementPointer($this->counter); if ($this->coupons) { $item = array('item' => array('obj' => $plan), 'terms' => $terms); $cpsh = new couponsHandler($metaUser, $InvoiceFactory, $this->coupons); $item = $cpsh->applyAllToItems(0, $item); $terms = $item['terms']; // Coupons might have changed the terms - reset pointer $terms->setPointer($this->counter); } $allfree = $terms->checkFree(); if (is_object($terms->nextterm)) { $this->amount = $terms->nextterm->renderTotal(); } else { $this->amount = '0.00'; } break; } // TODO: This is just a bandaid. We really need to move stuff from the factory over to the invoice class if (!empty($InvoiceFactory->items->grand_total->cost['amount'])) { $this->amount = $InvoiceFactory->items->grand_total->cost['amount']; } $this->amount = AECToolbox::correctAmount($this->amount); if (!$recurring || $allfree) { if (strcmp($this->amount, '0.00') === 0) { $this->method = 'free'; $madefree = true; } elseif (strcmp($this->amount, '0.00') === 0 && strcmp($this->method, 'free') !== 0) { $short = 'invoice amount error'; $event = 'When computing invoice amount: Method error, amount 0.00, but method = ' . $this->method; $tags = 'processor,loading,error'; $params = array(); $eventlog = new eventLog(); $eventlog->issue($short, $tags, $event, 128, $params); $this->method = 'error'; } } if ($save) { $this->storeload(); } if ($madefree) { $this->made_free = true; } }
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 readProcessors() { $lang = JFactory::getLanguage(); $readout = array(); $r = array(); $r['head'] = "Processors"; $processors = PaymentProcessorHandler::getInstalledNameList(); foreach ($processors as $procname) { $pp = null; $pp = new PaymentProcessor(); if (!$pp->loadName($procname)) { continue; } $pp->fullInit(); $readout[] = $r; $r = array(); $r['head'] = $pp->info['longname']; $r['type'] = "table"; $r['sub'] = true; $r['def'] = array("ID" => array('id'), "Published" => array('active', 'bool')); foreach ($pp->info as $iname => $ic) { if (empty($iname)) { continue; } $cname = 'CFG_' . strtoupper($procname) . '_' . strtoupper($iname) . '_NAME'; $gname = 'CFG_PROCESSOR_' . strtoupper($iname) . '_NAME'; if ($lang->hasKey($cname)) { $tname = JText::_($cname); } elseif ($lang->hasKey($gname)) { $tname = JText::_($gname); } else { $tname = $iname; } $r['def'][$tname] = array(array('info', $iname), 'smartlimit'); } $bsettings = $pp->getBackendSettings(); foreach ($bsettings as $psname => $sc) { if (empty($psname) || is_numeric($psname) || $psname == 'lists') { continue; } $cname = 'CFG_' . strtoupper($procname) . '_' . strtoupper($psname) . '_NAME'; $gname = 'CFG_PROCESSOR_' . strtoupper($psname) . '_NAME'; if ($lang->hasKey($cname)) { $tname = JText::_($cname); } elseif ($lang->hasKey($gname)) { $tname = JText::_($gname); } else { $tname = $psname; } if ($sc[0] == 'list_yesno') { $stype = 'bool'; } else { $stype = 'smartlimit'; } $r['def'][$tname] = array(array('settings', $psname), $stype); } $ps = array(); foreach ($r['def'] as $nn => $def) { $ps = array_merge($ps, $this->conversionHelper($def, $pp)); } $r['set'] = array(0 => $ps); } $readout[] = $r; return $readout; }