public function modifyPrice($request) { if (!isset($request->params['amt'])) { return null; } $price = AECToolbox::correctAmount($request->params['amt']); $request->add['terms']->nextterm->addCost($price, array('details' => $this->settings['confirm_name'], 'no-discount' => true)); return null; }
public function addCost($request, $item) { $total = $item['terms']->terms[0]->renderTotal(); if ($this->settings['mode'] == 'basic') { $extracost = -$this->settings['amount']; } else { $extracost = -AECToolbox::correctAmount($total * ($this->settings['amount'] / 100)); } $item['terms']->terms[0]->addCost($extracost, array('details' => $this->settings['extra'])); $item['cost'] = $item['terms']->renderTotal(); return $request; }
public function request($type, $start, $end) { $tree = new stdClass(); switch ($type) { case 'sales': $tree = array(); if (empty($end)) { $end = date('Y-m-d H:i:s', (int) gmdate('U')); } $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $start . '\'' . ' AND transaction_date <= \'' . $end . '\'' . ' ORDER BY transaction_date ASC'; $this->db->setQuery($query); $entries = xJ::getDBArray($this->db); if (empty($entries)) { echo json_encode($tree); exit; } $historylist = array(); $groups = array(); foreach ($entries as $id) { $entry = new logHistory(); $entry->load($id); $entry->amount = AECToolbox::correctAmount($entry->amount); $refund = false; if (is_array($entry->response) && !empty($entry->response)) { $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied'); foreach ($entry->response as $v) { if (in_array($v, $filter)) { continue 2; } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') { $refund = true; } } } else { continue; } $pgroups = ItemGroupHandler::parentGroups($entry->plan_id); if (empty($pgroups[0])) { $pgroups[0] = 0; } if (!in_array($pgroups[0], $groups)) { $groups[] = $pgroups[0]; } $sale = new stdClass(); $sale->id = $id; //$sale->invoice = $entry->invoice_number; $sale->date = $entry->transaction_date; //$sale->datejs = date( 'F d, Y H:i:s', strtotime( $entry->transaction_date ) ); $sale->plan = $entry->plan_id; $sale->group = $pgroups[0]; $sale->amount = $refund ? -$entry->amount : $entry->amount; $tree[] = $sale; } break; } echo json_encode($tree); exit; }
public function modifyPrice($request) { if (!isset($request->params['amt'])) { return null; } $price = AECToolbox::correctAmount($request->params['amt']); if (!empty($this->settings['max'])) { if ($price > $this->settings['max']) { $price = $this->settings['max']; } } if (!empty($this->settings['min'])) { if ($price < $this->settings['min']) { $price = $this->settings['min']; } } $price = AECToolbox::correctAmount($price); $request->add['terms']->nextterm->setCost($price); return null; }
public function check($fields = array()) { $unset = array('made_free'); foreach ($unset as $varname) { if (isset($this->{$varname})) { unset($this->{$varname}); } } $this->amount = AECToolbox::correctAmount($this->amount); parent::check($fields); return true; }
public function saveParams($params) { // If the admin wants this to be a free plan, we have to make this more explicit // Setting processors to zero and full_free if ($params['full_free'] && $params['processors'] == '') { $params['processors'] = ''; } elseif (!$params['full_amount'] || $params['full_amount'] == '0.00' || $params['full_amount'] == '') { $params['full_free'] = 1; $params['processors'] = ''; } // Correct a malformed Full Amount if (!strlen($params['full_amount'])) { $params['full_amount'] = '0.00'; $params['full_free'] = 1; $params['processors'] = ''; } else { $params['full_amount'] = AECToolbox::correctAmount($params['full_amount']); } // Correct a malformed Trial Amount if (strlen($params['trial_amount'])) { $params['trial_amount'] = AECToolbox::correctAmount($params['trial_amount']); } // Prevent setting Trial Amount to 0.00 if no free trial was asked for if (!$params['trial_free'] && strcmp($params['trial_amount'], "0.00") === 0) { $params['trial_amount'] = ''; } $this->params = $params; }
public function getCheckout($metaUser, $counter = 0, $InvoiceFactory = null) { $c = array(); $totalcost = 0; if (empty($this->content)) { return array(); } $return = array(); foreach ($this->content as $cid => $content) { // Cache items if (!isset($c[$content['type']][$content['id']])) { switch ($content['type']) { case 'plan': $obj = new SubscriptionPlan(); $obj->load($content['id']); $o = array(); $o['obj'] = $obj; $o['name'] = $obj->getProperty('name'); $o['desc'] = $obj->getProperty('desc'); $terms = $obj->getTermsForUser(false, $metaUser); if ($counter) { $terms->incrementPointer($counter); } $o['terms'] = $terms; $o['cost'] = $terms->nextterm->renderCost(); $c[$content['type']][$content['id']] = $o; break; } } $entry = array(); $entry['obj'] = $c[$content['type']][$content['id']]['obj']; $entry['fullamount'] = $c[$content['type']][$content['id']]['cost']; $entry['name'] = $c[$content['type']][$content['id']]['name']; $entry['desc'] = $c[$content['type']][$content['id']]['desc']; $entry['terms'] = $c[$content['type']][$content['id']]['terms']; $item = array('item' => array('obj' => $entry['obj']), 'terms' => $entry['terms']); if (!empty($content['coupons'])) { $cpsh = new couponsHandler($metaUser, false, $content['coupons']); $item = $cpsh->applyAllToItems(0, $item); $entry['terms'] = $item['terms']; } $entry['cost'] = $entry['terms']->nextterm->renderTotal(); if ($entry['cost'] > 0) { $total = $content['quantity'] * $entry['cost']; $entry['cost_total'] = AECToolbox::correctAmount($total); } else { $entry['cost_total'] = AECToolbox::correctAmount('0.00'); } if ($entry['cost_total'] == '0.00') { $entry['free'] = true; } else { $entry['free'] = false; } $entry['cost'] = AECToolbox::correctAmount($entry['cost']); $entry['quantity'] = $content['quantity']; $totalcost += $entry['cost_total']; $return[$cid] = $entry; } if (!empty($this->params['overall_coupons'])) { $cpsh = new couponsHandler($metaUser, $InvoiceFactory, $this->params['overall_coupons']); $totalcost_ncp = $totalcost; $totalcost = $cpsh->applyToAmount($totalcost); } else { $totalcost_ncp = $totalcost; } // Append total cost $return[] = array('name' => '', 'count' => '', 'cost' => AECToolbox::correctAmount($totalcost_ncp), 'cost_total' => AECToolbox::correctAmount($totalcost), 'is_total' => true, 'obj' => false); return $return; }
public function modifyPrice($request) { $discount = AECToolbox::correctAmount($request->params['use_points'] * $this->settings['checkout_conversion']); $original_price = $request->add['terms']->nextterm->renderTotal(); if ($discount > $original_price) { $discount = $original_price; $request->params['use_points'] = (int) $discount / $this->settings['checkout_conversion']; while ($request->params['use_points'] * $this->settings['checkout_conversion'] < $original_price) { $request->params['use_points']++; } $request->params['use_points_final'] = $request->params['use_points']; $request->metaUser->meta->setMIParams($request->parent->id, $request->plan->id, $request->params, true); $request->metaUser->meta->storeload(); } $request->add['terms']->nextterm->discount($discount, null, array('details' => $request->params['use_points'] . " Points")); return true; }
public function exportSales() { $db = JFactory::getDBO(); $query = 'SELECT `id`' . ' FROM #__acctexp_log_history' . ' WHERE transaction_date >= \'' . $this->filter['date_start'] . '\'' . ' AND transaction_date <= \'' . $this->filter['date_end'] . '\'' . ' ORDER BY transaction_date ASC'; $db->setQuery($query); $entries = xJ::getDBArray($db); switch ($this->options['collate']) { default: case 'day': $collation = 'Y-m-d'; break; case 'week': $collation = 'Y-W'; break; case 'month': $collation = 'Y-m'; break; case 'year': $collation = 'Y'; break; } $collators = array(); switch ($this->options['breakdown']) { default: case 'plan': break; case 'group': $all_groups = ItemGroupHandler::getGroups(); $collators = array(); foreach ($all_groups as $gid) { $collators[$gid] = ItemGroupHandler::getChildren($gid, 'item'); } break; } $historylist = array(); foreach ($entries as $id) { $entry = new logHistory(); $entry->load($id); if (empty($entry->plan_id) || empty($entry->amount)) { continue; } if (!empty($this->filter['groupid'])) { if (empty($this->filter['planid'])) { $this->filter['planid'] = array(); } $children = ItemGroupHandler::getChildren($this->filter['groupid'], 'item'); if (!empty($children)) { $this->filter['planid'] = array_merge($this->filter['planid'], $children); $this->filter['planid'] = array_unique($this->filter['planid']); } } if (!empty($this->filter['planid'])) { if (!in_array($entry->plan_id, $this->filter['planid'])) { continue; } } if (!empty($this->filter['method'])) { if (!in_array($entry->proc_id, $this->filter['method'])) { continue; } } $refund = false; if (is_array($entry->response)) { $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied'); $refund = false; foreach ($entry->response as $v) { if (in_array($v, $filter)) { continue 2; } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') { $refund = true; } } } $date = date($collation, strtotime($entry->transaction_date)); if ($this->options['breakdown'] == 'plan') { if (!array_key_exists($entry->plan_id, $collators)) { $collators[$entry->plan_id] = 0; } } if (!isset($historylist[$date])) { $historylist[$date] = array(); } $historylist[$date][] = $entry; } $line = array("line" => "Date"); if ($this->options['breakdown'] == 'plan') { foreach ($collators as $col => $colamount) { $line['plan-' . $col] = "Plan #{$col}: " . SubscriptionPlanHandler::planName($col); } } elseif ($this->options['breakdown'] == 'group') { foreach ($collators as $col => $colplans) { $line['group-' . $col] = "Group #{$col}:" . ItemGroupHandler::groupName($col); } } $line['total_sum'] = "Total"; // Remove whitespaces and newlines foreach ($line as $larrid => $larrval) { $line[$larrid] = trim($larrval); if (is_numeric($larrval)) { $line[$larrid] = AECToolbox::correctAmount($larrval); } } $this->exphandler->putDescription($line); $totalsum = 0; $collate_all = array(); foreach ($collators as $col => $colv) { $collate_all[$col] = 0; } foreach ($historylist as $date => $collater) { $linesum = 0; $collatex = array(); foreach ($collators as $col => $colv) { $collatex[$col] = 0; } foreach ($collater as $entry) { if ($this->options['breakdown'] == 'plan') { $collatex[$entry->plan_id] += $entry->amount; $collate_all[$entry->plan_id] += $entry->amount; $linesum += $entry->amount; $totalsum += $entry->amount; } else { $pgroup = 0; foreach ($collators as $gid => $gplans) { if ($entry->plan_id == $gid) { $pgroup = $gid; break; } } if ($pgroup) { $collatex[$pgroup] += $entry->amount; $collate_all[$pgroup] += $entry->amount; } $linesum += $entry->amount; $totalsum += $entry->amount; } } $line = array("date" => $date); foreach ($collators as $col => $colamount) { if ($this->options['breakdown'] == 'plan') { $line['plan-' . $col] = $collatex[$col]; } else { $line['group-' . $col] = $collatex[$col]; } } $line['total_sum'] = $linesum; // Remove whitespaces and newlines $i = 0; foreach ($line as $larrid => $larrval) { $line[$larrid] = trim($larrval); if (is_numeric($larrval) && $i) { $line[$larrid] = AECToolbox::correctAmount($larrval); } $i++; } $this->exphandler->putln($line); } $line = array("line" => "Grand Total"); foreach ($collate_all as $col => $colamount) { if ($this->options['breakdown'] == 'plan') { $line['plan-' . $col] = $colamount; } else { $line['group-' . $col] = $colamount; } } $line['total_sum'] = $totalsum; // Remove whitespaces and newlines foreach ($line as $larrid => $larrval) { $line[$larrid] = trim($larrval); if (is_numeric($larrval)) { $line[$larrid] = AECToolbox::correctAmount($larrval); } } $this->exphandler->putSum($line); }
public function createGatewayLink($request) { if ($this->settings['testmode']) { $var['post_url'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; } else { $var['post_url'] = 'https://www.paypal.com/cgi-bin/webscr'; } $var['cmd'] = '_xclick'; if (!empty($this->settings['invoice_tax']) && isset($request->items->tax)) { $tax = 0; foreach ($request->items->tax as $itax) { $tax += $itax['cost']; } $var['tax'] = AECToolbox::correctAmount($tax); $var['amount'] = $request->items->total->cost['amount']; } elseif (!empty($this->settings['tax']) && $this->settings['tax'] > 0) { $amount = $request->int_var['amount'] / (100 + $this->settings['tax']) * 100; $var['tax'] = AECToolbox::correctAmount($request->int_var['amount'] - $amount, 2); $var['amount'] = AECToolbox::correctAmount($amount, 2); } else { $var['amount'] = $request->int_var['amount']; } $var['business'] = $this->settings['business']; $var['invoice'] = $request->invoice->invoice_number; $var['cancel_return'] = AECToolbox::deadsureURL('index.php?option=com_acctexp&task=cancel'); if (strpos($this->settings['altipnurl'], 'http://') === 0) { $var['notify_url'] = $this->settings['altipnurl'] . 'index.php?option=com_acctexp&task=paypalnotification'; } else { $var['notify_url'] = AECToolbox::deadsureURL('index.php?option=com_acctexp&task=paypalnotification'); } $var['item_number'] = AECToolbox::rewriteEngineRQ($this->settings['item_number'], $request); $var['item_name'] = AECToolbox::rewriteEngineRQ($this->settings['item_name'], $request); $var['no_shipping'] = $this->settings['no_shipping']; $var['no_note'] = '1'; $var['rm'] = '2'; $var['return'] = $request->int_var['return_url']; $var['currency_code'] = $this->settings['currency']; $var['lc'] = $this->settings['lc']; // Customizations $customizations = array('cbt', 'cn', 'cpp_header_image', 'cpp_headerback_color', 'cpp_headerborder_color', 'cpp_payflow_color', 'image_url', 'page_style'); foreach ($customizations as $cust) { if (!empty($this->settings[$cust])) { $var[$cust] = $this->settings[$cust]; } } if (isset($this->settings['cs'])) { if ($this->settings['cs'] != 0) { $var['cs'] = $this->settings['cs']; } } return $var; }
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; }
public function createGatewayLink($request) { $baseurl = AECToolbox::deadsureURL('index.php?option=com_acctexp&task=payernotification', false, true); $Auth_url = $baseurl . '&action=authenticate'; $Settle_url = $baseurl . '&action=settle'; $Success_url = $request->int_var['return_url']; $Shop_url = JURI::root() . "index.php"; // Explode Name $namearray = explode(" ", $request->metaUser->cmsUser->name); $firstfirstname = $namearray[0]; $maxname = count($namearray) - 1; $lastname = $namearray[$maxname]; unset($namearray[$maxname]); $firstname = implode(' ', $namearray); // Header $xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; $xml .= "<payread_post_api_0_2 " . "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " . "xsi:noNamespaceSchemaLocation=\"payread_post_api_0_2.xsd\"" . ">"; // Seller details $xml .= "<seller_details>" . "<agent_id>" . htmlspecialchars($this->settings['agentid']) . "</agent_id>" . "</seller_details>"; // Buyer details $xml .= "<buyer_details>" . "<first_name>" . htmlspecialchars($firstname) . "</first_name>" . "<last_name>" . htmlspecialchars($lastname) . "</last_name>" . "<address_line_1>" . htmlspecialchars("AddressLine1") . "</address_line_1>" . "<address_line_2>" . htmlspecialchars("AddressLine2") . "</address_line_2>" . "<postal_code>" . htmlspecialchars("Postalcode") . "</postal_code>" . "<city>" . htmlspecialchars("City") . "</city>" . "<country_code>" . htmlspecialchars("CountryCode") . "</country_code>" . "<phone_home>" . htmlspecialchars("PhoneHome") . "</phone_home>" . "<phone_work>" . htmlspecialchars("PhoneWork") . "</phone_work>" . "<phone_mobile>" . htmlspecialchars("PhoneMobile") . "</phone_mobile>" . "<email>" . $request->metaUser->cmsUser->email . "</email>" . "</buyer_details>"; // Purchase $xml .= "<purchase>" . "<currency>" . $this->settings['currency'] . "</currency>"; // Add RefId if used $xml .= "<reference_id>" . $request->invoice->invoice_number . "</reference_id>"; // Start the Purchase list $xml .= "<purchase_list>"; $desc = AECToolbox::rewriteEngineRQ($this->settings['item_name'], $request); if (!empty($this->settings['invoice_tax'])) { foreach ($request->items->tax as $tax) { $tax += $tax['cost']; } } else { $tax = $this->settings['tax']; } $tax = AECToolbox::correctAmount($tax); // Purchase list (freeform purchases) $xml .= "<freeform_purchase>" . "<line_number>" . htmlspecialchars(1) . "</line_number>" . "<description>" . htmlspecialchars($desc) . "</description>" . "<price_including_vat>" . htmlspecialchars($request->int_var['amount']) . "</price_including_vat>" . "<vat_percentage>" . htmlspecialchars($tax) . "</vat_percentage>" . "<quantity>" . htmlspecialchars(1) . "</quantity>" . "</freeform_purchase>"; $xml .= "</purchase_list>" . "</purchase>"; //Processing control $xml .= "<processing_control>" . "<success_redirect_url>" . htmlspecialchars($this->mySuccessRedirectUrl) . "</success_redirect_url>" . "<authorize_notification_url>" . htmlspecialchars($this->myAuthorizeNotificationUrl) . "</authorize_notification_url>" . "<settle_notification_url>" . htmlspecialchars($this->mySettleNotificationUrl) . "</settle_notification_url>" . "<redirect_back_to_shop_url>" . htmlspecialchars($this->myRedirectBackToShopUrl) . "</redirect_back_to_shop_url>" . "</processing_control>"; // Database overrides $xml .= "<database_overrides>"; // Payment methods $xml .= "<accepted_payment_methods>"; $methods = explode(';', $this->settings["payment_method"]); foreach ($methods as $method) { $xml .= "<payment_method>" . $method . "</payment_method>"; } $xml .= "</accepted_payment_methods>"; // Debug mode $xml .= "<debug_mode>" . $this->settings['debugmode'] . "</debug_mode>"; // Test mode $xml .= "<test_mode>" . $this->settings['testmode'] . "</test_mode>"; // Language $xml .= "<language>" . $this->settings['language'] . "</language>"; $xml .= "</database_overrides>"; // Footer $xml .= "</payread_post_api_0_2>"; $var['post_url'] = "https://secure.pay-read.se/PostAPI_V1/InitPayFlow"; $var['payread_agentid'] = $this->settings['agentid']; $var['payread_xml_writer'] = "payread_php_0_2"; $var['payread_data'] = base64_encode($xml); $var['payread_checksum'] = md5($this->settings['key1'] . $xml . $this->settings['key2']); return $var; }
$t .= ' [' . $tmpl->lnk(array('task' => 'InvoiceRemoveCoupon', 'invoice' => $InvoiceFactory->invoice->invoice_number, 'coupon_code' => $citem->cost['coupon']), JText::_('CHECKOUT_INVOICE_COUPON_REMOVE')) . ']'; } } $cost[] = array('type' => $cost->type, 'details' => $t, 'cost' => $c); } } } } if (!empty($InvoiceFactory->items->tax)) { foreach ($InvoiceFactory->items->tax as $titems) { foreach ($titems['terms']->terms as $titem) { $citem = $titem->renderCost(); foreach ($citem as $cost) { if ($cost->type == 'tax') { $t = JText::_(strtoupper('aec_checkout_' . $cost->type)); $amount = AECToolbox::correctAmount($cost->cost['amount']); $c = AECToolbox::formatAmount($amount, $InvoiceFactory->payment->currency); if (!empty($cost->cost['details'])) { $t .= ' ( ' . $cost->cost['details'] . ' )'; } } $cost[] = array('type' => $cost->type, 'details' => $t, 'cost' => $c); } } } } $i['terms'][] = array('type' => 'total', 'current' => 1, 'cost' => $cost); $itemlist[] = $i; if (!empty($InvoiceFactory->items->grand_total)) { $i = array('name' => JText::_('AEC_CHECKOUT_GRAND_TOTAL'), 'quantity' => 1, 'terms' => array()); $c = AECToolbox::formatAmount($InvoiceFactory->items->grand_total->renderCost(), $InvoiceFactory->payment->currency);
public function saveDiscount($params) { // Correct a malformed Amount if (!strlen($params['amount'])) { $params['amount_use'] = 0; } else { $params['amount'] = AECToolbox::correctAmount($params['amount']); } $this->discount = $params; }
public function Action() { if (empty($_POST['start_date'])) { return null; } $db = JFactory::getDBO(); $start_timeframe = $_POST['start_date'] . ' 00:00:00'; if (empty($end)) { $end = date('Y-m-d', (int) gmdate('U')); } $end_timeframe = $end . ' 23:59:59'; $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(); $entry->load($id); $refund = false; if (is_array($entry->response)) { $filter = array('new_case', 'subscr_signup', 'paymentreview', 'subscr_eot', 'subscr_failed', 'subscr_cancel', 'Pending', 'Denied'); $refund = false; foreach ($entry->response as $v) { if (in_array($v, $filter)) { continue 2; } elseif ($v == 'refund' || $v == 'Reversed' || $v == 'Refunded') { $refund = true; } } } $date = date('Y-m-d', strtotime($entry->transaction_date)); $pgroups = ItemGroupHandler::parentGroups($entry->plan_id); if (!in_array($pgroups[0], $groups)) { $groups[] = $pgroups[0]; } if (!isset($historylist[$date])) { $historylist[$date] = array('amount' => null, 'groups' => null); } if ($refund) { $historylist[$date]['amount'] -= (double) $entry->amount; $historylist[$date]['groups'][$pgroups[0]]--; } else { $historylist[$date]['amount'] += (double) $entry->amount; $historylist[$date]['groups'][$pgroups[0]]++; } } foreach ($historylist as $date => $entry) { ksort($historylist[$date]['groups']); } $return = ""; $return .= '<table style="background-color: fff; width: 30%; margin: 0 auto; text-align: center !important; font-size: 180%;">'; $groupnames = array(); foreach ($groups as $group) { $groupnames[$group] = ItemGroupHandler::groupName($group); } $closer = 0; $incomplete = false; foreach ($historylist as $date => $history) { if (date('D', strtotime($date)) == 'Mon') { $week = array(); } elseif (!isset($week)) { $week = array(); $incomplete = true; } $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>'; foreach ($groups as $group) { if (empty($history['groups'][$group])) { $count = 0; } else { $count = $history['groups'][$group]; } $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; if (isset($week)) { $week['groups'][$group] += $count; } } if (isset($week)) { $week['amount'] += $history['amount']; } $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($history['amount']) . '</td>'; $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 0; if (date('D', strtotime($date)) == 'Sun') { $return .= '<tr ' . ($incomplete ? 'title="Incomplete!"' : '') . 'style="border-bottom: 2px solid #999 !important; height: 2em; background-color: #ddd;">'; $return .= '<td style="text-align: left !important; color: #aaa;">' . ($incomplete ? '(Week)' : 'Week') . '</td>'; $return .= '<td style="width: 5em;"> </td>'; foreach ($groups as $group) { if (empty($week['groups'][$group])) { $count = 0; } else { $count = $week['groups'][$group]; } if ($incomplete) { $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">(' . $count . ')</td>'; } else { $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; } } $return .= '<td style="width: 5em;"> </td>'; if ($incomplete) { $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">(' . AECToolbox::correctAmount($week['amount']) . ')</td>'; } else { $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>'; } $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 1; $incomplete = false; } } if (!$closer) { $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;">(Week)</td>'; $return .= '<td style="width: 5em;"> </td>'; foreach ($groups as $group) { if (empty($week['groups'][$group])) { $count = 0; } else { $count = $week['groups'][$group]; } $return .= '<td title="' . $groupnames[$group] . '" style="font-weight: bold; width: 5em;">' . $count . '</td>'; } $return .= '<td style="width: 5em;"> </td>'; $return .= '<td title="Amount" style="text-align: right !important; color: #608919;">' . AECToolbox::correctAmount($week['amount']) . '</td>'; $return .= '</tr>'; $return .= '<tr style="height: 1px; background-color: #999;">'; $return .= '<td colspan="' . (count($groups) + 4) . '"></td>'; $return .= '</tr>'; $closer = 1; } $return .= '</table><br /><br />'; return $return; }
static function formatAmount($amount, $currency = null, $round = true) { global $aecConfig; $amount = AECToolbox::correctAmount($amount, $round); $a = explode('.', $amount); if ($aecConfig->cfg['amount_use_comma']) { $amount = number_format($amount, $round ? 2 : strlen($a[1]), ',', '.'); } else { $amount = number_format($amount, $round ? 2 : strlen($a[1]), '.', ','); } if (!empty($currency)) { if (!empty($aecConfig->cfg['amount_currency_symbol'])) { $currency = AECToolbox::getCurrencySymbol($currency); } if ($aecConfig->cfg['amount_currency_symbolfirst']) { $amount = $currency . ' ' . $amount; } else { $amount .= ' ' . $currency; } } return $amount; }
public function invoice_items_total($request) { if (isset($request->add->tax)) { return true; } else { $request->add->tax = array(); } $taxtypes = array(); $taxcollections = array(); // Collect all the taxes from the individual item costs foreach ($request->add->itemlist as $item) { foreach ($item['terms']->nextterm->cost as $cost) { if ($cost->type == 'tax') { if (in_array($cost->cost['details'], $taxtypes)) { $typeid = array_search($cost->cost['details'], $taxtypes); } else { $taxtypes[] = $cost->cost['details']; $typeid = count($taxtypes) - 1; } if (!isset($taxcollections[$typeid])) { $taxcollections[$typeid] = 0; } $taxcollections[$typeid] += $cost->renderCost() * $item['quantity']; } } } if (count($taxcollections) == 0) { return null; } $taxamount = 0; // Add tax items to total foreach ($taxcollections as $tid => $amount) { // Create tax $term = new itemTerm(); if (!empty($taxtypes[$tid])) { $term->addCost($amount, array('details' => $taxtypes[$tid], 'tax' => true)); } else { $term->addCost($amount, array('tax' => true)); } $terms = new itemTerms(); $terms->addTerm($term); // Add the "Tax" row $request->add->tax[] = array('cost' => $amount, 'terms' => $terms); $taxamount += $amount; } $grand_total = $request->add->total->cost['amount']; if (!empty($request->add->discount)) { foreach ($request->add->discount as $citems) { foreach ($citems as $ccitem) { $citem = $ccitem->renderCost(); foreach ($citem as $cost) { if ($cost->type == 'discount') { $grand_total += $cost->cost['amount']; } } } } } $grand_total = AECToolbox::correctAmount($grand_total + $taxamount); // Modify grand total according to tax $request->add->grand_total->set('cost', array('amount' => $grand_total)); // Formatting for total $request->add->total->cost['amount'] = AECToolbox::correctAmount($request->add->total->cost['amount']); return true; }
public function addCost($request, $item, $option) { $total = $item['terms']->terms[0]->renderTotal(); if ($option['mode'] == 'basic') { $extracost = $option['amount']; } else { $extracost = AECToolbox::correctAmount($total * ($option['amount'] / 100)); } $newtotal = AECToolbox::correctAmount($total + $option['amount']); $item['terms']->terms[0]->addCost($extracost, array('details' => $option['extra'])); $item['cost'] = $item['terms']->renderTotal(); return $request; }