/**
 * Add member to an RCP subscription level when they purchase a specific product
 *
 */
function pw_edd_add_customer_to_level($payment_id = 0)
{
    $user_id = edd_get_payment_user_id($payment_id);
    if ($user_id <= 0) {
        return;
    }
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if ($downloads) {
        $level = false;
        foreach ($downloads as $download) {
            // Set the subscription level based on the product ID(s) purchased
            switch ($download['id']) {
                case 45:
                    // Set the subscription level to add the user to
                    $level = 4;
                    break;
                case 742:
                    break;
            }
        }
        if (!empty($level) && function_exists('rcp_set_status')) {
            // Give user one month of access
            $expiration = date('Y-m-d H:i:s', strtotime('+1 month'));
            update_user_meta($user_id, 'rcp_subscription_level', $level);
            update_user_meta($user_id, 'rcp_expiration', $expiration);
            rcp_set_status($user_id, 'active');
        }
    }
}
/**
 * Has User Purchased
 *
 * Checks to see if a user has purchased a download.
 *
 * @access      public
 * @since       1.0
 * @param       int $user_id - the ID of the user to check
 * @param       array $downloads - Array of IDs to check if purchased. If an int is passed, it will be converted to an array
 * @param       int $variable_price_id - the variable price ID to check for
 * @return      boolean - true if has purchased, false otherwise
 */
function edd_has_user_purchased($user_id, $downloads, $variable_price_id = null)
{
    if (!is_user_logged_in()) {
        return false;
    }
    // At some point this should support email checking
    $users_purchases = edd_get_users_purchases($user_id);
    $return = false;
    if (!is_array($downloads)) {
        $downloads = array($downloads);
    }
    if ($users_purchases) {
        foreach ($users_purchases as $purchase) {
            $purchased_files = edd_get_payment_meta_downloads($purchase->ID);
            if (is_array($purchased_files)) {
                foreach ($purchased_files as $download) {
                    if (in_array($download['id'], $downloads)) {
                        $variable_prices = edd_has_variable_prices($download['id']);
                        if ($variable_prices && !is_null($variable_price_id) && $variable_price_id !== false) {
                            if (isset($download['options']['price_id']) && $variable_price_id == $download['options']['price_id']) {
                                return true;
                            } else {
                                $return = false;
                            }
                        } else {
                            $return = true;
                        }
                    }
                }
            }
        }
    }
    return $return;
}
Exemplo n.º 3
0
function ao_edd_set_customer_role($payment_id)
{
    $email = edd_get_payment_user_email($payment_id);
    $downloads = edd_get_payment_meta_downloads($payment_id);
    $user_id = edd_get_payment_user_id($payment_id);
    if ($user_id) {
        $user = new WP_User($user_id);
        // Add role
        $user->add_role('buyer');
    }
}
Exemplo n.º 4
0
/**
 * Displays a Manage Licenses link in purchase history
 *
 * @since 2.7
 */
function edd_sl_site_management_links($payment_id, $purchase_data)
{
    $licensing = edd_software_licensing();
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if ($downloads) {
        $manage_licenses_url = esc_url(add_query_arg(array('action' => 'manage_licenses', 'payment_id' => $payment_id)));
        echo '<td class="edd_license_key">';
        if (edd_is_payment_complete($payment_id)) {
            echo '<a href="' . esc_url($manage_licenses_url) . '">' . __('View Licenses', 'edd_sl') . '</a>';
        } else {
            echo '-';
        }
        echo '</td>';
    }
}
/**
 * Resend the Email Purchase Receipt. (This can be done from the Payment History page)
 *
 * @since 1.0
 * @param array $data Payment Data
 * @return void
 */
function edd_resend_purchase_receipt($data)
{
    $purchase_id = $data['purchase_id'];
    edd_email_purchase_receipt($purchase_id, false);
    // Grab all downloads of the purchase and update their file download limits, if needed
    // This allows admins to resend purchase receipts to grant additional file downloads
    $downloads = edd_get_payment_meta_downloads($purchase_id);
    if (is_array($downloads)) {
        foreach ($downloads as $download) {
            $limit = edd_get_file_download_limit($download['id']);
            if (!empty($limit)) {
                edd_set_file_download_limit_override($download['id'], $purchase_id);
            }
        }
    }
    wp_redirect(add_query_arg(array('edd-message' => 'email_sent', 'edd-action' => false, 'purchase_id' => false)));
    exit;
}
/**
 * Resends a purchase receipt
 */
function resend_purchase_receipt()
{
    authorize_request();
    $payment_id = absint($_GET['payment_id']);
    edd_email_purchase_receipt($payment_id, false);
    // Grab all downloads of the purchase and update their file download limits, if needed
    // This allows admins to resend purchase receipts to grant additional file downloads
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if (is_array($downloads)) {
        foreach ($downloads as $download) {
            $limit = edd_get_file_download_limit($download['id']);
            if (!empty($limit)) {
                edd_set_file_download_limit_override($download['id'], $payment_id);
            }
        }
    }
    die('<script>window.close();</script>');
}
Exemplo n.º 7
0
/**
 * Get posts/pages restricted to the purchased files
 *
 * @since       1.3.0
 * @param       int $payment_id The ID of this payment
 * @return      array $meta The list of accessible files
 */
function edd_cr_get_restricted_pages($payment_id = 0)
{
    if (empty($payment_id)) {
        return false;
    }
    $posts = array();
    $post_ids = array();
    $files = edd_get_payment_meta_downloads($payment_id);
    $ids = array_unique(wp_list_pluck($files, 'id'));
    foreach ($ids as $download_id) {
        $meta = get_post_meta($download_id, '_edd_cr_protected_post');
        if ($meta) {
            $post_ids = array_merge($post_ids, $meta);
        }
    }
    $post_ids = array_unique(array_map('absint', $post_ids));
    if (!empty($post_ids)) {
        $args = array('post_type' => 'any', 'nopaging' => true, 'post__in' => $post_ids);
        $query = new WP_Query($args);
        $posts = $query->posts;
    }
    return $posts;
}
Exemplo n.º 8
0
/**
 * Get user purchase count for download
 *
 * @since       1.0.1
 * @param       int $user_id the ID of the user to check
 * @param       int $download_id the download ID to check
 * @param       int $variable_price_id the variable price ID to check
 * @return      int $count the number of times the product has been purchased
 */
function edd_pl_get_user_purchase_count($user_id, $download_id, $variable_price_id = null)
{
    if (!is_user_logged_in()) {
        return 0;
    }
    $users_purchases = edd_get_users_purchases($user_id, 999);
    $count = 0;
    $download_id = array($download_id);
    if ($users_purchases) {
        foreach ($users_purchases as $purchase) {
            $purchased_files = edd_get_payment_meta_downloads($purchase->ID);
            if (is_array($purchased_files)) {
                foreach ($purchased_files as $download) {
                    if (isset($download['id']) && in_array($download['id'], $download_id)) {
                        $count++;
                    }
                }
            }
        }
    }
    return $count;
}
/**
 * Forum Sidebar
 *
 * @since        1.0.0
 * @return        void
 */
