/**
 * Price
 *
 * Displays a formatted price for a download.
 *
 * @access      public
 * @since       1.0
 * @param       int $download_id the ID of the download price to show
 * @param		bool whether to echo or return the results
* @return       void
*/
function edd_price($download_id, $echo = true)
{
    if (edd_has_variable_prices($download_id)) {
        $prices = edd_get_variable_prices($download_id);
        // return the lowest price
        $price_float = 0;
        foreach ($prices as $key => $value) {
            if ((double) $prices[$key]['amount'] < $price_float or $price_float == 0) {
                $price_float = (double) $prices[$key]['amount'];
            }
        }
        $price = edd_sanitize_amount($price_float);
    } else {
        $price = edd_get_download_price($download_id);
    }
    if (edd_use_taxes() && edd_taxes_on_prices()) {
        $price += edd_calculate_tax($price);
    }
    $price = apply_filters('edd_download_price', $price, $download_id);
    $price = '<span class="edd_price" id="edd_price_' . $download_id . '">' . $price . '</span>';
    if ($echo) {
        echo $price;
    } else {
        return $price;
    }
}
Пример #2
0
/**
 * Load Scripts
 *
 * Enqueues the required scripts.
 *
 * @since 1.0
 * @global $post
 * @return void
 */
function edd_load_scripts()
{
    global $post;
    $js_dir = EDD_PLUGIN_URL . 'assets/js/';
    // Use minified libraries if SCRIPT_DEBUG is turned off
    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
    // Get position in cart of current download
    if (isset($post->ID)) {
        $position = edd_get_item_position_in_cart($post->ID);
    }
    if (edd_is_checkout()) {
        if (edd_is_cc_verify_enabled()) {
            wp_register_script('creditCardValidator', $js_dir . 'jquery.creditCardValidator' . $suffix . '.js', array('jquery'), EDD_VERSION);
            wp_enqueue_script('creditCardValidator');
        }
        wp_register_script('edd-checkout-global', $js_dir . 'edd-checkout-global' . $suffix . '.js', array('jquery'), EDD_VERSION);
        wp_enqueue_script('edd-checkout-global');
        wp_localize_script('edd-checkout-global', 'edd_global_vars', apply_filters('edd_global_checkout_script_vars', array('ajaxurl' => edd_get_ajax_url(), 'checkout_nonce' => wp_create_nonce('edd_checkout_nonce'), 'currency_sign' => edd_currency_filter(''), 'currency_pos' => edd_get_option('currency_position', 'before'), 'no_gateway' => __('Please select a payment method', 'edd'), 'no_discount' => __('Please enter a discount code', 'edd'), 'enter_discount' => __('Enter discount', 'edd'), 'discount_applied' => __('Discount Applied', 'edd'), 'no_email' => __('Please enter an email address before applying a discount code', 'edd'), 'no_username' => __('Please enter a username before applying a discount code', 'edd'), 'purchase_loading' => __('Please Wait...', 'edd'), 'complete_purchase' => __('Purchase', 'edd'), 'taxes_enabled' => edd_use_taxes() ? '1' : '0', 'edd_version' => EDD_VERSION)));
    }
    // Load AJAX scripts, if enabled
    if (!edd_is_ajax_disabled()) {
        wp_register_script('edd-ajax', $js_dir . 'edd-ajax' . $suffix . '.js', array('jquery'), EDD_VERSION);
        wp_enqueue_script('edd-ajax');
        wp_localize_script('edd-ajax', 'edd_scripts', apply_filters('edd_ajax_script_vars', array('ajaxurl' => edd_get_ajax_url(), 'position_in_cart' => isset($position) ? $position : -1, 'already_in_cart_message' => __('You have already added this item to your cart', 'edd'), 'empty_cart_message' => __('Your cart is empty', 'edd'), 'loading' => __('Loading', 'edd'), 'select_option' => __('Please select an option', 'edd'), 'ajax_loader' => set_url_scheme(EDD_PLUGIN_URL . 'assets/images/loading.gif', 'relative'), 'is_checkout' => edd_is_checkout() ? '1' : '0', 'default_gateway' => edd_get_default_gateway(), 'redirect_to_checkout' => edd_straight_to_checkout() || edd_is_checkout() ? '1' : '0', 'checkout_page' => edd_get_checkout_uri(), 'permalinks' => get_option('permalink_structure') ? '1' : '0', 'quantities_enabled' => edd_item_quantities_enabled(), 'taxes_enabled' => edd_use_taxes() ? '1' : '0')));
    }
}
 /**
  * Get EDD details
  *
  * ## OPTIONS
  *
  * None. Returns basic info regarding your EDD instance.
  *
  * ## EXAMPLES
  *
  * wp edd details
  *
  * @access		public
  * @param		array $args
  * @param		array $assoc_args
  * @return		void
  */
 public function details($args, $assoc_args)
 {
     $symlink_file_downloads = edd_get_option('symlink_file_downloads', false);
     $purchase_page = edd_get_option('purchase_page', '');
     $success_page = edd_get_option('success_page', '');
     $failure_page = edd_get_option('failure_page', '');
     WP_CLI::line(sprintf(__('You are running EDD version: %s', 'easy-digital-downloads'), EDD_VERSION));
     WP_CLI::line("\n" . sprintf(__('Test mode is: %s', 'easy-digital-downloads'), edd_is_test_mode() ? __('Enabled', 'easy-digital-downloads') : __('Disabled', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Ajax is: %s', 'easy-digital-downloads'), edd_is_ajax_enabled() ? __('Enabled', 'easy-digital-downloads') : __('Disabled', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Guest checkouts are: %s', 'easy-digital-downloads'), edd_no_guest_checkout() ? __('Disabled', 'easy-digital-downloads') : __('Enabled', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Symlinks are: %s', 'easy-digital-downloads'), apply_filters('edd_symlink_file_downloads', isset($symlink_file_downloads)) && function_exists('symlink') ? __('Enabled', 'easy-digital-downloads') : __('Disabled', 'easy-digital-downloads')));
     WP_CLI::line("\n" . sprintf(__('Checkout page is: %s', 'easy-digital-downloads'), !edd_get_option('purchase_page', false) ? __('Valid', 'easy-digital-downloads') : __('Invalid', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Checkout URL is: %s', 'easy-digital-downloads'), !empty($purchase_page) ? get_permalink($purchase_page) : __('Undefined', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Success URL is: %s', 'easy-digital-downloads'), !empty($success_page) ? get_permalink($success_page) : __('Undefined', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Failure URL is: %s', 'easy-digital-downloads'), !empty($failure_page) ? get_permalink($failure_page) : __('Undefined', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Downloads slug is: %s', 'easy-digital-downloads'), defined('EDD_SLUG') ? '/' . EDD_SLUG : '/downloads'));
     WP_CLI::line("\n" . sprintf(__('Taxes are: %s', 'easy-digital-downloads'), edd_use_taxes() ? __('Enabled', 'easy-digital-downloads') : __('Disabled', 'easy-digital-downloads')));
     WP_CLI::line(sprintf(__('Tax rate is: %s', 'easy-digital-downloads'), edd_get_tax_rate() * 100 . '%'));
     $rates = edd_get_tax_rates();
     if (!empty($rates)) {
         foreach ($rates as $rate) {
             WP_CLI::line(sprintf(__('Country: %s, State: %s, Rate: %s', 'easy-digital-downloads'), $rate['country'], $rate['state'], $rate['rate']));
         }
     }
 }
/**
 * Process PayPal Purchase
 *
 * @since 1.0
 * @global $edd_options Array of all the EDD Options
 * @param array $purchase_data Purchase Data
 * @return void
 */
function edd_process_paypal_purchase($purchase_data)
{
    global $edd_options;
    // Check there is a gateway name
    if (!isset($purchase_data['post_data']['edd-gateway'])) {
        return;
    }
    /*
    Purchase data comes in like this:
    
    $purchase_data = array(
        'downloads'     => array of download IDs,
        'tax' 			=> taxed amount on shopping cart
        'subtotal'		=> total price before tax
        'price'         => total price of cart contents after taxes,
        'purchase_key'  =>  // Random key
        'user_email'    => $user_email,
        'date'          => date( 'Y-m-d H:i:s' ),
        'user_id'       => $user_id,
        'post_data'     => $_POST,
        'user_info'     => array of user's information and used discount code
        'cart_details'  => array of cart details,
     );
    */
    // Collect payment data
    $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'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
    // Record the pending payment
    $payment = edd_insert_payment($payment_data);
    // Check payment
    if (!$payment) {
        // Record the error
        edd_record_gateway_error(__('Payment Error', 'edd'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'edd'), json_encode($payment_data)), $payment);
        // Problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        // Only send to PayPal if the pending payment is created successfully
        $listener_url = trailingslashit(home_url()) . '?edd-listener=IPN';
        // Get the success url
        $return_url = add_query_arg('payment-confirmation', 'paypal', get_permalink($edd_options['success_page']));
        // Get the complete cart cart_summary
        $summary = edd_get_purchase_summary($purchase_data, false);
        // Get the PayPal redirect uri
        $paypal_redirect = trailingslashit(edd_get_paypal_redirect()) . '?';
        // Setup PayPal arguments
        $paypal_args = array('cmd' => '_xclick', 'amount' => round($purchase_data['price'] - $purchase_data['tax'], 2), 'business' => $edd_options['paypal_email'], 'item_name' => stripslashes_deep(html_entity_decode(wp_strip_all_tags($summary), ENT_COMPAT, 'UTF-8')), 'email' => $purchase_data['user_email'], 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => edd_get_currency(), 'item_number' => $purchase_data['purchase_key'], 'charset' => get_bloginfo('charset'), 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'cancel_return' => edd_get_failed_transaction_uri(), 'notify_url' => $listener_url, 'page_style' => edd_get_paypal_page_style());
        if (edd_use_taxes()) {
            $paypal_args['tax'] = $purchase_data['tax'];
        }
        $paypal_args = apply_filters('edd_paypal_redirect_args', $paypal_args, $purchase_data);
        // Build query
        $paypal_redirect .= http_build_query($paypal_args);
        // Get rid of cart contents
        edd_empty_cart();
        // Redirect to PayPal
        wp_redirect($paypal_redirect);
        exit;
    }
}
/**
 * Track new users
 *
 * @since       1.0.0
 * @param       int $payment_id The ID of a given payment
 * @return      void
 */
function edd_customerio_connect_register_user($payment_id)
{
    // Bail if API isn't setup
    if (!edd_customerio_connect()->api) {
        return;
    }
    // Setup the request body
    $user_info = edd_get_payment_meta_user_info($payment_id);
    $payment_meta = edd_get_payment_meta($payment_id);
    $cart_items = isset($payment_meta['cart_details']) ? maybe_unserialize($payment_meta['cart_details']) : false;
    $user_name = false;
    if ($payment_meta['user_info']['first_name']) {
        $user_name = $payment_meta['user_info']['first_name'];
        if ($payment_meta['user_info']['last_name']) {
            $user_name .= ' ' . $payment_meta['user_info']['last_name'];
        }
    }
    $body = array('email' => $payment_meta['user_info']['email'], 'created_at' => $payment_meta['date']);
    if ($user_name) {
        $body['name'] = $user_name;
    }
    $response = edd_customerio_connect()->api->call($payment_meta['user_info']['id'], $body);
    // Track the purchases
    if (empty($cart_items) || !$cart_items) {
        $cart_items = maybe_unserialize($payment_meta['downloads']);
    }
    if ($cart_items) {
        $body = array('name' => 'purchased', 'data' => array('discount' => $payment_meta['user_info']['discount']));
        foreach ($cart_items as $key => $cart_item) {
            $item_id = isset($payment_meta['cart_details']) ? $cart_item['id'] : $cart_item;
            $price = $cart_item['price'];
            $body['data']['items'][$cart_item['id']] = array('price' => $price, 'product_id' => $cart_item['id'], 'product_name' => esc_attr($cart_item['name']));
            if (edd_has_variable_prices($cart_item['id'])) {
                $body['data']['items'][$cart_item['id']]['price_id'] = $cart_item['item_number']['options']['price_id'];
                $body['data']['items'][$cart_item['id']]['price_name'] = edd_get_price_option_name($cart_item['id'], $cart_item['item_number']['options']['price_id']);
                $body['data']['items'][$cart_item['id']]['quantity'] = $cart_item['item_number']['quantity'];
            } else {
                $body['data']['items'][$cart_item['id']]['quantity'] = $cart_item['quantity'];
            }
            if (edd_use_taxes()) {
                $body['data']['items'][$cart_item['id']]['tax'] = $cart_item['tax'];
            }
        }
        $response = edd_customerio_connect()->api->call($payment_meta['user_info']['id'], $body, 'POST', 'events');
    }
}
Пример #6
0
/**
 * Get Cart Item Template
 *
 * @access      public
 * @since       1.0
 * @return      string
*/
function edd_get_cart_item_template($cart_key, $item, $ajax = false)
{
    global $post;
    $id = is_array($item) ? $item['id'] : $item;
    $remove_url = edd_remove_item_url($cart_key, $post, $ajax);
    $title = get_the_title($id);
    $options = !empty($item['options']) ? $item['options'] : array();
    $price = edd_get_cart_item_price($id, $options);
    if (edd_use_taxes() && edd_taxes_on_prices()) {
        $price += edd_calculate_tax($price);
    }
    if (!empty($options)) {
        $title .= ' <span class="edd-cart-item-separator">-</span> ' . edd_get_price_name($id, $item['options']);
    }
    $remove = '<a href="' . esc_url($remove_url) . '" data-cart-item="' . absint($cart_key) . '" data-download-id="' . absint($id) . '" data-action="edd_remove_from_cart" class="edd-remove-from-cart">' . __('remove', 'edd') . '</a>';
    $item = '<li class="edd-cart-item"><span class="edd-cart-item-title">' . $title . '</span>&nbsp;';
    $item .= '<span class="edd-cart-item-separator">-</span>&nbsp;' . edd_currency_filter(edd_format_amount($price)) . '&nbsp;';
    $item .= '<span class="edd-cart-item-separator">-</span> ' . $remove . '</li>';
    return apply_filters('edd_cart_item', $item, $id);
}
/**
 * Get final price of a download after discount
 * 
 * Modified From:
 * includes/download-functions.php -> edd_price()
 * Modified Parts:
 * Remove the price as a number, without the html formatting.
 * 
 * @param  int   $download_id ID of the download
 * @return float              Download price
 */
function vp_edd_fd_get_calculated_price($download_id)
{
    if (edd_has_variable_prices($download_id)) {
        $prices = edd_get_variable_prices($download_id);
        // Return the lowest price
        $price_float = 0;
        foreach ($prices as $key => $value) {
            if ((double) $prices[$key]['amount'] < $price_float or $price_float == 0) {
                $price_float = (double) $prices[$key]['amount'];
            }
        }
        $price = edd_sanitize_amount($price_float);
    } else {
        $price = edd_get_download_price($download_id);
    }
    if (edd_use_taxes() && edd_taxes_on_prices()) {
        $price += edd_calculate_tax($price);
    }
    return $price;
}
/**
 * Retrieves subtotal for payment (this is the amount before taxes) and then
 * returns a non formatted amount.
 *
 * @since 1.3.3
 * @param int $payment_id Payment ID
 * @return float $subtotal Subtotal for payment (non formatted)
 */
function edd_get_payment_subtotal($payment_id = 0)
{
    $subtotal = 0;
    $cart_details = edd_get_payment_meta_cart_details($payment_id);
    if (is_array($cart_details)) {
        foreach ($cart_details as $item) {
            if (isset($item['subtotal'])) {
                $subtotal += $item['subtotal'];
            }
        }
    } else {
        $subtotal = edd_get_payment_amount($payment_id);
        $tax = edd_use_taxes() ? edd_get_payment_tax($payment_id) : 0;
        $subtotal -= $tax;
    }
    return apply_filters('edd_get_payment_subtotal', $subtotal, $payment_id);
}
    /**
     * Display the wallet and address forms
     *
     * @access public
     * @since  2.4
     * @return void
     */
    public function wallet_form()
    {
        $profile = EDD()->session->get('amazon_profile');
        remove_action('edd_purchase_form_after_cc_form', 'edd_checkout_tax_fields', 999);
        ob_start();
        ?>
		<fieldset id="edd_cc_fields" class="edd-amazon-fields">
			<p class="edd-amazon-profile-wrapper">
				<?php 
        _e('Currently logged into Amazon as', 'edd');
        ?>
: <span class="edd-amazon-profile-name"><?php 
        echo $profile['name'];
        ?>
</span>
				<span class="edd-amazon-logout">(<a id="Logout"><?php 
        _e('Logout', 'edd');
        ?>
</a>)</span>
			</p>
			<?php 
        if (edd_use_taxes()) {
            ?>
				<div id="edd-amazon-address-box"></div>
			<?php 
        }
        ?>
			<div id="edd-amazon-wallet-box"></div>
			<script>
				var edd_scripts;
				if( '1' == edd_scripts.taxes_enabled ) {
					new OffAmazonPayments.Widgets.AddressBook({
						sellerId: edd_amazon.sellerId,
						amazonOrderReferenceId: edd_amazon.referenceID,
						onOrderReferenceCreate: function(orderReference) {
							orderReference.getAmazonOrderReferenceId();
						},
						onAddressSelect: function(orderReference) {
							jQuery.ajax({
								type: "POST",
								data: {
									action       : 'edd_amazon_get_address',
									reference_id : edd_amazon.referenceID
								},
								dataType: "json",
								url: edd_scripts.ajaxurl,
								xhrFields: {
									withCredentials: true
								},
								success: function (response) {
									jQuery('#card_city').val( response.City );
									jQuery('#card_address').val( response.AddressLine1 );
									jQuery('#card_address_2').val( response.AddressLine2 );
									jQuery('#card_zip').val( response.PostalCode );
									jQuery('#billing_country').val( response.CountryCode );
									jQuery('#card_state').val( response.StateOrRegion ).trigger( 'change' );
								}
							}).fail(function (response) {
								if ( window.console && window.console.log ) {
									console.log( response );
								}
							}).done(function (response) {

							});
						},
						design: {
							designMode: 'responsive'
						},
						onError: function(error) {
							jQuery('#edd-amazon-address-box').hide();
							jQuery('#edd_purchase_submit').prepend( '<div class="edd_errors"><p class="edd_error" id="edd_error_"' + error.getErrorCode() + '>' + error.getErrorMessage() + '</p></div>' );
						}
					}).bind("edd-amazon-address-box");

					new OffAmazonPayments.Widgets.Wallet({
						sellerId: edd_amazon.sellerId,
						amazonOrderReferenceId: edd_amazon.referenceID,
						design: {
							designMode: 'responsive'
						},
						onPaymentSelect: function(orderReference) {
							// Display your custom complete purchase button
						},
						onError: function(error) {
							jQuery('#edd_purchase_submit').prepend( '<div class="edd_errors"><p class="edd_error" id="edd_error_"' + error.getErrorCode() + '>' + error.getErrorMessage() + '</p></div>' );
						}
					}).bind("edd-amazon-wallet-box");

				} else {

					new OffAmazonPayments.Widgets.Wallet({
						sellerId: edd_amazon.sellerId,
						design: {
							designMode: 'responsive'
						},
						onOrderReferenceCreate: function(orderReference) {
							jQuery( '#edd_amazon_reference_id' ).val( orderReference.getAmazonOrderReferenceId() );
						},
						onPaymentSelect: function(orderReference) {
							// Display your custom complete purchase button
						},
						onError: function(error) {
							jQuery('#edd_purchase_submit').prepend( '<div class="edd_errors"><p class="edd_error" id="edd_error_"' + error.getErrorCode() + '>' + error.getErrorMessage() + '</p></div>' );
						}
					}).bind("edd-amazon-wallet-box");

				}
			</script>

			<div id="edd_cc_address">
				<input type="hidden" name="edd_amazon_reference_id" id="edd_amazon_reference_id" value="<?php 
        echo esc_attr($this->reference_id);
        ?>
"/>
				<input type="hidden" name="card_city" class="card_city" id="card_city" value=""/>
				<input type="hidden" name="card_address" class="card_address" id="card_address" value=""/>
				<input type="hidden" name="card_address_2" class="card_address_2" id="card_address_2" value=""/>
				<input type="hidden" name="card_zip" class="card_zip" id="card_zip" value=""/>
				<input type="hidden" name="card_state" class="card_state" id="card_state" value=""/>
				<input type="hidden" name="billing_country" class="billing_country" id="billing_country" value=""/>
			</div>

		</fieldset>

		<?php 
        $form = ob_get_clean();
        echo $form;
    }
				<th colspan="<?php echo edd_checkout_cart_columns(); ?>" class="edd_cart_subtotal">
					<?php _e( 'Subtotal', 'edd' ); ?>:&nbsp;<span class="edd_cart_subtotal_amount"><?php echo edd_cart_subtotal(); ?></span>
				</th>
				<?php do_action( 'edd_checkout_table_subtotal_last' ); ?>
			</tr>
		<?php endif; ?>

		<tr class="edd_cart_footer_row edd_cart_discount_row" <?php if( ! edd_cart_has_discounts() )  echo ' style="display:none;"'; ?>>
			<?php do_action( 'edd_checkout_table_discount_first' ); ?>
			<th colspan="<?php echo edd_checkout_cart_columns(); ?>" class="edd_cart_discount">
				<?php edd_cart_discounts_html(); ?>
			</th>
			<?php do_action( 'edd_checkout_table_discount_last' ); ?>
		</tr>

		<?php if( edd_use_taxes() ) : ?>
			<tr class="edd_cart_footer_row edd_cart_tax_row"<?php if( ! edd_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
				<?php do_action( 'edd_checkout_table_tax_first' ); ?>
				<th colspan="<?php echo edd_checkout_cart_columns(); ?>" class="edd_cart_tax">
					<?php _e( 'Tax', 'edd' ); ?>:&nbsp;<span class="edd_cart_tax_amount" data-tax="<?php echo edd_get_cart_tax( false ); ?>"><?php echo esc_html( edd_cart_tax() ); ?></span>
				</th>
				<?php do_action( 'edd_checkout_table_tax_last' ); ?>
			</tr>

		<?php endif; ?>

		<tr class="edd_cart_footer_row">
			<?php do_action( 'edd_checkout_table_footer_first' ); ?>
			<th colspan="<?php echo edd_checkout_cart_columns(); ?>" class="edd_cart_total"><?php _e( 'Total', 'edd' ); ?>: <span class="edd_cart_amount" data-subtotal="<?php echo edd_get_cart_total(); ?>" data-total="<?php echo edd_get_cart_total(); ?>"><?php edd_cart_total(); ?></span></th>
			<?php do_action( 'edd_checkout_table_footer_last' ); ?>
		</tr>
/**
 * Shows the tax opt-in checkbox
 *
 * @since 1.3.3
 * @global $edd_options Array of all the EDD Options
 * @return void
 */
function edd_show_local_tax_opt_in()
{
    global $edd_options;
    if (edd_use_taxes() && isset($edd_options['tax_condition']) && $edd_options['tax_condition'] == 'local') {
        ?>
		<fieldset id="edd_tax_opt_in_fields">
			<p id="edd-tax-opt-in-wrap">
				<label for="edd_tax_opt_in"><?php 
        echo isset($edd_options['tax_location']) ? $edd_options['tax_location'] : __('Opt Into Taxes?', 'edd');
        ?>
</label>
				<input name="edd_tax_opt_in" type="checkbox" id="edd_tax_opt_in" value="1"<?php 
        checked(true, edd_local_tax_opted_in());
        ?>
/>
			</p>
		</fieldset>
<?php 
    }
}
/**
 * Adds item to the cart via AJAX.
 *
 * @since 1.0
 * @return void
 */
function edd_ajax_add_to_cart()
{
    if (isset($_POST['download_id'])) {
        $to_add = array();
        if (isset($_POST['price_ids']) && is_array($_POST['price_ids'])) {
            foreach ($_POST['price_ids'] as $price) {
                $to_add[] = array('price_id' => $price);
            }
        }
        $items = '';
        foreach ($to_add as $options) {
            if ($_POST['download_id'] == $options['price_id']) {
                $options = array();
            }
            parse_str($_POST['post_data'], $post_data);
            if (isset($options['price_id']) && isset($post_data['edd_download_quantity_' . $options['price_id']])) {
                $options['quantity'] = absint($post_data['edd_download_quantity_' . $options['price_id']]);
            } else {
                $options['quantity'] = isset($post_data['edd_download_quantity']) ? absint($post_data['edd_download_quantity']) : 1;
            }
            $key = edd_add_to_cart($_POST['download_id'], $options);
            $item = array('id' => $_POST['download_id'], 'options' => $options);
            $item = apply_filters('edd_ajax_pre_cart_item_template', $item);
            $items .= html_entity_decode(edd_get_cart_item_template($key, $item, true), ENT_COMPAT, 'UTF-8');
        }
        $return = array('subtotal' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_total())), ENT_COMPAT, 'UTF-8'), 'cart_item' => $items, 'cart_quantity' => html_entity_decode(edd_get_cart_quantity()));
        if (edd_use_taxes()) {
            $cart_tax = (double) edd_get_cart_tax();
            $return['tax'] = html_entity_decode(edd_currency_filter(edd_format_amount($cart_tax)), ENT_COMPAT, 'UTF-8');
        }
        echo json_encode($return);
    }
    edd_die();
}
/**
 * Process PayPal Purchase
 *
 * @since 1.0
 * @param array   $purchase_data Purchase Data
 * @return void
 */
