function ck_edd_user_download_button($purchase_form, $args) { global $edd_options; if (!is_user_logged_in()) { return $purchase_form; } $download_id = (string) $args['download_id']; $current_user_id = get_current_user_id(); // If the user has purchased this item, itterate through their purchases to get the specific // purchase data and pull out the key and email associated with it. This is necessary for the // generation of the download link if (edd_has_user_purchased($current_user_id, $download_id, $variable_price_id = null)) { $user_purchases = edd_get_users_purchases($current_user_id, -1, false, 'complete'); foreach ($user_purchases as $purchase) { $cart_items = edd_get_payment_meta_cart_details($purchase->ID); $item_ids = wp_list_pluck($cart_items, 'id'); if (in_array($download_id, $item_ids)) { $email = edd_get_payment_user_email($purchase->ID); $payment_key = edd_get_payment_key($purchase->ID); } } $download_ids = array(); if (edd_is_bundled_product($download_id)) { $download_ids = edd_get_bundled_products($download_id); } else { $download_ids[] = $download_id; } // Setup the style and colors associated with the settings $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button'; $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue'; $new_purchase_form = ''; foreach ($download_ids as $item) { // Attempt to get the file data associated with this download $download_data = edd_get_download_files($item, null); if ($download_data) { foreach ($download_data as $filekey => $file) { // Generate the file URL and then make a link to it $file_url = edd_get_download_file_url($payment_key, $email, $filekey, $item, null); $new_purchase_form .= '<a href="' . $file_url . '" class="' . $style . ' ' . $color . ' edd-submit"><span class="edd-add-to-cart-label">Download ' . $file['name'] . '</span></a> '; } } // As long as we ended up with links to show, use them. if (!empty($new_purchase_form)) { $purchase_form = '<h4>' . __('You already own this product. Download it now:', 'edd') . '</h4>' . $new_purchase_form; } } } return $purchase_form; }
/** * Helper Functions */ function wc_edd_email_purchase_receipt($payment_id, $download_id) { $payment_data = edd_get_payment_meta($payment_id); $download = get_post($download_id); $license = edd_software_licensing()->get_license_by_purchase($payment_id, $download_id); $from_name = edd_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); $from_name = apply_filters('edd_purchase_from_name', $from_name, $payment_id, $payment_data); $from_email = edd_get_option('from_email', get_bloginfo('admin_email')); $from_email = apply_filters('edd_purchase_from_address', $from_email, $payment_id, $payment_data); $to_email = edd_get_payment_user_email($payment_id); $subject = edd_get_option('purchase_subject', __('New License Key', 'edd')); $subject = apply_filters('edd_purchase_subject', wp_strip_all_tags($subject), $payment_id); $subject = edd_do_email_tags($subject, $payment_id); $message = "Dear " . edd_email_tag_first_name($payment_id) . ",\n\n"; $message .= "As you have updated " . $download->post_title . ", please use following new license key to continue getting future updates: \n\n"; $message .= "License Key : " . edd_software_licensing()->get_license_key($license->ID) . "\n\n"; $message .= "Sorry for inconvenience."; $emails = EDD()->emails; $emails->__set('from_name', $from_name); $emails->__set('from_email', $from_email); $emails->__set('heading', __('Purchase Receipt', 'edd')); $headers = apply_filters('edd_receipt_headers', $emails->get_headers(), $payment_id, $payment_data); $emails->__set('headers', $headers); $emails->send($to_email, $subject, $message, array()); if ($admin_notice && !edd_admin_notices_disabled($payment_id)) { do_action('edd_admin_sale_notice', $payment_id, $payment_data); } }
/** * Trigger the tickets email * * @param int $payment_id * * @return string */ public function trigger($payment_id = 0) { global $edd_options; $payment_data = edd_get_payment_meta($payment_id); $user_id = edd_get_payment_user_id($payment_id); $user_info = maybe_unserialize($payment_data['user_info']); $email = edd_get_payment_user_email($payment_id); if (isset($user_id) && $user_id > 0) { $user_data = get_userdata($user_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 = $email; } $message = $this->get_content_html($payment_id); $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name'); $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email'); $subject = !empty($edd_options['ticket_subject']) ? wp_strip_all_tags($edd_options['ticket_subject'], true) : $this->default_subject; $subject = apply_filters('edd_ticket_receipt_subject', $subject, $payment_id); $subject = edd_email_template_tags($subject, $payment_data, $payment_id); $headers = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n"; $headers .= 'Reply-To: ' . $from_email . "\r\n"; $headers .= "Content-Type: text/html; charset=utf-8\r\n"; $headers = apply_filters('edd_ticket_receipt_headers', $headers, $payment_id, $payment_data); // Allow add-ons to add file attachments $attachments = apply_filters('edd_ticket_receipt_attachments', array(), $payment_id, $payment_data); if (apply_filters('edd_email_ticket_receipt', true)) { wp_mail($email, $subject, $message, $headers, $attachments); } }
/** * This function renders most of the columns in the list table. * * @access public * @since 1.4 * * @param array $item Contains all the data of the log item * @param string $column_name The name of the column * * @return string Column Name */ public function column_default($item, $column_name) { $return = ''; switch ($column_name) { case 'download': $return = '<a href="' . add_query_arg('download', $item[$column_name]) . '" >' . get_the_title($item[$column_name]) . '</a>'; break; case 'user_id': $user = !empty($item['user_id']) ? $item['user_id'] : edd_get_payment_user_email($item['payment_id']); $return = '<a href="' . admin_url('edit.php?post_type=download&page=edd-payment-history&user='******'">' . $item['user_name'] . '</a>'; break; case 'item_price': $return = edd_currency_filter(edd_format_amount($item['item_price'])); break; case 'amount': $return = edd_currency_filter(edd_format_amount($item['amount'] / $item['quantity'])); break; case 'payment_id': $return = '<a href="' . admin_url('edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=' . $item['payment_id']) . '">' . edd_get_payment_number($item['payment_id']) . '</a>'; break; default: $return = $item[$column_name]; break; } return $return; }
/** * Email the download link(s) and payment confirmation to the buyer in a * customizable Purchase Receipt * * @since 1.0 * @param int $payment_id Payment ID * @param bool $admin_notice Whether to send the admin email notification or not (default: true) * @return void */ function edd_email_purchase_receipt($payment_id, $admin_notice = true) { global $edd_options; $payment_data = edd_get_payment_meta($payment_id); $user_info = maybe_unserialize($payment_data['user_info']); $email = edd_get_payment_user_email($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 = $email; } $message = edd_get_email_body_header(); $message .= edd_get_email_body_content($payment_id, $payment_data); $message .= edd_get_email_body_footer(); $from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name'); $from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email'); $subject = apply_filters('edd_purchase_subject', isset($edd_options['purchase_subject']) ? trim($edd_options['purchase_subject']) : __('Purchase Receipt', 'edd'), $payment_id); $subject = edd_email_template_tags($subject, $payment_data, $payment_id); $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n"; $headers .= "Reply-To: " . $from_email . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=utf-8\r\n"; $headers = apply_filters('edd_receipt_headers', $headers, $payment_id, $payment_data); // Allow add-ons to add file attachments $attachments = apply_filters('edd_receipt_attachments', array(), $payment_id, $payment_data); wp_mail($email, $subject, $message, $headers, $attachments); if ($admin_notice && !edd_admin_notices_disabled()) { do_action('edd_admin_sale_notice', $payment_id, $payment_data); } }
/** * Records a pending referral when a pending payment is created * * @access public * @since 1.0 */ public function add_pending_referral($payment_id = 0, $payment_data = array()) { if ($this->was_referred()) { $customer_email = edd_get_payment_user_email($payment_id); if ($this->is_affiliate_email($customer_email)) { return; // Customers cannot refer themselves } if (affiliate_wp()->settings->get('edd_disable_on_renewals')) { $was_renewal = get_post_meta($payment_id, '_edd_sl_is_renewal', true); if ($was_renewal) { return; } } // get referral total $referral_total = $this->get_referral_total($payment_id, $this->affiliate_id); // Referral description $desc = $this->get_referral_description($payment_id); if (empty($desc)) { return; } // insert a pending referral $referral_id = $this->insert_pending_referral($referral_total, $payment_id, $desc, $this->get_products($payment_id)); } }
/** * Email the download link(s) and payment confirmation to the buyer in a * customizable Purchase Receipt * * @since 1.0 * @param int $payment_id Payment ID * @param bool $admin_notice Whether to send the admin email notification or not (default: true) * @return void */ function edd_email_purchase_receipt($payment_id, $admin_notice = true) { $payment_data = edd_get_payment_meta($payment_id); $from_name = edd_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); $from_name = apply_filters('edd_purchase_from_name', $from_name, $payment_id, $payment_data); $from_email = edd_get_option('from_email', get_bloginfo('admin_email')); $from_email = apply_filters('edd_purchase_from_address', $from_email, $payment_id, $payment_data); $to_email = edd_get_payment_user_email($payment_id); $subject = edd_get_option('purchase_subject', __('Purchase Receipt', 'edd')); $subject = apply_filters('edd_purchase_subject', wp_strip_all_tags($subject), $payment_id); $subject = edd_do_email_tags($subject, $payment_id); $heading = edd_get_option('purchase_heading', __('Purchase Receipt', 'edd')); $heading = apply_filters('edd_purchase_heading', $heading, $payment_id, $payment_data); $attachments = apply_filters('edd_receipt_attachments', array(), $payment_id, $payment_data); $message = edd_do_email_tags(edd_get_email_body_content($payment_id, $payment_data), $payment_id); $emails = EDD()->emails; $emails->__set('from_name', $from_name); $emails->__set('from_email', $from_email); $emails->__set('heading', $heading); $headers = apply_filters('edd_receipt_headers', $emails->get_headers(), $payment_id, $payment_data); $emails->__set('headers', $headers); $emails->send($to_email, $subject, $message, $attachments); if ($admin_notice && !edd_admin_notices_disabled($payment_id)) { do_action('edd_admin_sale_notice', $payment_id, $payment_data); } }
public function set_from_address($emails_class) { global $edd_payment_id; if (empty($edd_payment_id)) { return; } $emails_class->from_address = edd_get_payment_user_email($edd_payment_id); }
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'); } }
/** * Create identity and track purchase * @param int $payment_id * @return null */ public static function track_purchase($payment_id) { $user_id = edd_get_payment_user_id($payment_id); $uid = EDD_Segment_Identity::get_uid_from_user_id($user_id); // Send identity $traits = array('name' => edd_email_tag_fullname($payment_id), 'email' => edd_get_payment_user_email($payment_id)); do_action('edd_segment_identify', $uid, $traits); // Track the purchase event $props = array('trans_id' => edd_get_payment_transaction_id($payment_id), 'total' => edd_get_payment_amount($payment_id), 'time' => strtotime(edd_get_payment_completed_date($payment_id))); do_action('edd_segment_track', $uid, 'Checkout', $props); }
/** * @param int $payment_id The ID of the payment * * @return bool|string */ public function subscribe_from_edd($payment_id) { if (!$this->triggered($payment_id)) { return false; } $email = (string) edd_get_payment_user_email($payment_id); $merge_vars = array(); // add first and last name to merge vars, if given $user_info = (array) edd_get_payment_meta_user_info($payment_id); if (isset($user_info['first_name']) && isset($user_info['last_name'])) { $merge_vars['NAME'] = $user_info['first_name'] . ' ' . $user_info['last_name']; } if (isset($user_info['first_name'])) { $merge_vars['FNAME'] = $user_info['first_name']; } if (isset($user_info['last_name'])) { $merge_vars['LNAME'] = $user_info['last_name']; } return $this->subscribe($email, $merge_vars, $payment_id); }
/** * @param int $payment_id The ID of the payment * * @return bool|string */ public function subscribe_from_edd($payment_id) { if (!$this->triggered($payment_id)) { return false; } $email = (string) edd_get_payment_user_email($payment_id); $data = array('EMAIL' => $email); // add first and last name to merge vars, if given $user_info = (array) edd_get_payment_meta_user_info($payment_id); if (!empty($user_info['first_name']) && !empty($user_info['last_name'])) { $data['NAME'] = $user_info['first_name'] . ' ' . $user_info['last_name']; } if (!empty($user_info['first_name'])) { $data['FNAME'] = $user_info['first_name']; } if (!empty($user_info['last_name'])) { $data['LNAME'] = $user_info['last_name']; } return $this->subscribe($data, $payment_id); }
function edd_ti_send_tracking($post) { $nonce = !empty($post['nonce']) ? $post['nonce'] : false; if (!wp_verify_nonce($nonce, 'edd-ti-send-tracking')) { wp_die(); } $tracking_id = edd_ti_get_payment_tracking_id($post['payment_id']); if (empty($tracking_id)) { return; } $from_name = edd_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); $from_email = edd_get_option('from_email', get_bloginfo('admin_email')); $to_email = edd_get_payment_user_email($post['payment_id']); $subject = 'Your order has shipped'; $heading = 'Your order has shipped!'; $message = '<p>Your recent order ' . $post['payment_id'] . ' has been shipped.</p>'; $message .= '<p>Tracking ID: <a href="' . edd_ti_get_payment_tracking_link($post['payment_id']) . '">' . $tracking_id . '</a></p>'; $message .= '<p>Thank you!</p>'; $message .= '<p>The ' . $from_name . ' team</p>'; $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <{$from_email}>\r\n"; $headers .= "Reply-To: " . $from_email . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=utf-8\r\n"; $attachments = array(); $emails = EDD()->emails; $emails->__set('from_name', $from_name); $emails->__set('from_email', $from_email); $emails->__set('heading', $heading); $emails->__set('headers', $headers); $result = $emails->send($to_email, $subject, $message, $attachments); $response = array('success' => $result); $response['message'] = $result ? __('Email sent.', 'edd-tracking-info') : __('Error sending email. Try again later.', 'edd-tracking-info'); if ($result) { edd_update_payment_meta($post['payment_id'], 'edd_tracking_info_sent', true); edd_insert_payment_note($post['payment_id'], sprintf(__('Tracking information sent to %s.', 'edd-tracking-info'), $to_email)); } echo json_encode($response); die; }
/** * @param int $payment_id The ID of the payment * * @return bool|string */ public function subscribe_from_edd_purchase($payment_id) { $meta = get_post_meta($payment_id, '_yikes_easy_mc_optin', true); if ($meta == '0') { return false; } $email = (string) edd_get_payment_user_email($payment_id); $merge_vars = array(); // add first and last name to merge vars, if given $user_info = (array) edd_get_payment_meta_user_info($payment_id); if (isset($user_info['first_name']) && isset($user_info['last_name'])) { $merge_vars['NAME'] = $user_info['first_name'] . ' ' . $user_info['last_name']; } if (isset($user_info['first_name'])) { $merge_vars['FNAME'] = $user_info['first_name']; } if (isset($user_info['last_name'])) { $merge_vars['LNAME'] = $user_info['last_name']; } // subscribe the user $this->subscribe_user_integration(sanitize_email($email), $this->type, $merge_vars); }
/** * Email template tag: user_email * The buyer's email address * * @since 1.0.0 * @param int $payment_id * @return string user_email */ function edd_wallet_email_tag_user_email($payment_id) { if (get_post_type($payment_id) == 'edd_payment') { return edd_get_payment_user_email($payment_id); } else { $item = edd_wallet()->db->get_customer_wallet_item($payment_id); $user_data = get_userdata($item->user_id); return $user_data->user_email; } }
/** * Retrieves a new download link for a purchased file * * @since 2.0 * @return string */ function edd_ajax_generate_file_download_link() { if (!current_user_can('view_shop_reports')) { die('-1'); } $payment_id = absint($_POST['payment_id']); $download_id = absint($_POST['download_id']); $price_id = absint($_POST['price_id']); if (empty($payment_id)) { die('-2'); } if (empty($download_id)) { die('-3'); } $payment_key = edd_get_payment_key($payment_id); $email = edd_get_payment_user_email($payment_id); $limit = edd_get_file_download_limit($download_id); if (!empty($limit)) { // Increase the file download limit when generating new links edd_set_file_download_limit_override($download_id, $payment_id); } $files = edd_get_download_files($download_id, $price_id); if (!$files) { die('-4'); } $file_urls = ''; foreach ($files as $file_key => $file) { $file_urls .= edd_get_download_file_url($payment_key, $email, $file_key, $download_id, $price_id); $file_urls .= "\n\n"; } die($file_urls); }
/** * Get Payment Meta for a specific Payment * * @since 1.2 * @param int $payment_id Payment ID * @param string $meta_key The meta key to pull * @param bool $single Pull single meta entry or as an object * @return mixed $meta Payment Meta */ function edd_get_payment_meta($payment_id = 0, $meta_key = '_edd_payment_meta', $single = true) { $meta = get_post_meta($payment_id, $meta_key, $single); if ($meta_key === '_edd_payment_meta') { // Payment meta was simplified in EDD v1.5, so these are here for backwards compatibility if (empty($meta['key'])) { $meta['key'] = edd_get_payment_key($payment_id); } if (empty($meta['email'])) { $meta['email'] = edd_get_payment_user_email($payment_id); } if (empty($meta['date'])) { $meta['date'] = get_post_field('post_date', $payment_id); } } $meta = apply_filters('edd_get_payment_meta_' . $meta_key, $meta, $payment_id); return apply_filters('edd_get_payment_meta', $meta, $payment_id, $meta_key); }
/** * Retrieves Recent Sales * * @access public * @since 1.5 * @return array */ public function get_recent_sales() { global $wp_query; $sales = array(); if( ! user_can( $this->user_id, 'view_shop_reports' ) && ! $this->override ) { return $sales; } if( isset( $wp_query->query_vars['id'] ) ) { $query = array(); $query[] = edd_get_payment_by( 'id', $wp_query->query_vars['id'] ); } elseif( isset( $wp_query->query_vars['purchasekey'] ) ) { $query = array(); $query[] = edd_get_payment_by( 'key', $wp_query->query_vars['purchasekey'] ); } elseif( isset( $wp_query->query_vars['email'] ) ) { $query = edd_get_payments( array( 'meta_key' => '_edd_payment_user_email', 'meta_value' => $wp_query->query_vars['email'], 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish' ) ); } else { $query = edd_get_payments( array( 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish' ) ); } if ( $query ) { $i = 0; foreach ( $query as $payment ) { $payment_meta = edd_get_payment_meta( $payment->ID ); $user_info = edd_get_payment_meta_user_info( $payment->ID ); $cart_items = edd_get_payment_meta_cart_details( $payment->ID ); $sales['sales'][ $i ]['ID'] = edd_get_payment_number( $payment->ID ); $sales['sales'][ $i ]['transaction_id'] = edd_get_payment_transaction_id( $payment->ID ); $sales['sales'][ $i ]['key'] = edd_get_payment_key( $payment->ID ); $sales['sales'][ $i ]['discount'] = isset( $user_info['discount'] ) && $user_info['discount'] != 'none' ? explode( ',', $user_info['discount'] ) : array(); $sales['sales'][ $i ]['subtotal'] = edd_get_payment_subtotal( $payment->ID ); $sales['sales'][ $i ]['tax'] = edd_get_payment_tax( $payment->ID ); $sales['sales'][ $i ]['fees'] = edd_get_payment_fees( $payment->ID ); $sales['sales'][ $i ]['total'] = edd_get_payment_amount( $payment->ID ); $sales['sales'][ $i ]['gateway'] = edd_get_payment_gateway( $payment->ID ); $sales['sales'][ $i ]['email'] = edd_get_payment_user_email( $payment->ID ); $sales['sales'][ $i ]['date'] = $payment->post_date; $sales['sales'][ $i ]['products'] = array(); $c = 0; foreach ( $cart_items as $key => $item ) { $item_id = isset( $item['id'] ) ? $item['id'] : $item; $price = isset( $item['price'] ) ? $item['price'] : false; $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; $quantity = isset( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; if( ! $price ) { // This function is only used on payments with near 1.0 cart data structure $price = edd_get_download_final_price( $item_id, $user_info, null ); } $price_name = ''; if ( isset( $item['item_number'] ) && isset( $item['item_number']['options'] ) ) { $price_options = $item['item_number']['options']; if ( isset( $price_options['price_id'] ) ) { $price_name = edd_get_price_option_name( $item['id'], $price_options['price_id'], $payment->ID ); } } $sales['sales'][ $i ]['products'][ $c ]['quantity'] = $quantity; $sales['sales'][ $i ]['products'][ $c ]['name'] = get_the_title( $item['id'] ); $sales['sales'][ $i ]['products'][ $c ]['price'] = $price; $sales['sales'][ $i ]['products'][ $c ]['price_name'] = $price_name; $c++; } $i++; } } return $sales; }
/** * Determines the receipt visibility status * * @return bool Whether the receipt is visible or not. */ function edd_can_view_receipt($payment_key = '') { $return = false; if (empty($payment_key)) { return $return; } global $edd_receipt_args; $edd_receipt_args['id'] = edd_get_purchase_id_by_key($payment_key); $user_id = (int) edd_get_payment_user_id($edd_receipt_args['id']); $payment_meta = edd_get_payment_meta($edd_receipt_args['id']); if (is_user_logged_in()) { if ($user_id === (int) get_current_user_id()) { $return = true; } elseif (wp_get_current_user()->user_email === edd_get_payment_user_email($edd_receipt_args['id'])) { $return = true; } elseif (current_user_can('view_shop_sensitive_data')) { $return = true; } } $session = edd_get_purchase_session(); if (!empty($session) && !is_user_logged_in()) { if ($session['purchase_key'] === $payment_meta['key']) { $return = true; } } return (bool) apply_filters('edd_can_view_receipt', $return, $payment_key); }
/** * Retrieves Recent Sales * * @access public * @since 1.5 * @return array */ public function get_recent_sales() { $sales = array(); $query = edd_get_payments(array('number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish')); if ($query) { $i = 0; foreach ($query as $payment) { $payment_meta = edd_get_payment_meta($payment->ID); $user_info = edd_get_payment_meta_user_info($payment->ID); $cart_items = edd_get_payment_meta_cart_details($payment->ID); $sales['sales'][$i]['ID'] = $payment->ID; $sales['sales'][$i]['key'] = edd_get_payment_key($payment->ID); $sales['sales'][$i]['subtotal'] = edd_get_payment_subtotal($payment->ID); $sales['sales'][$i]['tax'] = edd_get_payment_tax($payment->ID); $sales['sales'][$i]['fees'] = edd_get_payment_fees($payment->ID); $sales['sales'][$i]['total'] = edd_get_payment_amount($payment->ID); $sales['sales'][$i]['gateway'] = edd_get_payment_gateway($payment->ID); $sales['sales'][$i]['email'] = edd_get_payment_user_email($payment->ID); $sales['sales'][$i]['date'] = $payment->post_date; $sales['sales'][$i]['products'] = array(); $c = 0; foreach ($cart_items as $key => $item) { $price_override = isset($payment_meta['cart_details']) ? $item['price'] : null; $price = edd_get_download_final_price($item['id'], $user_info, $price_override); if (isset($cart_items[$key]['item_number'])) { $price_name = ''; $price_options = $cart_items[$key]['item_number']['options']; if (isset($price_options['price_id'])) { $price_name = edd_get_price_option_name($item['id'], $price_options['price_id'], $payment->ID); } } $sales['sales'][$i]['products'][$c]['name'] = get_the_title($item['id']); $sales['sales'][$i]['products'][$c]['price'] = $price; $sales['sales'][$i]['products'][$c]['price_name'] = $price_name; $c++; } $i++; } } return $sales; }
/** * Get the avatar for the backer. * * @param WP_Post $backer * @param int $size * @return string */ function wpo_crowdfunding_get_backer_avatar($backer, $size = 115) { return get_avatar(edd_get_payment_user_email($backer->ID), $size, '', $backer->post_title); }
/** * Render the Customer Column * * @access public * @since 2.4.3 * @param array $payment Contains all the data of the payment * @return string Data shown in the User column */ public function column_customer($payment) { $customer_id = edd_get_payment_customer_id($payment->ID); if (!empty($customer_id)) { $customer = new EDD_Customer($customer_id); $value = '<a href="' . esc_url(admin_url("edit.php?post_type=download&page=edd-customers&view=overview&id={$customer_id}")) . '">' . $customer->name . '</a>'; } else { $email = edd_get_payment_user_email($payment->ID); $value = '<a href="' . esc_url(admin_url("edit.php?post_type=download&page=edd-payment-history&s={$email}")) . '">' . __('(customer missing)', 'easy-digital-downloads') . '</a>'; } return apply_filters('edd_payments_table_column', $value, $payment->ID, 'user'); }
/** * Sale Notification Template Body * * @since 1.7 * @author Daniel J Griffiths * @param int $payment_id Payment ID * @param array $payment_data Payment Data * @return string $email_body Body of the email */ function edd_get_sale_notification_body_content($payment_id = 0, $payment_data = array()) { global $edd_options; $user_info = maybe_unserialize($payment_data['user_info']); $email = edd_get_payment_user_email($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 = $email; } $download_list = ''; $downloads = maybe_unserialize($payment_data['downloads']); if (is_array($downloads)) { foreach ($downloads as $download) { $id = isset($payment_data['cart_details']) ? $download['id'] : $download; $title = get_the_title($id); if (isset($download['options'])) { if (isset($download['options']['price_id'])) { $title .= ' - ' . edd_get_price_option_name($id, $download['options']['price_id'], $payment_id); } } $download_list .= html_entity_decode($title, ENT_COMPAT, 'UTF-8') . "\n"; } } $gateway = edd_get_gateway_admin_label(get_post_meta($payment_id, '_edd_payment_gateway', true)); $default_email_body = __('Hello', 'edd') . "\n\n" . sprintf(__('A %s purchase has been made', 'edd'), edd_get_label_plural()) . ".\n\n"; $default_email_body .= sprintf(__('%s sold:', 'edd'), edd_get_label_plural()) . "\n\n"; $default_email_body .= $download_list . "\n\n"; $default_email_body .= __('Purchased by: ', 'edd') . " " . html_entity_decode($name, ENT_COMPAT, 'UTF-8') . "\n"; $default_email_body .= __('Amount: ', 'edd') . " " . html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_payment_amount($payment_id))), ENT_COMPAT, 'UTF-8') . "\n"; $default_email_body .= __('Payment Method: ', 'edd') . " " . $gateway . "\n\n"; $default_email_body .= __('Thank you', 'edd'); $email = isset($edd_options['sale_notification']) ? stripslashes($edd_options['sale_notification']) : $default_email_body; //$email_body = edd_email_template_tags( $email, $payment_data, $payment_id, true ); $email_body = edd_do_email_tags($email, $payment_id); return apply_filters('edd_sale_notification', wpautop($email_body), $payment_id, $payment_data); }
/** * Gets the download links for each item purchased * * @since 1.1.5 * @param int $payment_id The ID of the payment to retrieve download links for * @return string */ function edd_get_purchase_download_links($payment_id = 0) { $downloads = edd_get_payment_meta_cart_details($payment_id, true); $payment_key = edd_get_payment_key($payment_id); $email = edd_get_payment_user_email($payment_id); $links = '<ul class="edd_download_links">'; foreach ($downloads as $download) { $links .= '<li>'; $links .= '<h3 class="edd_download_link_title">' . esc_html(get_the_title($download['id'])) . '</h3>'; $price_id = isset($download['options']) && isset($download['options']['price_id']) ? $download['options']['price_id'] : null; $files = edd_get_download_files($download['id'], $price_id); if (is_array($files)) { foreach ($files as $filekey => $file) { $links .= '<div class="edd_download_link_file">'; $links .= '<a href="' . esc_url(edd_get_download_file_url($payment_key, $email, $filekey, $download['id'], $price_id)) . '">'; if (isset($file['name'])) { $links .= esc_html($file['name']); } else { $links .= esc_html($file['file']); } $links .= '</a>'; $links .= '</div>'; } } $links .= '</li>'; } $links .= '</ul>'; return $links; }
/** * Process web accept (one time) payment IPNs * * @since 1.3.4 * @param array $data IPN Data * @return void */ function edd_process_paypal_web_accept_and_cart($data, $payment_id) { if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { return; } if (empty($payment_id)) { return; } // Collect payment details $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; $paypal_amount = $data['mc_gross']; $payment_status = strtolower($data['payment_status']); $currency_code = strtolower($data['mc_currency']); $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); $payment_meta = edd_get_payment_meta($payment_id); if (edd_get_payment_gateway($payment_id) != 'paypal') { return; // this isn't a PayPal standard IPN } // Verify payment recipient if (strcasecmp($business_email, trim(edd_get_option('paypal_email', false))) != 0) { edd_record_gateway_error(__('IPN Error', 'edd'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'edd'), json_encode($data)), $payment_id); edd_update_payment_status($payment_id, 'failed'); edd_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'edd')); return; } // Verify payment currency if ($currency_code != strtolower($payment_meta['currency'])) { edd_record_gateway_error(__('IPN Error', 'edd'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'edd'), json_encode($data)), $payment_id); edd_update_payment_status($payment_id, 'failed'); edd_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'edd')); return; } if (!edd_get_payment_user_email($payment_id)) { // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal // No email associated with purchase, so store from PayPal edd_update_payment_meta($payment_id, '_edd_payment_user_email', $data['payer_email']); // Setup and store the customers's details $address = array(); $address['line1'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; $address['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; $address['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; $address['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; $address['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; $user_info = array('id' => '-1', 'email' => sanitize_text_field($data['payer_email']), 'first_name' => sanitize_text_field($data['first_name']), 'last_name' => sanitize_text_field($data['last_name']), 'discount' => '', 'address' => $address); $payment_meta['user_info'] = $user_info; edd_update_payment_meta($payment_id, '_edd_payment_meta', $payment_meta); } if ($payment_status == 'refunded' || $payment_status == 'reversed') { // Process a refund edd_process_paypal_refund($data, $payment_id); } else { if (get_post_status($payment_id) == 'publish') { return; // Only complete payments once } // Retrieve the total purchase amount (before PayPal) $payment_amount = edd_get_payment_amount($payment_id); if (number_format((double) $paypal_amount, 2) < number_format((double) $payment_amount, 2)) { // The prices don't match edd_record_gateway_error(__('IPN Error', 'edd'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'edd'), json_encode($data)), $payment_id); edd_update_payment_status($payment_id, 'failed'); edd_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'edd')); return; } if ($purchase_key != edd_get_payment_key($payment_id)) { // Purchase keys don't match edd_record_gateway_error(__('IPN Error', 'edd'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'edd'), json_encode($data)), $payment_id); edd_update_payment_status($payment_id, 'failed'); edd_insert_payment_note($payment_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'edd')); return; } if ('completed' == $payment_status || edd_is_test_mode()) { edd_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'edd'), $data['txn_id'])); edd_set_payment_transaction_id($payment_id, $data['txn_id']); edd_update_payment_status($payment_id, 'publish'); } else { if ('pending' == $payment_status && isset($data['pending_reason'])) { // Look for possible pending reasons, such as an echeck $note = ''; switch (strtolower($data['pending_reason'])) { case 'echeck': $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'edd'); break; case 'address': $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'edd'); break; case 'intl': $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'edd'); break; case 'multi-currency': $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'edd'); break; case 'paymentreview': case 'regulatory_review': $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'edd'); break; case 'unilateral': $note = __('Payment was sent to non-confirmed or non-registered email address.', 'edd'); break; case 'upgrade': $note = __('PayPal account must be upgraded before this payment can be accepted', 'edd'); break; case 'verify': $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'edd'); break; case 'other': $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'edd'); break; } if (!empty($note)) { edd_insert_payment_note($payment_id, $note); } } } } }
/** * Process the license upgrade during purchase * * @since 3.3 * @return void */ function edd_sl_process_license_upgrade($download_id = 0, $payment_id = 0, $type = 'default', $cart_item = array(), $cart_index = 0) { // Bail if this is not a renewal item if (empty($cart_item['item_number']['options']['is_upgrade'])) { return; } $license_id = $cart_item['item_number']['options']['license_id']; $upgrade_id = $cart_item['item_number']['options']['upgrade_id']; $upgrade = edd_sl_get_upgrade_path($download_id, $upgrade_id); $old_payment_ids = get_post_meta($license_id, '_edd_sl_payment_id'); $old_payment_id = end($old_payment_ids); // We only want the most recent one $old_download_id = edd_software_licensing()->get_download_id($license_id); $old_price_id = edd_software_licensing()->get_price_id($license_id); $purchase_date = get_post_field('post_date', $old_payment_id); if (edd_is_bundled_product($download_id)) { // Upgrade to a bundle from a standard license $downloads = array(); $bundle_licensing = (bool) get_post_meta($download_id, '_edd_sl_enabled', true); $parent_license_id = 0; $activation_limit = false; $user_info = edd_get_payment_meta_user_info($payment_id); if ($bundle_licensing) { $downloads[] = $download_id; } $downloads = array_merge($downloads, edd_get_bundled_products($download_id)); if (edd_has_variable_prices($download_id)) { $activation_limit = edd_software_licensing()->get_price_activation_limit($download_id, $cart_item['item_number']['options']['price_id']); $is_lifetime = edd_software_licensing()->get_price_is_lifetime($download_id, $cart_item['item_number']['options']['price_id']); } foreach ($downloads as $d_id) { if ((int) $d_id === (int) $old_download_id) { continue; } if (!get_post_meta($d_id, '_edd_sl_enabled', true)) { continue; } $license_title = get_the_title($d_id) . ' - ' . $user_info['email']; $license_args = array('post_type' => 'edd_license', 'post_title' => $license_title, 'post_status' => 'publish', 'post_date' => get_post_field('post_date', $payment_id, 'raw')); if ($parent_license_id) { $license_args['post_parent'] = $parent_license_id; } $l_id = wp_insert_post(apply_filters('edd_sl_insert_license_args', $license_args)); if ($bundle_licensing && $download_id == $d_id && !$parent_license_id) { $parent_license_id = $l_id; } $license_key = edd_software_licensing()->get_new_download_license_key($d_id); if (!$license_key) { // No predefined license key available, generate a random one $license_key = edd_software_licensing()->generate_license_key($l_id, $d_id, $payment_id, $cart_index); } $price_id = isset($cart_item['item_number']['options']['price_id']) ? (int) $cart_item['item_number']['options']['price_id'] : false; add_post_meta($l_id, '_edd_sl_download_id', $d_id); if (false !== $price_id) { add_post_meta($l_id, '_edd_sl_download_price_id', $price_id); } add_post_meta($l_id, '_edd_sl_cart_index', $cart_index); add_post_meta($l_id, '_edd_sl_payment_id', $payment_id); add_post_meta($l_id, '_edd_sl_key', $license_key); add_post_meta($l_id, '_edd_sl_user_id', $user_info['id']); add_post_meta($l_id, '_edd_sl_status', 'inactive'); add_post_meta($l_id, '_edd_sl_site_count', 0); if ($parent_license_id && !empty($activation_limit)) { add_post_meta($l_id, '_edd_sl_limit', $activation_limit); } // Get license length $license_length = edd_software_licensing()->get_license_length($l_id, $payment_id, $d_id); if (empty($is_lifetime) && 'lifetime' !== $license_length) { // Set license expiration date delete_post_meta($l_id, '_edd_sl_is_lifetime'); edd_software_licensing()->set_license_expiration($l_id, strtotime($license_length, strtotime($purchase_date))); } else { edd_software_licensing()->set_license_as_lifetime($l_id); } do_action('edd_sl_store_license', $l_id, $d_id, $payment_id, $type); } // Now update the original license wp_update_post(array('ID' => $license_id, 'post_parent' => $parent_license_id)); update_post_meta($license_id, '_edd_sl_cart_index', $cart_index); add_post_meta($license_id, '_edd_sl_payment_id', $payment_id); } else { // Standard license upgrade $new_title = get_the_title($download_id) . ' - ' . edd_get_payment_user_email($payment_id); wp_update_post(array('ID' => $license_id, 'post_title' => $new_title)); update_post_meta($license_id, '_edd_sl_cart_index', $cart_index); add_post_meta($license_id, '_edd_sl_payment_id', $payment_id); update_post_meta($license_id, '_edd_sl_download_id', $download_id); if (edd_has_variable_prices($download_id)) { $limit = edd_software_licensing()->get_price_activation_limit($download_id, $upgrade['price_id']); $is_lifetime = edd_software_licensing()->get_price_is_lifetime($download_id, $upgrade['price_id']); update_post_meta($license_id, '_edd_sl_download_price_id', $upgrade['price_id']); } else { $limit = edd_software_licensing()->get_license_limit($download_id, $license_id); } update_post_meta($license_id, '_edd_sl_limit', $limit); $license_length = edd_software_licensing()->get_license_length($license_id, $payment_id, $download_id); if (empty($is_lifetime) && 'lifetime' !== $license_length) { // Set license expiration date delete_post_meta($license_id, '_edd_sl_is_lifetime'); edd_software_licensing()->set_license_expiration($license_id, strtotime($license_length, strtotime($purchase_date))); } else { edd_software_licensing()->set_license_as_lifetime($license_id); } } // Now store upgrade details / notes on payments $old_product = get_the_title($old_download_id); if (false !== $old_price_id) { $old_product .= ' - ' . edd_get_price_option_name($old_download_id, $old_price_id); } $new_product = get_the_title($download_id); if (edd_has_variable_prices($download_id)) { $new_product .= ' - ' . edd_get_price_option_name($download_id, $upgrade['price_id']); } $note = sprintf(__('License upgraded from %s to %s', 'edd_sl'), $old_product, $new_product); edd_insert_payment_note($payment_id, $note); update_post_meta($payment_id, '_edd_sl_upgraded_payment_id', $old_payment_id); update_post_meta($old_payment_id, '_edd_sl_upgraded_to_payment_id', $payment_id); }
</p> <p> <?php $download_log_url = admin_url('edit.php?post_type=download&page=edd-reports&tab=logs&user='******'View customer download log', 'edd'); ?> </a> </p> <p> <?php $purchase_url = admin_url('edit.php?post_type=download&page=edd-payment-history&user='******'View all purchases of customer', 'edd'); ?> </a> </p> </div> <?php do_action('edd_view_order_details_logs_inner', $payment_id); ?>
/** * Record a subscription payment * * @since 1.0.1 * @return void */ public function record_subscription_payment($parent_id = 0, $amount = '', $txn_id = '', $unique_key = 0) { global $edd_options; if ($this->payment_exists($unique_key)) { return; } // increase the earnings for each product in the subscription $downloads = edd_get_payment_meta_downloads($parent_id); if ($downloads) { foreach ($downloads as $download) { edd_increase_earnings($download['id'], $amount); } } // setup the payment daya $payment_data = array('parent' => $parent_id, 'price' => $amount, 'user_email' => edd_get_payment_user_email($parent_id), 'purchase_key' => get_post_meta($parent_id, '_edd_payment_purchase_key', true), 'currency' => edd_get_option('currency', 'usd'), 'downloads' => $downloads, 'user_info' => edd_get_payment_meta_user_info($parent_id), 'cart_details' => edd_get_payment_meta_cart_details($parent_id), 'status' => 'edd_subscription', 'gateway' => edd_get_payment_gateway($parent_id)); // record the subscription payment $payment = edd_insert_payment($payment_data); if (!empty($unique_key)) { update_post_meta($payment, '_edd_recurring_' . $unique_key, '1'); } // Record transaction ID if (!empty($txn_id)) { if (function_exists('edd_set_payment_transaction_id')) { edd_set_payment_transaction_id($payment, $txn_id); } } // Update the expiration date of license keys, if EDD Software Licensing is active if (function_exists('edd_software_licensing')) { $licenses = edd_software_licensing()->get_licenses_of_purchase($parent_id); if (!empty($licenses)) { foreach ($licenses as $license) { // Update the expiration dates of the license key edd_software_licensing()->renew_license($license->ID, $parent_id); } } } do_action('edd_recurring_record_payment', $payment, $parent_id, $amount, $txn_id, $unique_key); }
if (empty($payment)) { ?> <div class="edd_errors edd-alert edd-alert-error"> <?php _e('The specified receipt ID appears to be invalid', 'easy-digital-downloads'); ?> </div> <?php return; } $meta = edd_get_payment_meta($payment->ID); $cart = edd_get_payment_meta_cart_details($payment->ID, true); $user = edd_get_payment_meta_user_info($payment->ID); $email = edd_get_payment_user_email($payment->ID); $status = edd_get_payment_status($payment, true); ?> <table id="edd_purchase_receipt"> <thead> <?php do_action('edd_payment_receipt_before', $payment, $edd_receipt_args); ?> <?php if ($edd_receipt_args['payment_id']) { ?> <tr> <th><strong><?php _e('Payment', 'easy-digital-downloads'); ?>
/** * Email template tag: user_email * The buyer's email address * * @param int $payment_id * * @return string user_email */ function edd_email_tag_user_email($payment_id) { return edd_get_payment_user_email($payment_id); }