function wi_bbp_sidebar()
{
    global $post;
    $user_id = get_the_author_meta('ID');
    $user_data = get_userdata($user_id);
    ?>
	<div class="box">

		<?php 
    do_action('wi_bbp_sidebar');
    ?>

		<h3><?php 
    echo get_the_author_meta('first_name') . '  ' . get_the_author_meta('last_name');
    ?>
</h3>

		<p class="bbp-user-forum-role"><?php 
    printf('Forum Role: %s', bbp_get_user_display_role($user_id));
    ?>
</p>

		<p class="bbp-user-topic-count"><?php 
    printf('Topics Started: %s', bbp_get_user_topic_count_raw($user_id));
    ?>
</p>

		<p class="bbp-user-reply-count"><?php 
    printf('Replies Created: %s', bbp_get_user_reply_count_raw($user_id));
    ?>
</p>


		<div class="wi_users_purchases">
			<h3><?php 
    _e('User\'s Purchases:', 'wi_bbp');
    ?>
</h3>
			<?php 
    $purchases = edd_get_users_purchases($user_data->user_email, 100, false, 'any');
    if ($purchases) {
        echo '<ul>';
        foreach ($purchases as $purchase) {
            echo '<li>';
            echo '<strong><a href="' . admin_url('edit.php?post_type=download&page=give-payment-history&view=view-order-details&id=' . $purchase->ID) . '">#' . $purchase->ID . ' - ' . edd_get_payment_status($purchase, true) . '</a></strong><br/>';
            $downloads = edd_get_payment_meta_downloads($purchase->ID);
            foreach ($downloads as $download) {
                echo get_the_title($download['id']) . ' - ' . date('F j, Y', strtotime($purchase->post_date)) . '<br/>';
            }
            //Check license key
            if (function_exists('edd_software_licensing')) {
                $licenses = edd_software_licensing()->get_licenses_of_purchase($purchase->ID);
                if ($licenses) {
                    echo '<strong>Licenses:</strong><br/>';
                    foreach ($licenses as $license) {
                        $key = edd_software_licensing()->get_license_key($license->ID);
                        echo '<a href="' . admin_url('edit.php?post_type=download&page=give-licenses&s=' . $key) . '">' . $key . '</a>';
                        echo ' - ' . edd_software_licensing()->get_license_status($license->ID);
                        echo '<br/>';
                    }
                }
                echo '<hr/>';
            }
            echo '</li>';
        }
        echo '</ul>';
    } else {
        echo '<p>This user has never purchased anything.</p>';
    }
    ?>
		</div>
	</div>
	<?php 
}
/**
 * Track number or purchases by a registered user.
 *
 * @since Astoundify Crowdfunding 1.3
 *
 * @param int $payment the ID number of the payment
 * @param string $new_status
 * @param string $old_status
 * @return void
 */