function edd_process_paypal_purchase($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'edd-gateway')) {
        wp_die(__('Nonce verification has failed', 'edd'), __('Error', 'edd'), array('response' => 403));
    }
    // Collect payment data
    $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'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => 'paypal', 'status' => !empty($purchase_data['buy_now']) ? 'private' : 'pending');
    // Record the pending payment
    $payment = edd_insert_payment($payment_data);
    // Check payment
    if (!$payment) {
        // Record the error
        edd_record_gateway_error(__('Payment Error', 'edd'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'edd'), json_encode($payment_data)), $payment);
        // Problems? send back
        edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
    } else {
        // Only send to PayPal if the pending payment is created successfully
        $listener_url = add_query_arg('edd-listener', 'IPN', home_url('index.php'));
        // Get the success url
        $return_url = add_query_arg(array('payment-confirmation' => 'paypal', 'payment-id' => $payment), get_permalink(edd_get_option('success_page', false)));
        // Get the PayPal redirect uri
        $paypal_redirect = trailingslashit(edd_get_paypal_redirect()) . '?';
        // Setup PayPal arguments
        $paypal_args = array('business' => edd_get_option('paypal_email', false), 'email' => $purchase_data['user_email'], 'first_name' => $purchase_data['user_info']['first_name'], 'last_name' => $purchase_data['user_info']['last_name'], 'invoice' => $purchase_data['purchase_key'], 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => edd_get_currency(), 'charset' => get_bloginfo('charset'), 'custom' => $payment, 'rm' => '2', 'return' => $return_url, 'cancel_return' => edd_get_failed_transaction_uri('?payment-id=' . $payment), 'notify_url' => $listener_url, 'page_style' => edd_get_paypal_page_style(), 'cbt' => get_bloginfo('name'), 'bn' => 'EasyDigitalDownloads_SP');
        if (!empty($purchase_data['user_info']['address'])) {
            $paypal_args['address1'] = $purchase_data['user_info']['address']['line1'];
            $paypal_args['address2'] = $purchase_data['user_info']['address']['line2'];
            $paypal_args['city'] = $purchase_data['user_info']['address']['city'];
            $paypal_args['country'] = $purchase_data['user_info']['address']['country'];
        }
        $paypal_extra_args = array('cmd' => '_cart', 'upload' => '1');
        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
        // Add cart items
        $i = 1;
        foreach ($purchase_data['cart_details'] as $item) {
            $item_amount = round($item['subtotal'] / $item['quantity'] - $item['discount'] / $item['quantity'], 2);
            if ($item_amount <= 0) {
                $item_amount = 0;
            }
            $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(edd_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
            $paypal_args['quantity_' . $i] = $item['quantity'];
            $paypal_args['amount_' . $i] = $item_amount;
            if (edd_use_skus()) {
                $paypal_args['item_number_' . $i] = edd_get_download_sku($item['id']);
            }
            $i++;
        }
        // Calculate discount
        $discounted_amount = 0.0;
        if (!empty($purchase_data['fees'])) {
            $i = empty($i) ? 1 : $i;
            foreach ($purchase_data['fees'] as $fee) {
                if (floatval($fee['amount']) > '0') {
                    // this is a positive fee
                    $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wp_strip_all_tags($fee['label']), ENT_COMPAT, 'UTF-8'));
                    $paypal_args['quantity_' . $i] = '1';
                    $paypal_args['amount_' . $i] = edd_sanitize_amount($fee['amount']);
                    $i++;
                } else {
                    // This is a negative fee (discount)
                    $discounted_amount += abs($fee['amount']);
                }
            }
        }
        if ($discounted_amount > '0') {
            $paypal_args['discount_amount_cart'] = edd_sanitize_amount($discounted_amount);
        }
        // Add taxes to the cart
        if (edd_use_taxes()) {
            $paypal_args['tax_cart'] = edd_sanitize_amount($purchase_data['tax']);
        }
        $paypal_args = apply_filters('edd_paypal_redirect_args', $paypal_args, $purchase_data);
        // Build query
        $paypal_redirect .= http_build_query($paypal_args);
        // Fix for some sites that encode the entities
        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
        // Get rid of cart contents
        edd_empty_cart();
        // Redirect to PayPal
        wp_redirect($paypal_redirect);
        exit;
    }
}
Пример #14
0
/**
 * 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;
}
/**
 * Check to see if we should show included taxes
 *
 * Some countries (notably in the EU) require included taxes to be displayed.
 *
 * @since 1.7
 * @author Daniel J Griffiths
 * @return bool
 */
