function kfg_check_if_is_renewal($return)
{
    if (EDD()->session->get('edd_is_renewal')) {
        edd_set_error('edd-discount-error', __('This discount is not valid with renewals.', 'edd'));
        return false;
    }
    return $return;
}
 public function discount_validation($data)
 {
     if ($data['discount'] == 'none' || empty($data['discount'])) {
         $options = get_option('foa_edd_force_discount', '');
         $errornotice = empty($options['errornotice']) ? __('Discount code is a required field. Please enter a discount code.', 'edd-force-discount') : $options['errornotice'];
         edd_set_error('efdfoa_error_notice', $errornotice);
     }
 }
function sumobi_edd_set_minimum_password_length($valid_data, $post_data)
{
    // how many characters should the password be?
    $length = 8;
    if (strlen($post_data['edd_user_pass']) < $length) {
        edd_set_error('password_too_short', sprintf(__('Please enter a password of %s characters or more.', 'edd'), $length));
    }
}
/**
 * Prevents logged-in customers from purchasing an item twice
 *
 */
function pw_edd_prevent_duplicate_purchase($valid_data, $posted)
{
    $cart_contents = edd_get_cart_contents();
    foreach ($cart_contents as $item) {
        if (edd_has_user_purchased(get_current_user_id(), $item['id'])) {
            edd_set_error('duplicate_item', 'You have already purchased this item so may not purchase it again');
        }
    }
}
예제 #5
0
/**
 * Sets an error on checkout if no gateways are enabled
 *
 * @since 1.3.4
 * @return void
 */
function edd_no_gateway_error()
{
    $gateways = edd_get_enabled_payment_gateways();
    if (empty($gateways)) {
        edd_set_error('no_gateways', __('You must enable a payment gateway to use Easy Digital Downloads', 'edd'));
    } else {
        edd_unset_error('no_gateways');
    }
}
예제 #6
0
/**
 * Validates the survey results on checkout
 *
 * @since  1.0
 * @param  array $valid_data The array of valid data
 * @param  array $data       The data submitted
 * @return void
 */
function edd_acq_validate_custom_fields($valid_data, $data)
{
    $methods = edd_acq_get_methods();
    if (empty($methods)) {
        return;
    }
    $required = edd_get_option('acq_require_response', false);
    if ($required && (empty($data['edd_acquisition_method']) || $data['edd_acquisition_method'] == '-1')) {
        // check for a phone number
        edd_set_error('invalid_acquisition_method', __('Please tell us how you found us.', 'edd-acquisition-survey'));
    }
}
예제 #7
0
function pw_edd_recurring_limit_one_subscription($valid_data, $post_data)
{
    if (!class_exists('EDD_Recurring_Customer')) {
        return;
    }
    if (!is_user_logged_in()) {
        return;
    }
    $purchase_data = array('downloads' => edd_get_cart_contents());
    if (EDD_Recurring_Customer::is_customer_active() && EDD_Recurring()->is_purchase_recurring($purchase_data)) {
        edd_set_error('edd-one-subscription', __('You already have an active subscription so may not purchase a second one.', 'edd'));
    }
}
 public function edd_email_domain_validation($data)
 {
     // return if email doesn't exists
     if (empty($data['logged_in_user']['user_email']) && empty($data['guest_user_data']['user_email'])) {
         return;
     }
     $email = empty($data['logged_in_user']['user_email']) ? $data['guest_user_data']['user_email'] : $data['logged_in_user']['user_email'];
     $email = trim($email);
     // return if email is unvalid
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return;
     }
     $error = $this->verify_email($email);
     // show error notice for blacklisted emails
     if ($error) {
         edd_set_error('wedb_blacklisted_email', $error);
     }
 }
예제 #9
0
 /**
  * Ensure out of stock tickets cannot be purchased even if they manage to get added to the cart
  */
 public function checkout_errors()
 {
     foreach ((array) edd_get_cart_contents() as $item) {
         $remaining = $this->stock_control->available_units($item['id']);
         // We have to append the item IDs otherwise if we have multiple errors of the same type one will overwrite
         // the other
         if (!$remaining) {
             edd_set_error('no_stock_' . $item['id'], sprintf(__('%s ticket is sold out', 'event-tickets-plus'), get_the_title($item['id'])));
         } elseif (self::UNLIMITED !== $remaining && $item['quantity'] > $remaining) {
             edd_set_error('insufficient_stock_' . $item['id'], sprintf(__('Sorry! Only %d tickets remaining for %s', 'event-tickets-plus'), $remaining, get_the_title($item['id'])));
         }
     }
 }
/**
 * 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']) ? '&nbsp;&ndash;&nbsp;' . $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&#37; 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&#37; 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);
}
/**
 * Process Profile Updater Form
 *
 * Processes the profile updater form by updating the necessary fields
 *
 * @since 1.4
 * @author Sunny Ratilal
 * @param array $data Data sent from the profile editor
 * @return void
 */
