/**
 * 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();
}
 /**
  * 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 Total Cart Amount
 *
 * Returns amount after taxes and discounts
 *
 * @since 1.4.1
 * @param bool $discounts Array of discounts to apply (needed during AJAX calls)
 * @return float Cart amount
 */
function edd_get_cart_total($discounts = false)
{
    $subtotal = edd_get_cart_subtotal();
    $discounts = edd_get_cart_discounted_amount();
    $cart_tax = edd_get_cart_tax();
    $fees = edd_get_cart_fee_total();
    $total = $subtotal - $discounts + $cart_tax + $fees;
    if ($total < 0) {
        $total = 0.0;
    }
    return (double) apply_filters('edd_get_cart_total', $total);
}
Exemplo n.º 5
0
?>

	<?php 
if (edd_use_taxes() && cart_has_tax()) {
    ?>
		<hr class="hr--no-pointer tight">

		<div class="row iceberg--small">
			<div class="grid">
				<div class="three-seventh offset-three-seventh small-four-fifth"><?php 
    _e('Subtotal', 'yoastcom');
    ?>
</div>
				<div class="one-seventh small-one-fifth edd_cart_subtotal_amount">
					<?php 
    echo esc_html(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal() - edd_get_cart_discounted_amount())));
    ?>
				</div>
			</div>
		</div>

		<?php 
    if (!edd_prices_show_tax_on_checkout()) {
        ?>
			<div class="row iceberg--small">
				<div class="grid">
					<div class="three-seventh offset-three-seventh small-four-fifth">
						<?php 
        printf(__('VAT (<span class="yst-tax-rate">%s</span>%%)', 'yoastcom'), number_format(edd_get_tax_rate() * 100, 1));
        ?>
					</div>
/**
 * Get Cart Amount
 *
 * @since 1.0
 * @deprecated 1.9
 * @param bool $add_taxes Whether to apply taxes (if enabled) (default: true)
 * @param bool $local_override Force the local opt-in param - used for when not reading $_POST (default: false)
 * @return float Total amount
*/
function edd_get_cart_amount($add_taxes = true, $local_override = false)
{
    $backtrace = debug_backtrace();
    _edd_deprecated_function(__FUNCTION__, '1.9', 'edd_get_cart_subtotal() or edd_get_cart_total()', $backtrace);
    $amount = edd_get_cart_subtotal();
    if (!empty($_POST['edd-discount']) || edd_get_cart_discounts() !== false) {
        // Retrieve the discount stored in cookies
        $discounts = edd_get_cart_discounts();
        // Check for a posted discount
        $posted_discount = isset($_POST['edd-discount']) ? trim($_POST['edd-discount']) : '';
        if ($posted_discount && !in_array($posted_discount, $discounts)) {
            // This discount hasn't been applied, so apply it
            $amount = edd_get_discounted_amount($posted_discount, $amount);
        }
        if (!empty($discounts)) {
            // Apply the discounted amount from discounts already applied
            $amount -= edd_get_cart_discounted_amount();
        }
    }
    if (edd_use_taxes() && edd_is_cart_taxed() && $add_taxes) {
        $tax = edd_get_cart_tax();
        $amount += $tax;
    }
    if ($amount < 0) {
        $amount = 0.0;
    }
    return apply_filters('edd_get_cart_amount', $amount, $add_taxes, $local_override);
}
Exemplo n.º 7
0
?>
	<div class="three-seventh<?php 
if (!$title) {
    ?>
 offset-three-seventh<?php 
}
?>
">
		<?php 
echo esc_html($discount['name']);
?>
	</div>
	<div class="one-seventh">
		<?php 
if ($cart_item) {
    ?>
			<?php 
    echo esc_html(edd_currency_filter(edd_format_amount(-1 * edd_get_cart_item_discount_amount($cart_item))));
    ?>
		<?php 
} else {
    ?>
			<?php 
    echo esc_html(edd_currency_filter(edd_format_amount(-1 * edd_get_cart_discounted_amount())));
    ?>
		<?php 
}
?>
	</div>
</li>
<?php 
/**
 * Gets the total tax amount for the cart contents
 *
 * @since 1.2.3
 * @param array $discounts Array of discounts to take into account (required for AJAX calls)
 * @return string Total tax amount
 */
function edd_get_cart_tax($discounts = false)
{
    $subtotal = edd_get_cart_subtotal(false);
    $subtotal += edd_get_cart_fee_total();
    $cart_tax = 0;
    if (edd_is_cart_taxed()) {
        if (edd_taxes_after_discounts()) {
            $subtotal -= edd_get_cart_discounted_amount($discounts);
        }
        $cart_tax = edd_calculate_tax($subtotal, false);
    }
    return apply_filters('edd_get_cart_tax', $cart_tax, $subtotal);
}