function edd_display_tax_rate()
{
    $ret = edd_use_taxes() && edd_get_option('display_tax_rate', false);
    return apply_filters('edd_display_tax_rate', $ret);
}
Пример #16
0
 /**
  * Enqueues all theme assets
  */
 public function enqueue_assets()
 {
     wp_enqueue_style('yoast-com');
     wp_enqueue_script('yoast-com');
     wp_localize_script('yoast-com', 'YoastAjax', array('ajaxurl' => admin_url('admin-ajax.php')));
     if (function_exists('edd_is_checkout') && edd_is_checkout()) {
         wp_enqueue_style('chosen');
         wp_enqueue_script('yoast-com-checkout');
         wp_localize_script('yoast-com-checkout', 'yoast_com_checkout_vars', array('ajaxurl' => edd_get_ajax_url(), 'checkout_nonce' => wp_create_nonce('edd_checkout_nonce'), 'taxes_enabled' => edd_use_taxes() ? '1' : '0', 'tax_rates' => $this->get_tax_rates()));
     }
     // Remove the cross selling CSS because we overwrite it completely.
     wp_deregister_style('edd-csau-css');
     if (is_singular('post') && !Hide_Comments::hide_comments() && comments_open()) {
         wp_enqueue_script('comment-reply');
     }
     if (is_singular(array('course', 'lesson', 'llms_quiz'))) {
         wp_enqueue_script('yoast-com-academy');
     }
 }
