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 printout($invoice_number, $standalone = true) { $invoice = new Invoice(); $invoice->loadInvoiceNumber($invoice_number); $iFactory = new InvoiceFactory($invoice->userid, null, null, null, null, null, false, true); $iFactory->invoiceprint($invoice->invoice_number, $standalone); }
function getShippingOptions($data, $invoice_data) { $if = new InvoiceFactory(); $transaction_arr = FALSE; if (is_array($data)) { $transaction_arr = $this->convertRawInvoiceDataToTransactionArray($data); $weight_and_dimensions_arr = $if->getWeightAndDimensions($transaction_arr); $shipping_option_data = $if->getShippingOptionData($invoice_data[1], $weight_and_dimensions_arr, $invoice_data[3]); $shipping_options = $if->getShippingOptions($shipping_option_data, $invoice_data[3], TRUE); } if (isset($shipping_options)) { //Debug::Arr($shipping_options, 'Shipping Options: ', __FILE__, __LINE__, __METHOD__, 10); return $shipping_options; } return FALSE; }
public function getInvoice($invoice) { ob_start(); $iFactory = new InvoiceFactory($invoice->userid, null, null, null, null, null, false, true); $iFactory->invoiceprint($invoice->invoice_number, false, array('mi_aecinvoiceprintemail' => true), true); $content = AECToolbox::rewriteEngineRQ(ob_get_contents(), $iFactory); ob_end_clean(); return $content; }
public function Action() { if (empty($_POST['start_date'])) { return null; } $db = JFactory::getDBO(); $start_timeframe = $_POST['start_date'] . ' 00:00:00'; if (!empty($_POST['end_date'])) { $end_timeframe = $_POST['end_date'] . ' 23:59:59'; } else { $end_timeframe = date('Y-m-d', (int) gmdate('U')); } $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $start_timeframe . '\'' . ' AND transaction_date <= \'' . $end_timeframe . '\'' . ' ORDER BY transaction_date ASC'; $db->setQuery($query); $entries = xJ::getDBArray($db); if (empty($entries)) { return "nothing to list"; } $historylist = array(); $groups = array(); foreach ($entries as $id) { $entry = new logHistory($db); $entry->load($id); $refund = false; if (is_array($entry->response)) { $filter = array('subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel'); $refund = false; foreach ($entry->response as $v) { if (in_array($v, $filter)) { continue 2; } elseif ($v == 'refund') { $refund = true; } } } $date = date('Y-m-d', strtotime($entry->transaction_date)); $iFactory = new InvoiceFactory($entry->user_id, null, null, null, null, null, false, true); if ($iFactory->userid != $entry->user_id) { continue; } $iFactory->loadMetaUser(); $iFactory->touchInvoice($entry->invoice_number, false, true); if ($iFactory->invoice_number != $entry->invoice_number) { continue; } $iFactory->puffer(); $iFactory->loadItems(); $iFactory->loadItemTotal(); if (isset($iFactory->items->total)) { $amount = $iFactory->items->total->cost['amount']; } else { continue; } $tax = 0; foreach ($iFactory->items->tax as $item) { $tax += $item['cost']; } if ($refund) { $historylist[$date]['amount'] -= $amount; if ($tax) { $historylist[$date]['taxed'] -= $amount; $historylist[$date]['tax'] -= $tax; } else { $historylist[$date]['untaxed'] -= $amount; } } else { $historylist[$date]['amount'] += $amount; if ($tax) { $historylist[$date]['taxed'] += $amount; $historylist[$date]['tax'] += $tax; } else { $historylist[$date]['untaxed'] += $amount; } } } $return = ""; $return .= '<table style="background-color: fff; width: 30%; margin: 0 auto; text-align: center !important; font-size: 180%;">'; $i = 0; foreach ($historylist as $date => $history) { $i++; if (date('j', strtotime($date)) == 1 || $i === 1) { $month = array(); } $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em;">'; $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">' . $date . '</td>'; $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Non-Taxed" style="font-weight: bold; width: 5em;">' . AECToolbox::correctAmount($history['untaxed']) . '</td>'; if (!empty($history['taxed'])) { $return .= '<td style="width: 5em;">+</td>'; $return .= '<td title="Taxed including Tax" style="font-weight: bold; width: 5em;">' . AECToolbox::correctAmount($history['taxed'] + $history['tax']) . '</td>'; $return .= '<td title="Taxed" style="font-weight: bold; width: 5em; color: #aaa;">(' . AECToolbox::correctAmount($history['taxed']) . '</td>'; $return .= '<td style="width: 5em; color: #aaa;">+</td>'; $return .= '<td title="Tax" style="font-weight: bold; width: 5em; color: #aaa;">' . AECToolbox::correctAmount($history['tax']) . ')</td>'; } else { $return .= '<td colspan="5"></td>'; } $return .= '<td style="width: 5em;">=</td>'; $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Grand Total" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($history['amount'] + $history['tax']) . '</td>'; $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="11"></td>'; $return .= '</tr>'; if (isset($month)) { $month['amount'] += $history['amount']; $month['tax'] += $history['tax']; $month['taxed'] += $history['taxed']; $month['untaxed'] += $history['untaxed']; } if (isset($month) && (date('j', strtotime($date)) == date('t', strtotime($date)) || $i == count($historylist))) { $return .= '<tr style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">'; $return .= '<td title="Date" style="text-align: left !important; color: #aaa;">Month</td>'; $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Non-Taxed" style="font-weight: bold; width: 5em;">' . AECToolbox::correctAmount($month['untaxed']) . '</td>'; if (!empty($month['taxed'])) { $return .= '<td style="width: 5em;">+</td>'; $return .= '<td title="Taxed including Tax" style="font-weight: bold; width: 5em;">' . AECToolbox::correctAmount($month['taxed'] + $month['tax']) . '</td>'; $return .= '<td title="Taxed" style="font-weight: bold; width: 5em; color: #aaa;">(' . AECToolbox::correctAmount($month['taxed']) . '</td>'; $return .= '<td style="width: 5em; color: #aaa;">+</td>'; $return .= '<td title="Tax" style="font-weight: bold; width: 5em; color: #aaa;">' . AECToolbox::correctAmount($month['tax']) . ')</td>'; } else { $return .= '<td colspan="5"></td>'; } $return .= '<td style="width: 5em;">=</td>'; $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Grand Total" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($month['amount'] + $month['tax']) . '</td>'; $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="11"></td>'; $return .= '</tr>'; } } $return .= '</table><br /><br />'; return $return; }
function processNotification($option, $processor) { global $aecConfig; // Legacy naming support switch ($processor) { case 'vklix': $processor = 'viaklix'; break; case 'auth': $processor = 'authorize'; break; case '2co': $processor = '2checkout'; break; case 'eps': $processor = 'epsnetpay'; break; } if (!empty($aecConfig->cfg['debug_processor_notifications'])) { aecDebug("ResponseFunction:processNotification"); aecDebug($_GET); aecDebug($_POST); aecDebug($_REQUEST); aecDebug(file_get_contents("php://input")); } $response = array(); $response['fullresponse'] = aecPostParamClear($_POST); // parse processor notification $pp = new PaymentProcessor(); if ($pp->loadName($processor)) { $pp->init(); $response = array_merge($response, $pp->parseNotification($response['fullresponse'])); } else { $eventlog = new eventLog(); $eventlog->issue('processor loading failure', 'processor,loading,error', 'When receiving payment notification, tried to load processor: ' . $processor, 128); return; } // Get Invoice record if (!empty($response['invoice'])) { $id = aecInvoiceHelper::InvoiceIDfromNumber($response['invoice']); } else { $id = false; $response['invoice'] = 'empty'; } if (!$id) { $short = JText::_('AEC_MSG_PROC_INVOICE_FAILED_SH'); $event = ''; $tags = ''; if (isset($response['null'])) { if (isset($response['explanation'])) { $short = JText::_('AEC_MSG_PROC_INVOICE_ACTION_SH'); $event .= $response['explanation']; } else { $event .= JText::_('AEC_MSG_PROC_INVOICE_ACTION_EV_NULL'); } $tags .= 'invoice,processor,payment,null'; } else { $event = sprintf(JText::_('AEC_MSG_PROC_INVOICE_FAILED_EV'), $processor, $response['invoice']); $tags = 'invoice,processor,payment,error'; } $params = array(); $eventlog = new eventLog(); if (isset($response['null'])) { if (isset($response['error'])) { $eventlog->issue($short, $tags, $response['error'], 128, $params); } else { $eventlog->issue($short, $tags, $event, 8, $params); } } else { $eventlog->issue($short, $tags, $event, 128, $params); $error = 'Invoice Number not found. Invoice number provided: "' . $response['invoice'] . '"'; $pp->notificationError($response, $error); } return; } else { $iFactory = new InvoiceFactory(null, null, null, null, $response['invoice']); $iFactory->processorResponse($response); } }
/** * @param Subscription $subscription_id */ public function validateSubscription($subscription_id) { if (empty($this->settings)) { $this->getSettings(); } if (method_exists($this->processor, 'validateSubscription')) { $subscription = new Subscription(); $subscription->load($subscription_id); $allowed = array("Trial", "Active"); if (!in_array($subscription->status, $allowed)) { return null; } $invoice = new Invoice(); $invoice->loadbySubscriptionId($subscription_id); if (empty($invoice->id)) { return null; } $iFactory = new InvoiceFactory(null, null, null, $this->processor_name); $iFactory->userid = $subscription->userid; $iFactory->usage = $invoice->usage; $iFactory->processor = $this->processor_name; $iFactory->loadMetaUser(); $iFactory->touchInvoice($invoice->invoice_number); $iFactory->puffer(); $iFactory->loadItems(); $iFactory->loadItemTotal(); foreach ($iFactory->items->itemlist as $item) { $this->exchangeSettingsByPlan($item['obj']); } $result = $this->processor->validateSubscription($iFactory, $subscription); $resp = array(); if (!empty($result['raw'])) { if (is_array($result['raw'])) { $resp = $result['raw']; } else { $resp['response'] = $result['raw']; } } $iFactory->invoice->processorResponse($iFactory, $result, $resp, true); if (!empty($result['valid'])) { return true; } elseif (empty($result['error'])) { return null; } } else { return null; } }