Пример #1
0
 public function cartItemsPPselectForm()
 {
     $pgroups = aecCartHelper::getCartProcessorGroups($this->cartobject, $this->recurring);
     $c = false;
     $exception = false;
     $selected = array();
     $selected_form = array();
     $single_select = true;
     foreach ($pgroups as $pgid => $pgroup) {
         if (count($pgroup['processors']) < 2) {
             if (!empty($pgroup['processors'][0])) {
                 $pgroups[$pgid]['processor'] = $pgroup['processors'][0];
             }
             continue;
         }
         $ex = array();
         if ($c) {
             $ex['head'] = null;
             $ex['desc'] = null;
         } else {
             $ex['head'] = "Select Payment Processor";
             $ex['desc'] = "There are a number of possible payment processors for one or more of your items, please select one below:<br />";
         }
         $ex['rows'] = array();
         $fname = 'cartgroup_' . $pgid . '_processor';
         $pgsel = aecGetParam($fname, null, true, array('word', 'string'));
         if (empty($pgsel)) {
             $pgsel = aecGetParam($pgid . '_' . $fname, null, true, array('word', 'string'));
         }
         $selection = false;
         if (!is_null($pgsel)) {
             if (in_array($pgsel, $pgroup['processors'])) {
                 $selection = $pgsel;
             }
         }
         if (!empty($selection)) {
             if (count($selected) > 0) {
                 if (!in_array($selection, $selected)) {
                     $single_select = false;
                 }
             }
             $pgroups[$pgid]['processor'] = $selection;
             $selected[] = $selection;
             $selected_form[] = array('hidden', $pgsel, $fname, $pgsel);
             $this->processor_userselect = true;
             continue;
         } else {
             $c = true;
             $ex['desc'] .= "<ul>";
             foreach ($pgroup['members'] as $pgmember) {
                 $ex['desc'] .= "<li><strong>" . $this->cart[$pgmember]['name'] . "</strong><br /></li>";
             }
             $ex['desc'] .= "</ul>";
             foreach ($pgroup['processors'] as $pid => $pgproc) {
                 $recurring = true;
                 if (strpos($pgproc, '_recurring')) {
                     $pgproc = str_replace('_recurring', '', $pgproc);
                 } else {
                     $recurring = false;
                 }
                 $ex['rows'][] = array('radio', $fname, $pgproc, true, $pgroup['processor_names'][$pid] . ($recurring ? ' (recurring billing)' : ''));
             }
         }
         if (!empty($ex['rows']) && $c) {
             $this->raiseException($ex);
             $exception = true;
         }
     }
     if ($exception && !empty($selected_form)) {
         $ex = array();
         $ex['head'] = null;
         $ex['desc'] = null;
         $ex['rows'] = array();
         foreach ($selected_form as $silent) {
             $ex['rows'][] = $silent;
         }
         $this->raiseException($ex);
     }
     $finalinvoice = null;
     if ($single_select) {
         if (!empty($selection)) {
             $this->processor = PaymentProcessor::getNameById(str_replace('_recurring', '', $selection));
         }
     } else {
         // We have different processors selected for this cart
         $prelg = array();
         foreach ($pgroups as $pgid => $pgroup) {
             $prelg[$pgroup['processor']][] = $pgroup;
         }
         foreach ($prelg as $processor => $pgroups) {
             if (strpos($processor, '_recurring')) {
                 $processor_name = PaymentProcessor::getNameById(str_replace('_recurring', '', $processor));
                 $procrecurring = true;
             } else {
                 $processor_name = PaymentProcessor::getNameById($processor);
                 if (isset($_POST['recurring'])) {
                     $procrecurring = $_POST['recurring'];
                 } else {
                     $procrecurring = false;
                 }
             }
             $groupkeys = array_keys($pgroups);
             $mpg = array_pop($groupkeys);
             if (count($pgroups) > 1 || count($pgroups[$mpg]['members']) > 1) {
                 // We have more than one item for this processor, create temporary cart
                 $tempcart = new aecCart();
                 $tempcart->userid = $this->userid;
                 foreach ($pgroups as $pgr) {
                     foreach ($pgr['members'] as $member) {
                         $tempcart->addItem(array(), $this->cartobject->content[$member]['id']);
                     }
                 }
                 $tempcart->storeload();
                 $carthash = 'c.' . $tempcart->id;
                 // Create a cart invoice
                 $invoice = new Invoice();
                 $invoice->create($this->userid, $carthash, $processor_name, null, true, $this, $procrecurring);
             } else {
                 // Only one item in this, create a simple invoice
                 $member = $pgroups[$mpg]['members'][0];
                 $invoice = new Invoice();
                 $invoice->create($this->userid, $this->cartobject->content[$member]['id'], $processor_name, null, true, $this, $procrecurring);
             }
             if ($invoice->amount == "0.00") {
                 $invoice->pay();
             } else {
                 $finalinvoice = $invoice;
             }
         }
         $ex = array();
         $ex['head'] = "Invoice split up";
         $ex['desc'] = "The contents of your shopping cart cannot be processed in one go. This is why we have split up the invoice - you can pay for the first part right now and access the other parts as separate invoices later from your membership page.";
         $ex['rows'] = array();
         $this->raiseException($ex);
         $this->invoice_number = $finalinvoice->invoice_number;
         $this->invoice = $finalinvoice;
         $this->touchInvoice();
         $objUsage = $this->invoice->getObjUsage();
         if (is_a($objUsage, 'aecCart')) {
             $this->cartobject = $objUsage;
             $this->getCart();
         } else {
             $this->plan = $objUsage;
         }
     }
 }