/** * Get Purchase Link * * Builds a Purchase link for a specified download based on arguments passed. * This function is used all over EDD to generate the Purchase or Add to Cart * buttons. If no arguments are passed, the function uses the defaults that have * been set by the plugin. The Purchase link is built for simple and variable * pricing and filters are available throughout the function to override * certain elements of the function. * * $download_id = null, $link_text = null, $style = null, $color = null, $class = null * * @since 1.0 * @param array $args Arguments for display * @return string $purchase_form */ function edd_get_purchase_link($args = array()) { global $edd_options, $post; if (!isset($edd_options['purchase_page']) || $edd_options['purchase_page'] == 0) { edd_set_error('set_checkout', sprintf(__('No checkout page has been configured. Visit <a href="%s">Settings</a> to set one.', 'edd'), admin_url('edit.php?post_type=download&page=edd-settings'))); edd_print_errors(); return false; } $post_id = is_object($post) ? $post->ID : 0; $defaults = apply_filters('edd_purchase_link_defaults', array('download_id' => $post_id, 'price' => (bool) true, 'direct' => edd_get_download_button_behavior($post_id) == 'direct' ? true : false, 'text' => !empty($edd_options['add_to_cart_text']) ? $edd_options['add_to_cart_text'] : __('Purchase', 'edd'), 'style' => isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button', 'color' => isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue', 'class' => 'edd-submit')); $args = wp_parse_args($args, $defaults); if ('publish' != get_post_field('post_status', $args['download_id']) && !current_user_can('edit_product', $args['download_id'])) { return false; // Product not published or user doesn't have permission to view drafts } // Override color if color == inherit $args['color'] = $args['color'] == 'inherit' ? '' : $args['color']; $variable_pricing = edd_has_variable_prices($args['download_id']); $data_variable = $variable_pricing ? ' data-variable-price="yes"' : 'data-variable-price="no"'; $type = edd_single_price_option_mode($args['download_id']) ? 'data-price-mode=multi' : 'data-price-mode=single'; if ($args['price'] && $args['price'] !== 'no' && !$variable_pricing) { $price = edd_get_download_price($args['download_id']); $button_text = !empty($args['text']) ? ' – ' . $args['text'] : ''; if (0 == $price) { $args['text'] = __('Free', 'edd') . $button_text; } else { $args['text'] = edd_currency_filter(edd_format_amount($price)) . $button_text; } } if (edd_item_in_cart($args['download_id']) && !$variable_pricing) { $button_display = 'style="display:none;"'; $checkout_display = ''; } else { $button_display = ''; $checkout_display = 'style="display:none;"'; } global $edd_displayed_form_ids; $form_id = !empty($args['form_id']) ? $args['form_id'] : 'edd_purchase_' . $args['download_id']; $args = apply_filters('edd_purchase_link_args', $args); ob_start(); ?> <form id="<?php echo $form_id; ?> " class="edd_download_purchase_form" method="post"> <?php do_action('edd_purchase_link_top', $args['download_id'], $args); ?> <div class="edd_purchase_submit_wrapper"> <?php $class = implode(' ', array($args['style'], $args['color'], trim($args['class']))); if (!edd_is_ajax_disabled()) { echo '<a href="#" class="edd-add-to-cart ' . esc_attr($class) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($args['download_id']) . '" ' . $data_variable . ' ' . $type . ' ' . $button_display . '><span class="edd-add-to-cart-label">' . $args['text'] . '</span> <span class="edd-loading"><i class="edd-icon-spinner edd-icon-spin"></i></span></a>'; } echo '<input type="submit" class="edd-add-to-cart edd-no-js ' . esc_attr($class) . '" name="edd_purchase_download" value="' . esc_attr($args['text']) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($args['download_id']) . '" ' . $data_variable . ' ' . $type . ' ' . $button_display . '/>'; echo '<a href="' . esc_url(edd_get_checkout_uri()) . '" class="edd_go_to_checkout ' . esc_attr($class) . '" ' . $checkout_display . '>' . __('Checkout', 'edd') . '</a>'; ?> <?php if (!edd_is_ajax_disabled()) { ?> <span class="edd-cart-ajax-alert"> <span class="edd-cart-added-alert" style="display: none;"> <?php printf(__('<i class="edd-icon-ok"></i> Added to cart', 'edd'), '<a href="' . esc_url(edd_get_checkout_uri()) . '" title="' . __('Go to Checkout', 'edd') . '">', '</a>'); ?> </span> </span> <?php } ?> <?php if (edd_display_tax_rate() && edd_prices_include_tax()) { echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Includes %1$s% tax', 'edd'), edd_get_tax_rate() * 100) . '</span>'; } elseif (edd_display_tax_rate() && !edd_prices_include_tax()) { echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Excluding %1$s% tax', 'edd'), edd_get_tax_rate() * 100) . '</span>'; } ?> </div><!--end .edd_purchase_submit_wrapper--> <input type="hidden" name="download_id" value="<?php echo esc_attr($args['download_id']); ?> "> <?php if (!empty($args['direct'])) { ?> <input type="hidden" name="edd_action" class="edd_action_input" value="straight_to_gateway"> <?php } else { ?> <input type="hidden" name="edd_action" class="edd_action_input" value="add_to_cart"> <?php } ?> <?php do_action('edd_purchase_link_end', $args['download_id'], $args); ?> </form><!--end #<?php echo esc_attr($form_id); ?> --> <?php $purchase_form = ob_get_clean(); return apply_filters('edd_purchase_download_form', $purchase_form, $args); }
/** * Calculate the taxed amount * * @since 1.3.3 * @param $amount float The original amount to calculate a tax cost * @param $country string The country to calculate tax for. Will use default if not passed * @param $state string The state to calculate tax for. Will use default if not passed * @return float $tax Taxed amount */ function edd_calculate_tax($amount = 0, $country = false, $state = false) { global $edd_options; $rate = edd_get_tax_rate($country, $state); $tax = 0.0; if (edd_use_taxes()) { if (edd_prices_include_tax()) { $pre_tax = $amount / (1 + $rate); $tax = $amount - $pre_tax; } else { $tax = $amount * $rate; } } return apply_filters('edd_taxed_amount', $tax, $rate, $country, $state); }
/** * Add a download to a given payment * * @since 2.5 * @param int $download_id The download to add * @param int $args Other arguments to pass to the function * @return void */ public function add_download($download_id = 0, $args = array(), $options = array()) { $download = new EDD_Download($download_id); // Bail if this post isn't a download if (!$download || $download->post_type !== 'download') { return false; } // Set some defaults $defaults = array('quantity' => 1, 'price_id' => false, 'item_price' => 0.0, 'discount' => 0, 'tax' => 0.0, 'fees' => array()); $args = wp_parse_args(apply_filters('edd_payment_add_download_args', $args, $download->ID), $defaults); // Allow overriding the price if ($args['item_price']) { $item_price = $args['item_price']; } else { // Deal with variable pricing if (edd_has_variable_prices($download->ID)) { $prices = get_post_meta($download->ID, 'edd_variable_prices', true); if ($args['price_id'] && array_key_exists($args['price_id'], (array) $prices)) { $item_price = $prices[$args['price_id']]['amount']; } else { $item_price = edd_get_lowest_price_option($download->ID); $args['price_id'] = edd_get_lowest_price_id($download->ID); } } else { $item_price = edd_get_download_price($download->ID); } } // Sanitizing the price here so we don't have a dozen calls later $item_price = edd_sanitize_amount($item_price); $quantity = edd_item_quantities_enabled() ? absint($args['quantity']) : 1; $amount = round($item_price * $quantity, edd_currency_decimal_filter()); if (!empty($args['fees'])) { foreach ($args['fees'] as $key => $fee) { if (empty($fee['download_id'])) { $args['fees'][$key]['download_id'] = $download_id; } $this->add_fee($args['fees'][$key], false); } } // Setup the downloads meta item $new_download = array('id' => $download->ID, 'quantity' => $quantity, 'fees' => $args['fees']); $default_options = array('quantity' => $quantity); if (!empty($args['price_id'])) { $default_options['price_id'] = (int) $args['price_id']; } $options = wp_parse_args($options, $default_options); $new_download['options'] = $options; $this->downloads[] = $new_download; $discount = $args['discount']; $subtotal = $amount; $tax = $args['tax']; if (edd_prices_include_tax()) { $subtotal -= round($tax, edd_currency_decimal_filter()); } $total = $subtotal - $discount + $tax; // Do not allow totals to go negatve if ($total < 0) { $total = 0; } // Silly item_number array $item_number = array('id' => $download->ID, 'quantity' => $quantity, 'options' => $options); $this->cart_details[] = array('name' => $download->post_title, 'id' => $download->ID, 'item_number' => $item_number, 'item_price' => round($item_price, edd_currency_decimal_filter()), 'quantity' => $quantity, 'discount' => $discount, 'subtotal' => round($subtotal, edd_currency_decimal_filter()), 'tax' => round($tax, edd_currency_decimal_filter()), 'fees' => $args['fees'], 'price' => round($total, edd_currency_decimal_filter())); $added_download = end($this->cart_details); $added_download['action'] = 'add'; $this->pending['downloads'][] = $added_download; reset($this->cart_details); $this->increase_subtotal($subtotal - $discount); $this->increase_tax($tax); return true; }
/** * Calculate the taxed amount * * @since 1.3.3 * @param $amount float The original amount to calculate a tax cost * @return float $tax Taxed amount */ function edd_calculate_tax($amount, $sum = true) { global $edd_options; // Not using taxes if (!edd_use_taxes()) { return $amount; } $rate = edd_get_tax_rate(); $tax = 0.0; $prices_include_tax = edd_prices_include_tax(); if ($prices_include_tax) { $tax = $amount - $amount / ($rate + 1); } else { $tax = $amount * $rate; } if ($sum) { if ($prices_include_tax) { $tax = $amount - $tax; } else { $tax = $amount + $tax; } } return apply_filters('edd_taxed_amount', round($tax, 2), $rate); }
/** * Get system info * * @since 2.0 * @access public * @global object $wpdb Used to query the database using the WordPress Database API * @global array $edd_options Array of all EDD options * @return string $return A string containing the info to output */ function edd_tools_sysinfo_get() { global $wpdb, $edd_options; if (!class_exists('Browser')) { require_once EDD_PLUGIN_DIR . 'includes/libraries/browser.php'; } $browser = new Browser(); // Get theme info if (get_bloginfo('version') < '3.4') { $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css'); $theme = $theme_data['Name'] . ' ' . $theme_data['Version']; } else { $theme_data = wp_get_theme(); $theme = $theme_data->Name . ' ' . $theme_data->Version; } // Try to identify the hosting provider $host = edd_get_host(); $return = '### Begin System Info ###' . "\n\n"; // Start with the basics... $return .= '-- Site Info' . "\n\n"; $return .= 'Site URL: ' . site_url() . "\n"; $return .= 'Home URL: ' . home_url() . "\n"; $return .= 'Multisite: ' . (is_multisite() ? 'Yes' : 'No') . "\n"; $return = apply_filters('edd_sysinfo_after_site_info', $return); // Can we determine the site's host? if ($host) { $return .= "\n" . '-- Hosting Provider' . "\n\n"; $return .= 'Host: ' . $host . "\n"; $return = apply_filters('edd_sysinfo_after_host_info', $return); } // The local users' browser information, handled by the Browser class $return .= "\n" . '-- User Browser' . "\n\n"; $return .= $browser; $return = apply_filters('edd_sysinfo_after_user_browser', $return); // WordPress configuration $return .= "\n" . '-- WordPress Configuration' . "\n\n"; $return .= 'Version: ' . get_bloginfo('version') . "\n"; $return .= 'Language: ' . (defined('WPLANG') && WPLANG ? WPLANG : 'en_US') . "\n"; $return .= 'Permalink Structure: ' . (get_option('permalink_structure') ? get_option('permalink_structure') : 'Default') . "\n"; $return .= 'Active Theme: ' . $theme . "\n"; $return .= 'Show On Front: ' . get_option('show_on_front') . "\n"; // Only show page specs if frontpage is set to 'page' if (get_option('show_on_front') == 'page') { $front_page_id = get_option('page_on_front'); $blog_page_id = get_option('page_for_posts'); $return .= 'Page On Front: ' . ($front_page_id != 0 ? get_the_title($front_page_id) . ' (#' . $front_page_id . ')' : 'Unset') . "\n"; $return .= 'Page For Posts: ' . ($blog_page_id != 0 ? get_the_title($blog_page_id) . ' (#' . $blog_page_id . ')' : 'Unset') . "\n"; } // Make sure wp_remote_post() is working $request['cmd'] = '_notify-validate'; $params = array('sslverify' => false, 'timeout' => 60, 'user-agent' => 'EDD/' . EDD_VERSION, 'body' => $request); $response = wp_remote_post('https://www.paypal.com/cgi-bin/webscr', $params); if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) { $WP_REMOTE_POST = 'wp_remote_post() works'; } else { $WP_REMOTE_POST = 'wp_remote_post() does not work'; } $return .= 'Remote Post: ' . $WP_REMOTE_POST . "\n"; $return .= 'Table Prefix: ' . 'Length: ' . strlen($wpdb->prefix) . ' Status: ' . (strlen($wpdb->prefix) > 16 ? 'ERROR: Too long' : 'Acceptable') . "\n"; $return .= 'WP_DEBUG: ' . (defined('WP_DEBUG') ? WP_DEBUG ? 'Enabled' : 'Disabled' : 'Not set') . "\n"; $return .= 'Memory Limit: ' . WP_MEMORY_LIMIT . "\n"; $return .= 'Registered Post Stati: ' . implode(', ', get_post_stati()) . "\n"; $return = apply_filters('edd_sysinfo_after_wordpress_config', $return); // EDD configuration $return .= "\n" . '-- EDD Configuration' . "\n\n"; $return .= 'Version: ' . EDD_VERSION . "\n"; $return .= 'Upgraded From: ' . get_option('edd_version_upgraded_from', 'None') . "\n"; $return .= 'Test Mode: ' . (edd_is_test_mode() ? "Enabled\n" : "Disabled\n"); $return .= 'Ajax: ' . (!edd_is_ajax_disabled() ? "Enabled\n" : "Disabled\n"); $return .= 'Guest Checkout: ' . (edd_no_guest_checkout() ? "Disabled\n" : "Enabled\n"); $return .= 'Symlinks: ' . (apply_filters('edd_symlink_file_downloads', isset($edd_options['symlink_file_downloads'])) && function_exists('symlink') ? "Enabled\n" : "Disabled\n"); $return .= 'Download Method: ' . ucfirst(edd_get_file_download_method()) . "\n"; $return .= 'Currency Code: ' . edd_get_currency() . "\n"; $return .= 'Currency Position: ' . edd_get_option('currency_position', 'before') . "\n"; $return .= 'Decimal Separator: ' . edd_get_option('decimal_separator', '.') . "\n"; $return .= 'Thousands Separator: ' . edd_get_option('thousands_separator', ',') . "\n"; $return = apply_filters('edd_sysinfo_after_edd_config', $return); // EDD pages $return .= "\n" . '-- EDD Page Configuration' . "\n\n"; $return .= 'Checkout: ' . (!empty($edd_options['purchase_page']) ? "Valid\n" : "Invalid\n"); $return .= 'Checkout Page: ' . (!empty($edd_options['purchase_page']) ? get_permalink($edd_options['purchase_page']) . "\n" : "Unset\n"); $return .= 'Success Page: ' . (!empty($edd_options['success_page']) ? get_permalink($edd_options['success_page']) . "\n" : "Unset\n"); $return .= 'Failure Page: ' . (!empty($edd_options['failure_page']) ? get_permalink($edd_options['failure_page']) . "\n" : "Unset\n"); $return .= 'Downloads Slug: ' . (defined('EDD_SLUG') ? '/' . EDD_SLUG . "\n" : "/downloads\n"); $return = apply_filters('edd_sysinfo_after_edd_pages', $return); // EDD gateways $return .= "\n" . '-- EDD Gateway Configuration' . "\n\n"; $active_gateways = edd_get_enabled_payment_gateways(); if ($active_gateways) { $default_gateway_is_active = edd_is_gateway_active(edd_get_default_gateway()); if ($default_gateway_is_active) { $default_gateway = edd_get_default_gateway(); $default_gateway = $active_gateways[$default_gateway]['admin_label']; } else { $default_gateway = 'Test Payment'; } $gateways = array(); foreach ($active_gateways as $gateway) { $gateways[] = $gateway['admin_label']; } $return .= 'Enabled Gateways: ' . implode(', ', $gateways) . "\n"; $return .= 'Default Gateway: ' . $default_gateway . "\n"; } else { $return .= 'Enabled Gateways: None' . "\n"; } $return = apply_filters('edd_sysinfo_after_edd_gateways', $return); // EDD Taxes $return .= "\n" . '-- EDD Tax Configuration' . "\n\n"; $return .= 'Taxes: ' . (edd_use_taxes() ? "Enabled\n" : "Disabled\n"); $return .= 'Tax Rate: ' . edd_get_tax_rate() * 100 . "\n"; $return .= 'Display On Checkout: ' . (!empty($edd_options['checkout_include_tax']) ? "Displayed\n" : "Not Displayed\n"); $return .= 'Prices Include Tax: ' . (edd_prices_include_tax() ? "Yes\n" : "No\n"); $rates = edd_get_tax_rates(); if (!empty($rates)) { $return .= 'Country / State Rates: ' . "\n"; foreach ($rates as $rate) { $return .= ' Country: ' . $rate['country'] . ', State: ' . $rate['state'] . ', Rate: ' . $rate['rate'] . "\n"; } } $return = apply_filters('edd_sysinfo_after_edd_taxes', $return); // EDD Templates $dir = get_stylesheet_directory() . '/edd_templates/*'; if (is_dir($dir) && count(glob("{$dir}/*")) !== 0) { $return .= "\n" . '-- EDD Template Overrides' . "\n\n"; foreach (glob($dir) as $file) { $return .= 'Filename: ' . basename($file) . "\n"; } $return = apply_filters('edd_sysinfo_after_edd_templates', $return); } // WordPress active plugins $return .= "\n" . '-- WordPress Active Plugins' . "\n\n"; $plugins = get_plugins(); $active_plugins = get_option('active_plugins', array()); foreach ($plugins as $plugin_path => $plugin) { if (!in_array($plugin_path, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } $return = apply_filters('edd_sysinfo_after_wordpress_plugins', $return); // WordPress inactive plugins $return .= "\n" . '-- WordPress Inactive Plugins' . "\n\n"; foreach ($plugins as $plugin_path => $plugin) { if (in_array($plugin_path, $active_plugins)) { continue; } $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } $return = apply_filters('edd_sysinfo_after_wordpress_plugins_inactive', $return); if (is_multisite()) { // WordPress Multisite active plugins $return .= "\n" . '-- Network Active Plugins' . "\n\n"; $plugins = wp_get_active_network_plugins(); $active_plugins = get_site_option('active_sitewide_plugins', array()); foreach ($plugins as $plugin_path) { $plugin_base = plugin_basename($plugin_path); if (!array_key_exists($plugin_base, $active_plugins)) { continue; } $plugin = get_plugin_data($plugin_path); $return .= $plugin['Name'] . ': ' . $plugin['Version'] . "\n"; } $return = apply_filters('edd_sysinfo_after_wordpress_ms_plugins', $return); } // Server configuration (really just versioning) $return .= "\n" . '-- Webserver Configuration' . "\n\n"; $return .= 'PHP Version: ' . PHP_VERSION . "\n"; $return .= 'MySQL Version: ' . $wpdb->db_version() . "\n"; $return .= 'Webserver Info: ' . $_SERVER['SERVER_SOFTWARE'] . "\n"; $return = apply_filters('edd_sysinfo_after_webserver_config', $return); // PHP configs... now we're getting to the important stuff $return .= "\n" . '-- PHP Configuration' . "\n\n"; $return .= 'Safe Mode: ' . (ini_get('safe_mode') ? 'Enabled' : 'Disabled' . "\n"); $return .= 'Memory Limit: ' . ini_get('memory_limit') . "\n"; $return .= 'Upload Max Size: ' . ini_get('upload_max_filesize') . "\n"; $return .= 'Post Max Size: ' . ini_get('post_max_size') . "\n"; $return .= 'Upload Max Filesize: ' . ini_get('upload_max_filesize') . "\n"; $return .= 'Time Limit: ' . ini_get('max_execution_time') . "\n"; $return .= 'Max Input Vars: ' . ini_get('max_input_vars') . "\n"; $return .= 'Display Errors: ' . (ini_get('display_errors') ? 'On (' . ini_get('display_errors') . ')' : 'N/A') . "\n"; $return = apply_filters('edd_sysinfo_after_php_config', $return); // PHP extensions and such $return .= "\n" . '-- PHP Extensions' . "\n\n"; $return .= 'cURL: ' . (function_exists('curl_init') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'fsockopen: ' . (function_exists('fsockopen') ? 'Supported' : 'Not Supported') . "\n"; $return .= 'SOAP Client: ' . (class_exists('SoapClient') ? 'Installed' : 'Not Installed') . "\n"; $return .= 'Suhosin: ' . (extension_loaded('suhosin') ? 'Installed' : 'Not Installed') . "\n"; $return = apply_filters('edd_sysinfo_after_php_ext', $return); // Session stuff $return .= "\n" . '-- Session Configuration' . "\n\n"; $return .= 'EDD Use Sessions: ' . (defined('EDD_USE_PHP_SESSIONS') && EDD_USE_PHP_SESSIONS ? 'Enforced' : (EDD()->session->use_php_sessions() ? 'Enabled' : 'Disabled')) . "\n"; $return .= 'Session: ' . (isset($_SESSION) ? 'Enabled' : 'Disabled') . "\n"; // The rest of this is only relevant is session is enabled if (isset($_SESSION)) { $return .= 'Session Name: ' . esc_html(ini_get('session.name')) . "\n"; $return .= 'Cookie Path: ' . esc_html(ini_get('session.cookie_path')) . "\n"; $return .= 'Save Path: ' . esc_html(ini_get('session.save_path')) . "\n"; $return .= 'Use Cookies: ' . (ini_get('session.use_cookies') ? 'On' : 'Off') . "\n"; $return .= 'Use Only Cookies: ' . (ini_get('session.use_only_cookies') ? 'On' : 'Off') . "\n"; } $return = apply_filters('edd_sysinfo_after_session_config', $return); $return .= "\n" . '### End System Info ###'; return $return; }
foreach ($price as $row => $value) { if (is_object($post) && ($post->post_content == '[purchase_history]' || $post->post_content == '[downloads_history]') && $payment_id > 0) { if (isset($edd_options['expired'][$payment_id]) && $edd_options['expired'][$payment_id] == $download_id) { if (!isset($value['renew'])) { unset($price[$row]); } } } else { if (isset($value['renew'])) { unset($price[$row]); } } } } return $price; } //add_action( 'edd_purchase_variable_prices', 'edd_plans_filter_download_price', 900, 2 ); add_filter('edd_get_download_price', 'edd_plans_filter_download_price', 11, 2); add_filter('edd_get_variable_prices', 'edd_plans_filter_download_price', 11, 2); function edd_plans_filter_cart_price($price, $download_id, $options, $include_taxes = false) { global $edd_options; $price = false; if (edd_has_variable_prices($download_id) && !empty($options)) {
/** * Process stripe checkout submission * * @access public * @since 1.0 * @return void */ function edds_process_stripe_payment($purchase_data) { global $edd_options; if (!class_exists('Stripe')) { require_once EDDS_PLUGIN_DIR . '/Stripe/Stripe.php'; } if (edd_is_test_mode()) { $secret_key = trim($edd_options['test_secret_key']); } else { $secret_key = trim($edd_options['live_secret_key']); } $purchase_summary = edd_get_purchase_summary($purchase_data, false); // make sure we don't have any left over errors present edd_clear_errors(); if (!isset($_POST['edd_stripe_token'])) { // check for fallback mode if (isset($edd_options['stripe_js_fallback'])) { if (!isset($_POST['card_name']) || strlen(trim($_POST['card_name'])) == 0) { edd_set_error('no_card_name', __('Please enter a name for the credit card.', 'edds')); } if (!isset($_POST['card_number']) || strlen(trim($_POST['card_number'])) == 0) { edd_set_error('no_card_number', __('Please enter a credit card number.', 'edds')); } if (!isset($_POST['card_cvc']) || strlen(trim($_POST['card_cvc'])) == 0) { edd_set_error('no_card_cvc', __('Please enter a CVC/CVV for the credit card.', 'edds')); } if (!isset($_POST['card_exp_month']) || strlen(trim($_POST['card_exp_month'])) == 0) { edd_set_error('no_card_exp_month', __('Please enter a expiration month.', 'edds')); } if (!isset($_POST['card_exp_year']) || strlen(trim($_POST['card_exp_year'])) == 0) { edd_set_error('no_card_exp_year', __('Please enter a expiration year.', 'edds')); } $card_data = array('number' => $purchase_data['card_info']['card_number'], 'name' => $purchase_data['card_info']['card_name'], 'exp_month' => $purchase_data['card_info']['card_exp_month'], 'exp_year' => $purchase_data['card_info']['card_exp_year'], 'cvc' => $purchase_data['card_info']['card_cvc'], 'address_line1' => $purchase_data['card_info']['card_address'], 'address_line2' => $purchase_data['card_info']['card_address_2'], 'address_city' => $purchase_data['card_info']['card_city'], 'address_zip' => $purchase_data['card_info']['card_zip'], 'address_state' => $purchase_data['card_info']['card_state'], 'address_country' => $purchase_data['card_info']['card_country']); } else { // no Stripe token edd_set_error('no_token', __('Missing Stripe token. Please contact support.', 'edds')); edd_record_gateway_error(__('Missing Stripe Token', 'edds'), __('A Stripe token failed to be generated. Please check Stripe logs for more information', ' edds')); } } else { $card_data = $_POST['edd_stripe_token']; } $errors = edd_get_errors(); if (!$errors) { try { Stripe::setApiKey($secret_key); // setup the payment details $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'cart_details' => $purchase_data['cart_details'], 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => 'stripe'); $customer_exists = false; if (is_user_logged_in()) { $user = get_user_by('email', $purchase_data['user_email']); if ($user) { $customer_id = get_user_meta($user->ID, edd_stripe_get_customer_key(), true); if ($customer_id) { $customer_exists = true; try { // Update the customer to ensure their card data is up to date $cu = Stripe_Customer::retrieve($customer_id); if (isset($cu->deleted) && $cu->deleted) { // This customer was deleted $customer_exists = false; } else { $cu->card = $card_data; $cu->save(); } // No customer found } catch (Exception $e) { $customer_exists = false; } } } } if (!$customer_exists) { // Create a customer first so we can retrieve them later for future payments $customer = Stripe_Customer::create(array('description' => $purchase_data['user_email'], 'email' => $purchase_data['user_email'], 'card' => $card_data)); $customer_id = is_array($customer) ? $customer['id'] : $customer->id; if (is_user_logged_in()) { update_user_meta($user->ID, edd_stripe_get_customer_key(), $customer_id); } } if (edds_is_recurring_purchase($purchase_data) && (!empty($customer) || $customer_exists)) { // Process a recurring subscription purchase $cu = Stripe_Customer::retrieve($customer_id); /********************************************************** * Taxes, fees, and discounts have to be handled differently * with recurring subscriptions, so each is added as an * invoice item and then charged as one time items **********************************************************/ $invoice_items = array(); $needs_invoiced = false; if ($purchase_data['tax'] > 0 && !edd_prices_include_tax()) { if (edds_is_zero_decimal_currency()) { $tax = $purchase_data['tax']; } else { $tax = $purchase_data['tax'] * 100; } $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $tax, 'currency' => edd_get_currency(), 'description' => sprintf(__('Sales tax for order %s', 'edds'), $purchase_data['purchase_key']))); if (!empty($invoice->id)) { $invoice_items[] = $invoice->id; } $needs_invoiced = true; } if (!empty($purchase_data['fees'])) { foreach ($purchase_data['fees'] as $fee) { if (edds_is_zero_decimal_currency()) { $fee_amount = $fee['amount']; } else { $fee_amount = $fee['amount'] * 100; } $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $fee_amount, 'currency' => edd_get_currency(), 'description' => $fee['label'])); if (!empty($invoice->id)) { $invoice_items[] = $invoice->id; } } $needs_invoiced = true; } if ($purchase_data['discount'] > 0) { if (edds_is_zero_decimal_currency()) { $discount_amount = $purchase_data['discount']; } else { $discount_amount = $purchase_data['discount'] * 100; } $invoice = Stripe_InvoiceItem::create(array('customer' => $customer_id, 'amount' => $discount_amount * -1, 'currency' => edd_get_currency(), 'description' => $purchase_data['user_info']['discount'])); if (!empty($invoice->id)) { $invoice_items[] = $invoice->id; } $needs_invoiced = true; } try { $plan_id = edds_get_plan_id($purchase_data); // record the pending payment $payment = edd_insert_payment($payment_data); set_transient('_edd_recurring_payment_' . $payment, '1', DAY_IN_SECONDS); // Store the parent payment ID in the user meta EDD_Recurring_Customer::set_customer_payment_id($user->ID, $payment); // Update the customer's subscription in Stripe $customer_response = $cu->updateSubscription(array('plan' => $plan_id)); // Set user as subscriber EDD_Recurring_Customer::set_as_subscriber($user->ID); // store the customer recurring ID EDD_Recurring_Customer::set_customer_id($user->ID, $customer_id); // Set the customer status EDD_Recurring_Customer::set_customer_status($user->ID, 'active'); // Calculate the customer's new expiration date $new_expiration = EDD_Recurring_Customer::calc_user_expiration($user->ID, $payment); // Set the customer's new expiration date EDD_Recurring_Customer::set_customer_expiration($user->ID, $new_expiration); } catch (Stripe_CardError $e) { $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('payment_error', $err['message']); } else { edd_set_error('payment_error', __('There was an error processing your payment, please ensure you have entered your card number correctly.', 'edds')); } edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error while processing a Stripe payment. Payment data: %s', ' edds'), json_encode($err)), 0); } catch (Stripe_ApiConnectionError $e) { $body = $e->getJsonBody(); $err = $body['error']; edd_set_error('payment_error', __('There was an error processing your payment (Stripe\'s API is down), please try again', 'edds')); edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error processing your payment (Stripe\'s API was down). Error: %s', 'edds'), json_encode($err['message'])), 0); } catch (Stripe_InvalidRequestError $e) { $body = $e->getJsonBody(); $err = $body['error']; // Bad Request of some sort. Maybe Christoff was here ;) if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('request_error', sprintf(__('The Stripe API request was invalid, please try again. Error: %s', 'edds'), json_encode($err['message']))); } } catch (Stripe_ApiError $e) { $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds')); } edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error with Stripe\'s API: ', 'edds'), json_encode($err['message'])), 0); } catch (Stripe_AuthenticationError $e) { $body = $e->getJsonBody(); $err = $body['error']; // Authentication error. Stripe keys in settings are bad. if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('The API keys entered in settings are incorrect', 'edds')); } } catch (Stripe_Error $e) { $body = $e->getJsonBody(); $err = $body['error']; // generic stripe error if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('Something went wrong.', 'edds')); } } catch (Exception $e) { // some sort of other error $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('Something went wrong.', 'edds')); } } if (!empty($err)) { // Delete any invoice items we created for fees, taxes, and other foreach ($invoice_items as $invoice) { $ii = Stripe_InvoiceItem::retrieve($invoice); $ii->delete(); } edd_send_back_to_checkout('?payment-mode=stripe'); } } elseif (!empty($customer) || $customer_exists) { // Process a normal one-time charge purchase if (!isset($edd_options['stripe_preapprove_only'])) { if (edds_is_zero_decimal_currency()) { $amount = $purchase_data['price']; } else { $amount = $purchase_data['price'] * 100; } $charge = Stripe_Charge::create(array("amount" => $amount, "currency" => edd_get_currency(), "customer" => $customer_id, "description" => html_entity_decode($purchase_summary, ENT_COMPAT, 'UTF-8'), 'statement_description' => substr($purchase_summary, 0, 15), 'metadata' => array('email' => $purchase_data['user_info']['email']))); } // record the pending payment $payment = edd_insert_payment($payment_data); } else { edd_record_gateway_error(__('Customer Creation Failed', 'edds'), sprintf(__('Customer creation failed while processing a payment. Payment Data: %s', ' edds'), json_encode($payment_data)), $payment); } if ($payment && (!empty($customer_id) || !empty($charge))) { if (!empty($needs_invoiced)) { try { // Create the invoice containing taxes / discounts / fees $invoice = Stripe_Invoice::create(array('customer' => $customer_id)); $invoice = $invoice->pay(); } catch (Exception $e) { // If there is nothing to pay, it just means the invoice item was taken care of with the subscription payment } } if (isset($edd_options['stripe_preapprove_only'])) { edd_update_payment_status($payment, 'preapproval'); add_post_meta($payment, '_edds_stripe_customer_id', $customer_id); } else { edd_update_payment_status($payment, 'publish'); } // You should be using Stripe's API here to retrieve the invoice then confirming it's been paid if (!empty($charge)) { edd_insert_payment_note($payment, 'Stripe Charge ID: ' . $charge->id); if (function_exists('edd_set_payment_transaction_id')) { edd_set_payment_transaction_id($payment, $charge->id); } } elseif (!empty($customer_id)) { edd_insert_payment_note($payment, 'Stripe Customer ID: ' . $customer_id); } edd_empty_cart(); edd_send_to_success_page(); } else { edd_set_error('payment_not_recorded', __('Your payment could not be recorded, please contact the site administrator.', 'edds')); // if errors are present, send the user back to the purchase page so they can be corrected edd_send_back_to_checkout('?payment-mode=stripe'); } } catch (Stripe_CardError $e) { $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('payment_error', $err['message']); } else { edd_set_error('payment_error', __('There was an error processing your payment, please ensure you have entered your card number correctly.', 'edds')); } edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error while processing a Stripe payment. Payment data: %s', ' edds'), json_encode($err)), 0); edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_ApiConnectionError $e) { $body = $e->getJsonBody(); $err = $body['error']; edd_set_error('payment_error', __('There was an error processing your payment (Stripe\'s API is down), please try again', 'edds')); edd_record_gateway_error(__('Stripe Error', 'edds'), sprintf(__('There was an error processing your payment (Stripe\'s API was down). Error: %s', 'edds'), json_encode($err['message'])), 0); edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_InvalidRequestError $e) { $body = $e->getJsonBody(); $err = $body['error']; // Bad Request of some sort. Maybe Christoff was here ;) if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds')); } edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_ApiError $e) { $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('request_error', __('The Stripe API request was invalid, please try again', 'edds')); } edd_set_error('request_error', sprintf(__('The Stripe API request was invalid, please try again. Error: %s', 'edds'), json_encode($err['message']))); edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_AuthenticationError $e) { $body = $e->getJsonBody(); $err = $body['error']; // Authentication error. Stripe keys in settings are bad. if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('The API keys entered in settings are incorrect', 'edds')); } edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Stripe_Error $e) { $body = $e->getJsonBody(); $err = $body['error']; // generic stripe error if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('Something went wrong.', 'edds')); } edd_send_back_to_checkout('?payment-mode=stripe'); } catch (Exception $e) { // some sort of other error $body = $e->getJsonBody(); $err = $body['error']; if (isset($err['message'])) { edd_set_error('request_error', $err['message']); } else { edd_set_error('api_error', __('Something went wrong.', 'edds')); } edd_send_back_to_checkout('?payment-mode=stripe'); } } else { edd_send_back_to_checkout('?payment-mode=stripe'); } }
/** * Get Cart Item Price * * @since 1.0 * * @param int $item_id Download (cart item) ID number * @param array $options Optional parameters, used for defining variable prices * @return string Fully formatted price */ function edd_cart_item_price($item_id = 0, $options = array()) { $price = edd_get_cart_item_price($item_id, $options); $label = ''; $price_id = isset($options['price_id']) ? $options['price_id'] : false; if (!edd_is_free_download($item_id, $price_id) && !edd_download_is_tax_exclusive($item_id)) { if (edd_prices_show_tax_on_checkout() && !edd_prices_include_tax()) { $price += edd_get_cart_item_tax($item_id, $options, $price); } if (!edd_prices_show_tax_on_checkout() && edd_prices_include_tax()) { $price -= edd_get_cart_item_tax($item_id, $options, $price); } if (edd_display_tax_rate()) { $label = ' – '; if (edd_prices_show_tax_on_checkout()) { $label .= sprintf(__('includes %s tax', 'edd'), edd_get_formatted_tax_rate()); } else { $label .= sprintf(__('excludes %s tax', 'edd'), edd_get_formatted_tax_rate()); } $label = apply_filters('edd_cart_item_tax_description', $label, $item_id, $options); } } $price = edd_currency_filter(edd_format_amount($price)); return apply_filters('edd_cart_item_price_label', $price . $label, $item_id, $options); }
public static function payment_creation_form() { // Determine our float accuracy for the steps and rounding $decimals = edd_currency_decimal_filter(); if (empty($decimals)) { $step = 1; } else { $i = 1; $step = '0.'; while ($i < $decimals) { $step .= '0'; $i++; } $step .= '1'; $step = (double) $step; } $tax_included = 'false'; if (edd_use_taxes() && edd_prices_include_tax()) { $tax_included = 'true'; } $columns = 4; ?> <div class="wrap"> <h2><?php _e('Create New Payment', 'edd-manual-purchases'); ?> </h2> <script type="text/javascript"> jQuery(document).ready(function($) { $(document.body).on('input', '.edd-mp-amount,.edd-mp-tax,.edd-mp-quantity', function() { eddmp_update_total(); }); // check for variable prices $('#edd_mp_create_payment').on('change', '.mp-downloads', function() { var $this = $(this); var selected_download = $('option:selected', this).val(); $this.parent().parent().find('.download-price-option-wrap').html(''); if( parseInt( selected_download ) != 0) { var edd_mp_nonce = $('#edd_create_payment_nonce').val(); var key = $this.parent().parent().data('key'); $.ajax({ type: "POST", url: ajaxurl, data: { action: 'edd_mp_check_for_variations', download_id: selected_download, key: key, nonce: edd_mp_nonce }, dataType: "json", success: function(response) { $this.parent().parent().find('.download-price-option-wrap').html( response.html ); $this.parent().parent().find('input[name="downloads['+ key +'][amount]"]').val( response.amount ); eddmp_update_total(); } }).fail(function (data) { if ( window.console && window.console.log ) { console.log( data ); } }); } else { $this.parent().parent().find('.download-price-option-wrap').html('N/A'); } }); // Update the price when a variation changes $('#edd_mp_create_payment').on('change', '.edd-mp-price-select', function() { var $this = $(this); var price_id = $('option:selected', this).val(); var edd_mp_nonce = $('#edd_create_payment_nonce').val(); var key = $this.parent().parent().data('key'); var download_id = $('select[name="downloads[' + key + '][id]"]').val(); $.ajax({ type: "POST", url: ajaxurl, data: { action: 'edd_mp_variation_change', download_id: download_id, price_id: price_id, key: key, nonce: edd_mp_nonce }, dataType: "json", success: function(response) { $this.parent().parent().find('input[name="downloads['+ key +'][amount]"]').val( response.amount ); eddmp_update_total(); } }).fail(function (data) { if ( window.console && window.console.log ) { console.log( data ); } }); }); $('.edd_add_repeatable').click(function() { setTimeout( function() { $('.edd_repeatable_row:last').find('.download-price-option-wrap').html(''); $('.edd_repeatable_row:last').find('.edd-mp-quantity').val('1'); }, 300 ); }); $(document.body).on('click', '.edd_remove_repeatable', function() { setTimeout( function() { var row_count = $('.edd_repeatable_row').length; if ( 1 === row_count ) { var current_quantity = $('.edd_repeatable_row:first').find('.edd-mp-quantity').val(); if ( '' === current_quantity ) { $('.edd_repeatable_row:first').find('.edd-mp-quantity').val('1'); } } eddmp_update_total(); }, 100 ); }); if ($('.form-table .edd_datepicker').length > 0) { var dateFormat = 'mm/dd/yy'; $('.edd_datepicker').datepicker({ dateFormat: dateFormat }); } function eddmp_update_total() { // Setup some place holder vars for each row var item_amount = 0; var item_tax = 0; var item_quantity = 1; var item_total = 0; // Our final total to show to the customer var total = 0; var prices_include_tax = <?php echo $tax_included; ?> ; // Iterate over each line item and add amount + tax * quantity to get the total $('.edd_repeatable_row').each(function() { var row = $(this); item_amount = parseFloat( row.find('.edd-mp-amount').val() ); if (row.find('.edd-mp-tax').length) { item_tax = parseFloat(row.find('.edd-mp-tax').val() ); if (! isNaN(item_tax) && ! prices_include_tax) { item_amount = item_amount + item_tax; } } if (row.find('.edd-mp-quantity').length) { item_quantity = parseFloat(row.find('.edd-mp-quantity').val() ); } item_total = item_amount * item_quantity; total += item_total; }); if ( isNaN( total ) ){ total = 0; } $('#edd-mp-total-amount').html(total.toFixed(<?php echo $decimals; ?> )); } }); </script> <form id="edd_mp_create_payment" method="post"> <table class="form-table" id="edd-customer-details"> <tbody id="edd-mp-table-body"> <tr class="form-field edd-mp-download-wrap"> <th scope="row" valign="top"> <label><?php echo edd_get_label_plural(); ?> </label> </th> <td class="edd-mp-downloads"> <div id="edd_file_fields" class="edd_meta_table_wrap"> <table class="widefat edd_repeatable_table" style="width: auto;" cellpadding="0" cellspacing="0"> <thead> <tr> <th style="padding: 10px;"><?php echo edd_get_label_plural(); ?> </th> <th style="padding: 10px;"><?php _e('Price Option', 'edd-manual-purchases'); ?> </th> <th style="padding: 10px; width: 150px;"><?php _e('Amount', 'edd-manual-purchases'); ?> </th> <?php if (edd_use_taxes()) { ?> <th style="padding: 10px; width: 150px;"><?php _e('Tax', 'edd-manual-purchases'); ?> </th> <?php $columns++; ?> <?php } if (edd_item_quantities_enabled()) { ?> <th style="padding: 10px; width: 50px;"><?php _e('Quantity', 'edd-manual-purchases'); ?> </th> <?php $columns++; ?> <?php } ?> <th style="padding: 10px; width: 5px;" </tr> </thead> <tbody> <tr class="edd_repeatable_product_wrapper edd_repeatable_row" data-key="1"> <td> <?php echo EDD()->html->product_dropdown(array('name' => 'downloads[1][id]', 'id' => 'downloads', 'class' => 'mp-downloads', 'multiple' => false, 'chosen' => true)); ?> </td> <td class="download-price-option-wrap"><?php _e('N/A', 'edd-manual-purchases'); ?> </td> <td> <input type="number" step="<?php echo $step; ?> " class="edd-mp-amount" name="downloads[1][amount]" value="" min="0" placeholder="<?php esc_attr_e('Item price', 'edd-manual-purchases'); ?> "/> </td> <?php if (edd_use_taxes()) { ?> <td> <?php if (!edd_prices_include_tax()) { ?> + <?php } ?> <input type="number" style="width: 65%" step="<?php echo $step; ?> " class="edd-mp-tax" name="downloads[1][tax]" value="" min="0" placeholder="<?php esc_attr_e('Item Tax', 'edd-manual-purchases'); ?> "/> </td> <?php } ?> <?php if (edd_item_quantities_enabled()) { ?> <td> × <input type="number" step="1" class="edd-mp-quantity" style="width: 65%" name="downloads[1][quantity]" value="1" min="1" placeholder="<?php esc_attr_e('Enter quantity', 'edd-manual-purchases'); ?> "/> </td> <?php } ?> <td> <a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?> ) no-repeat;">×</a> </td> </tr> <tr> <td class="submit" colspan="<?php echo $columns; ?> " style="float: none; clear:both; background: #fff;"> <a class="button-secondary edd_add_repeatable" style="margin: 6px 0 10px;"><?php _e('Add New', 'edd-manual-purchases'); ?> </a> <span style="line-height: 38px;"> Total: <?php echo edd_currency_symbol(); ?> <span id="edd-mp-total-amount">0.00</span> <?php if (edd_use_taxes()) { ?> <sup>†</sup> <?php } ?> </span> </td> </tr> </tbody> </table> </div> <span> <small> <?php if (edd_use_taxes()) { ?> <sup>†</sup> <?php if (!edd_prices_include_tax()) { ?> <em><?php _e('Total is based on prices exclusive of tax.', 'edd-manual-purchases'); ?> </em> <?php } else { ?> <em><?php _e('Total is based on prices inclusive of tax.', 'edd-manual-purchases'); ?> </em> <?php } ?> <?php } ?> </small> </span> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="edd-mp-user"><?php _e('Customer', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-email"> <div class="customer-info"> <?php echo EDD()->html->customer_dropdown(array('name' => 'customer')); ?> </div> <div class="description customer-info"> <a href="#new" class="edd-payment-new-customer" title="<?php _e('New Customer', 'edd-manual-purchases'); ?> "><?php _e('Create new customer', 'edd-manual-purchases'); ?> </a> </div> <div class="description new-customer" style="display: none"> <a href="#cancel" class="edd-payment-new-customer-cancel" title="<?php _e('Existing Customer', 'edd-manual-purchases'); ?> "><?php _e('Select existing customer', 'edd-manual-purchases'); ?> </a> </div> </td> </tr> <tr class="form-field new-customer" style="display: none"> <th scope="row" valign="top"> <label for="edd-mp-user"><?php _e('Customer Email', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-email"> <input type="text" class="small-text" id="edd-mp-email" name="email" style="width: 180px;"/> <div class="description"><?php _e('Enter the email address of the customer.', 'edd-manual-purchases'); ?> </div> </td> </tr> <tr class="form-field new-customer" style="display: none"> <th scope="row" valign="top"> <label for="edd-mp-last"><?php _e('Customer First Name', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-last"> <input type="text" class="small-text" id="edd-mp-last" name="first" style="width: 180px;"/> <div class="description"><?php _e('Enter the first name of the customer (optional).', 'edd-manual-purchases'); ?> </div> </td> </tr> <tr class="form-field new-customer" style="display: none"> <th scope="row" valign="top"> <label for="edd-mp-last"><?php _e('Customer Last Name', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-last"> <input type="text" class="small-text" id="edd-mp-last" name="last" style="width: 180px;"/> <div class="description"><?php _e('Enter the last name of the customer (optional).', 'edd-manual-purchases'); ?> </div> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="edd-mp-amount"><?php _e('Amount', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-downloads"> <input type="text" class="small-text" id="edd-mp-amount" name="amount" style="width: 180px;"/> <?php if (edd_item_quantities_enabled()) { ?> <div class="description"><?php _e('Enter the total purchase amount, or leave blank to auto calculate price based on the selected items and quantities above. Use 0.00 for 0.', 'edd-manual-purchases'); ?> </div> <?php } else { ?> <div class="description"><?php _e('Enter the total purchase amount, or leave blank to auto calculate price based on the selected items above. Use 0.00 for 0.', 'edd-manual-purchases'); ?> </div> <?php } ?> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <?php _e('Payment status', 'edd-manual-purchases'); ?> </th> <td class="edd-mp-status"> <?php echo EDD()->html->select(array('name' => 'status', 'options' => edd_get_payment_statuses(), 'selected' => 'publish', 'show_option_all' => false, 'show_option_none' => false)); ?> <label for="edd-mp-status" class="description"><?php _e('Select the status of this payment.', 'edd-manual-purchases'); ?> </label> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="edd-mp-payment-method"><?php _e('Payment Method', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-gateways"> <select name="gateway" id="edd-mp-payment-method"> <option value="manual_purchases"><?php esc_html_e('Manual Payment', 'edd-manual-purchases'); ?> </option> <?php foreach (edd_get_payment_gateways() as $gateway_id => $gateway) { ?> <option value="<?php echo esc_attr($gateway_id); ?> "><?php echo esc_html($gateway['admin_label']); ?> </option> <?php } ?> </select> <div class="description"><?php _e('Select the payment method used.', 'edd-manual-purchases'); ?> </div> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="edd-mp-transaction-id"><?php _e('Transaction ID', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-downloads"> <input type="text" class="small-text" id="edd-mp-transaction-id" name="transaction_id" style="width: 180px;"/> <div class="description"><?php _e('Enter the transaction ID, if any.', 'edd-manual-purchases'); ?> </div> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="edd-mp-date"><?php _e('Date', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-downloads"> <input type="text" class="small-text edd_datepicker" id="edd-mp-date" name="date" style="width: 180px;"/> <div class="description"><?php _e('Enter the purchase date, or leave blank for today\'s date.', 'edd-manual-purchases'); ?> </div> </td> </tr> <?php if (function_exists('eddc_record_commission')) { ?> <tr class="form-field"> <th scope="row" valign="top"> <?php _e('Commission', 'edd-manual-purchases'); ?> </th> <td class="edd-mp-downloads"> <label for="edd-mp-commission"> <input type="checkbox" id="edd-mp-commission" name="commission" style="width: auto;"/> <?php _e('Record commissions (if any) for this manual purchase?', 'edd-manual-purchases'); ?> </label> </td> </tr> <?php } ?> <?php if (class_exists('EDD_Simple_Shipping')) { ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="edd-mp-shipped"><?php _e('Shipped', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-shipped"> <label for="edd-mp-shipped"> <input type="checkbox" id="edd-mp-shipped" name="shipped" style="width: auto;"/> <?php _e('Mark order as shipped?', 'edd-manual-purchases'); ?> </label> </td> </tr> <?php } ?> <?php if (class_exists('EDD_Wallet')) { ?> <tr class="form-field"> <th scope="row" valign="top"> <label for="edd-mp-wallet"><?php _e('Pay From Wallet', 'edd-manual-purchases'); ?> </label> </th> <td class="edd-mp-wallet"> <label for="edd-mp-wallet"> <input type="checkbox" id="edd-mp-wallet" name="wallet" style="width: auto;"/> <?php _e('Use funds from the customers\' wallet to pay for this payment.', 'edd-manual-purchases'); ?> </label> </td> </tr> <?php } ?> <tr class="form-field"> <th scope="row" valign="top"> <?php _e('Send Receipt', 'edd-manual-purchases'); ?> </th> <td class="edd-mp-receipt"> <label for="edd-mp-receipt"> <input type="checkbox" id="edd-mp-receipt" name="receipt" style="width: auto;" checked="1" value="1"/> <?php _e('Send the purchase receipt to the buyer?', 'edd-manual-purchases'); ?> </label> </td> </tr> </tbody> </table> <?php wp_nonce_field('edd_create_payment_nonce', 'edd_create_payment_nonce'); ?> <input type="hidden" name="edd-gateway" value="manual_purchases"/> <input type="hidden" name="edd-action" value="create_payment" /> <?php submit_button(__('Create Payment', 'edd-manual-purchases')); ?> </form> </div> <?php }
/** * Get Cart Item Price * * @since 1.0 * * @param int $item_id Download (cart item) ID number * @param array $options Optional parameters, used for defining variable prices * @return string Fully formatted price */ function edd_cart_item_price($item_id = 0, $options = array()) { global $edd_options; $price = edd_get_cart_item_price($item_id, $options); $label = ''; if (edd_prices_show_tax_on_checkout() && !edd_prices_include_tax()) { $price += edd_get_cart_item_tax($item_id, $options, $price); } if (!edd_prices_show_tax_on_checkout() && edd_prices_include_tax()) { $price -= edd_get_cart_item_tax($item_id, $options, $price); } $price = edd_currency_filter(edd_format_amount($price)); if (edd_display_tax_rate()) { $label = ' – '; if (edd_prices_show_tax_on_checkout()) { $label .= sprintf(__('includes %s tax', 'edd'), edd_get_formatted_tax_rate()); } else { $label .= sprintf(__('excludes %s tax', 'edd'), edd_get_formatted_tax_rate()); } } return esc_html($price . $label); }
/** * Checkout sale price. * * Display the sale price, and the regular price with a strike at the checkout. * This requires a hook added in EDD 2.3.0 * * @since 1.0.0, EDD 2.4.0 * * @param double $price Regular price of the product. * @param int $download_id ID of the download we're changing the price for. * @return double The new price, if the product is in sale this will be the sale price. */ public function checkout_maybe_display_sale_price($label, $item_id, $options) { global $edd_options; $download = new EDD_Download($item_id); $regular_price = get_post_meta($item_id, 'edd_price', true); $price = edd_get_cart_item_price($item_id, $options); // Get sale price if it exists if ($download->has_variable_prices()) { $prices = $download->get_prices(); $regular_price = isset($prices[$options['price_id']]['regular_amount']) ? $prices[$options['price_id']]['regular_amount'] : $regular_price; $sale_price = $prices[$options['price_id']]['sale_price']; } else { $sale_price = get_post_meta($item_id, 'edd_sale_price', true); } // Bail if no sale price is set if (empty($sale_price)) { return $label; } $label = ''; $price_id = isset($options['price_id']) ? $options['price_id'] : false; if (!edd_is_free_download($item_id, $price_id) && !edd_download_is_tax_exclusive($item_id)) { if (edd_prices_show_tax_on_checkout() && !edd_prices_include_tax()) { $regular_price += edd_get_cart_item_tax($item_id, $options, $regular_price); $price += edd_get_cart_item_tax($item_id, $options, $price); } if (!edd_prices_show_tax_on_checkout() && edd_prices_include_tax()) { $regular_price -= edd_get_cart_item_tax($item_id, $options, $regular_price); $price -= edd_get_cart_item_tax($item_id, $options, $price); } if (edd_display_tax_rate()) { $label = ' – '; if (edd_prices_show_tax_on_checkout()) { $label .= sprintf(__('includes %s tax', 'edd'), edd_get_formatted_tax_rate()); } else { $label .= sprintf(__('excludes %s tax', 'edd'), edd_get_formatted_tax_rate()); } $label = apply_filters('edd_cart_item_tax_description', $label, $item_id, $options); } } $regular_price = '<del>' . edd_currency_filter(edd_format_amount($regular_price)) . '</del>'; $price = edd_currency_filter(edd_format_amount($price)); return $regular_price . ' ' . $price . $label; }
function eddpdfi_pdf_template_vat($eddpdfi_pdf, $eddpdfi_payment, $eddpdfi_payment_meta, $eddpdfi_buyer_info, $eddpdfi_payment_gateway, $eddpdfi_payment_method, $address_line_2_line_height, $company_name, $eddpdfi_payment_date, $eddpdfi_payment_status) { global $edd_options; if (!isset($edd_options['eddpdfi_templates'])) { $edd_options['eddpdfi_templates'] = 'default'; } $color = empty($edd_options['edd_vat_pdf_colors']) ? "blue" : $edd_options['edd_vat_pdf_colors']; switch ($color) { case 'blue': $colors = array('body' => array(8, 75, 110), 'emphasis' => array(71, 155, 198), 'title' => array(0, 127, 192), 'header' => array(202, 226, 238), 'sub' => array(234, 242, 245), 'border' => array(166, 205, 226), 'notes' => array(7, 46, 66)); break; case 'red': $colors = array('body' => array(110, 8, 8), 'emphasis' => array(198, 71, 71), 'title' => array(192, 0, 0), 'header' => array(238, 202, 202), 'sub' => array(245, 243, 243), 'border' => array(226, 166, 166), 'notes' => array(66, 7, 7)); break; case 'green': $colors = array('body' => array(8, 110, 39), 'emphasis' => array(71, 198, 98), 'title' => array(0, 192, 68), 'header' => array(202, 238, 212), 'sub' => array(243, 245, 244), 'border' => array(166, 226, 179), 'notes' => array(7, 66, 28)); break; case 'orange': $colors = array('body' => array(110, 54, 8), 'emphasis' => array(198, 134, 71), 'title' => array(192, 81, 0), 'header' => array(238, 219, 202), 'sub' => array(245, 245, 243), 'border' => array(226, 224, 166), 'notes' => array(65, 66, 7)); break; case 'yellow': $colors = array('body' => array(109, 110, 8), 'emphasis' => array(197, 198, 71), 'title' => array(192, 190, 0), 'header' => array(238, 238, 202), 'sub' => array(245, 244, 243), 'border' => array(226, 193, 166), 'notes' => array(66, 38, 7)); break; case 'purple': $colors = array('body' => array(66, 8, 110), 'emphasis' => array(137, 71, 198), 'title' => array(72, 0, 192), 'header' => array(208, 202, 238), 'sub' => array(244, 243, 245), 'border' => array(189, 166, 226), 'notes' => array(35, 7, 66)); break; case 'pink': $colors = array('body' => array(110, 8, 82), 'emphasis' => array(198, 71, 152), 'title' => array(92, 0, 65), 'header' => array(238, 202, 232), 'sub' => array(245, 243, 245), 'border' => array(226, 166, 213), 'notes' => array(66, 7, 51)); break; } $eddpdfi_pdf->AddFont('opensans', ''); $eddpdfi_pdf->AddFont('opensansb', ''); $font = isset($edd_options['eddpdfi_enable_char_support']) ? 'freesans' : 'opensans'; $fontb = isset($edd_options['eddpdfi_enable_char_support']) ? 'freesans' : 'opensansb'; $eddpdfi_pdf->SetMargins(8, 8, 8); $eddpdfi_pdf->SetX(8); $eddpdfi_pdf->AddPage(); $eddpdfi_pdf->Ln(5); $eddpdfi_logo_size = 0; if (isset($eddpdfi_logo_size) && isset($edd_options['eddpdfi_logo_upload']) && !empty($edd_options['eddpdfi_logo_upload'])) { // $file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array() $eddpdfi_pdf->Image($edd_options['eddpdfi_logo_upload'], 8, 10, 0, '25', '', false, 'LTR', false, 96); } else { $eddpdfi_pdf->SetFont($font, '', 22); $eddpdfi_pdf->SetTextColor(50, 50, 50); $eddpdfi_pdf->Cell(0, 0, $company_name, 0, 2, 'L', false); } $eddpdfi_pdf->SetFont($font, '', 18); $eddpdfi_pdf->SetTextColor($colors['title'][0], $colors['title'][1], $colors['title'][2]); $eddpdfi_pdf->SetY(45); if ($eddpdfi_payment_status === 'Refunded') { $eddpdfi_pdf->Cell(0, 0, 'Invoice Correction', 0, 2, 'L', false); } else { $eddpdfi_pdf->Cell(0, 0, __('Invoice', 'eddpdfi'), 0, 2, 'L', false); } $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->SetXY(8, 60); $eddpdfi_pdf->SetFont($fontb, '', 10); $eddpdfi_pdf->Cell(0, 6, __('From', 'eddpdfi'), 0, 2, 'L', false); $eddpdfi_pdf->SetFont($font, '', 10); if (!empty($edd_options['edd_vat_company_name'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['edd_vat_company_name']), $edd_options['edd_vat_company_name'], 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_name'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_name']), eddpdfi_get_settings($eddpdfi_pdf, 'name'), 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_address_line1'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_address_line1']), eddpdfi_get_settings($eddpdfi_pdf, 'addr_line1'), 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_address_line2'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_address_line2']), eddpdfi_get_settings($eddpdfi_pdf, 'addr_line2'), 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_address_city_state_zip'])) { $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_address_city_state_zip']), eddpdfi_get_settings($eddpdfi_pdf, 'city_state_zip'), 0, 2, 'L', false); } if (!empty($edd_options['base_country'])) { $countries = edd_get_country_list(); $countries['UK'] = $countries['GB']; $country = $countries[$edd_options['base_country']]; $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($country), $country, 0, 2, 'L', false); } if (!empty($edd_options['eddpdfi_email_address'])) { $eddpdfi_pdf->SetTextColor(41, 102, 152); $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($edd_options['eddpdfi_email_address']), eddpdfi_get_settings($eddpdfi_pdf, 'email'), 0, 2, 'L', false); } if (isset($edd_options['eddpdfi_url']) && $edd_options['eddpdfi_url']) { $eddpdfi_pdf->SetTextColor(41, 102, 152); $eddpdfi_pdf->Cell(0, 6, get_option('siteurl'), 0, 2, 'L', false); } if (!empty($edd_options['edd_vat_number'])) { $vat_number = maybe_unserialize($edd_options['edd_vat_number']); if (!empty($vat_number['number'])) { //$vat_number = __(sprintf('%s ID ', apply_filters('lsl_tax_label','Tax')), 'edd_vat') . $vat_number['number']; $vat_number = 'VAT No. ' . $vat_number['number']; $eddpdfi_pdf->Cell(0, eddpdfi_calculate_line_height($vat_number), $vat_number, 0, 2, 'L', false); } } $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Ln(12); $eddpdfi_pdf->Ln(); $eddpdfi_pdf->SetXY(60, 60); $eddpdfi_pdf->SetFont($fontb, '', 10); $eddpdfi_pdf->Cell(0, 6, __('To', 'eddpdfi'), 0, 2, 'L', false); $eddpdfi_pdf->SetFont($font, '', 10); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_buyer_info['first_name'] . ' ' . $eddpdfi_buyer_info['last_name'], 0, 2, 'L', false); $eddpdfi_pdf->SetTextColor(41, 102, 152); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_meta['email'], 0, 2, 'L', false); $eddpdfi_pdf->SetTextColor(50, 50, 50); $eddpdfi_pdf->Ln(4); $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Invoice Date', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_date, 0, 2, 'L', false); $eddpdfi_pdf->SetXY(60, 92); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Invoice ID', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); if (function_exists('eddpdfi_get_payment_number') && isset($edd_options['edd_vat_invoice_number'])) { $eddpdfi_pdf->Cell(0, 6, eddpdfi_get_payment_number($eddpdfi_payment->ID), 0, 2, 'L', false); } else { $eddpdfi_pdf->Cell(0, 6, '#' . $eddpdfi_payment->ID, 0, 2, 'L', false); } $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Purchase Key', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_meta['key'], 0, 2, 'L', false); $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Payment Status', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_status, 0, 2, 'L', false); $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetTextColor($colors['emphasis'][0], $colors['emphasis'][1], $colors['emphasis'][2]); $eddpdfi_pdf->Cell(30, 6, __('Payment Method', 'eddpdfi'), 0, 0, 'L', false); $eddpdfi_pdf->SetTextColor($colors['body'][0], $colors['body'][1], $colors['body'][2]); $eddpdfi_pdf->Cell(0, 6, $eddpdfi_payment_method, 0, 2, 'L', false); $offset = apply_filters('eddpdfi_pdf_template_extra_fields', 0, 'color', $eddpdfi_pdf, $eddpdfi_payment, $eddpdfi_payment_meta, $eddpdfi_buyer_info, $colors); $eddpdfi_pdf->SetXY(61, 120 + $offset); $eddpdfi_pdf->SetFillColor($colors['header'][0], $colors['header'][1], $colors['header'][2]); $eddpdfi_pdf->SetDrawColor($colors['border'][0], $colors['border'][1], $colors['border'][2]); $eddpdfi_pdf->SetFont($fontb, '', 10); $eddpdfi_pdf->Cell(140, 8, __('Invoice Items', 'eddpdfi'), 1, 2, 'C', true); $eddpdfi_pdf->Ln(0.2); $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->SetFillColor($colors['sub'][0], $colors['sub'][1], $colors['sub'][2]); $eddpdfi_pdf->SetFont($font, '', 9); $qenabled = version_compare(EDD_VERSION, "1.9") >= 0 ? true : (function_exists('edd_item_quanities_enabled') ? edd_item_quanities_enabled() : false); $eddpdfi_pdf->Cell($qenabled ? 95 : 102, 7, __('PRODUCT NAME', 'eddpdfi'), 'BL', 0, 'L', true); if ($qenabled) { $eddpdfi_pdf->Cell(10, 7, __('#', 'eddpdfi'), 'B', 0, 0, true); } $eddpdfi_pdf->Cell($qenabled ? 35 : 38, 7, __('PRICE', 'eddpdfi'), 'BR', 0, 'R', true); $eddpdfi_pdf->Ln(0.2); $eddpdfi_pdf_downloads = isset($eddpdfi_payment_meta['cart_details']) ? maybe_unserialize($eddpdfi_payment_meta['cart_details']) : false; $eddpdfi_pdf->Ln(); if ($eddpdfi_pdf_downloads) { $eddpdfi_pdf->SetX(61); $includes_taxes = edd_prices_include_tax(); foreach ($eddpdfi_pdf_downloads as $key => $download) { $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->SetFont($font, '', 10); $eddpdfi_download_id = isset($eddpdfi_payment_meta['cart_details']) ? $download['id'] : $download; $eddpdfi_price_override = isset($eddpdfi_payment_meta['cart_details']) ? $download['price'] : null; $user_info = maybe_unserialize($eddpdfi_payment_meta['user_info']); $eddpdfi_final_download_price = edd_get_download_final_price($eddpdfi_download_id, $user_info, $eddpdfi_price_override); if (isset($user_info['discount']) && $user_info['discount'] != 'none') { $eddpdfi_discount = $user_info['discount']; } else { $eddpdfi_discount = __('None', 'eddpdfi'); } // $eddpdfi_total_price = html_entity_decode( edd_currency_filter( edd_format_amount( $eddpdfi_payment_meta['amount'] ) ) ); $eddpdfi_download_title = html_entity_decode(get_the_title($eddpdfi_download_id), ENT_COMPAT, 'UTF-8'); if (edd_has_variable_prices($eddpdfi_download_id)) { $eddpdfi_download_title .= ' - ' . edd_get_cart_item_price_name($download); $options = $download['item_number']['options']; } // error_log(print_r($download,true)); $options['is_item'] = $eddpdfi_download_id; $price = edd_get_cart_item_price($eddpdfi_download_id, $options, $includes_taxes); $eddpdfi_download_price = ' ' . html_entity_decode(edd_currency_filter(edd_format_amount($price)), ENT_COMPAT, 'UTF-8'); // $eddpdfi_download_price = ' ' . html_entity_decode( edd_currency_filter( edd_format_amount( $eddpdfi_final_download_price ) ), ENT_COMPAT, 'UTF-8' ); $eddpdfi_pdf->Cell($qenabled ? 95 : 102, 8, $eddpdfi_download_title, 'B', 0, 'L', false); if ($qenabled) { $quantity = is_array($download) ? $download['quantity'] : 1; $eddpdfi_pdf->Cell(10, 8, $quantity, 'B', 0, 'C', false); } $eddpdfi_pdf->Cell($qenabled ? 35 : 38, 8, $eddpdfi_download_price, 'B', 2, 'R', false); } $eddpdfi_pdf->Ln(5); $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->SetFillColor($colors['header'][0], $colors['header'][1], $colors['header'][2]); $eddpdfi_pdf->SetFont($fontb, '', 10); $eddpdfi_pdf->Cell(140, 8, __('Invoice Totals', 'eddpdfi'), 1, 2, 'C', true); $eddpdfi_pdf->Ln(0.2); $eddpdfi_pdf->SetX(61); if (edd_use_taxes()) { //$taxrate = (edd_get_payment_amount( $eddpdfi_payment->ID ) - round(edd_get_payment_subtotal( $eddpdfi_payment->ID ))) / round(edd_get_payment_subtotal( $eddpdfi_payment->ID )) * 100; switch ($eddpdfi_buyer_info['address']['country']) { case 'BE': $taxrate = '21%'; break; case 'BG': $taxrate = '20%'; break; case 'CZ': $taxrate = '21%'; break; case 'DK': $taxrate = '25%'; break; case 'GB': $taxrate = '20%'; break; case 'UK': $taxrate = '20%'; break; case 'DE': $taxrate = '19%'; break; case 'EE': $taxrate = '20%'; break; case 'EL': $taxrate = '23%'; break; case 'ES': $taxrate = '21%'; break; case 'FR': $taxrate = '20%'; break; case 'HR': $taxrate = '25%'; break; case 'IE': $taxrate = '23%'; break; case 'IT': $taxrate = '22%'; break; case 'CY': $taxrate = '19%'; break; case 'LV': $taxrate = '21%'; break; case 'LT': $taxrate = '21%'; break; case 'LU': $taxrate = '17%'; break; case 'HU': $taxrate = '27%'; break; case 'MT': $taxrate = '18%'; break; case 'NL': $taxrate = '21%'; break; case 'AT': $taxrate = '20%'; break; case 'PL': $taxrate = '23%'; break; case 'PT': $taxrate = '23%'; break; case 'RO': $taxrate = '24%'; break; case 'SI': $taxrate = '22%'; break; case 'SK': $taxrate = '20%'; break; case 'FI': $taxrate = '24%'; break; case 'SE': $taxrate = '25%'; break; default: $taxrate = '0%'; } $eddpdfi_pdf->Cell(102, 8, __('Subtotal', 'eddpdfi'), 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, html_entity_decode(edd_payment_subtotal($eddpdfi_payment->ID), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', false); $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->Cell(102, 8, __(apply_filters('lsl_tax_label', 'Tax'), 'eddpdfi'), 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, html_entity_decode(edd_payment_tax($eddpdfi_payment->ID), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', false); $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->Cell(102, 8, __('VAT RATE', 'eddpdfi'), 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, $taxrate, 'B', 2, 'R', false); } $fees = edd_get_payment_fees($eddpdfi_payment->ID); if (!empty($fees)) { foreach ($fees as $fee) { $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->Cell(102, 8, $fee['label'], 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, html_entity_decode(edd_currency_filter($fee['amount']), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', true); } } if ($eddpdfi_discount !== __('None', 'eddpdfi')) { $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->Cell(102, 8, __('Discount Used', 'eddpdfi'), 'B', 0, 'L', false); $eddpdfi_pdf->Cell(38, 8, $eddpdfi_discount, 'B', 2, 'R', false); } $eddpdfi_pdf->SetX(61); $eddpdfi_pdf->SetFont($fontb, '', 11); $eddpdfi_pdf->Cell(102, 10, __('Total Due', 'eddpdfi'), 'B', 0, 'L', false); if ($eddpdfi_payment_status === 'Refunded') { $eddpdfi_pdf->Cell(38, 10, '-' . html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_payment_amount($eddpdfi_payment->ID))), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', false); } else { $eddpdfi_pdf->Cell(38, 10, html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_payment_amount($eddpdfi_payment->ID))), ENT_COMPAT, 'UTF-8'), 'B', 2, 'R', false); } $eddpdfi_pdf->Ln(10); if (isset($edd_options['eddpdfi_additional_notes']) && !empty($edd_options['eddpdfi_additional_notes'])) { $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetFont($font, '', 13); $eddpdfi_pdf->Cell(0, 6, __('Additional Notes', 'eddpdfi'), 0, 2, 'L', false); $eddpdfi_pdf->Ln(2); $eddpdfi_pdf->SetX(60); $eddpdfi_pdf->SetFont($font, '', 10); $eddpdfi_pdf->SetTextColor($colors['notes'][0], $colors['notes'][1], $colors['notes'][2]); $eddpdfi_pdf->MultiCell(0, 6, eddpdfi_get_settings($eddpdfi_pdf, 'notes'), 0, 'L', false); } } }
/** * Get Total Cart Amount * * Returns amount after taxes and discounts * * @since 1.4.1 * @global $edd_options Array of all the EDD Options * @param array $discounts Array of discounts to apply (needed during AJAX calls) * @return float Cart amount */ function edd_get_cart_total($discounts = false) { global $edd_options; $subtotal = edd_get_cart_subtotal(edd_prices_include_tax()); $fees = edd_get_cart_fee_total(); $cart_tax = edd_is_cart_taxed() ? edd_get_cart_tax($discounts) : 0; $discount = edd_get_cart_discounted_amount($discounts); $total = $subtotal + $fees + $cart_tax - $discount; return (double) apply_filters('edd_get_cart_total', $total); }
/** * Get Purchase Link * * Builds a Purchase link for a specified download based on arguments passed. * This function is used all over EDD to generate the Purchase or Add to Cart * buttons. If no arguments are passed, the function uses the defaults that have * been set by the plugin. The Purchase link is built for simple and variable * pricing and filters are available throughout the function to override * certain elements of the function. * * $download_id = null, $link_text = null, $style = null, $color = null, $class = null * * @since 1.0 * @param array $args Arguments for display * @return string $purchase_form */ function edd_get_purchase_link($args = array()) { global $post, $edd_displayed_form_ids; $purchase_page = edd_get_option('purchase_page', false); if (!$purchase_page || $purchase_page == 0) { edd_set_error('set_checkout', sprintf(__('No checkout page has been configured. Visit <a href="%s">Settings</a> to set one.', 'easy-digital-downloads'), admin_url('edit.php?post_type=download&page=edd-settings'))); edd_print_errors(); return false; } $post_id = is_object($post) ? $post->ID : 0; $button_behavior = edd_get_download_button_behavior($post_id); $defaults = apply_filters('edd_purchase_link_defaults', array('download_id' => $post_id, 'price' => (bool) true, 'price_id' => isset($args['price_id']) ? $args['price_id'] : false, 'direct' => $button_behavior == 'direct' ? true : false, 'text' => $button_behavior == 'direct' ? edd_get_option('buy_now_text', __('Buy Now', 'easy-digital-downloads')) : edd_get_option('add_to_cart_text', __('Purchase', 'easy-digital-downloads')), 'style' => edd_get_option('button_style', 'button'), 'color' => edd_get_option('checkout_color', 'blue'), 'class' => 'edd-submit')); $args = wp_parse_args($args, $defaults); // Override the stright_to_gateway if the shop doesn't support it if (!edd_shop_supports_buy_now()) { $args['direct'] = false; } $download = new EDD_Download($args['download_id']); if (empty($download->ID)) { return false; } if ('publish' !== $download->post_status && !current_user_can('edit_product', $download->ID)) { return false; // Product not published or user doesn't have permission to view drafts } // Override color if color == inherit $args['color'] = $args['color'] == 'inherit' ? '' : $args['color']; $options = array(); $variable_pricing = $download->has_variable_prices(); $data_variable = $variable_pricing ? ' data-variable-price="yes"' : 'data-variable-price="no"'; $type = $download->is_single_price_mode() ? 'data-price-mode=multi' : 'data-price-mode=single'; $show_price = $args['price'] && $args['price'] !== 'no'; $data_price_value = 0; $price = false; if ($variable_pricing && false !== $args['price_id']) { $price_id = $args['price_id']; $prices = $download->prices; $options['price_id'] = $args['price_id']; $found_price = isset($prices[$price_id]) ? $prices[$price_id]['amount'] : false; $data_price_value = $found_price; if ($show_price) { $price = $found_price; } } elseif (!$variable_pricing) { $data_price_value = $download->price; if ($show_price) { $price = $download->price; } } $args['display_price'] = $data_price_value; $data_price = 'data-price="' . $data_price_value . '"'; $button_text = !empty($args['text']) ? ' – ' . $args['text'] : ''; if (false !== $price) { if (0 == $price) { $args['text'] = __('Free', 'easy-digital-downloads') . $button_text; } else { $args['text'] = edd_currency_filter(edd_format_amount($price)) . $button_text; } } if (edd_item_in_cart($download->ID, $options) && (!$variable_pricing || !$download->is_single_price_mode())) { $button_display = 'style="display:none;"'; $checkout_display = ''; } else { $button_display = ''; $checkout_display = 'style="display:none;"'; } // Collect any form IDs we've displayed already so we can avoid duplicate IDs if (isset($edd_displayed_form_ids[$download->ID])) { $edd_displayed_form_ids[$download->ID]++; } else { $edd_displayed_form_ids[$download->ID] = 1; } $form_id = !empty($args['form_id']) ? $args['form_id'] : 'edd_purchase_' . $download->ID; // If we've already generated a form ID for this download ID, apped -# if ($edd_displayed_form_ids[$download->ID] > 1) { $form_id .= '-' . $edd_displayed_form_ids[$download->ID]; } $args = apply_filters('edd_purchase_link_args', $args); ob_start(); ?> <form id="<?php echo $form_id; ?> " class="edd_download_purchase_form edd_purchase_<?php echo absint($download->ID); ?> " method="post"> <?php do_action('edd_purchase_link_top', $download->ID, $args); ?> <div class="edd_purchase_submit_wrapper"> <?php $class = implode(' ', array($args['style'], $args['color'], trim($args['class']))); if (!edd_is_ajax_disabled()) { echo '<a href="#" class="edd-add-to-cart ' . esc_attr($class) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($download->ID) . '" ' . $data_variable . ' ' . $type . ' ' . $data_price . ' ' . $button_display . '><span class="edd-add-to-cart-label">' . $args['text'] . '</span> <span class="edd-loading"><i class="edd-icon-spinner edd-icon-spin"></i></span></a>'; } echo '<input type="submit" class="edd-add-to-cart edd-no-js ' . esc_attr($class) . '" name="edd_purchase_download" value="' . esc_attr($args['text']) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($download->ID) . '" ' . $data_variable . ' ' . $type . ' ' . $button_display . '/>'; echo '<a href="' . esc_url(edd_get_checkout_uri()) . '" class="edd_go_to_checkout ' . esc_attr($class) . '" ' . $checkout_display . '>' . __('Checkout', 'easy-digital-downloads') . '</a>'; ?> <?php if (!edd_is_ajax_disabled()) { ?> <span class="edd-cart-ajax-alert"> <span class="edd-cart-added-alert" style="display: none;"> <?php echo '<i class="edd-icon-ok"></i> ' . __('Added to cart', 'easy-digital-downloads'); ?> </span> </span> <?php } ?> <?php if (!$download->is_free($args['price_id'])) { ?> <?php if (edd_display_tax_rate() && edd_prices_include_tax()) { echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Includes %1$s% tax', 'easy-digital-downloads'), edd_get_tax_rate() * 100) . '</span>'; } elseif (edd_display_tax_rate() && !edd_prices_include_tax()) { echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Excluding %1$s% tax', 'easy-digital-downloads'), edd_get_tax_rate() * 100) . '</span>'; } ?> <?php } ?> </div><!--end .edd_purchase_submit_wrapper--> <input type="hidden" name="download_id" value="<?php echo esc_attr($download->ID); ?> "> <?php if ($variable_pricing && isset($price_id) && isset($prices[$price_id])) { ?> <input type="hidden" name="edd_options[price_id][]" id="edd_price_option_<?php echo $download->ID; ?> _1" class="edd_price_option_<?php echo $download->ID; ?> " value="<?php echo $price_id; ?> "> <?php } ?> <?php if (!empty($args['direct']) && !$download->is_free($args['price_id'])) { ?> <input type="hidden" name="edd_action" class="edd_action_input" value="straight_to_gateway"> <?php } else { ?> <input type="hidden" name="edd_action" class="edd_action_input" value="add_to_cart"> <?php } ?> <?php if (apply_filters('edd_download_redirect_to_checkout', edd_straight_to_checkout(), $download->ID, $args)) { ?> <input type="hidden" name="edd_redirect_to_checkout" id="edd_redirect_to_checkout" value="1"> <?php } ?> <?php do_action('edd_purchase_link_end', $download->ID, $args); ?> </form><!--end #<?php echo esc_attr($form_id); ?> --> <?php $purchase_form = ob_get_clean(); return apply_filters('edd_purchase_download_form', $purchase_form, $args); }
/** * Custom pledge level fix. * * If there is a custom price, figure out the difference * between that, and the price level they have chosen. Store * the differene in the cart item meta, so it can be added to * the total in the future. * * @since Astoundify Crowdfunding 1.6 * * @param array $cart_item The current cart item to be added. * @return array $cart_item The modified cart item. */ function atcf_edd_add_to_cart_item($cart_item) { if (isset($_POST['post_data'])) { $post_data = array(); parse_str($_POST['post_data'], $post_data); $custom_price = $post_data['atcf_custom_price']; } else { $custom_price = $_POST['atcf_custom_price']; } $custom_price = edd_sanitize_amount($custom_price); $price = edd_get_cart_item_price($cart_item['id'], $cart_item['options'], edd_prices_include_tax()); if ($custom_price > $price) { $cart_item['options']['atcf_extra_price'] = $custom_price - $price; } return $cart_item; }
/** * Get Cart Item Price * * Gets the price of the cart item. Always exclusive of taxes * * Do not use this for getting the final price (with taxes and discounts) of an item. * Use edd_get_cart_item_final_price() * * @since 1.0 * @param int $download_id Download ID number * @param array $options Optional parameters, used for defining variable prices * @param bool $remove_tax_from_inclusive Remove the tax amount from tax inclusive priced products. * @return float|bool Price for this item */ function edd_get_cart_item_price($download_id = 0, $options = array(), $remove_tax_from_inclusive = false) { $price = 0; $variable_prices = edd_has_variable_prices($download_id); if ($variable_prices) { $prices = edd_get_variable_prices($download_id); if ($prices) { if (!empty($options)) { $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; } else { $price = false; } } } if (!$variable_prices || false === $price) { // Get the standard Download price if not using variable prices $price = edd_get_download_price($download_id); } if ($remove_tax_from_inclusive && edd_prices_include_tax()) { $price -= edd_get_cart_item_tax($download_id, $options, $price); } return apply_filters('edd_cart_item_price', $price, $download_id, $options); }
"> <th colspan="<?php echo edd_checkout_cart_columns(); ?> "> <?php do_action('edd_cart_footer_buttons'); ?> </th> </tr> <?php } ?> <?php if (edd_use_taxes() && !edd_prices_include_tax()) { ?> <tr class="edd_cart_footer_row edd_cart_subtotal_row"<?php if (!edd_is_cart_taxed()) { echo ' style="display:none;"'; } ?> > <?php do_action('edd_checkout_table_subtotal_first'); ?> <th colspan="<?php echo edd_checkout_cart_columns(); ?> " class="edd_cart_subtotal"> <?php
/** * Calculate Maximum Possible discount available * * Handles to calculate maximum possible discount * * @package Easy Digital Downloads - Points and Rewards * @since 1.0.0 **/ public function edd_points_get_discount_for_redeeming_points() { global $edd_options; //get users points $available_user_disc = $this->edd_points_get_userpoints_value(); //get cart subtotal $cartsubtotal = edd_get_cart_subtotal() - edd_get_cart_discounted_amount(); //check price is include tas or not if (edd_prices_include_tax() == 'yes') { $cartsubtotal = $cartsubtotal - edd_get_cart_tax(); } //check user has points or not if (empty($available_user_disc)) { return 0; } //get cart content $cartdata = edd_get_cart_contents(); $discount_applied = 0; // calculate the discount to be applied by iterating through each item in the cart and calculating the individual // maximum discount available foreach ($cartdata as $item_key => $item) { //max discount $max_discount = $this->edd_points_get_max_points_discount_for_download($item['id']); //check item of options set then consider that if (isset($item['options'])) { $itemoptions = $item['options']; } elseif (isset($item['item_number']['options'])) { $itemoptions = $item['item_number']['options']; } else { $itemoptions = array(); } //get download price $downloadprice = edd_get_cart_item_price($item['id'], $itemoptions); if (is_numeric($max_discount)) { // adjust the max discount by the quantity being ordered $max_discount *= $item['quantity']; // if the discount available is greater than the max discount, apply the max discount $discount = $available_user_disc <= $max_discount ? $available_user_disc : $max_discount; } else { //when maximum discount is not set for product then allow maximum total cost of product as a discount $max_price_discount = $downloadprice * $item['quantity']; // if the discount available is greater than the max discount, apply the max discount $discount = $available_user_disc <= $max_price_discount ? $available_user_disc : $max_price_discount; } // add the discount to the amount to be applied $discount_applied += $discount; // reduce the remaining discount available to be applied $available_user_disc -= $discount; } //end for loop // if the available discount is greater than the order total, make the discount equal to the order total less any other discounts $discount_applied = max(0, min($discount_applied, $cartsubtotal)); //$discount_applied = max( 0, $discount_applied ); // limit the discount available by the global maximum discount if set $max_discount = $edd_options['edd_points_cart_max_discount']; if ($max_discount && $max_discount < $discount_applied) { $discount_applied = $max_discount; } return $discount_applied; }
/** * Get the discounted amount on a price * * @since 1.9 * @param array $item Cart item array * @return float The discounted amount */ function edd_get_cart_item_discount_amount($item = array()) { $amount = 0; $price = edd_get_cart_item_price($item['id'], $item['options'], edd_prices_include_tax()); $discounted_price = $price; // Retrieve all discounts applied to the cart $discounts = edd_get_cart_discounts(); if ($discounts) { foreach ($discounts as $discount) { $code_id = edd_get_discount_id_by_code($discount); $reqs = edd_get_discount_product_reqs($code_id); $excluded_products = edd_get_discount_excluded_products($code_id); // Make sure requirements are set and that this discount shouldn't apply to the whole cart if (!empty($reqs) && edd_is_discount_not_global($code_id)) { // This is a product(s) specific discount foreach ($reqs as $download_id) { if ($download_id == $item['id'] && !in_array($item['id'], $excluded_products)) { $discounted_price -= $price - edd_get_discounted_amount($discount, $price); } } } else { // This is a global cart discount if (!in_array($item['id'], $excluded_products)) { if ('flat' === edd_get_discount_type($code_id)) { /* * * In order to correctly record individual item amounts, global flat rate discounts * are distributed across all cart items. The discount amount is divided by the number * of items in the cart and then a portion is evenly applied to each cart item */ $discounted_amount = edd_get_discount_amount($code_id); $discounted_amount = $discounted_amount / edd_get_cart_quantity(); $discounted_price -= $discounted_amount; } else { $discounted_price -= $price - edd_get_discounted_amount($discount, $price); } } } } $amount = $price - apply_filters('edd_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price); if ('flat' !== edd_get_discount_type($code_id)) { $amount = $amount * $item['quantity']; } } return $amount; }