function atcf_gateway_pap_log_payments_per_user($payment_id, $new_status, $old_status)
{
    global $edd_options;
    if (!atcf_is_gatweay_active('paypal_adaptive_payments')) {
        return;
    }
    if (!isset($edd_options['epap_payments_per_user'])) {
        return;
    }
    if ($old_status != 'pending') {
        return;
    }
    if (in_array($new_status, array('refunded', 'failed', 'revoked'))) {
        return;
    }
    $gateway = get_post_meta($payment_id, '_edd_payment_gateway', true);
    if ('paypal_adaptive_payments' != $gateway) {
        return;
    }
    $user_id = get_post_meta($payment_id, '_edd_payment_user_id', true);
    $user = get_userdata($user_id);
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if (!is_array($downloads)) {
        return;
    }
    $contributed_to = $user->get('atcf_contributed_to');
    foreach ($downloads as $download) {
        if (isset($contributed_to[$download['id']])) {
            $contributed_to[$download['id']] = $contributed_to[$download['id']] + 1;
        } else {
            $contributed_to[$download['id']] = 1;
        }
    }
    update_user_meta($user->ID, 'atcf_contributed_to', $contributed_to);
}
 /**
  * Process Get Downloads API Request to retrieve download logs
  *
  * @access public
  * @since 2.5
  * @author Daniel J Griffiths
  *
  * @param  int $customer_id The customer ID you wish to retrieve download logs for
  * @return array            Multidimensional array of the download logs
  */
 public function get_download_logs($customer_id = 0)
 {
     global $edd_logs;
     $downloads = array();
     $errors = array();
     $paged = $this->get_paged();
     $per_page = $this->per_page();
     $offset = $per_page * ($paged - 1);
     $meta_query = array();
     if (!empty($customer_id)) {
         $customer = new EDD_Customer($customer_id);
         $invalid_customer = false;
         if ($customer->id > 0) {
             $meta_query['relation'] = 'OR';
             if ($customer->id > 0) {
                 // Based on customer->user_id
                 $meta_query[] = array('key' => '_edd_log_user_id', 'value' => $customer->user_id);
             }
             // Based on customer->email
             $meta_query[] = array('key' => '_edd_log_user_info', 'value' => $customer->email, 'compare' => 'LIKE');
         } else {
             $invalid_customer = true;
         }
     }
     $query = array('log_type' => 'file_download', 'paged' => $paged, 'meta_query' => $meta_query, 'posts_per_page' => $per_page, 'update_post_meta_cache' => false, 'update_post_term_cache' => false);
     $logs = array();
     if (!$invalid_customer) {
         $logs = $edd_logs->get_connected_logs($query);
     }
     if (empty($logs)) {
         $error['error'] = __('No download logs found!', 'easy-digital-downloads');
         return $error;
     }
     foreach ($logs as $log) {
         $item = array();
         $log_meta = get_post_custom($log->ID);
         $user_info = isset($log_meta['_edd_log_user_info']) ? maybe_unserialize($log_meta['_edd_log_user_info'][0]) : array();
         $payment_id = isset($log_meta['_edd_log_payment_id']) ? $log_meta['_edd_log_payment_id'][0] : false;
         $payment_customer_id = edd_get_payment_customer_id($payment_id);
         $payment_customer = new EDD_Customer($payment_customer_id);
         $user_id = $payment_customer->user_id > 0 ? $payment_customer->user_id : false;
         $ip = $log_meta['_edd_log_ip'][0];
         $files = edd_get_payment_meta_downloads($payment_id);
         $files = edd_get_download_files($files[0]['id']);
         $file_id = (int) $log_meta['_edd_log_file_id'][0];
         $file_id = $file_id !== false ? $file_id : 0;
         $file_name = isset($files[$file_id]['name']) ? $files[$file_id]['name'] : null;
         $item = array('ID' => $log->ID, 'user_id' => $user_id, 'product_id' => $log->post_parent, 'product_name' => get_the_title($log->post_parent), 'customer_id' => $payment_customer_id, 'payment_id' => $payment_id, 'file' => $file_name, 'ip' => $ip, 'date' => $log->post_date);
         $item = apply_filters('edd_api_download_log_item', $item, $log, $log_meta);
         $downloads['download_logs'][] = $item;
     }
     return $downloads;
 }
    /**
     * Front-end display of widget.
     *
     * @see WP_Widget::widget()
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
    public function widget($args, $instance)
    {
        //No EDD? Bail
        if (!class_exists('Easy_Digital_Downloads')) {
            return false;
        }
        //Not EDD admin? Bail
        if (!current_user_can('view_shop_sensitive_data')) {
            return false;
        }
        //Handle before_widget args
        echo $args['before_widget'];
        if (!empty($instance['title'])) {
            echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
        }
        $user_id = get_the_author_meta('ID');
        $user_data = get_userdata($user_id);
        ?>
		<div class="box">

			<?php 
        do_action('wi_bbp_sidebar');
        ?>

			<h3><?php 
        echo get_the_author_meta('first_name') . '  ' . get_the_author_meta('last_name');
        ?>
</h3>

			<p class="bbp-user-forum-role"><?php 
        printf('Forum Role: %s', bbp_get_user_display_role($user_id));
        ?>
</p>

			<p class="bbp-user-topic-count"><?php 
        printf('Topics Started: %s', bbp_get_user_topic_count_raw($user_id));
        ?>
</p>

			<p class="bbp-user-reply-count"><?php 
        printf('Replies Created: %s', bbp_get_user_reply_count_raw($user_id));
        ?>
</p>


			<div class="wi_users_purchases">
				<h3><?php 
        _e('User\'s Purchases:', 'wi_bbp');
        ?>
</h3>
				<?php 
        $purchases = edd_get_users_purchases($user_data->user_email, 100, false, 'any');
        if ($purchases) {
            echo '<ul>';
            foreach ($purchases as $purchase) {
                echo '<li>';
                echo '<strong><a href="' . admin_url('edit.php?post_type=download&page=give-payment-history&view=view-order-details&id=' . $purchase->ID) . '">#' . $purchase->ID . ' - ' . edd_get_payment_status($purchase, true) . '</a></strong><br/>';
                $downloads = edd_get_payment_meta_downloads($purchase->ID);
                foreach ($downloads as $download) {
                    echo get_the_title($download['id']) . ' - ' . date('F j, Y', strtotime($purchase->post_date)) . '<br/>';
                }
                //Check license key
                if (function_exists('edd_software_licensing')) {
                    $licenses = edd_software_licensing()->get_licenses_of_purchase($purchase->ID);
                    if ($licenses) {
                        echo '<strong>' . __('Licenses:', 'edd') . '</strong><br/>';
                        foreach ($licenses as $license) {
                            $key = edd_software_licensing()->get_license_key($license->ID);
                            $download_id = edd_software_licensing()->get_download_by_license($key);
                            $title = get_the_title($download_id);
                            //output license URL
                            echo $title . ' - <a href="' . admin_url('edit.php?post_type=download&page=give-licenses&s=' . $key) . '">' . $key . '</a>';
                            echo ' - ' . edd_software_licensing()->get_license_status($license->ID);
                            echo '<br/>';
                        }
                    }
                    echo '<hr/>';
                }
                echo '</li>';
            }
            echo '</ul>';
        } else {
            echo '<p>' . __('This user has never purchased anything.', 'wi_bbp') . '</p>';
        }
        ?>
			</div>
		</div>
		<?php 
        //After widget args
        echo $args['after_widget'];
        return false;
    }
Exemplo n.º 13
0
/**	
 * Has User Purchased	
 *	
 * Checks to see if a user has purchased a download.	
 *	
 * @access      public	
 * @since       1.0	
 * @param       int $user_id - the ID of the user to check	
 * @param       array $downloads - Array of IDs to check if purchased. If an int is passed, it will be converted to an array	
 * @param       int $variable_price_id - the variable price ID to check for	
 * @return      boolean - true if has purchased and license is active, false otherwise	
 */