Пример #17
0
/**
 * Gets the total tax amount for the cart contents
 *
 * @access      public
 * @since       1.2.3
 * @return      string
*/
function edd_get_cart_tax()
{
    if (!edd_use_taxes()) {
        return 0;
    }
    $cart_sub_total = edd_get_cart_subtotal();
    $cart_tax = edd_calculate_tax($cart_sub_total);
    $cart_tax = number_format($cart_tax, 2);
    return apply_filters('edd_get_cart_tax', $cart_tax, $cart_sub_total);
}
/**
 * Stores the tax info in the payment meta
 *
 * @access      public
 * @since       1.3.3
 * @param 		$payment_meta array The meta data to store with the payment
 * @param 		$payment_data array The info sent from process-purchase.php
 * @return      array
*/
function edd_record_taxed_amount($payment_meta, $payment_data)
{
    if (!edd_use_taxes()) {
        return $payment_meta;
    }
    if (edd_local_taxes_only() && isset($_POST['edd_tax_opt_in'])) {
        // calculate local taxes
        $payment_meta['subtotal'] = edd_get_cart_amount(false);
        $payment_meta['tax'] = edd_get_cart_tax();
    } elseif (!edd_local_taxes_only()) {
        // calculate global taxes
        $payment_meta['subtotal'] = edd_get_cart_amount(false);
        $payment_meta['tax'] = edd_get_cart_tax();
    }
    return $payment_meta;
}
/**
 * Check to see if we should show included taxes
 *
 * Some countries (notably in the EU) require included taxes to be displayed.
 *
 * @since 1.7
 * @author Daniel J Griffiths
 * @return bool
 */
