/** * Renders the admin screen * * @author Jonathan Davis * @since 1.3 * * @return void **/ public function screen() { if (!current_user_can('shopp_financials')) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } extract($this->options, EXTR_SKIP); $Report = $this->Report; $Report->pagination(); $ListTable = ShoppUI::table_set_pagination($screen, $Report->total, $Report->pages, $per_page); $ranges = array('all' => __('Show All Orders', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp')); $format = shopp_setting('report_format'); if (!$format) { $format = 'tab'; } $columns = array_merge(ShoppPurchase::exportcolumns(), ShoppPurchased::exportcolumns()); $selected = shopp_setting('purchaselog_columns'); if (empty($selected)) { $selected = array_keys($columns); } $reports = self::reports(); $report_title = isset($reports[$report]) ? $reports[$report]['name'] : __('Report', 'Shopp'); include $this->ui('reports.php'); }
public function __construct() { $this->purchase_cols = ShoppPurchase::exportcolumns(); $this->purchased_cols = ShoppPurchased::exportcolumns(); $this->defined = array_merge($this->purchase_cols, $this->purchased_cols); $this->sitename = get_bloginfo('name'); $this->headings = shopp_setting('purchaselog_headers') == "on"; $this->selected = shopp_setting('purchaselog_columns'); $this->date_format = get_option('date_format'); $this->time_format = get_option('time_format'); shopp_set_setting('purchaselog_lastexport', current_time('timestamp')); }
/** * Interface processor for the orders list interface * * @author Jonathan Davis * * @return void **/ public function orders() { if (!current_user_can('shopp_orders')) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } global $Shopp, $Orders; $defaults = array('page' => false, 'update' => false, 'newstatus' => false, 'paged' => 1, 'per_page' => 20, 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); $s = stripslashes($s); $statusLabels = shopp_setting('order_status'); if (empty($statusLabels)) { $statusLabels = array(''); } $txnstatus_labels = Lookup::txnstatus_labels(); $Purchase = new ShoppPurchase(); $Orders = $this->orders; $ordercount = $this->ordercount; $num_pages = ceil($ordercount->total / $per_page); $ListTable = ShoppUI::table_set_pagination($this->screen, $ordercount->total, $num_pages, $per_page); $ranges = array('all' => __('Show All Orders', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft® Excel.xls', 'Shopp'), 'iif' => __('Intuit® QuickBooks.iif', 'Shopp')); $formatPref = shopp_setting('purchaselog_format'); if (!$formatPref) { $formatPref = 'tab'; } $exportcolumns = array_merge(ShoppPurchase::exportcolumns(), ShoppPurchased::exportcolumns()); $selected = shopp_setting('purchaselog_columns'); if (empty($selected)) { $selected = array_keys($exportcolumns); } $Gateways = $Shopp->Gateways; include $this->ui('orders.php'); }
/** * Handles product file download requests * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function download() { $Shopp = Shopp::object(); $download = $this->request['shopp_download']; $Purchase = false; $Purchased = false; if (defined('WP_ADMIN')) { $forbidden = false; $Download = new ProductDownload($download); } else { $Order = ShoppOrder(); $accounts = 'none' != shopp_setting('account_system'); $Download = new ProductDownload(); $Download->loadby_dkey($download); $Purchased = $Download->purchased(); $Purchase = new ShoppPurchase($Purchased->purchase); $Purchase->load_events(); $name = $Purchased->name . (!empty($Purchased->optionlabel) ? ' (' . $Purchased->optionlabel . ')' : ''); $forbidden = false; // Voided orders if ($Purchase->isvoid()) { shopp_add_error(Shopp::__('"%s" cannot be downloaded because the order has been cancelled.', $name)); $forbidden = true; } // Purchase Completion check if (!$Purchase->ispaid() && !SHOPP_PREPAYMENT_DOWNLOADS) { shopp_add_error(Shopp::__('"%s" cannot be downloaded because payment has not been received yet.', $name)); $forbidden = true; } // If accounts are used and this is not a guest account if ($accounts && Shopp::__('Guest') != ShoppCustomer()->type) { // User must be logged in when accounts are being used if (!ShoppCustomer()->loggedin()) { shopp_add_error(Shopp::__('You must login to download purchases.')); $forbidden = true; } // Logged in account must be the owner of the purchase if (ShoppCustomer()->id != $Purchase->customer) { shopp_add_error(Shopp::__('You are not authorized to download the requested file.')); $forbidden = true; } } // Download limit checking if (shopp_setting('download_limit') && $Purchased->downloads + 1 > shopp_setting('download_limit')) { shopp_add_error(Shopp::__('"%s" is no longer available for download because the download limit has been reached.', $name)); $forbidden = true; } // Download expiration checking if (shopp_setting('download_timelimit') && $Purchased->created + shopp_setting('download_timelimit') < current_time('timestamp')) { shopp_add_error(Shopp::__('"%s" is no longer available for download because it has expired.', 'Shopp', $name)); $forbidden = true; } // IP restriction checks if ('ip' == shopp_setting('download_restriction') && !empty($Purchase->ip) && $Purchase->ip != $_SERVER['REMOTE_ADDR']) { shopp_add_error(Shopp::__('"%s" cannot be downloaded because your computer could not be verified as the system the file was purchased from.', $name)); $forbidden = true; } do_action_ref_array('shopp_download_request', array($Purchased)); } if (apply_filters('shopp_download_forbidden', $forbidden, $Purchased)) { Shopp::redirect(add_query_arg('downloads', '', Shopp::url(false, 'account')), true, 303); } // Send the download $download = $Download->download(); if (is_a($download, 'ShoppError')) { // If the result is an error redirect to the account downloads page Shopp::redirect(add_query_arg('downloads', '', Shopp::url(false, 'account')), true, 303); } else { do_action_ref_array('shopp_download_success', array($Purchased, $Purchase, $Download)); // @deprecated use shopp_download_order_event instead shopp_add_order_event($Purchase->id, 'download', array('purchased' => $Purchased->id, 'download' => $Download->id, 'ip' => ShoppShopping()->ip, 'customer' => ShoppCustomer()->id)); } exit; }
/** * shopp_order_exists - determine if an order exists with the specified id, or transaction id. * * @api * @since 1.2 * * @param int $id the order id, or the transaction id * @param string $by (optional default:id) lookup by 'id', or 'trans' * @return Purchase|bool Purchase object returned if the order exists, else returns false **/ function shopp_order_exists($id = false, $by = 'id') { $Purchase = new ShoppPurchase(); if ($by == 'trans') { $Purchase->load($id, 'txnid'); } else { $Purchase->load($id); } if (!$Purchase->id) { return false; } return $Purchase; }
private function process($event, ShoppPurchase $Purchase) { if (!$Purchase->lock()) { return false; } // Only process order updates if this process can get a lock $Message = $this->Message; if (in_array($event, array('sale', 'auth', 'capture'))) { $this->updates(); // Make sure purchase orders are invoiced if ('purchase' === $Purchase->txnstatus) { ShoppOrder()->invoice($Purchase); } elseif ('invoiced' === $Purchase->txnstatus) { $this->sale($Purchase); } elseif ('capture' === $event) { if (!$Purchase->capturable()) { return ShoppOrder()->success(); } // Already captured if ('voided' === $Purchase->txnstatus) { ShoppOrder()->invoice($Purchase); } // Reinvoice for cancel-reversals shopp_add_order_event($Purchase->id, 'capture', array('txnid' => $Purchase->txnid, 'gateway' => $Purchase->gateway, 'amount' => $Message->amount(), 'user' => $this->settings['label'])); } } elseif ('void' == $event) { shopp_add_order_event($Purchase->id, 'void', array('txnid' => $Purchase->txnid, 'gateway' => $this->module, 'reason' => $Message->reversal(), 'user' => $this->settings['label'], 'note' => $Message->reversal())); } elseif ('refund' == $event) { shopp_add_order_event($Purchase->id, 'refund', array('txnid' => $Purchase->txnid, 'gateway' => $this->module, 'amount' => $Message->amount(), 'reason' => $Message->reversal(), 'user' => $this->settings['label'])); } elseif ($txn_type = $Message->type()) { shopp_add_order_event($Purchase->id, 'review', array('kind' => 'txn_type', 'note' => $Message->type())); } $Purchase->unlock(); }
/** * Creates a customer record (and WordPress user) and attaches the order to it * * @author Jonathan Davis * @since 1.2 * * @return void **/ public function accounts($Event) { $Purchase = $Event->order(); if (!$Purchase) { shopp_debug('No purchase available for account registration processing.'); return; } if (!$this->Customer->exists()) { $registration = $Purchase->registration(); if (empty($registration)) { shopp_debug('No purchase registration data available for account registration processing.'); return; } $this->Customer->copydata($registration['Customer']); $this->Billing->copydata($registration['Billing']); $this->Shipping->copydata($registration['Shipping']); // Validation already conducted during the checkout process add_filter('shopp_validate_registration', '__return_true'); // Prevent redirection to account page after registration add_filter('shopp_registration_redirect', '__return_false'); } ShoppRegistration::process(); // Update Purchase with link to created customer record if (!empty($this->Customer->id)) { $Purchase = ShoppPurchase(); if ($Purchase->id != $Event->order) { $Purchase = new ShoppPurchase($Event->order); } $Purchase->customer = $this->Customer->id; $Purchase->billing = $this->Billing->id; $Purchase->shipping = $this->Shipping->id; $Purchase->save(); } }
/** * Loads an order by id associated with only this customer * * @author Jonathan Davis * @since 1.3 * * @param int $id The purchase record ID * @return void **/ public function order($id) { $Purchase = new ShoppPurchase(array('id' => (int) $id, 'customer' => $this->id)); if ($Purchase->exists()) { ShoppPurchase($Purchase); $Purchase->load_purchased(); return; } shopp_add_error(Shopp::__('Order number %s could not be found in your order history.', (int) $id), SHOPP_AUTH_ERR); }
public function save_totals() { if (!$this->form('save-totals')) { return; } $Purchase = new ShoppPurchase($this->form('id')); if (!$Purchase->exists()) { return; } $totals = array(); if ($this->form('totals')) { $totals = $this->form('totals'); } $objects = array('tax' => 'OrderAmountTax', 'shipping' => 'OrderAmountShipping', 'discount' => 'OrderAmountDiscount'); $methods = array('fee' => 'fees', 'tax' => 'taxes', 'shipping' => 'shipfees', 'discount' => 'discounts'); $total = 0; foreach ($totals as $property => $fields) { if (empty($fields)) { continue; } if (count($fields) > 1) { if (isset($fields['labels'])) { $labels = $fields['labels']; unset($fields['labels']); if (count($fields) > count($labels)) { $totalfield = array_pop($fields); } $fields = array_combine($labels, $fields); } $fields = array_map(array('Shopp', 'floatval'), $fields); $entries = array(); $OrderAmountObject = isset($objects[$property]) ? $objects[$property] : 'OrderAmountFee'; foreach ($fields as $label => $amount) { $entries[] = new $OrderAmountObject(array('id' => count($entries) + 1, 'label' => $label, 'amount' => $amount)); } $savetotal = isset($methods[$property]) ? $methods[$property] : $fees; $Purchase->{$savetotal}($entries); $sum = array_sum($fields); if ($sum > 0) { $Purchase->{$property} = $sum; } } else { $Purchase->{$property} = Shopp::floatval($fields[0]); } $total += 'discount' == $property ? $Purchase->{$property} * -1 : $Purchase->{$property}; } $Purchase->total = $Purchase->subtotal + $total; $Purchase->save(); }
/** * Provides the receipt markup generated from the receipt template * * @api `shopp('purchase.receipt')` * @since 1.1 * * @param string $result The output * @param array $options The options * @param ShoppPurchase $O The working object * @return string The receipt markup **/ public static function receipt($result, $options, $O) { $template = ''; if (isset($options['template']) && !empty($options['template'])) { return $O->receipt($options['template']); } return $O->receipt(); }