function dwqa_siteinfo_has_user_purchased($user_id, $downloads, $variable_price_id = null, $verify_purchase = false)
{
    $users_purchases = edd_get_users_purchases($user_id);
    $return = false;
    if (!is_array($downloads) && $downloads !== NULL) {
        $downloads = array($downloads);
    }
    $now = strtotime(date('Y-m-d H:i:s'));
    if ($users_purchases) {
        foreach ($users_purchases as $purchase) {
            $purchased_files = edd_get_payment_meta_downloads($purchase->ID);
            $licenses = edd_software_licensing()->get_licenses_of_purchase($purchase->ID);
            $licenses_products = array();
            if (is_array($licenses)) {
                foreach ($licenses as $license) {
                    $download_id = get_post_meta($license->ID, '_edd_sl_download_id', true);
                    $status = get_post_meta($license->ID, '_edd_sl_status', true);
                    $expire = get_post_meta($license->ID, '_edd_sl_expiration', true);
                    $licenses_products[$download_id] = array();
                    $licenses_products[$download_id]['status'] = $status;
                    $licenses_products[$download_id]['expire'] = $expire;
                }
            } else {
                return false;
            }
            if (is_array($purchased_files)) {
                foreach ($purchased_files as $download) {
                    if ($downloads === NULL || in_array($download['id'], $downloads)) {
                        //check to see if the license is active
                        //echo $licenses_products[$download['id']]['expire'] . ">" . $now . "==========";
                        if (isset($licenses_products[$download['id']]['expire']) && $now > $licenses_products[$download['id']]['expire']) {
                            // || $licenses_products[$download['id']]['status'] == 'inactive'
                            if ($verify_purchase) {
                                return "purchased_expired";
                            } else {
                                return false;
                            }
                        }
                        $variable_prices = edd_has_variable_prices($download['id']);
                        if ($variable_prices && !is_null($variable_price_id) && $variable_price_id !== false) {
                            if (isset($download['options']['price_id']) && $variable_price_id == $download['options']['price_id']) {
                                return true;
                            } else {
                                return false;
                            }
                        } else {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Exemplo n.º 14
0
/**
 * Email Template Tags
 *
 * @param string $message
 * @param array  $payment_data
 * @param int    $payment_id
 *
 * @access private
 * @since 1.0
 * @return string
 */
function edd_email_template_tags($message, $payment_data, $payment_id)
{
    $user_info = maybe_unserialize($payment_data['user_info']);
    $fullname = '';
    if (isset($user_info['id']) && $user_info['id'] > 0 && isset($user_info['first_name'])) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_info['first_name'];
        $fullname = $user_info['first_name'] . ' ' . $user_info['last_name'];
        $username = $user_data->user_login;
    } elseif (isset($user_info['first_name'])) {
        $name = $user_info['first_name'];
        $fullname = $user_info['first_name'] . ' ' . $user_info['last_name'];
        $username = $user_info['first_name'];
    } else {
        $name = $user_info['email'];
        $username = $user_info['email'];
    }
    $file_urls = '';
    $download_list = '<ul>';
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if ($downloads) {
        $show_names = apply_filters('edd_email_show_names', true);
        foreach ($downloads as $download) {
            $id = isset($payment_data['cart_details']) ? $download['id'] : $download;
            if ($show_names) {
                $download_list .= '<li>' . get_the_title($id) . '<br/>';
                $download_list .= '<ul>';
            }
            $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
            $files = edd_get_download_files($id, $price_id);
            if ($files) {
                foreach ($files as $filekey => $file) {
                    $download_list .= '<li>';
                    $file_url = edd_get_download_file_url($payment_data['key'], $payment_data['email'], $filekey, $id);
                    $download_list .= '<a href="' . esc_url($file_url) . '">' . $file['name'] . '</a>';
                    $download_list .= '</li>';
                    $file_urls .= esc_html($file_url) . '<br/>';
                }
            }
            if ($show_names) {
                $download_list .= '</ul>';
            }
            if ('' != edd_get_product_notes($id)) {
                $download_list .= ' &mdash; <small>' . edd_get_product_notes($id) . '</small>';
            }
            if ($show_names) {
                $download_list .= '</li>';
            }
        }
    }
    $download_list .= '</ul>';
    $subtotal = isset($payment_data['subtotal']) ? $payment_data['subtotal'] : $payment_data['amount'];
    $subtotal = edd_currency_filter(edd_format_amount($subtotal));
    $tax = isset($payment_data['tax']) ? $payment_data['tax'] : 0;
    $tax = edd_currency_filter(edd_format_amount($tax));
    $price = edd_currency_filter(edd_format_amount($payment_data['amount']));
    $gateway = edd_get_gateway_checkout_label(get_post_meta($payment_id, '_edd_payment_gateway', true));
    $receipt_id = $payment_data['key'];
    $message = str_replace('{name}', $name, $message);
    $message = str_replace('{fullname}', $fullname, $message);
    $message = str_replace('{username}', $username, $message);
    $message = str_replace('{download_list}', $download_list, $message);
    $message = str_replace('{file_urls}', $file_urls, $message);
    $message = str_replace('{date}', date_i18n(get_option('date_format'), strtotime($payment_data['date'])), $message);
    $message = str_replace('{sitename}', get_bloginfo('name'), $message);
    $message = str_replace('{subtotal}', $subtotal, $message);
    $message = str_replace('{tax}', $tax, $message);
    $message = str_replace('{price}', $price, $message);
    $message = str_replace('{payment_method}', $gateway, $message);
    $message = str_replace('{receipt_id}', $receipt_id, $message);
    $message = apply_filters('edd_email_template_tags', $message, $payment_data, $payment_id);
    return $message;
}
 /**
  * Calculate a new expiration date
  *
  * @since  1.0
  * @param  $_customer_or_user_id      INT depending on EDD Version, this is a customer or User ID
  * @param  $payment_id   INT The original payment ID
  * @return int
  */
 public static function calc_user_expiration($_customer_or_user_id = 0, $payment_id = 0)
 {
     $edd_version = get_option('edd_version');
     if (version_compare($edd_version, '2.3', '<')) {
         $user_id = $_customer_or_user_id;
     } else {
         $user_id = self::get_user_id_from_customer_id($_customer_or_user_id);
     }
     // Retrieve the items purchased from the original payment
     $downloads = edd_get_payment_meta_downloads($payment_id);
     $download = $downloads[0];
     // We only care about the first (and only) item
     $period = $download['options']['recurring']['period'];
     $expiration = strtotime('+ 1 ' . $period . ' 23:59:59');
     return apply_filters('edd_recurring_calc_expiration', $expiration, $user_id, $payment_id, $period);
 }
Exemplo n.º 16
0
 /**
  * Retrieves the referral description
  *
  * @access  public
  * @since   1.1
  */
 public function get_referral_description($payment_id = 0)
 {
     $description = array();
     $downloads = edd_get_payment_meta_downloads($payment_id);
     foreach ($downloads as $key => $item) {
         if (get_post_meta($item['id'], '_affwp_' . $this->context . '_referrals_disabled', true)) {
             continue;
             // Referrals are disabled on this product
         }
         $description[] = get_the_title($item['id']);
     }
     return implode(', ', $description);
 }
 /**
  * Filter attachments
  *
  * @since 1.0
  */
 public function attachments($attachments, $payment_id, $payment_data)
 {
     global $edd_options;
     // get array of download IDs
     $downloads = edd_get_payment_meta_downloads($payment_id);
     if ($downloads) {
         $files = array();
         $attachments = array();
         foreach ($downloads as $download) {
             // if per download email attachments is enabled, only get downloads with checkbox enabled
             if (isset($edd_options['edd_dea_per_download_attachments'])) {
                 if (!get_post_meta($download['id'], '_edd_dea_enabled', true)) {
                     continue;
                 }
             }
             // is bundled product
             if (edd_is_bundled_product($download['id'])) {
                 $bundled_ids = get_post_meta($download['id'], '_edd_bundled_products', true);
                 if ($bundled_ids) {
                     foreach ($bundled_ids as $id) {
                         $files[] = get_post_meta($id, 'edd_download_files', true);
                     }
                 }
             } else {
                 $price_id = !empty($download['options']['price_id']) ? $download['options']['price_id'] : null;
                 $files[] = edd_get_download_files($download['id'], $price_id);
             }
         }
         if ($files) {
             $file_urls = array();
             foreach ($files as $key => $file) {
                 // get the file URLs
                 foreach ($file as $value) {
                     $file_urls[] = $value['file'];
                 }
             }
             if ($file_urls) {
                 foreach ($file_urls as $file_url) {
                     $attachments[] = get_attached_file($this->get_file_id($file_url));
                 }
             }
         }
     }
     return $attachments;
 }
Exemplo n.º 18
0
/**
 * Get a customer's purchases
 * @param  [type] $user_id           [description]
 * @param  [type] $download_id       [description]
 * @param  [type] $variable_price_id [description]
 * @since  1.0
 * @return [type]                    [description]
 */
function edd_wl_get_purchases($user_id, $download_id, $variable_price_id = null)
{
    $users_purchases = edd_get_users_purchases($user_id);
    $return = false;
    if ($users_purchases) {
        foreach ($users_purchases as $purchase) {
            $purchased_files = edd_get_payment_meta_downloads($purchase->ID);
            if (is_array($purchased_files)) {
                foreach ($purchased_files as $download) {
                    $variable_prices = edd_has_variable_prices($download['id']);
                    if ($variable_prices && !is_null($variable_price_id) && $variable_price_id !== false) {
                        if (isset($download['options']['price_id']) && $variable_price_id == $download['options']['price_id']) {
                            $return = true;
                            break 2;
                        } else {
                            $return = false;
                        }
                    } elseif ($download_id == $download['id']) {
                        $return = true;
                    }
                }
            }
        }
    }
    return $return;
}
/**
 * Deletes a Purchase
 *
 * @since 1.0
 * @global $edd_logs
 *
 * @uses EDD_Logging::delete_logs()
 *
 * @param int $payment_id Payment ID (default: 0)
 * @param bool $update_customer If we should update the customer stats (default:true)
 * @param bool $delete_download_logs If we should remove all file download logs associated with the payment (default:false)
 *
 * @return void
 */
function edd_delete_purchase($payment_id = 0, $update_customer = true, $delete_download_logs = false)
{
    global $edd_logs;
    $post = get_post($payment_id);
    if (!$post) {
        return;
    }
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if (is_array($downloads)) {
        // Update sale counts and earnings for all purchased products
        foreach ($downloads as $download) {
            edd_undo_purchase($download['id'], $payment_id);
        }
    }
    $amount = edd_get_payment_amount($payment_id);
    $status = $post->post_status;
    $customer_id = edd_get_payment_customer_id($payment_id);
    $customer = new EDD_Customer($customer_id);
    if ($status == 'revoked' || $status == 'publish') {
        // Only decrease earnings if they haven't already been decreased (or were never increased for this payment)
        edd_decrease_total_earnings($amount);
        // Clear the This Month earnings (this_monththis_month is NOT a typo)
        delete_transient(md5('edd_earnings_this_monththis_month'));
        if ($customer->id && $update_customer) {
            // Decrement the stats for the customer
            $customer->decrease_purchase_count();
            $customer->decrease_value($amount);
        }
    }
    do_action('edd_payment_delete', $payment_id);
    if ($customer->id && $update_customer) {
        // Remove the payment ID from the customer
        $customer->remove_payment($payment_id);
    }
    // Remove the payment
    wp_delete_post($payment_id, true);
    // Remove related sale log entries
    $edd_logs->delete_logs(null, 'sale', array(array('key' => '_edd_log_payment_id', 'value' => $payment_id)));
    if ($delete_download_logs) {
        $edd_logs->delete_logs(null, 'file_download', array(array('key' => '_edd_log_payment_id', 'value' => $payment_id)));
    }
    do_action('edd_payment_deleted', $payment_id);
}
Exemplo n.º 20
0
 /**
  * Process the request
  *  - Find purchase data
  *  - Generate response*
  * @link http://developer.helpscout.net/custom-apps/style-guide/ HelpScout Custom Apps Style Guide
  * @return string
  */
 private function build_response_html()
 {
     if (count($this->customer_payments) === 0) {
         // No purchase data was found
         return sprintf('<p>No payments founds for %s.</p>', '<strong>' . join('</strong> or <strong>', $this->customer_emails) . '</strong>');
     }
     // build array of purchases
     $orders = array();
     foreach ($this->customer_payments as $payment) {
         $order = array();
         $order['payment_id'] = $payment->ID;
         $order['date'] = $payment->post_date;
         $order['amount'] = edd_get_payment_amount($payment->ID);
         $order['status'] = $payment->post_status;
         $order['payment_method'] = $this->get_payment_method($payment->ID);
         $order['downloads'] = array();
         $order['resend_receipt_link'] = '';
         $order['is_renewal'] = false;
         $order['is_completed'] = $payment->post_status === 'publish';
         // do stuff for completed orders
         if ($payment->post_status === 'publish') {
             $args = array('payment_id' => (string) $order['payment_id']);
             $request = new Request($args);
             $order['resend_receipt_link'] = $request->get_signed_url('resend_purchase_receipt');
         }
         // find purchased Downloads.
         $order['downloads'] = (array) edd_get_payment_meta_downloads($payment->ID);
         // for each download, find license + sites
         if (function_exists('edd_software_licensing')) {
             /**
              * @var EDD_Software_Licensing
              */
             $licensing = edd_software_licensing();
             // was this order a renewal?
             $order['is_renewal'] = (string) get_post_meta($payment->ID, '_edd_sl_is_renewal', true) !== '';
             if ($order['is_completed']) {
                 foreach ($order['downloads'] as $key => $download) {
                     // only proceed if this download has EDD Software Licensing enabled
                     if ('' === (string) get_post_meta($download['id'], '_edd_sl_enabled', true)) {
                         continue;
                     }
                     // find license that was given out for this download purchase
                     $license = $licensing->get_license_by_purchase($payment->ID, $download['id']);
                     if (is_object($license)) {
                         $key = (string) get_post_meta($license->ID, '_edd_sl_key', true);
                         // add support for "lifetime" licenses
                         if (method_exists($licensing, 'is_lifetime_license') && $licensing->is_lifetime_license($license->ID)) {
                             $is_expired = false;
                         } else {
                             $expires = (string) get_post_meta($license->ID, '_edd_sl_expiration', true);
                             $is_expired = $expires < time();
                         }
                         $order['downloads'][$key]['license'] = array('limit' => 0, 'key' => $key, 'is_expired' => $is_expired, 'sites' => array());
                         // look-up active sites if license is not expired
                         if (!$is_expired) {
                             // get license limit
                             $order['downloads'][$key]['license']['limit'] = $licensing->get_license_limit($download['id'], $license->ID);
                             $sites = (array) $licensing->get_sites($license->ID);
                             foreach ($sites as $site) {
                                 $args = array('license_id' => (string) $license->ID, 'site_url' => $site);
                                 // make sure site url is prefixed with "http://"
                                 $site_url = strpos($site, '://') !== false ? $site : 'http://' . $site;
                                 $request = new Request($args);
                                 $order['downloads'][$key]['license']['sites'][] = array('url' => $site_url, 'deactivate_link' => $request->get_signed_url('deactivate_site_license'));
                             }
                         }
                         //endif not expired
                     }
                     // endif license found
                 }
                 // end foreach downloads
             }
             // endif order completed
         }
         $orders[] = $order;
     }
     // build HTML output
     $html = '';
     foreach ($orders as $order) {
         $html .= str_replace('\\t', '', $this->order_row($order));
     }
     return $html;
 }
/**
 * EDD Forum Sidebar
 *
 * @since		1.0.0
 * @return		void
 */
function edd_bbp_sidebar()
{
    global $post;
    $user_id = get_the_author_meta('ID');
    $user_data = get_userdata($user_id);
    ?>
	<div class="box">

		<?php 
    do_action('edd_bbp_sidebar');
    ?>

		<h3><?php 
    echo get_the_author_meta('first_name') . '  ' . get_the_author_meta('last_name');
    ?>
</h3>
		<p class="bbp-user-forum-role"><?php 
    printf('Forum Role: %s', bbp_get_user_display_role($user_id));
    ?>
</p>
		<p class="bbp-user-topic-count"><?php 
    printf('Topics Started: %s', bbp_get_user_topic_count_raw($user_id));
    ?>
</p>
		<p class="bbp-user-reply-count"><?php 
    printf('Replies Created: %s', bbp_get_user_reply_count_raw($user_id));
    ?>
</p>

		<div class="rcp_support_status">
			<h4>Priority Support Access</h4>
			<?php 
    if (function_exists('rcp_is_active')) {
        if (rcp_is_active($user_id)) {
            ?>
				<p>Has <strong>Priority Support</strong> access.</p>
			<?php 
        } elseif (rcp_is_expired($user_id)) {
            ?>
				<p><strong>Priority Support</strong> access has <span style="color:red;">expired</span>.</p>
			<?php 
        } else {
            ?>
				<p>Has no priority support accesss</p>
			<?php 
        }
    }
    ?>
		</div><!-- /.rcp_support_status -->

		<div class="edd_users_purchases">
			<h4>User's Purchases:</h4>
			<?php 
    $purchases = edd_get_users_purchases($user_data->user_email, 100, false, 'any');
    if ($purchases) {
        echo '<ul>';
        foreach ($purchases as $purchase) {
            echo '<li>';
            echo '<strong><a href="' . admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $purchase->ID) . '">#' . $purchase->ID . ' - ' . edd_get_payment_status($purchase, true) . '</a></strong><br/>';
            $downloads = edd_get_payment_meta_downloads($purchase->ID);
            foreach ($downloads as $download) {
                echo get_the_title($download['id']) . ' - ' . date('F j, Y', strtotime($purchase->post_date)) . '<br/>';
            }
            if (function_exists('edd_software_licensing')) {
                $licenses = edd_software_licensing()->get_licenses_of_purchase($purchase->ID);
                if ($licenses) {
                    echo '<strong>Licenses:</strong><br/>';
                    foreach ($licenses as $license) {
                        $key = edd_software_licensing()->get_license_key($license->ID);
                        echo '<a href="' . admin_url('edit.php?post_type=download&page=edd-licenses&s=' . $key) . '">' . $key . '</a>';
                        echo ' - ' . edd_software_licensing()->get_license_status($license->ID);
                        echo '<br/>';
                    }
                }
                echo '<hr/>';
            }
            echo '</li>';
        }
        echo '</ul>';
    } else {
        echo '<p>This user has never purchased anything.</p>';
    }
    ?>
		</div>
	</div>
	<?php 
}
/**
 * Get Users Purchased Products
 *
 * Returns a list of unique products purchased by a specific user
 *
 * @since  2.0
 *
 * @param int    $user User ID or email address
 * @param string $status
 *
 * @return bool|object List of unique products purchased by user
 */
function edd_get_users_purchased_products($user = 0, $status = 'complete')
{
    if (empty($user)) {
        $user = get_current_user_id();
    }
    if (empty($user)) {
        return false;
    }
    $by_user_id = is_numeric($user) ? true : false;
    $customer = new EDD_Customer($user, $by_user_id);
    if (empty($customer->payment_ids)) {
        return false;
    }
    // Get all the items purchased
    $payment_ids = array_reverse(explode(',', $customer->payment_ids));
    $limit_payments = apply_filters('edd_users_purchased_products_payments', 50);
    if (!empty($limit_payments)) {
        $payment_ids = array_slice($payment_ids, 0, $limit_payments);
    }
    $purchase_data = array();
    foreach ($payment_ids as $payment_id) {
        $purchase_data[] = edd_get_payment_meta_downloads($payment_id);
    }
    if (empty($purchase_data)) {
        return false;
    }
    // Grab only the post ids of the products purchased on this order
    $purchase_product_ids = array();
    foreach ($purchase_data as $purchase_meta) {
        $purchase_product_ids[] = @wp_list_pluck($purchase_meta, 'id');
    }
    // Ensure that grabbed products actually HAVE downloads
    $purchase_product_ids = array_filter($purchase_product_ids);
    if (empty($purchase_product_ids)) {
        return false;
    }
    // Merge all orders into a single array of all items purchased
    $purchased_products = array();
    foreach ($purchase_product_ids as $product) {
        $purchased_products = array_merge($product, $purchased_products);
    }
    // Only include each product purchased once
    $product_ids = array_unique($purchased_products);
    // Make sure we still have some products and a first item
    if (empty($product_ids) || !isset($product_ids[0])) {
        return false;
    }
    $post_type = get_post_type($product_ids[0]);
    $args = apply_filters('edd_get_users_purchased_products_args', array('include' => $product_ids, 'post_type' => $post_type, 'posts_per_page' => -1));
    return apply_filters('edd_users_purchased_products_list', get_posts($args));
}
					<th class="edd_download_download_files"><?php 
        _e('Files', 'edd');
        ?>
</th>
				<?php 
    }
    ?>
				<?php 
    do_action('edd_download_history_header_end');
    ?>
			</tr>
		</thead>
		<?php 
    foreach ($purchases as $post) {
        setup_postdata($post);
        $downloads = edd_get_payment_meta_downloads($post->ID);
        $purchase_data = edd_get_payment_meta($post->ID);
        if ($downloads) {
            foreach ($downloads as $download) {
                echo '<tr class="edd_download_history_row">';
                $id = isset($purchase_data['cart_details']) ? $download['id'] : $download;
                $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
                $download_files = edd_get_download_files($id, $price_id);
                do_action('edd_download_history_row_start', $post->ID, $id);
                echo '<td class="edd_download_download_name">' . get_the_title($id) . '</td>';
                if (!edd_no_redownload()) {
                    echo '<td class="edd_download_download_files">';
                    if ($download_files) {
                        foreach ($download_files as $filekey => $file) {
                            $download_url = edd_get_download_file_url($purchase_data['key'], $purchase_data['email'], $filekey, $id);
                            echo '<div class="edd_download_file"><a href="' . esc_url($download_url) . '" class="edd_download_file_link">' . esc_html($file['name']) . '</a></div>';
Exemplo n.º 24
0
/**
 * Get the actual pending email body content. Default text, can be filtered, and will
 * use all template tags that EDD supports.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 *
 * @param int $payment_id The ID of the payment
 * @param array $payment_data The relevant payment data
 * @return string $email_body The actual email body
 */
function atcf_get_email_body_content($payment_id = 0, $payment_data = array())
{
    global $edd_options;
    $downloads = edd_get_payment_meta_downloads($payment_id);
    $campaign = '';
    if ($downloads) {
        foreach ($downloads as $download) {
            $id = isset($payment_data['cart_details']) ? $download['id'] : $download;
            $campaign = get_the_title($id);
            continue;
        }
    }
    $default_email_body = __('Dear {name}', 'atcf') . "\n\n";
    $default_email_body .= sprintf(__('Thank you for your pledging to support %1$s. This email is just to let you know your pledge was processed without a hitch! You will only be charged your pledge amount if the %2$s receives 100% funding.', 'atcf'), $campaign, strtolower(edd_get_label_singular())) . "\n\n";
    $default_email_body .= "{sitename}";
    $email = $default_email_body;
    $email_body = edd_email_template_tags($email, $payment_data, $payment_id);
    return apply_filters('atcf_pending_purchase_receipt', $email_body, $payment_id, $payment_data);
}
Exemplo n.º 25
0
/**
 * Sends a notice to site admins about the pending sale
 *
 * @since  1.1
 * @return void
 */
function edd_cg_send_admin_notice($payment_id = 0)
{
    /* Send an email notification to the admin */
    $admin_email = edd_get_admin_notice_emails();
    $user_info = edd_get_payment_meta_user_info($payment_id);
    if (isset($user_info['id']) && $user_info['id'] > 0) {
        $user_data = get_userdata($user_info['id']);
        $name = $user_data->display_name;
    } elseif (isset($user_info['first_name']) && isset($user_info['last_name'])) {
        $name = $user_info['first_name'] . ' ' . $user_info['last_name'];
    } else {
        $name = $user_info['email'];
    }
    $amount = edd_currency_filter(edd_format_amount(edd_get_payment_amount($payment_id)));
    $admin_subject = apply_filters('eddcg_admin_purchase_notification_subject', __('New pending purchase', 'eddcg'), $payment_id);
    $admin_message = __('Hello', 'eddcg') . "\n\n" . sprintf(__('A %s purchase has been made', 'eddcg'), edd_get_label_plural()) . ".\n\n";
    $admin_message .= sprintf(__('%s sold:', 'eddcg'), edd_get_label_plural()) . "\n\n";
    $download_list = '';
    $downloads = edd_get_payment_meta_downloads($payment_id);
    if (is_array($downloads)) {
        foreach ($downloads as $download) {
            $title = get_the_title($download['id']);
            if (isset($download['options'])) {
                if (isset($download['options']['price_id'])) {
                    $title .= ' - ' . edd_get_price_option_name($download['id'], $download['options']['price_id'], $payment_id);
                }
            }
            $download_list .= html_entity_decode($title, ENT_COMPAT, 'UTF-8') . "\n";
        }
    }
    $order_url = admin_url('edit.php?post_type=download&page=edd-payment-history&edd-action=view-order-details&id=' . $payment_id);
    $admin_message .= $download_list . "\n";
    $admin_message .= __('Purchased by: ', 'eddcg') . " " . html_entity_decode($name, ENT_COMPAT, 'UTF-8') . "\n";
    $admin_message .= __('Amount: ', 'eddcg') . " " . html_entity_decode($amount, ENT_COMPAT, 'UTF-8') . "\n\n";
    $admin_message .= __('This is a pending purchase awaiting payment.', 'eddcg') . "\n\n";
    $admin_message .= sprintf(__('View Order Details: %s.', 'eddcg'), $order_url) . "\n\n";
    $admin_message = apply_filters('eddcg_admin_purchase_notification', $admin_message, $payment_id);
    $admin_headers = apply_filters('eddcg_admin_purchase_notification_headers', array(), $payment_id);
    $attachments = apply_filters('eddcg_admin_purchase_notification_attachments', array(), $payment_id);
    wp_mail($admin_email, $admin_subject, $admin_message, $admin_headers, $attachments);
}
Exemplo n.º 26
0
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     global $user_ID, $edd_options;
     if (is_user_logged_in()) {
         $purchases = edd_get_users_purchases($user_ID);
         if ($purchases) {
             echo $before_widget;
             if ($title) {
                 echo $before_title . $title . $after_title;
             }
             foreach ($purchases as $purchase) {
                 $purchase_data = edd_get_payment_meta($purchase->ID);
                 $downloads = edd_get_payment_meta_downloads($purchase->ID);
                 if ($downloads) {
                     foreach ($downloads as $download) {
                         $id = isset($purchase_data['cart_details']) ? $download['id'] : $download;
                         $price_id = isset($download['options']['price_id']) ? $download['options']['price_id'] : null;
                         $download_files = edd_get_download_files($id, $price_id);
                         echo '<div class="edd-purchased-widget-purchase edd-purchased-widget-purchase-' . $purchase->ID . '" id="edd-purchased-widget-purchase-' . $id . '">';
                         echo '<div class="edd-purchased-widget-purchase-name">' . get_the_title($id) . '</div>';
                         echo '<ul class="edd-purchased-widget-file-list">';
                         if (!edd_no_redownload()) {
                             if ($download_files) {
                                 foreach ($download_files as $filekey => $file) {
                                     $download_url = edd_get_download_file_url($purchase_data['key'], $purchase_data['email'], $filekey, $id, $price_id);
                                     echo '<li class="edd-purchased-widget-file"><a href="' . $download_url . '" class="edd-purchased-widget-file-link">' . $file['name'] . '</a></li>';
                                 }
                             } else {
                                 echo '<li class="edd-purchased-widget-no-file">' . __('No downloadable files found.', 'edd');
                             }
                         }
                         echo '</ul>';
                         echo '</div>';
                     }
                 }
             }
         }
         echo $after_widget;
     }
 }
Exemplo n.º 27
0
 /**
  * Adds a message to EDD's order email confirmation.
  * @param $order
  * @param $payment_id
  * @param $unused_payment_data
  */
 public function add_tickets_msg_to_email($email_body, $payment_id, $unused_payment_data)
 {
     //if( did_action( 'eddtickets-send-tickets-email' ) )
     //return $email_body;
     $order_items = edd_get_payment_meta_downloads($payment_id);
     // Bail if the order is empty
     if (empty($order_items)) {
         return $email_body;
     }
     $has_tickets = false;
     // Iterate over each product
     foreach ((array) $order_items as $item) {
         $product_id = isset($item['id']) ? $item['id'] : false;
         // Get the event this tickets is for
         $event_id = get_post_meta($product_id, self::$event_key, true);
         if (!empty($event_id)) {
             $has_tickets = true;
             break;
         }
     }
     if (!$has_tickets) {
         return $email_body;
     }
     $message = __("You'll receive your tickets in another email.", 'event-tickets-plus');
     return $email_body . '<br/>' . apply_filters('eddtickets_email_message', $message);
 }
/**
 * Fixes the edd_log meta for 2.2.6
 *
 * @since 2.2.6
 * @return void
 */
function edd_v226_upgrade_payments_price_logs_db()
{
    global $wpdb;
    if (!current_user_can('manage_shop_settings')) {
        wp_die(__('You do not have permission to do shop upgrades', 'edd'), __('Error', 'edd'), array('response' => 403));
    }
    ignore_user_abort(true);
    if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
        @set_time_limit(0);
    }
    $step = isset($_GET['step']) ? absint($_GET['step']) : 1;
    $number = 25;
    $offset = $step == 1 ? 0 : ($step - 1) * $number;
    if (1 === $step) {
        // Check if we have any variable price products on the first step
        $sql = "SELECT ID FROM {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} m ON p.ID = m.post_id WHERE m.meta_key = '_variable_pricing' AND m.meta_value = 1 LIMIT 1";
        $has_variable = $wpdb->get_col($sql);
        if (empty($has_variable)) {
            // We had no variable priced products, so go ahead and just complete
            update_option('edd_version', preg_replace('/[^0-9.].*/', '', EDD_VERSION));
            delete_option('edd_doing_upgrade');
            wp_redirect(admin_url());
            exit;
        }
    }
    $payment_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'edd_payment' ORDER BY post_date DESC LIMIT %d,%d;", $offset, $number));
    if (!empty($payment_ids)) {
        foreach ($payment_ids as $payment_id) {
            $payment_downloads = edd_get_payment_meta_downloads($payment_id);
            $variable_downloads = array();
            if (!is_array($payment_downloads)) {
                continue;
                // May not be an array due to some very old payments, move along
            }
            foreach ($payment_downloads as $download) {
                // Don't care if the download is a single price id
                if (!isset($download['options']['price_id'])) {
                    continue;
                }
                $variable_downloads[] = array('id' => $download['id'], 'price_id' => $download['options']['price_id']);
            }
            $variable_download_ids = array_unique(wp_list_pluck($variable_downloads, 'id'));
            $unique_download_ids = implode(',', $variable_download_ids);
            if (empty($unique_download_ids)) {
                continue;
                // If there were no downloads, just fees, move along
            }
            // Get all Log Ids where the post parent is in the set of download IDs we found in the cart meta
            $logs = $wpdb->get_results("SELECT m.post_id AS log_id, p.post_parent AS download_id FROM {$wpdb->postmeta} m LEFT JOIN {$wpdb->posts} p ON m.post_id = p.ID WHERE meta_key = '_edd_log_payment_id' AND meta_value = {$payment_id} AND p.post_parent IN ({$unique_download_ids})", ARRAY_A);
            $mapped_logs = array();
            // Go through each cart item
            foreach ($variable_downloads as $cart_item) {
                // Itterate through the logs we found attached to this payment
                foreach ($logs as $key => $log) {
                    // If this Log ID is associated with this download ID give it the price_id
                    if ((int) $log['download_id'] === (int) $cart_item['id']) {
                        $mapped_logs[$log['log_id']] = $cart_item['price_id'];
                        // Remove this Download/Log ID from the list, for multipurchase compatibility
                        unset($logs[$key]);
                        // These aren't the logs we're looking for. Move Along, Move Along.
                        break;
                    }
                }
            }
            if (!empty($mapped_logs)) {
                $update = "UPDATE {$wpdb->postmeta} SET meta_value = ";
                $case = "CASE post_id ";
                foreach ($mapped_logs as $post_id => $value) {
                    $case .= "WHEN {$post_id} THEN {$value} ";
                }
                $case .= "END ";
                $log_ids = implode(',', array_keys($mapped_logs));
                $where = "WHERE post_id IN ({$log_ids}) AND meta_key = '_edd_log_price_id'";
                $sql = $update . $case . $where;
                // Execute our query to update this payment
                $wpdb->query($sql);
            }
        }
        // More Payments found so upgrade them
        $step++;
        $redirect = add_query_arg(array('page' => 'edd-upgrades', 'edd-upgrade' => 'upgrade_payments_price_logs_db', 'step' => $step), admin_url('index.php'));
        wp_redirect($redirect);
        exit;
    } else {
        // No more payments found, finish up
        update_option('edd_version', preg_replace('/[^0-9.].*/', '', EDD_VERSION));
        delete_option('edd_doing_upgrade');
        wp_redirect(admin_url());
        exit;
    }
}
Exemplo n.º 29
0
    /**
     * Displays the recurring details on the [edd_receipt]
     *
     * @since  1.0
     * @return void
     */
    public function receipt($payment, $receipt_args)
    {
        $downloads = edd_get_payment_meta_downloads($payment->ID);
        $download = isset($downloads[0]) ? $downloads[0] : $downloads[1];
        if (!isset($download['options']['recurring'])) {
            return;
        }
        $period = $download['options']['recurring']['period'];
        $times = $download['options']['recurring']['times'];
        $details = '';
        if ($times > 0) {
            switch ($period) {
                case 'day':
                    $details = sprintf(_n('Daily, %d Time', 'Daily, %d Times', $times, 'edd-recurring'), $times);
                    break;
                case 'week':
                    $details = sprintf(_n('Weekly, %d Time', 'Weekly, %d Times', $times, 'edd-recurring'), $times);
                    break;
                case 'month':
                    $details = sprintf(_n('Monthly, %d Time', 'Monthly, %d Times', $times, 'edd-recurring'), $times);
                    break;
                case 'year':
                    $details = sprintf(_n('Yearly, %d Time', 'Yearly, %d Times', $times, 'edd-recurring'), $times);
                    break;
                default:
                    $details = apply_filters('edd_recurring_receipt_details_multiple', $details, $period, $times);
                    break;
            }
        } else {
            switch ($period) {
                case 'day':
                    $details = __('Daily', 'edd-recurring');
                    break;
                case 'week':
                    $details = __('Weekly', 'edd-recurring');
                    break;
                case 'month':
                    $details = __('Monthly', 'edd-recurring');
                    break;
                case 'year':
                    $details = __('Yearly', 'edd-recurring');
                    break;
                default:
                    $details = apply_filters('edd_recurring_receipt_details', $details, $period);
                    break;
            }
        }
        if (!empty($details)) {
            ?>
		<tr>
			<td><strong><?php 
            _e('Recurring Details', 'edd-recurring');
            ?>
:</strong></td>
			<td><?php 
            echo $details;
            ?>
</td>
		</tr>
		<?php 
        }
    }
Exemplo n.º 30
0
     require __DIR__ . '/vendor/autoload.php';
 }
 // determine log file
 if (defined('EDD_LOG_FILE')) {
     $handler = new StreamHandler(EDD_LOG_FILE);
 } else {
     $handler = new ErrorLogHandler();
 }
 // setup log instance
 $log = new Logger('edd');
 $log->pushHandler($handler);
 // log new purchases & renewals
 add_action('edd_complete_purchase', function ($payment_id) use($log) {
     $amount = edd_get_payment_amount($payment_id);
     $amount = edd_get_currency() . edd_format_amount($amount);
     $items = edd_get_payment_meta_downloads($payment_id);
     $item = $items[0];
     $user_info = edd_get_payment_meta_user_info($payment_id);
     $purchase_type = !empty($item['options']['is_renewal']) ? 'license renewal' : 'purchase';
     $log->info(sprintf("New %s: %s by %s", $purchase_type, $amount, $user_info['email']));
 });
 // log license activations
 add_action('edd_sl_activate_license', function ($license_id, $download_id) use($log) {
     $item_name = get_the_title($download_id);
     $url = isset($_REQUEST['url']) ? $_REQUEST['url'] : '';
     if (empty($url)) {
         $domain = array_map('trim', explode(';', $_SERVER['HTTP_USER_AGENT']));
         $url = trim($domain[1]);
     }
     $log->info(sprintf("License #%d activated: %s on %s", $license_id, $item_name, $url));
 }, 10, 2);