function edd_display_tax_rate()
{
    global $edd_options;
    $ret = edd_use_taxes() && isset($edd_options['display_tax_rate']);
    return apply_filters('edd_display_tax_rate', $ret);
}
Пример #20
0
    foreach ($discounts as $i => $discount) {
        ?>
					<?php 
        get_template_part('html_includes/shop/discount-item', array('discount' => $discount, 'title' => 0 === $i ? __('Discount', 'yoastcom') : ''));
        ?>
				<?php 
    }
    ?>
			</ul>
		</div>
	<?php 
}
?>

	<?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>
 /**
  * Load javascript files and localized variables
  *
  * @access public
  * @since  2.4
  * @return void
  */
 public function load_scripts()
 {
     if (!edd_is_checkout()) {
         return;
     }
     $test_mode = edd_is_test_mode();
     $seller_id = edd_get_option('amazon_seller_id', '');
     $client_id = edd_get_option('amazon_client_id', '');
     $default_amazon_scope = array('profile', 'postal_code', 'payments:widget');
     if (edd_use_taxes()) {
         $default_amazon_scope[] = 'payments:shipping_address';
     }
     $default_amazon_button_settings = array('type' => 'PwA', 'color' => 'Gold', 'size' => 'medium', 'scope' => implode(' ', $default_amazon_scope), 'popup' => true);
     $amazon_button_settings = apply_filters('edd_amazon_button_settings', $default_amazon_button_settings);
     $base_url = '';
     $sandbox = $test_mode ? 'sandbox/' : '';
     switch (edd_get_shop_country()) {
         case 'GB':
             $base_url = 'https://static-eu.payments-amazon.com/OffAmazonPayments/uk/' . $sandbox . 'lpa/';
             break;
         case 'DE':
             $base_url = 'https://static-eu.payments-amazon.com/OffAmazonPayments/de/' . $sandbox . 'lpa/';
             break;
         default:
             $base_url = 'https://static-na.payments-amazon.com/OffAmazonPayments/us/' . $sandbox;
             break;
     }
     if (!empty($base_url)) {
         $url = $base_url . 'js/Widgets.js?sellerId=' . $seller_id;
         wp_enqueue_script('edd-amazon-widgets', $url, array('jquery'), null, false);
         wp_localize_script('edd-amazon-widgets', 'edd_amazon', apply_filters('edd_amazon_checkout_vars', array('sellerId' => $seller_id, 'clientId' => $client_id, 'referenceID' => $this->reference_id, 'buttonType' => $amazon_button_settings['type'], 'buttonColor' => $amazon_button_settings['color'], 'buttonSize' => $amazon_button_settings['size'], 'scope' => $amazon_button_settings['scope'], 'popup' => $amazon_button_settings['popup'], 'checkoutUri' => $this->get_amazon_checkout_uri(), 'redirectUri' => $this->get_amazon_authenticate_redirect(), 'signinUri' => $this->get_amazon_signin_redirect())));
     }
 }
 /**
  * Determine if the current payment method has billing fields
  *
  * If no billing fields are present, the shipping fields are always displayed
  *
  * @since 1.0
  *
  * @access private
  * @return bool
  */
 private function has_billing_fields()
 {
     $did_action = did_action('edd_after_cc_fields', 'edd_default_cc_address_fields');
     if (!$did_action && edd_use_taxes()) {
         $did_action = did_action('edd_purchase_form_after_cc_form', 'edd_checkout_tax_fields');
     }
     // Have to assume all gateways are using the default CC fields (they should be)
     return $did_action || isset($_POST['card_address']);
 }
