/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @return void */ function edd_process_purchase_form() { do_action('edd_pre_process_purchase'); // Make sure the cart isn't empty if (!edd_get_cart_contents() && !edd_cart_has_fees()) { $valid_data = false; edd_set_error('empty_cart', __('Your cart is empty', 'easy-digital-downloads')); } else { // Validate the form $_POST data $valid_data = edd_purchase_form_validate_fields(); // Allow themes and plugins to hook to errors do_action('edd_checkout_error_checks', $valid_data, $_POST); } $is_ajax = isset($_POST['edd_ajax']); // Process the login form if (isset($_POST['edd_login_submit'])) { edd_process_purchase_login(); } // Validate the user $user = edd_get_purchase_form_user($valid_data); if (false === $valid_data || edd_get_errors() || !$user) { if ($is_ajax) { do_action('edd_ajax_checkout_errors'); edd_die(); } else { return false; } } if ($is_ajax) { echo 'success'; edd_die(); } // Setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount'], 'address' => $user['address']); $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; // Setup purchase information $purchase_data = array('downloads' => edd_get_cart_contents(), 'fees' => edd_get_cart_fees(), 'subtotal' => edd_get_cart_subtotal(), 'discount' => edd_get_cart_discounted_amount(), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_total(), 'purchase_key' => strtolower(md5($user['user_email'] . date('Y-m-d H:i:s') . $auth_key . uniqid('edd', true))), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s', current_time('timestamp')), 'user_info' => stripslashes_deep($user_info), 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // Add the user data for hooks $valid_data['user'] = $user; // Allow themes and plugins to hook before the gateway do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data); // If the total amount in the cart is 0, send to the manual gateway. This emulates a free download purchase if (!$purchase_data['price']) { // Revert to manual $purchase_data['gateway'] = 'manual'; $_POST['edd-gateway'] = 'manual'; } // Allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data); // Setup the data we're storing in the purchase session $session_data = $purchase_data; // Make sure credit card numbers are never stored in sessions unset($session_data['card_info']['card_number']); // Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data. edd_set_purchase_session($session_data); // Send info to the gateway for payment processing edd_send_to_gateway($purchase_data['gateway'], $purchase_data); edd_die(); }
/** * Process Purchase Form * * Handles the purchase form process. * * @access private * @since 1.0 * @version 1.0.8.1 * @return void */ function edd_process_purchase_form() { // Make sure the cart isn't empty if (!edd_get_cart_contents()) { edd_set_error('empty_cart', __('Your cart is empty', 'edd')); } else { // Validate the form $_POST data $valid_data = edd_purchase_form_validate_fields(); // Allow themes and plugins to hoook to errors do_action('edd_checkout_error_checks', $valid_data, $_POST); } $is_ajax = isset($_POST['edd_ajax']); $user = edd_get_purchase_form_user($valid_data); if (edd_get_errors() || !$user) { if ($is_ajax) { do_action('edd_ajax_checkout_errors'); edd_die(); } else { return false; } } if ($is_ajax) { echo 'success'; edd_die(); } // Setup user information $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']); // Setup purchase information $purchase_data = array('downloads' => edd_get_cart_contents(), 'fees' => edd_get_cart_fees(), 'subtotal' => edd_get_cart_subtotal(), 'discount' => edd_get_cart_discounted_amount(), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_total(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']); // Add the user data for hooks $valid_data['user'] = $user; // Allow themes and plugins to hook before the gateway do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data); // Allow the purchase data to be modified before it is sent to the gateway $purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data); // If the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase if (!$purchase_data['price']) { // Revert to manual $valid_data['gateway'] = 'manual'; } // Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data. edd_set_purchase_session($purchase_data); // Send info to the gateway for payment processing edd_send_to_gateway($valid_data['gateway'], $purchase_data); edd_die(); }
/** * Get cart tax on Fees * * @since 2.0 * @uses EDD()->fees->get_fees() * @return float Total Cart tax on Fees */ function edd_get_cart_fee_tax() { $tax = 0; $fees = edd_get_cart_fees(); if ($fees) { foreach ($fees as $fee_id => $fee) { if (!empty($fee['no_tax'])) { continue; } // Fees must (at this time) be exclusive of tax add_filter('edd_prices_include_tax', '__return_false'); $tax += edd_calculate_tax($fee['amount']); remove_filter('edd_prices_include_tax', '__return_false'); } } return apply_filters('edd_get_cart_fee_tax', $tax); }
</tr> <?php } ?> <?php } ?> <?php do_action('edd_cart_items_middle'); ?> <!-- Show any cart fees, both positive and negative fees --> <?php if (edd_cart_has_fees()) { ?> <?php foreach (edd_get_cart_fees() as $fee_id => $fee) { ?> <tr class="edd_cart_fee" id="edd_cart_fee_<?php echo $fee_id; ?> "> <td class="edd_cart_fee_label"><?php echo esc_html($fee['label']); ?> </td> <td class="edd_cart_fee_amount"><?php echo esc_html(edd_currency_filter(edd_format_amount($fee['amount']))); ?> </td> <td> <?php
/** * Build the purchase data for a straight-to-gateway purchase button * * @since 1.7 * * @param int $download_id * @param array $options * @param int $quantity * @return mixed|void */ function edd_build_straight_to_gateway_data($download_id = 0, $options = array(), $quantity = 1) { $price_options = array(); if (empty($options) || !edd_has_variable_prices($download_id)) { $price = edd_get_download_price($download_id); } else { if (is_array($options['price_id'])) { $price_id = $options['price_id'][0]; } else { $price_id = $options['price_id']; } $prices = edd_get_variable_prices($download_id); // Make sure a valid price ID was supplied if (!isset($prices[$price_id])) { wp_die(__('The requested price ID does not exist.', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 404)); } $price_options = array('price_id' => $price_id, 'amount' => $prices[$price_id]['amount']); $price = $prices[$price_id]['amount']; } // Set up Downloads array $downloads = array(array('id' => $download_id, 'options' => $price_options)); // Set up Cart Details array $cart_details = array(array('name' => get_the_title($download_id), 'id' => $download_id, 'item_number' => array('id' => $download_id, 'options' => $price_options), 'tax' => 0, 'discount' => 0, 'item_price' => $price, 'subtotal' => $price * $quantity, 'price' => $price * $quantity, 'quantity' => $quantity)); if (is_user_logged_in()) { global $current_user; get_currentuserinfo(); } // Setup user information $user_info = array('id' => is_user_logged_in() ? get_current_user_id() : -1, 'email' => is_user_logged_in() ? $current_user->user_email : '', 'first_name' => is_user_logged_in() ? $current_user->user_firstname : '', 'last_name' => is_user_logged_in() ? $current_user->user_lastname : '', 'discount' => 'none', 'address' => array()); // Setup purchase information $purchase_data = array('downloads' => $downloads, 'fees' => edd_get_cart_fees(), 'subtotal' => $price * $quantity, 'discount' => 0, 'tax' => 0, 'price' => $price * $quantity, 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user_info['email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => array(), 'cart_details' => $cart_details, 'gateway' => 'paypal', 'buy_now' => true, 'card_info' => array()); return apply_filters('edd_straight_to_gateway_purchase_data', $purchase_data); }
<?php /** * Checkout page template. * * This template is only used if Easy Digital Downloads is active. * * @package Reach */ if (!reach_has_edd()) { return; } if (class_exists('Charitable_EDD_Cart')) { $cart = new Charitable_EDD_Cart(edd_get_cart_contents(), edd_get_cart_fees('item')); $campaigns = $cart->get_benefits_by_campaign(); } else { $campaigns = array(); } get_header('stripped'); ?> <main id="main" class="site-main site-content cf"> <div class="layout-wrapper"> <div id="primary" class="content-area <?php if (empty($campaigns)) { ?> no-sidebar<?php } ?> "> <?php