function edd_process_profile_editor_updates($data)
{
    // Profile field change request
    if (empty($_POST['edd_profile_editor_submit']) && !is_user_logged_in()) {
        return false;
    }
    // Nonce security
    if (!wp_verify_nonce($data['edd_profile_editor_nonce'], 'edd-profile-editor-nonce')) {
        return false;
    }
    $user_id = get_current_user_id();
    $display_name = sanitize_text_field($data['edd_display_name']);
    $first_name = sanitize_text_field($data['edd_first_name']);
    $last_name = sanitize_text_field($data['edd_last_name']);
    $email = sanitize_email($data['edd_email']);
    $userdata = array('ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'user_email' => $email);
    // New password
    if (!empty($data['edd_new_user_pass1'])) {
        if ($data['edd_new_user_pass1'] !== $data['edd_new_user_pass2']) {
            edd_set_error('password_mismatch', __('The passwords you entered do not match. Please try again.', 'edd'));
        } else {
            $userdata['user_pass'] = $data['edd_new_user_pass1'];
        }
    }
    // Update the user
    $updated = wp_update_user($userdata);
    if ($updated) {
        do_action('edd_user_profile_updated', $user_id, $userdata);
        wp_redirect(add_query_arg('updated', 'true', $data['edd_redirect']));
        edd_die();
    }
}
예제 #12
0
파일: s3.php 프로젝트: Rexix/edd-amazon-s3
 /**
  * Internal error handler
  *
  * @internal Internal error handler
  * @param string $message Error message
  * @param string $file Filename
  * @param integer $line Line number
  * @param integer $code Error code
  * @return void
  */
 private static function __triggerError($message, $file, $line, $code = 0)
 {
     edd_set_error('edd-amazon-s3', $message . ' - ' . $file . ':' . $line . "\n" . 'Code: ' . $code);
 }
 /**
  * Process payment submission
  *
  * @access      public
  * @since       1.0.0
  * @param       array $purchase_data The data for a specific purchase
  * @return      void
  */
 public function process_payment($purchase_data)
 {
     if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'edd-gateway')) {
         wp_die(__('Nonce verification has failed', 'edd-wallet'), __('Error', 'edd-wallet'), array('response' => 403));
     }
     $error = false;
     // Double check that we can afford this item
     $value = edd_wallet()->wallet->balance($purchase_data['user_email']);
     if ($value < $purchase_data['price']) {
         edd_record_gateway_error(__('Wallet Gateway Error', 'edd-wallet'), __('User wallet has insufficient funds.', 'edd-wallet'), 0);
         edd_set_error('wallet_error', __('Insufficient funds.', 'edd-wallet'));
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
     $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);
     if ($payment) {
         // Update payment status
         edd_update_payment_status($payment, 'publish');
         // Withdraw the funds
         edd_wallet()->wallet->withdraw($purchase_data['user_info']['id'], $payment_data['price'], 'withdrawal', $payment);
         edd_empty_cart();
         edd_send_to_success_page();
     } else {
         edd_record_gateway_error(__('Wallet Gateway Error', 'edd-wallet'), sprintf(__('Payment creation failed while processing a Wallet purchase. Payment data: %s', 'edd-wallet'), json_encode($payment_data)), $payment);
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
 }
예제 #14
0
 /**
  * Process Profile
  * 
  * Handles to process social profile
  * 
  * @package Easy Digital Download - Social Login
  * @since 1.5.6
  */
 public function edd_slg_process_profile($data = array())
 {
     global $wpdb;
     $user = null;
     $new_customer = false;
     $found_via = null;
     $message = edd_slg_messages();
     if (!empty($data) && !empty($data['type'])) {
         //social provider type
         $type = $data['type'];
         $identifier = $data['id'];
         // First, try to identify user based on the social identifier
         $user_id = $wpdb->get_var($wpdb->prepare('SELECT user_id FROM ' . $wpdb->usermeta . ' WHERE ( meta_key = "%1$s" AND meta_value = "%2$s" || meta_key = "%3$s" AND meta_value = "%2$s" )', 'edd_slg_social_' . $type . '_identifier', $identifier, 'edd_slg_social_identifier'));
         if ($user_id) {
             $user = get_user_by('id', $user_id);
             $found_via = 'social_identifier';
         }
         // Fall back to email - user may already have an account with the same email as in their social profile
         if (!$user && !empty($data['email'])) {
             $user = get_user_by('email', $data['email']);
             $found_via = 'email';
         }
         if (is_user_logged_in()) {
             // If a user is already logged in
             // check that the logged in user and found user are the same.
             // This happens when user is linking a new social profile to their account.
             if ($user && get_current_user_id() !== $user->ID) {
                 if ($found_via == 'social_identifier') {
                     $already_linked_error = isset($message['already_linked_error']) ? $message['already_linked_error'] : '';
                     return edd_set_error('edd_slg_account_already_linked', $already_linked_error);
                 } else {
                     $account_exist_error = isset($message['account_exist_error']) ? $message['account_exist_error'] : '';
                     return edd_set_error('edd_slg_account_already_exist', $account_exist_error);
                 }
             }
             // If the social profile is not linked to any user accounts,
             // use the currently logged in user as the customer
             if (!$user) {
                 $user = get_user_by('id', get_current_user_id());
             }
         }
         if (!$user) {
             // If no user was found, create one
             $user_id = $this->edd_slg_add_user($data);
             $user = get_user_by('id', $user_id);
             // indicate that a new user was created
             $new_customer = true;
         }
         // Update customer's WP user profile and billing details
         $this->edd_slg_update_customer_profile($user->ID, $data, $new_customer);
         if (!is_user_logged_in()) {
             // Log user in or add account linked notice for a logged in user
             wp_set_auth_cookie($user->ID);
             //update last login with social account
             edd_slg_update_social_last_login_timestamp($user->ID, $type);
             do_action('edd_slg_login_user_authenticated', $user->ID, $type);
         } else {
             $_SESSION['edd_slg_linked_notice'] = sprintf(__('Your %s account is now linked to your account.', 'eddslg'), $type);
         }
     }
 }
예제 #15
0
/**
 * Process Profile Updater Form
 *
 * Processes the profile updater form by updating the necessary fields
 *
 * @since 1.4
 * @author Sunny Ratilal
 * @param array $data Data sent from the profile editor
 * @return void
 */