/**
 * Is the cart taxed?
 *
 * @since 1.5
 * @return bool
 */
function edd_is_cart_taxed()
{
    return edd_use_taxes() && (edd_local_tax_opted_in() && edd_local_taxes_only() || !edd_local_taxes_only());
}
/**
 * Variable price output
 *
 * To override this output, remove this action, then add
 * your own via a theme, child theme, or plugin.
 *
 * @access      public
 * @since       1.2.3
 * @return      void
 */
function edd_purchase_variable_pricing($download_id)
{
    $variable_pricing = edd_has_variable_prices($download_id);
    if (!$variable_pricing) {
        return;
    }
    $prices = edd_get_variable_prices($download_id);
    do_action('edd_before_price_options', $download_id);
    ?>
	<div class="edd_price_options">
		<ul>
			<?php 
    if ($prices) {
        foreach ($prices as $key => $price) {
            $amount = $price['amount'];
            if (edd_use_taxes() && edd_taxes_on_prices()) {
                $amount += edd_calculate_tax($price['amount']);
            }
            printf('<li><label for="%2$s"><input type="radio" %1$s name="edd_options[price_id]" id="%2$s" class="%3$s" value="%4$s"/> %5$s</label></li>', checked(0, $key, false), esc_attr('edd_price_option_' . $download_id . '_' . $key), esc_attr('edd_price_option_' . $download_id), esc_attr($key), esc_html($price['name'] . ' - ' . edd_currency_filter(edd_format_amount($amount))));
        }
    }
    ?>
		</ul>
	</div><!--end .edd_price_options-->
<?php 
    add_action('edd_after_price_options', $download_id);
}
/**
 * Checks if the user has enabled the option to calculate taxes after discounts
 * have been entered
 *
 * @since 1.4.1
 * @deprecated 2.1
 * @global $edd_options
 * @return bool Whether or not taxes are calculated after discount
 */
