/**
 * 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();
}
/**
 * Get Checkout Form
 *
 * @since 1.0
 * @return string
 */
function edd_checkout_form()
{
    $payment_mode = edd_get_chosen_gateway();
    $form_action = esc_url(edd_get_checkout_uri('payment-mode=' . $payment_mode));
    ob_start();
    echo '<div id="edd_checkout_wrap">';
    if (edd_get_cart_contents() || edd_cart_has_fees()) {
        edd_checkout_cart();
        ?>
			<div id="edd_checkout_form_wrap" class="edd_clearfix">
				<?php 
        do_action('edd_before_purchase_form');
        ?>
				<form id="edd_purchase_form" class="edd_form" action="<?php 
        echo $form_action;
        ?>
" method="POST">
					<?php 
        /**
         * Hooks in at the top of the checkout form
         *
         * @since 1.0
         */
        do_action('edd_checkout_form_top');
        if (edd_show_gateways()) {
            do_action('edd_payment_mode_select');
        } else {
            do_action('edd_purchase_form');
        }
        /**
         * Hooks in at the bottom of the checkout form
         *
         * @since 1.0
         */
        do_action('edd_checkout_form_bottom');
        ?>
				</form>
				<?php 
        do_action('edd_after_purchase_form');
        ?>
			</div><!--end #edd_checkout_form_wrap-->
		<?php 
    } else {
        /**
         * Fires off when there is nothing in the cart
         *
         * @since 1.0
         */
        do_action('edd_cart_empty');
    }
    echo '</div><!--end #edd_checkout_wrap-->';
    return ob_get_clean();
}
/**
 * Get Checkout Form
 *
 * @since 1.0
 * @global $edd_options Array of all the EDD options
 * @global $user_ID ID of current logged in user
 * @global $post Current Post Object
 * @return string
 */
function edd_checkout_form()
{
    global $edd_options, $user_ID, $post;
    $payment_mode = edd_get_chosen_gateway();
    $form_action = esc_url(edd_get_checkout_uri('payment-mode=' . $payment_mode));
    ob_start();
    echo '<div id="edd_checkout_wrap">';
    if (edd_get_cart_contents() || edd_cart_has_fees()) {
        edd_checkout_cart();
        ?>
			<div id="edd_checkout_form_wrap" class="edd_clearfix">
				<?php 
        do_action('edd_before_purchase_form');
        ?>
				<form id="edd_purchase_form" class="edd_form" action="<?php 
        echo $form_action;
        ?>
" method="POST">
					<?php 
        do_action('edd_checkout_form_top');
        if (edd_show_gateways()) {
            do_action('edd_payment_mode_select');
        } else {
            do_action('edd_purchase_form');
        }
        do_action('edd_checkout_form_bottom');
        ?>
				</form>
				<?php 
        do_action('edd_after_purchase_form');
        ?>
			</div><!--end #edd_checkout_form_wrap-->
		<?php 
    } else {
        do_action('edd_cart_empty');
    }
    echo '</div><!--end #edd_checkout_wrap-->';
    return ob_get_clean();
}
Example #4
0
					<?php 
        do_action('edd_checkout_table_body_last', $item);
        ?>
				</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 class="edd_cart_actions">
						<?php if( edd_item_quantities_enabled() ) : ?>
							<input type="number" min="1" step="1" name="edd-cart-download-<?php echo $key; ?>-quantity" data-key="<?php echo $key; ?>" class="edd-input edd-item-quantity" value="<?php echo edd_get_cart_item_quantity( $item['id'], $item['options'] ); ?>"/>
							<input type="hidden" name="edd-cart-downloads[]" value="<?php echo $item['id']; ?>"/>
							<input type="hidden" name="edd-cart-download-<?php echo $key; ?>-options" value="<?php echo esc_attr( serialize( $item['options'] ) ); ?>"/>
						<?php endif; ?>
						<?php do_action( 'edd_cart_actions', $item, $key ); ?>
						<a class="edd_cart_remove_item_btn" href="<?php echo esc_url( edd_remove_item_url( $key ) ); ?>"><?php _e( 'Remove', 'edd' ); ?></a>
					</td>
					<?php do_action( 'edd_checkout_table_body_last', $item ); ?>
				</tr>
			<?php endforeach; ?>
		<?php endif; ?>
		<?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; ?>">

					<?php do_action( 'edd_cart_fee_rows_before', $fee_id, $fee ); ?>

					<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 if( ! empty( $fee['type'] ) && 'item' == $fee['type'] ) : ?>
							<a href="<?php echo esc_url( edd_remove_cart_fee_url( $fee_id ) ); ?>"><?php _e( 'Remove', 'edd' ); ?></a>
						<?php endif; ?>

					</td>

					<?php do_action( 'edd_cart_fee_rows_after', $fee_id, $fee ); ?>