function edd_process_profile_editor_updates($data)
{
    // Profile field change request
    if (empty($_POST['edd_profile_editor_submit']) && !is_user_logged_in()) {
        return false;
    }
    // Pending users can't edit their profile
    if (edd_user_pending_verification()) {
        return false;
    }
    // Nonce security
    if (!wp_verify_nonce($data['edd_profile_editor_nonce'], 'edd-profile-editor-nonce')) {
        return false;
    }
    $user_id = get_current_user_id();
    $old_user_data = get_userdata($user_id);
    $display_name = isset($data['edd_display_name']) ? sanitize_text_field($data['edd_display_name']) : $old_user_data->display_name;
    $first_name = isset($data['edd_first_name']) ? sanitize_text_field($data['edd_first_name']) : $old_user_data->first_name;
    $last_name = isset($data['edd_last_name']) ? sanitize_text_field($data['edd_last_name']) : $old_user_data->last_name;
    $email = isset($data['edd_email']) ? sanitize_email($data['edd_email']) : $old_user_data->user_email;
    $line1 = isset($data['edd_address_line1']) ? sanitize_text_field($data['edd_address_line1']) : '';
    $line2 = isset($data['edd_address_line2']) ? sanitize_text_field($data['edd_address_line2']) : '';
    $city = isset($data['edd_address_city']) ? sanitize_text_field($data['edd_address_city']) : '';
    $state = isset($data['edd_address_state']) ? sanitize_text_field($data['edd_address_state']) : '';
    $zip = isset($data['edd_address_zip']) ? sanitize_text_field($data['edd_address_zip']) : '';
    $country = isset($data['edd_address_country']) ? sanitize_text_field($data['edd_address_country']) : '';
    $userdata = array('ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'user_email' => $email);
    $address = array('line1' => $line1, 'line2' => $line2, 'city' => $city, 'state' => $state, 'zip' => $zip, 'country' => $country);
    do_action('edd_pre_update_user_profile', $user_id, $userdata);
    // New password
    if (!empty($data['edd_new_user_pass1'])) {
        if ($data['edd_new_user_pass1'] !== $data['edd_new_user_pass2']) {
            edd_set_error('password_mismatch', __('The passwords you entered do not match. Please try again.', 'easy-digital-downloads'));
        } else {
            $userdata['user_pass'] = $data['edd_new_user_pass1'];
        }
    }
    // Make sure the new email doesn't belong to another user
    if ($email != $old_user_data->user_email) {
        // Make sure the new email is valid
        if (!is_email($email)) {
            edd_set_error('email_invalid', __('The email you entered is invalid. Please enter a valid email.', 'easy-digital-downloads'));
        }
        // Make sure the new email doesn't belong to another user
        if (email_exists($email)) {
            edd_set_error('email_exists', __('The email you entered belongs to another user. Please use another.', 'easy-digital-downloads'));
        }
    }
    // Check for errors
    $errors = edd_get_errors();
    if ($errors) {
        // Send back to the profile editor if there are errors
        wp_redirect($data['edd_redirect']);
        edd_die();
    }
    // Update the user
    $meta = update_user_meta($user_id, '_edd_user_address', $address);
    $updated = wp_update_user($userdata);
    if ($updated) {
        do_action('edd_user_profile_updated', $user_id, $userdata);
        wp_redirect(add_query_arg('updated', 'true', $data['edd_redirect']));
        edd_die();
    }
}
예제 #16
0
 /**
  * Look for errors during checkout
  *
  * This makes sure that only one recurring item is purchased per order.
  *
  * This checks to ensure a user is creating an account, logged/ing in if purchasing a subscription
  *
  * @since  1.0
  * @return void
  */
 public function checkout_errors($valid_data, $post_data)
 {
     // Retrieve the cart contents
     $cart_items = edd_get_cart_contents();
     /********* Check for multiple recurring products *********/
     // If less than 2 items in the cart, get out
     if (count($cart_items) < 2) {
         return;
     }
     $has_recurring = false;
     // Loops through each item to see if any of them are recurring
     foreach ($cart_items as $cart_item) {
         $item_id = $cart_item['id'];
         $options = $cart_item['options'];
         $price_id = isset($options['price_id']) ? intval($options['price_id']) : null;
         // Only one subscription can be purchased at a time. Throw an error is more than one.
         // This also throws an error if a recurring and non recurring product are purchased at once.
         if (!empty($price_id) && self::is_price_recurring($item_id, $price_id) || self::is_recurring($item_id)) {
             $has_recurring = true;
             edd_set_error('subscription_invalid', __('Sorry, you cannot purchase items in the same checkout session as subscriptions.', 'edd-recurring'));
             break;
         }
     }
     /********* Ensure users create an account *********/
     // Only check if guest checkout is enabled
     if (!edd_no_guest_checkout() && $has_recurring && !is_user_logged_in()) {
         // If customer is purchasing as a guest, we must throw an error
         // TODO: this doesn't work yet
         if (isset($valid_data['new_user_data']) && ($valid_data['new_user_data'] = '-1')) {
             //edd_set_error( 'must_be_user', __( 'You must login or register to purchase a subscription.', 'edd-recurring') );
         }
     }
 }
/**
 * Check whether a discount code is valid (when purchasing).
 *
 * @since 1.0
 * @param string $code Discount Code
 * @param string $user User info
 * @return bool
 */
function edd_is_discount_valid($code = '', $user = '', $set_error = true)
{
    $return = false;
    $discount_id = edd_get_discount_id_by_code($code);
    $user = trim($user);
    if (edd_get_cart_contents()) {
        if ($discount_id) {
            if (edd_is_discount_active($discount_id) && edd_is_discount_started($discount_id) && !edd_is_discount_maxed_out($discount_id) && !edd_is_discount_used($code, $user, $discount_id) && edd_discount_is_min_met($discount_id) && edd_discount_product_reqs_met($discount_id)) {
                $return = true;
            }
        } elseif ($set_error) {
            edd_set_error('edd-discount-error', __('This discount is invalid.', 'edd'));
        }
    }
    return apply_filters('edd_is_discount_valid', $return, $discount_id, $code, $user);
}
예제 #18
0
/**
 * Ensure cart quantities are OK
 *
 * @since       1.0.0
 * @return      void
 */
function edd_pl_checkout_errors($valid_data, $posted)
{
    global $edd_prices_sold_out;
    $cart = edd_get_cart_contents();
    $scope = edd_get_option('edd_purchase_limit_scope') ? edd_get_option('edd_purchase_limit_scope') : 'site-wide';
    $errors = array();
    foreach ($cart as $item) {
        if (edd_has_variable_prices($item['id'])) {
            if (edd_pl_is_item_sold_out($item['id'], $item['options']['price_id'], false, false)) {
                $errors[] = array('id' => $item['id'], 'price' => $item['options']['price_id'], 'type' => 'soldout', 'avail' => null);
            }
        } else {
            $max_purchases = edd_pl_get_file_purchase_limit($item['id']);
            if ($scope == 'site-wide') {
                $purchases = edd_get_download_sales_stats($item['id']);
                if ($max_purchases && $purchases >= $max_purchases || !empty($edd_prices_sold_out)) {
                    $errors[] = array('id' => $item['id'], 'price' => null, 'type' => 'soldout', 'avail' => null);
                }
            } else {
                if (is_user_logged_in()) {
                    $purchases = edd_pl_get_user_purchase_count(get_current_user_id(), $item['id']);
                    if ($max_purchases && $purchases >= $max_purchases || !empty($edd_prices_sold_out)) {
                        $errors[] = array('id' => $item['id'], 'price' => null, 'type' => 'soldout', 'avail' => null);
                    }
                }
            }
        }
        if (edd_item_in_cart($item['id'])) {
            if (edd_has_variable_prices($item['id'])) {
                $max_purchases = edd_pl_get_file_purchase_limit($item['id'], null, $item['options']['price_id']);
                $purchases = edd_pl_get_file_purchases($item['id'], $item['options']['price_id']);
            }
            if ($max_purchases > 0) {
                $cart_qty = edd_get_cart_item_quantity($item['id']);
                $total = $purchases + $cart_qty;
                if ($total > $max_purchases) {
                    $errors[] = array('id' => $item['id'], 'price' => edd_has_variable_prices($item['id']) ? $item['options']['price_id'] : null, 'type' => 'toomany', 'avail' => $max_purchases - $purchases);
                }
            }
        }
    }
    if (count($errors) > 0) {
        foreach ($errors as $error) {
            $product = get_post($error['id']);
            if ($error['type'] == 'soldout') {
                edd_set_error('purchase_limit_reached', sprintf(__('The %s "%s" is sold out!', 'edd-purchase-limit'), strtolower(edd_get_label_singular()), $product->post_title));
            } elseif ($error['type'] == 'toomany') {
                edd_set_error('purchase_limit_exceeded', sprintf(_n('There is only %s available for the %s "%s"!', 'There are only %s available for the %s "%s"!', $error['avail'], 'edd-purchase-limit'), $error['avail'], strtolower(edd_get_label_singular()), $product->post_title));
            }
        }
    }
}
예제 #19
0
function wppb_check_edd_login_form($auth_cookie, $expire, $expiration, $user_id, $scheme)
{
    $wppb_generalSettings = get_option('wppb_general_settings', 'not_found');
    if ($wppb_generalSettings != 'not_found') {
        if (!empty($wppb_generalSettings['adminApproval']) && $wppb_generalSettings['adminApproval'] == 'yes') {
            if (isset($_REQUEST['edd_login_nonce'])) {
                if (wp_get_object_terms($user_id, 'user_status')) {
                    if (isset($_REQUEST['edd_redirect'])) {
                        wp_redirect($_REQUEST['edd_redirect']);
                        edd_set_error('user_unapproved', __('Your account has to be confirmed by an administrator before you can log in.', 'profile-builder'));
                        edd_get_errors();
                        edd_die();
                    }
                }
            }
        }
    }
}
예제 #20
0
 /**
  * Check for errors with out custom fields
  *
  * @param array $valid_data Unused.
  * @param array $data The data filled in by the customer.
  */
 public function validate_btw_nr($valid_data, $data)
 {
     if (!empty($data['yst_btw'])) {
         $vat_response = $this->check_vat($data['billing_country'], $data['yst_btw']);
         if (0 === $vat_response) {
             edd_set_error('yst_btw', __('We cannot verify this VAT number, this means you will have to pay VAT. Please make sure you\'ve entered the number correctly.', 'yoastcom'));
         } elseif (2 === $vat_response) {
             edd_set_error('yst_btw_unavailable', __('We cannot check if your VAT number is correct because the VAT checking system for the EU is currently down. We\'re sorry for the inconvenience. Please try again later.', 'yoastcom'));
         }
     }
 }
예제 #21
0
 /**
  * Trigger an error if the quantity for a capped ticket is exceeded.
  *
  * @param int $product_id
  */
 protected function cart_flag_capped_stock_error($product_id)
 {
     $error = new WP_Error();
     $ticket_name = get_the_title($product_id);
     $message = sprintf(__('Sorry, there is insufficient stock to fulfill your order with respect to %s', 'event-tickets-plus'), '<i>' . $ticket_name . '</i>');
     /**
      * Error message generated when an insufficiency of stock for a capped-sales ticket
      * is discovered during validation of cart item quantities.
      *
      * @param string $message
      * @param int    $product_ud
      */
     $message = apply_filters('tribe_tickets_plus_edd_global_stock_cart_error', $message, $product_id);
     $error->add('out-of-capped-stock-' . $product_id, $message);
     edd_set_error('insufficient_stock_capped_' . $product_id, $error->get_error_message());
 }
/**
 * Check the purchase to ensure a banned email is not allowed through
 *
 * @since       2.0
 * @return      void
 */
function edd_check_purchase_email($valid_data, $posted)
{
    $is_banned = false;
    $banned = edd_get_banned_emails();
    if (empty($banned)) {
        return;
    }
    if (is_user_logged_in()) {
        // The user is logged in, check that their account email is not banned
        $user_data = get_userdata(get_current_user_id());
        if (edd_is_email_banned($user_data->user_email)) {
            $is_banned = true;
        }
        if (edd_is_email_banned($posted['edd_email'])) {
            $is_banned = true;
        }
    } elseif (isset($posted['edd-purchase-var']) && $posted['edd-purchase-var'] == 'needs-to-login') {
        // The user is logging in, check that their email is not banned
        $user_data = get_user_by('login', $posted['edd_user_login']);
        if ($user_data && edd_is_email_banned($user_data->user_email)) {
            $is_banned = true;
        }
    } else {
        // Guest purchase, check that the email is not banned
        if (edd_is_email_banned($posted['edd_email'])) {
            $is_banned = true;
        }
    }
    if ($is_banned) {
        // Set an error and give the customer a general error (don't alert them that they were banned)
        edd_set_error('email_banned', __('An internal error has occurred, please try again or contact support.', 'easy-digital-downloads'));
    }
}
/**
 * Process Register Form
 *
 * @since 2.0
 * @param array $data Data sent from the register form
 * @return void
*/
function edd_process_register_form($data)
{
    if (is_user_logged_in()) {
        return;
    }
    if (empty($_POST['edd_register_submit'])) {
        return;
    }
    do_action('edd_pre_process_register_form');
    if (empty($data['edd_user_login'])) {
        edd_set_error('empty_username', __('Invalid username', 'edd'));
    }
    if (username_exists($data['edd_user_login'])) {
        edd_set_error('username_unavailable', __('Username already taken', 'edd'));
    }
    if (!validate_username($data['edd_user_login'])) {
        edd_set_error('username_invalid', __('Invalid username', 'edd'));
    }
    if (email_exists($data['edd_user_email'])) {
        edd_set_error('email_unavailable', __('Email address already taken', 'edd'));
    }
    if (empty($data['edd_user_email']) || !is_email($data['edd_user_email'])) {
        edd_set_error('email_invalid', __('Invalid email', 'edd'));
    }
    if (!empty($data['edd_payment_email']) && $data['edd_payment_email'] != $data['edd_user_email'] && !is_email($data['edd_payment_email'])) {
        edd_set_error('payment_email_invalid', __('Invalid payment email', 'edd'));
    }
    if (empty($_POST['edd_user_pass'])) {
        edd_set_error('empty_password', __('Please enter a password', 'edd'));
    }
    if (!empty($_POST['edd_user_pass']) && empty($_POST['edd_user_pass2']) || $_POST['edd_user_pass'] !== $_POST['edd_user_pass2']) {
        edd_set_error('password_mismatch', __('Passwords do not match', 'edd'));
    }
    do_action('edd_process_register_form');
    // Check for errors and redirect if none present
    $errors = edd_get_errors();
    if (empty($errors)) {
        $redirect = apply_filters('edd_register_redirect', $data['edd_redirect']);
        edd_register_and_login_new_user(array('user_login' => $data['edd_user_login'], 'user_pass' => $data['edd_user_pass'], 'user_email' => $data['edd_user_email'], 'user_registered' => date('Y-m-d H:i:s'), 'role' => get_option('default_role')));
        wp_redirect($redirect);
        edd_die();
    }
}
예제 #24
0
/**
 * Process the payment details edit
 *
 * @access      private
 * @since       1.9
 * @return      void
*/
function edd_update_payment_details($data)
{
    if (!current_user_can('edit_shop_payments', $data['edd_payment_id'])) {
        wp_die(__('You do not have permission to edit this payment record', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403));
    }
    check_admin_referer('edd_update_payment_details_nonce');
    // Retrieve the payment ID
    $payment_id = absint($data['edd_payment_id']);
    $payment = new EDD_Payment($payment_id);
    // Retrieve existing payment meta
    $meta = $payment->get_meta();
    $user_info = $payment->user_info;
    $status = $data['edd-payment-status'];
    $unlimited = isset($data['edd-unlimited-downloads']) ? '1' : '';
    $date = sanitize_text_field($data['edd-payment-date']);
    $hour = sanitize_text_field($data['edd-payment-time-hour']);
    // Restrict to our high and low
    if ($hour > 23) {
        $hour = 23;
    } elseif ($hour < 0) {
        $hour = 00;
    }
    $minute = sanitize_text_field($data['edd-payment-time-min']);
    // Restrict to our high and low
    if ($minute > 59) {
        $minute = 59;
    } elseif ($minute < 0) {
        $minute = 00;
    }
    $address = array_map('trim', $data['edd-payment-address'][0]);
    $curr_total = edd_sanitize_amount($payment->total);
    $new_total = edd_sanitize_amount($_POST['edd-payment-total']);
    $tax = isset($_POST['edd-payment-tax']) ? edd_sanitize_amount($_POST['edd-payment-tax']) : 0;
    $date = date('Y-m-d', strtotime($date)) . ' ' . $hour . ':' . $minute . ':00';
    $curr_customer_id = sanitize_text_field($data['edd-current-customer']);
    $new_customer_id = sanitize_text_field($data['customer-id']);
    // Setup purchased Downloads and price options
    $updated_downloads = isset($_POST['edd-payment-details-downloads']) ? $_POST['edd-payment-details-downloads'] : false;
    if ($updated_downloads && !empty($_POST['edd-payment-downloads-changed'])) {
        foreach ($updated_downloads as $download) {
            // If this item doesn't have a log yet, add one for each quantity count
            $has_log = absint($download['has_log']);
            $has_log = empty($has_log) ? false : true;
            if ($has_log) {
                continue;
            }
            if (empty($download['item_price'])) {
                $download['item_price'] = 0.0;
            }
            $item_price = $download['item_price'];
            $download_id = absint($download['id']);
            $quantity = absint($download['quantity']) > 0 ? absint($download['quantity']) : 1;
            $price_id = false;
            if (edd_has_variable_prices($download_id) && isset($download['price_id'])) {
                $price_id = absint($download['price_id']);
            }
            // Set some defaults
            $args = array('quantity' => $quantity, 'item_price' => $item_price, 'price_id' => $price_id);
            $payment->add_download($download_id, $args);
        }
        $deleted_downloads = json_decode(stripcslashes($data['edd-payment-removed']), true);
        foreach ($deleted_downloads as $deleted_download) {
            $deleted_download = $deleted_download[0];
            if (empty($deleted_download['id'])) {
                continue;
            }
            $price_id = empty($deleted_download['price_id']) ? 0 : (int) $deleted_download['price_id'];
            $args = array('quantity' => (int) $deleted_download['quantity'], 'price_id' => (int) $price_id, 'item_price' => (double) $deleted_download['amount']);
            $payment->remove_download($deleted_download['id'], $args);
            do_action('edd_remove_download_from_payment', $payment_id, $deleted_download['id']);
        }
    }
    do_action('edd_update_edited_purchase', $payment_id);
    $payment->date = $date;
    $updated = $payment->save();
    if (0 === $updated) {
        wp_die(__('Error Updating Payment', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 400));
    }
    $customer_changed = false;
    if (isset($data['edd-new-customer']) && $data['edd-new-customer'] == '1') {
        $email = isset($data['edd-new-customer-email']) ? sanitize_text_field($data['edd-new-customer-email']) : '';
        $names = isset($data['edd-new-customer-name']) ? sanitize_text_field($data['edd-new-customer-name']) : '';
        if (empty($email) || empty($names)) {
            wp_die(__('New Customers require a name and email address', 'easy-digital-downloads'));
        }
        $customer = new EDD_Customer($email);
        if (empty($customer->id)) {
            $customer_data = array('name' => $names, 'email' => $email);
            $user_id = email_exists($email);
            if (false !== $user_id) {
                $customer_data['user_id'] = $user_id;
            }
            if (!$customer->create($customer_data)) {
                // Failed to crete the new customer, assume the previous customer
                $customer_changed = false;
                $customer = new EDD_Customer($curr_customer_id);
                edd_set_error('edd-payment-new-customer-fail', __('Error creating new customer', 'easy-digital-downloads'));
            }
        }
        $new_customer_id = $customer->id;
        $previous_customer = new EDD_Customer($curr_customer_id);
        $customer_changed = true;
    } elseif ($curr_customer_id !== $new_customer_id) {
        $customer = new EDD_Customer($new_customer_id);
        $email = $customer->email;
        $names = $customer->name;
        $previous_customer = new EDD_Customer($curr_customer_id);
        $customer_changed = true;
    } else {
        $customer = new EDD_Customer($curr_customer_id);
        $email = $customer->email;
        $names = $customer->name;
    }
    // Setup first and last name from input values
    $names = explode(' ', $names);
    $first_name = !empty($names[0]) ? $names[0] : '';
    $last_name = '';
    if (!empty($names[1])) {
        unset($names[0]);
        $last_name = implode(' ', $names);
    }
    if ($customer_changed) {
        // Remove the stats and payment from the previous customer and attach it to the new customer
        $previous_customer->remove_payment($payment_id, false);
        $customer->attach_payment($payment_id, false);
        // If purchase was completed and not ever refunded, adjust stats of customers
        if ('revoked' == $status || 'publish' == $status) {
            $previous_customer->decrease_purchase_count();
            $previous_customer->decrease_value($new_total);
            $customer->increase_purchase_count();
            $customer->increase_value($new_total);
        }
        $payment->customer_id = $customer->id;
    }
    // Set new meta values
    $payment->user_id = $customer->user_id;
    $payment->email = $customer->email;
    $payment->first_name = $first_name;
    $payment->last_name = $last_name;
    $payment->address = $address;
    $payment->total = $new_total;
    $payment->tax = $tax;
    $payment->has_unlimited_downloads = $unlimited;
    // Check for payment notes
    if (!empty($data['edd-payment-note'])) {
        $note = wp_kses($data['edd-payment-note'], array());
        edd_insert_payment_note($payment->ID, $note);
    }
    // Set new status
    $payment->status = $status;
    // Adjust total store earnings if the payment total has been changed
    if ($new_total !== $curr_total && ('publish' == $status || 'revoked' == $status)) {
        if ($new_total > $curr_total) {
            // Increase if our new total is higher
            $difference = $new_total - $curr_total;
            edd_increase_total_earnings($difference);
        } elseif ($curr_total > $new_total) {
            // Decrease if our new total is lower
            $difference = $curr_total - $new_total;
            edd_decrease_total_earnings($difference);
        }
    }
    $payment->save();
    do_action('edd_updated_edited_purchase', $payment_id);
    wp_safe_redirect(admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&edd-message=payment-updated&id=' . $payment_id));
    exit;
}
/**
 * Hide the submission form if needed.
 *
 * @since Astoundify Crowdfunding 1.3
 *
 * @param boolean $show
 * @return void
 */
function atcf_gateway_pap_shortcode_submit_hide($show)
{
    global $edd_options;
    if (!is_user_logged_in()) {
        return $show;
    }
    if (!isset($edd_options['epap_campaigns_per_year'])) {
        return $show;
    }
    $user = wp_get_current_user();
    $submitted = $user->get('atcf_campaigns_created');
    $year = date('Y');
    $this_year = isset($submitted[$year]) ? $submitted[$year] : 0;
    if ($this_year == $edd_options['epap_campaigns_per_year']) {
        edd_set_error('campaign-limit-reached', __('You have submitted the maximum number of campaigns allowed for this year.', 'atcf'));
        return true;
    }
    return $show;
}
예제 #26
0
 /**
  * Process Payment
  *
  * Process payments trough the PagSeguro gateway.
  *
  * @return   void
  * @since    1.0
  */
 function process_payment($purchase_data)
 {
     global $edd_options;
     // check there is a gateway name
     if (!isset($purchase_data['post_data']['edd-gateway'])) {
         return;
     }
     // get credentials
     $credentials = $this->get_credentials();
     // check credentials have been set
     if (is_null($credentials['email']) || is_null($credentials['token'])) {
         edd_set_error(0, __('Please enter your PagSeguro Client Email and Token in settings', 'edd-pagseguro-gateway'));
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     }
     // get payment
     $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_option('currency', 'BRL'), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'status' => 'pending');
     // insert pending payment
     $payment = edd_insert_payment($payment_data);
     if (!$payment) {
         // problems? send back
         edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
     } else {
         // require PagSeguro files
         $this->load_pagseguro_sdk();
         // verify classes exists
         if (!class_exists('PagSeguroPaymentRequest')) {
             edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
         }
         // create payment request
         $paymentRequest = new PagSeguroPaymentRequest();
         // sets the currency
         $paymentRequest->setCurrency('BRL');
         // cart summary
         $cart_summary = edd_get_purchase_summary($purchase_data, false);
         // format total price
         $total_price = number_format($purchase_data['price'], 2, '.', '');
         // payment request details
         $paymentRequest->addItem('01', sanitize_text_field(substr($cart_summary, 0, 95)), '1', strval($total_price));
         // sets the reference code for this request
         $paymentRequest->setReference($payment);
         // sets customer information
         $paymentRequest->setSender(sanitize_text_field($purchase_data['user_info']['first_name'] . ' ' . $purchase_data['user_info']['last_name']), $purchase_data['user_email']);
         // redirect url
         $paymentRequest->setRedirectUrl(add_query_arg('payment-confirmation', 'pagseguro', edd_get_success_page_uri()));
         // IPN URL
         $paymentRequest->addParameter('notificationURL', get_site_url());
         /* TRY CHECKOUT */
         try {
             // generate credentials
             $credentials = new PagSeguroAccountCredentials($credentials['email'], $credentials['token']);
             // register this payment request in PagSeguro, to obtain the payment URL for redirect your customer
             $checkout_uri = $paymentRequest->register($credentials);
             if (gettype($checkout_uri) != 'string') {
                 throw new exception($checkout_uri);
             }
             // empty cart
             edd_empty_cart();
             // send the user to PagSeguro
             wp_redirect($checkout_uri);
             die;
         } catch (Exception $e) {
             //catch exception
             wp_mail(get_bloginfo('admin_email'), __('PagSeguro Checkout Error', 'edd-pagseguro-gateway'), $e->getMessage());
             edd_set_error('pagseguro_exception', $e->getMessage());
             edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']);
         }
     }
 }
예제 #27
0
/**
 * Renders the customer view wrapper
 *
 * @since  2.3
 * @param  string $view      The View being requested
 * @param  array $callbacks  The Registered views and their callback functions
 * @return void
 */
function edd_render_customer_view($view, $callbacks)
{
    $render = true;
    $customer_view_role = apply_filters('edd_view_customers_role', 'view_shop_reports');
    if (!current_user_can($customer_view_role)) {
        edd_set_error('edd-no-access', __('You are not permitted to view this data.', 'edd'));
        $render = false;
    }
    if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
        edd_set_error('edd-invalid_customer', __('Invalid Customer ID Provided.', 'edd'));
        $render = false;
    }
    $customer_id = (int) $_GET['id'];
    $customer = new EDD_Customer($customer_id);
    if (empty($customer->id)) {
        edd_set_error('edd-invalid_customer', __('Invalid Customer ID Provided.', 'edd'));
        $render = false;
    }
    $customer_tabs = edd_customer_tabs();
    ?>

	<div class='wrap'>
		<h2><?php 
    _e('Customer Details', 'edd');
    ?>
</h2>
		<?php 
    if (edd_get_errors()) {
        ?>
			<div class="error settings-error">
				<?php 
        edd_print_errors();
        ?>
			</div>
		<?php 
    }
    ?>

		<?php 
    if ($customer && $render) {
        ?>

			<div id="customer-tab-wrapper">
				<ul id="customer-tab-wrapper-list">
				<?php 
        foreach ($customer_tabs as $key => $tab) {
            ?>
					<?php 
            $active = $key === $view ? true : false;
            ?>
					<?php 
            $class = $active ? 'active' : 'inactive';
            ?>

					<?php 
            if (!$active) {
                ?>
					<a title="<?php 
                echo esc_attr($tab['title']);
                ?>
" aria-label="<?php 
                echo esc_attr($tab['title']);
                ?>
" href="<?php 
                echo esc_url(admin_url('edit.php?post_type=download&page=edd-customers&view=' . $key . '&id=' . $customer->id));
                ?>
">
					<?php 
            }
            ?>

					<li class="<?php 
            echo sanitize_html_class($class);
            ?>
"><span class="dashicons <?php 
            echo sanitize_html_class($tab['dashicon']);
            ?>
"></span></li>

					<?php 
            if (!$active) {
                ?>
					</a>
					<?php 
            }
            ?>

				<?php 
        }
        ?>
				</ul>
			</div>

			<div id="edd-customer-card-wrapper" style="float: left">
				<?php 
        $callbacks[$view]($customer);
        ?>
			</div>

		<?php 
    }
    ?>

	</div>
	<?php 
}
 /**
  * Process the purchase and create the charge in Amazon
  *
  * @access public
  * @since  2.4
  * @param  $purchase_data array Cart details
  * @return void
  */
 public function process_purchase($purchase_data)
 {
     if (empty($purchase_data['post_data']['edd_amazon_reference_id'])) {
         edd_set_error('missing_reference_id', __('Missing Reference ID, please try again', 'edd'));
     }
     $errors = edd_get_errors();
     if ($errors) {
         edd_send_back_to_checkout('?payment-mode=amazon');
     }
     $args = apply_filters('edd_amazon_charge_args', array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_reference_id' => $purchase_data['post_data']['edd_amazon_reference_id'], 'authorization_reference_id' => $purchase_data['purchase_key'], 'charge_amount' => $purchase_data['price'], 'currency_code' => edd_get_currency(), 'charge_note' => html_entity_decode(edd_get_purchase_summary($purchase_data, false)), 'charge_order_id' => $purchase_data['purchase_key'], 'store_name' => remove_accents(wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)), 'transaction_timeout' => 0), $purchase_data);
     $args['platform_id'] = 'A3JST9YM1SX7LB';
     $charge = $this->client->charge($args);
     if (200 == $charge->response['Status']) {
         $charge = new ResponseParser($charge->response);
         $charge = $charge->toArray();
         $status = $charge['AuthorizeResult']['AuthorizationDetails']['AuthorizationStatus']['State'];
         if ('Declined' === $status) {
             $reason = $charge['AuthorizeResult']['AuthorizationDetails']['AuthorizationStatus']['ReasonCode'];
             edd_set_error('payment_declined', sprintf(__('Your payment could not be authorized, please try a different payment method. Reason: %s', 'edd'), $reason));
             edd_send_back_to_checkout('?payment-mode=amazon&amazon_reference_id=' . $purchase_data['post_data']['edd_amazon_reference_id']);
         }
         // Setup payment data to be recorded
         $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' => $this->gateway_id, 'status' => 'pending');
         $payment_id = edd_insert_payment($payment_data);
         $authorization_id = $charge['AuthorizeResult']['AuthorizationDetails']['AmazonAuthorizationId'];
         $capture_id = str_replace('-A', '-C', $authorization_id);
         $reference_id = sanitize_text_field($_POST['edd_amazon_reference_id']);
         // Confirm the capture was completed
         $capture = $this->client->getCaptureDetails(array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_capture_id' => $capture_id));
         $capture = new ResponseParser($capture->response);
         $capture = $capture->toArray();
         // Check capture status
         edd_update_payment_meta($payment_id, '_edd_amazon_authorization_id', $authorization_id);
         edd_update_payment_meta($payment_id, '_edd_amazon_capture_id', $capture_id);
         edd_set_payment_transaction_id($payment_id, $reference_id);
         edd_update_payment_status($payment_id, 'publish');
         // Empty the shopping cart
         edd_empty_cart();
         edd_send_to_success_page();
     } else {
         // Set an error
         edd_set_error('amazon_error', sprintf(__('There was an issue processing your payment. Amazon error: %s', 'edd'), print_r($charge, true)));
         edd_send_back_to_checkout('?payment-mode=amazon&amazon_reference_id=' . $purchase_data['post_data']['edd_amazon_reference_id']);
     }
 }
 /**
  * Perform error checks during checkout
  *
  * @since 1.0
  *
  * @access public
  * @return void
  */
 public function error_checks($valid_data, $post_data)
 {
     // Only perform error checks if we have a product that needs shipping
     if (!$this->cart_needs_shipping()) {
         return;
     }
     // Check to see if shipping is different than billing
     if (isset($post_data['edd_use_different_shipping']) || !$this->has_billing_fields()) {
         // Shipping address is different
         if (empty($post_data['shipping_address'])) {
             edd_set_error('missing_address', __('Please enter a shipping address', 'edd-simple-shipping'));
         }
         if (empty($post_data['shipping_city'])) {
             edd_set_error('missing_city', __('Please enter a city for shipping', 'edd-simple-shipping'));
         }
         if (empty($post_data['shipping_zip'])) {
             edd_set_error('missing_zip', __('Please enter a zip/postal code for shipping', 'edd-simple-shipping'));
         }
     } else {
         // Shipping address is the same as billing
         if (empty($post_data['card_address'])) {
             edd_set_error('missing_address', __('Please enter a shipping address', 'edd-simple-shipping'));
         }
         if (empty($post_data['card_city'])) {
             edd_set_error('missing_city', __('Please enter a city for shipping', 'edd-simple-shipping'));
         }
         if (empty($post_data['card_zip'])) {
             edd_set_error('missing_zip', __('Please enter a zip/postal code for shipping', 'edd-simple-shipping'));
         }
     }
 }
예제 #30
0
/**
 * Process Profile Updater Form
 *
 * Processes the profile updater form by updating the necessary fields
 *
 * @access      private
 * @since       1.4
 * @author      Sunny Ratilal
*/
function edd_process_profile_editor_updates($data)
{
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($data['edd_profile_editor_submit']) && wp_verify_nonce($data['edd_profile_editor_nonce'], 'edd-profile-editor-nonce') && is_user_logged_in()) {
        $user_id = get_current_user_id();
        if (!empty($data['edd_first_name']) || !empty($data['edd_last_name'])) {
            $first_name = sanitize_text_field($data['edd_first_name']);
            $last_name = sanitize_text_field($data['edd_last_name']);
        }
        if (!empty($data['edd_display_name'])) {
            $display_name = sanitize_text_field($data['edd_display_name']);
        }
        if (!empty($data['edd_email'])) {
            $email = sanitize_email($data['edd_email']);
        }
        if (!empty($data['edd_new_user_pass1']) && !empty($data['edd_new_user_pass2'])) {
            if ($data['edd_new_user_pass1'] !== $data['edd_new_user_pass2']) {
                edd_set_error('password_mismatch', __('The passwords you entered do not match. Please try again.', 'edd'));
            } else {
                wp_set_password($data['edd_new_user_pass1'], $user_id);
                $updated = true;
            }
        }
        // Update user
        $updated = wp_update_user(array('ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'user_email' => $email));
        if ($updated) {
            wp_redirect(add_query_arg('updated', 'true', $data['edd_redirect']));
            exit;
        }
    } else {
        wp_die(__('Security check failed. Please try again.', 'edd'), __('Security Check Failed', 'edd'));
        exit;
    }
}