function edd_taxes_after_discounts()
{
    $backtrace = debug_backtrace();
    _edd_deprecated_function(__FUNCTION__, '2.1', 'none', $backtrace);
    global $edd_options;
    $ret = isset($edd_options['taxes_after_discounts']) && edd_use_taxes();
    return apply_filters('edd_taxes_after_discounts', $ret);
}
Пример #26
0
/**
 * Contribute now list options
 * @return void
**/
function wpo_campaign_contribute_options_custom($prices, $type, $download_id)
{
    $campaign = atcf_get_campaign($download_id);
    $uid = wpo_makeid();
    ?>
	<div class="edd_price_options <?php 
    echo $campaign->is_active() ? 'active' : 'expired';
    ?>
" <?php 
    echo $campaign->is_donations_only() ? 'style="display: none"' : null;
    ?>
>
		<ul>
			<?php 
    foreach ($prices as $key => $price) {
        ?>
				<?php 
        $amount = $price['amount'];
        $limit = isset($price['limit']) ? $price['limit'] : '';
        $bought = isset($price['bought']) ? $price['bought'] : 0;
        $allgone = false;
        if ($bought == absint($limit) && '' != $limit) {
            $allgone = true;
        }
        if (edd_use_taxes() && edd_taxes_on_prices()) {
            $amount += edd_calculate_tax($amount);
        }
        ?>
				<li class="atcf-price-option pledge-level <?php 
        echo $allgone ? 'inactive' : null;
        ?>
"  data-pri="<?php 
        echo edd_sanitize_amount($amount);
        ?>
"  data-price="<?php 
        echo edd_sanitize_amount($amount);
        ?>
-<?php 
        echo esc_attr($key);
        ?>
">
					<div class="clear">
						<h3><label><!-- <label for="<?php 
        echo esc_attr('edd_price_option_' . $download_id . '_' . $key);
        ?>
"> -->
							<?php 
        if ($campaign->is_active()) {
            if (!$allgone) {
                printf('<input type="radio" name="edd_options[price_id][]" id="%1$s" class="%2$s edd_price_options_input" value="%3$s"/>', esc_attr('edd_price_option_' . $download_id . '_' . $key . '_' . $uid), esc_attr('edd_price_option_' . $download_id), esc_attr($key));
            }
        }
        ?>
  
							<?php 
        echo edd_currency_filter(edd_format_amount($amount));
        ?>
						</label></h3>
						
						<div class="backers hidden">
							<div class="backer-count">
								<i class="icon-user"></i> <?php 
        printf(_n('1 Backer', '%1$s Backers', $bought, 'atcf'), $bought);
        ?>
							</div>
							<?php 
        if ('' != $limit && !$allgone) {
            ?>
								<small class="limit"><?php 
            printf(__('Limit of %d &mdash; %d remaining', 'atcf'), $limit, $limit - $bought);
            ?>
</small>
							<?php 
        } elseif ($allgone) {
            ?>
								<small class="gone"><?php 
            _e('All gone!', 'atcf');
            ?>
</small>
							<?php 
        }
        ?>
						</div>

					</div>
					<?php 
        //echo wpautop( wp_kses_data( $price[ 'name' ] ) );
        ?>
				</li>

			<?php 
    }
    ?>
			<li class="price-custom">
				<div class="campaign-price-input">
					<div class="price-wrapper"><span class="title"><?php 
    _e('Amount: ', TEXTDOMAIN);
    ?>
</span><input type="text" name="atcf_custom_price" value="" /></div>
				</div>	
			</li>

		</ul>
	</div><!--end .edd_price_options-->
<?php 
}
Пример #27
0
/**
 * Product tax settings
 *
 * Outputs the option to mark whether a product is exclusive of tax
 *
 * @since 1.9
 * @param int $post_id Download (Post) ID
 * @return void
 */
function edd_render_dowwn_tax_options($post_id = 0)
{
    if (!current_user_can('manage_shop_settings') || !edd_use_taxes()) {
        return;
    }
    $exclusive = edd_download_is_tax_exclusive($post_id);
    ?>
	<p><strong><?php 
    _e('Ignore Tax:', 'edd');
    ?>
</strong></p>
	<label for="_edd_download_tax_exclusive">
		<?php 
    echo EDD()->html->checkbox(array('name' => '_edd_download_tax_exclusive', 'current' => $exclusive));
    ?>
		<?php 
    _e('Mark this product as exclusive of tax', 'edd');
    ?>
	</label>
<?php 
}
 /**
  * Setup the payment subtotal
  *
  * @since  2.5
  * @return float The subtotal of the payment
  */
 private function setup_subtotal()
 {
     $subtotal = 0;
     $cart_details = $this->cart_details;
     if (is_array($cart_details)) {
         foreach ($cart_details as $item) {
             if (isset($item['subtotal'])) {
                 $subtotal += $item['subtotal'];
             }
         }
     } else {
         $subtotal = $this->total;
         $tax = edd_use_taxes() ? $this->tax : 0;
         $subtotal -= $tax;
     }
     return $subtotal;
 }
			<tr>
				<td><strong><?php 
    _e('Discount(s)', 'easy-digital-downloads');
    ?>
:</strong></td>
				<td><?php 
    echo $user['discount'];
    ?>
</td>
			</tr>
		<?php 
}
?>

		<?php 
if (edd_use_taxes()) {
    ?>
			<tr>
				<td><strong><?php 
    _e('Tax', 'easy-digital-downloads');
    ?>
</strong></td>
				<td><?php 
    echo edd_payment_tax($payment->ID);
    ?>
</td>
			</tr>
		<?php 
}
?>
/**
 * Purchase Form Required Fields
 *
 * @access      private
 * @since       1.5
 * @return      array
 */
function edd_purchase_form_required_fields()
{
    $required_fields = array('edd_email' => array('error_id' => 'invalid_email', 'error_message' => __('Please enter a valid email address', 'easy-digital-downloads')), 'edd_first' => array('error_id' => 'invalid_first_name', 'error_message' => __('Please enter your first name', 'easy-digital-downloads')));
    // Let payment gateways and other extensions determine if address fields should be required
    $require_address = apply_filters('edd_require_billing_address', edd_use_taxes() && edd_get_cart_total());
    if ($require_address) {
        $required_fields['card_zip'] = array('error_id' => 'invalid_zip_code', 'error_message' => __('Please enter your zip / postal code', 'easy-digital-downloads'));
        $required_fields['card_city'] = array('error_id' => 'invalid_city', 'error_message' => __('Please enter your billing city', 'easy-digital-downloads'));
        $required_fields['billing_country'] = array('error_id' => 'invalid_country', 'error_message' => __('Please select your billing country', 'easy-digital-downloads'));
        $required_fields['card_state'] = array('error_id' => 'invalid_state', 'error_message' => __('Please enter billing state / province', 'easy-digital-downloads'));
    }
    return apply_filters('edd_purchase_form_required_fields', $required_fields);
}