/** * Get the data being exported * * @access public * @since 1.2 * @return array */ public function get_data() { global $edd_logs; $data = array(); $args = array('nopaging' => true, 'post_type' => 'edd_payment', 'meta_key' => '_edd_payment_shipping_status', 'meta_value' => '1', 'fields' => 'ids'); $payments = get_posts($args); if ($payments) { foreach ($payments as $payment) { $user_info = edd_get_payment_meta_user_info($payment); $downloads = edd_get_payment_meta_cart_details($payment); $products = ''; if ($downloads) { foreach ($downloads as $key => $download) { // Display the Downoad Name $products .= get_the_title($download['id']); if ($key != count($downloads) - 1) { $products .= ' / '; } } } $data[] = array('id' => $payment, 'date' => get_post_field('post_date', $payment), 'first_name' => $user_info['first_name'], 'last_name' => $user_info['last_name'], 'email' => $user_info['email'], 'address' => $user_info['shipping_info']['address'], 'address2' => !empty($user_info['shipping_info']['address2']) ? $user_info['shipping_info']['address2'] : '', 'city' => $user_info['shipping_info']['city'], 'state' => $user_info['shipping_info']['state'], 'zip' => $user_info['shipping_info']['zip'], 'country' => $user_info['shipping_info']['country'], 'amount' => edd_get_payment_amount($payment), 'tax' => edd_get_payment_tax($payment), 'gateway' => edd_get_payment_gateway($payment), 'key' => edd_get_payment_key($payment), 'products' => $products, 'status' => get_post_field('post_status', $payment)); } } $data = apply_filters('edd_export_get_data', $data); $data = apply_filters('edd_export_get_data_' . $this->export_type, $data); return $data; }
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; }
/** * Email template tag: receipt_link * Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly * * @param $int payment_id * * @return string receipt_link */ function edd_email_tag_receipt_link($payment_id) { return sprintf(__('%1$sView it in your browser.%2$s', 'easy-digital-downloads'), '<a href="' . esc_url(add_query_arg(array('payment_key' => edd_get_payment_key($payment_id), 'edd_action' => 'view_receipt'), home_url())) . '">', '</a>'); }
/** * Get Payment Meta for a specific Payment * * @since 1.2 * @param int $payment_id Payment ID * @return array $meta Payment Meta */ function edd_get_payment_meta($payment_id) { $meta = get_post_meta($payment_id, '_edd_payment_meta', true); // Payment meta was simplified in EDD v1.5, so these are here for backwards compatibility if (!isset($meta['key'])) { $meta['key'] = edd_get_payment_key($payment_id); } if (!isset($meta['amount'])) { $meta['amount'] = edd_get_payment_amount($payment_id); } if (!isset($meta['email'])) { $meta['email'] = edd_get_payment_user_email($payment_id); } if (!isset($meta['date'])) { $meta['date'] = get_post_field('post_date', $payment_id); } return apply_filters('edd_get_payment_meta', $meta, $payment_id); }
echo edd_get_gateway_admin_label($gateway); ?> </p> </div> <?php } ?> <div class="edd-order-payment-key edd-admin-box-inside"> <p> <span class="label"><?php _e('Key:', 'edd'); ?> </span> <span><?php echo edd_get_payment_key($payment_id); ?> </span> </p> </div> <div class="edd-order-ip edd-admin-box-inside"> <p> <span class="label"><?php _e('IP:', 'edd'); ?> </span> <span><?php echo esc_attr(edd_get_payment_user_ip($payment_id)); ?> </span>
/** * 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; }
/** * 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); }
<span class="edd_purchase_status <?php echo $post->post_status; ?> "><?php echo edd_get_payment_status($post, true); ?> </span> <a href="<?php echo esc_url(add_query_arg('payment_key', edd_get_payment_key($post->ID), edd_get_success_page_uri())); ?> ">»</a> <?php } else { ?> <a href="<?php echo esc_url(add_query_arg('payment_key', edd_get_payment_key($post->ID), edd_get_success_page_uri())); ?> "><?php _e('View Details and Downloads', 'edd'); ?> </a> <?php } ?> </td> <?php do_action('edd_purchase_history_row_end', $post->ID, $purchase_data); ?> </tr> <?php
/** * 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); }
/** * Process web accept (one time) payment IPNs * * @since 1.3.4 * @global $edd_options Array of all the EDD Options * @param array $data IPN Data * @return void */ function edd_process_paypal_web_accept_and_cart($data) { global $edd_options; if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { return; } // Collect payment details $payment_id = $data['custom']; $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']); 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_options['paypal_email'])) != 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(edd_get_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']) ? $data['address_street'] : false; $address['city'] = !empty($data['address_city']) ? $data['address_city'] : false; $address['state'] = !empty($data['address_state']) ? $data['address_state'] : false; $address['country'] = !empty($data['address_country_code']) ? $data['address_country_code'] : false; $address['zip'] = !empty($data['address_zip']) ? $data['address_zip'] : false; $user_info = array('id' => '-1', 'email' => $data['payer_email'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'discount' => '', 'address' => $address); $payment_meta = get_post_meta($payment_id, '_edd_payment_meta', true); $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); } 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 ($payment_status == 'completed' || 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'); } } }
/** * Retrieve payments. * * The query can be modified in two ways; either the action before the * query is run, or the filter on the arguments (existing mainly for backwards * compatibility). * * @access public * @since 1.8 * @return object */ public function get_payments() { do_action('edd_pre_get_payments', $this); $query = new WP_Query($this->args); if ('payments' != $this->args['output']) { return $query->posts; } if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $details = new stdClass(); $payment_id = get_post()->ID; $details->ID = $payment_id; $details->date = get_post()->post_date; $details->post_status = get_post()->post_status; $details->total = edd_get_payment_amount($payment_id); $details->subtotal = edd_get_payment_subtotal($payment_id); $details->tax = edd_get_payment_tax($payment_id); $details->fees = edd_get_payment_fees($payment_id); $details->key = edd_get_payment_key($payment_id); $details->gateway = edd_get_payment_gateway($payment_id); $details->user_info = edd_get_payment_meta_user_info($payment_id); $details->cart_details = edd_get_payment_meta_cart_details($payment_id, true); if (edd_get_option('enable_sequential')) { $details->payment_number = edd_get_payment_number($payment_id); } $this->payments[] = apply_filters('edd_payment', $details, $payment_id, $this); } wp_reset_postdata(); } do_action('edd_post_get_payments', $this); return $this->payments; }
function edd_downloads_upgrade_license($license_id, $d_id, $payment_id, $type) { $payment_meta = edd_get_payment_meta($payment_id); if (empty($payment_meta)) { return true; } $remove = 0; foreach ($payment_meta['cart_details'] as $product) { if (isset($product['item_number']['upgrade']) && !empty($product['item_number']['upgrade'])) { $remove = 1; $old_attachment_id = absint($product['item_number']['upgrade']['old_attachment_id']); $new_attachment_id = absint($product['item_number']['upgrade']['new_attachment_id']); $old_product = absint($product['item_number']['upgrade']['old_product']); //$old_product = get_post_meta( $product['item_number']['upgrade']['upgrade_license'], '_edd_sl_download_id', true ); $payment_id_lic = get_post_meta($product['item_number']['upgrade']['upgrade_license'], '_edd_sl_payment_id', true); $upgrade_meta = edd_get_payment_meta(absint($payment_id_lic)); //$redirect_key = get_post_meta( $product['item_number']['upgrade']['upgrade_license'], '_edd_payment_purchase_key', true ); $payment_key = edd_get_payment_key(absint($payment_id_lic)); $new_product = get_post($product['item_number']['upgrade']['upgrade_product_to']); if (isset($upgrade_meta['downloads'])) { foreach ($upgrade_meta['downloads'] as $row => $download) { //$log .= $download['id'] ."==". $old_product; if ($download['id'] == $old_product) { $upgrade_meta['downloads'][$row]['id'] = $product['item_number']['upgrade']['upgrade_product_to']; if (isset($product['item_number']['upgrade']['options']) && !empty($product['item_number']['upgrade']['options'])) { $upgrade_meta['downloads'][$row]['options'] = $product['item_number']['upgrade']['options']; } else { $upgrade_meta['downloads'][$row]['options'] = array(); } if (isset($upgrade_meta['downloads'][$row]['upgrade'])) { unset($upgrade_meta['downloads'][$row]['upgrade']); } $upgrade_meta['cart_details'][$row]['name'] = $new_product->post_title; $upgrade_meta['cart_details'][$row]['id'] = $product['item_number']['upgrade']['upgrade_product_to']; $upgrade_meta['cart_details'][$row]['item_number']['id'] = $product['item_number']['upgrade']['upgrade_product_to']; if (isset($payment_meta['cart_details'])) { foreach ($payment_meta['cart_details'] as $row_payment => $payment) { if ($old_product == $payment['item_number']['upgrade']['old_product']) { $upgrade_meta['cart_details'][$row]['item_price'] = $payment['item_price']; $upgrade_meta['cart_details'][$row]['quantity'] = $payment['quantity']; $upgrade_meta['cart_details'][$row]['discount'] = $payment['discount']; $upgrade_meta['cart_details'][$row]['subtotal'] = $payment['subtotal']; $upgrade_meta['cart_details'][$row]['tax'] = $payment['tax']; $upgrade_meta['cart_details'][$row]['price'] = $payment['price']; } } } if (isset($product['item_number']['upgrade']['options']) && !empty($product['item_number']['upgrade']['options'])) { $upgrade_meta['cart_details'][$row]['item_number']['options'] = $product['item_number']['upgrade']['options']; } else { $upgrade_meta['cart_details'][$row]['item_number']['options'] = array(); } if (isset($upgrade_meta['cart_details'][$row]['item_number']['upgrade'])) { unset($upgrade_meta['cart_details'][$row]['item_number']['upgrade']); } } } } $sites = edd_software_licensing()->get_sites($product['item_number']['upgrade']['upgrade_license']); if (array_key_exists($old_attachment_id, $sites)) { $update_sites = $sites[$old_attachment_id]; unset($sites[$old_attachment_id]); $sites[$new_attachment_id] = $update_sites; update_post_meta($product['item_number']['upgrade']['upgrade_license'], '_edd_sl_sites', $sites); } update_post_meta($payment_id_lic, 'edd_price', $product['item_number']['upgrade']['upgrade_price']); update_post_meta($payment_id_lic, '_edd_payment_total', $product['item_number']['upgrade']['upgrade_price']); update_post_meta($payment_id_lic, '_edd_payment_meta', $upgrade_meta); // Store the updated user ID in the payment meta update_post_meta($product['item_number']['upgrade']['upgrade_license'], '_edd_sl_download_id', $product['item_number']['upgrade']['upgrade_product_to']); } } if ($remove == 1) { wp_delete_post($license_id); wp_delete_post($payment_id); //delete_post_meta( $post_id, $field ); global $wpdb; $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "postmeta WHERE post_id = %d OR post_id = %d", $license_id, $payment_id)); } return true; }
/** * Email template tag: unsubscribe (for plaintext emails only) * An unsubscribe link for customers to opt-out of future product updates * * @access public * @param mixed $payment_id * @return void */ function edd_pup_unsub_tag_plain($payment_id) { $purchase_data = get_post_meta($payment_id, '_edd_payment_meta', true); $unsub_link_params = array('order_id' => $payment_id, 'email' => rawurlencode($purchase_data['user_info']['email']), 'purchase_key' => isset($purchase_data['key']) ? $purchase_data['key'] : edd_get_payment_key($payment_id), 'edd_action' => 'prod_update_unsub'); return add_query_arg($unsub_link_params, '' . home_url()); }
<?php if (!isset($_GET['order_id'])) { _e('Access Denied', 'edd_fes'); return; } $key = edd_get_payment_key($_GET['order_id']); if (EDD_FES()->vendors->vendor_can_view_receipt(false, $key)) { do_action('fes_above_vendor_receipt'); echo '<h1 class="fes-headers" id="fes-edit-order-page-title">' . __('Order: #', 'edd_fes') . $_GET['order_id'] . '</h1>'; echo do_shortcode('[edd_receipt payment_key=' . $key . ']'); do_action('fes_below_vendor_receipt'); } else { _e('Access Denied', 'edd_fes'); }
esc_attr_e('Extend license', 'edd_sl'); ?> "><?php _e('Extend license', 'edd_sl'); ?> </a> <?php } ?> <?php } ?> </td> <td> <a href="<?php echo esc_url(edd_get_success_page_url('?payment_key=' . edd_get_payment_key($payment_id))); ?> " title="<?php esc_attr_e('View Purchase Record', 'edd_sl'); ?> ">#<?php echo edd_get_payment_number($payment_id); ?> </a> </td> <?php do_action('edd_sl_license_keys_row_end', $license->ID); ?> </tr> <?php }
/** * 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; }
/** * 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; }
/** * Charge a preapproved payment * * @since 1.6 * @return bool */ function edds_charge_preapproved($payment_id = 0) { global $edd_options; if (empty($payment_id)) { return false; } $customer_id = get_post_meta($payment_id, '_edds_stripe_customer_id', true); if (empty($customer_id) || empty($payment_id)) { return; } if ('preapproval' !== get_post_status($payment_id)) { return; } if (!class_exists('Stripe')) { require_once EDDS_PLUGIN_DIR . '/Stripe/Stripe.php'; } $secret_key = edd_is_test_mode() ? trim($edd_options['test_secret_key']) : trim($edd_options['live_secret_key']); Stripe::setApiKey($secret_key); if (edds_is_zero_decimal_currency()) { $amount = edd_get_payment_amount($payment_id); } else { $amount = edd_get_payment_amount($payment_id) * 100; } try { $charge = Stripe_Charge::create(array("amount" => $amount, "currency" => edd_get_currency(), "customer" => $customer_id, "description" => sprintf(__('Preappoved charge for purchase %s from %s', 'edds'), edd_get_payment_key($payment_id), home_url()))); } catch (Stripe_CardError $e) { $body = $e->getJsonBody(); $err = $body['error']; $error_message = isset($err['message']) ? $err['message'] : __('There was an error processing this charge', 'edds'); } catch (Stripe_ApiConnectionError $e) { $body = $e->getJsonBody(); $err = $body['error']; $error_message = isset($err['message']) ? $err['message'] : __('There was an error processing this charge', 'edds'); } catch (Stripe_InvalidRequestError $e) { $body = $e->getJsonBody(); $err = $body['error']; $error_message = isset($err['message']) ? $err['message'] : __('There was an error processing this charge', 'edds'); } catch (Stripe_ApiError $e) { $body = $e->getJsonBody(); $err = $body['error']; $error_message = isset($err['message']) ? $err['message'] : __('There was an error processing this charge', 'edds'); } catch (Stripe_AuthenticationError $e) { $body = $e->getJsonBody(); $err = $body['error']; $error_message = isset($err['message']) ? $err['message'] : __('There was an error processing this charge', 'edds'); } catch (Stripe_Error $e) { $body = $e->getJsonBody(); $err = $body['error']; $error_message = isset($err['message']) ? $err['message'] : __('There was an error processing this charge', 'edds'); } catch (Exception $e) { // some sort of other error $body = $e->getJsonBody(); $err = $body['error']; $error_message = isset($err['message']) ? $err['message'] : __('There was an error processing this charge', 'edds'); } if (!empty($charge)) { edd_insert_payment_note($payment_id, 'Stripe Charge ID: ' . $charge->id); edd_update_payment_status($payment_id, 'publish'); delete_post_meta($payment_id, '_edds_stripe_customer_id'); return true; } else { edd_insert_payment_note($payment_id, $error_message); return false; } }
/** * Refund a charge in Amazon * * @access public * @since 2.4 * @param $payment_id int The ID number of the payment being refunded * @return string */ private function refund($payment_id = 0) { $refund = $this->client->refund(array('merchant_id' => edd_get_option('amazon_seller_id', ''), 'amazon_capture_id' => edd_get_payment_meta($payment_id, '_edd_amazon_capture_id', true), 'refund_reference_id' => md5(edd_get_payment_key($payment_id) . '-refund'), 'refund_amount' => edd_get_payment_amount($payment_id), 'currency_code' => edd_get_payment_currency_code($payment_id))); if (200 == $refund->response['Status']) { $refund = new ResponseParser($refund->response); $refund = $refund->toArray(); $reference_id = $refund['RefundResult']['RefundDetails']['RefundReferenceId']; $status = $refund['RefundResult']['RefundDetails']['RefundStatus']['State']; switch ($status) { case 'Declined': $code = $refund['RefundResult']['RefundDetails']['RefundStatus']['ReasonCode']; $note = __('Refund declined in Amazon. Refund ID: %s', 'edd'); break; case 'Completed': $refund_id = $refund['RefundResult']['RefundDetails']['AmazonRefundId']; $note = sprintf(__('Refund completed in Amazon. Refund ID: %s', 'edd'), $refund_id); break; case 'Pending': $note = sprintf(__('Refund initiated in Amazon. Reference ID: %s', 'edd'), $reference_id); break; } edd_insert_payment_note($payment_id, $note); } else { edd_insert_payment_note($payment_id, __('Refund request failed in Amazon.', 'edd')); } }
<span class="edd_purchase_status <?php echo $payment->post_status; ?> "><?php echo edd_get_payment_status($payment, true); ?> </span> <a href="<?php echo esc_url(add_query_arg('payment_key', edd_get_payment_key($payment->ID), edd_get_success_page_uri())); ?> ">»</a> <?php } else { ?> <a href="<?php echo esc_url(add_query_arg('payment_key', edd_get_payment_key($payment->ID), edd_get_success_page_uri('single-order'))); ?> "><?php _e('<img src="' . get_site_url() . '/wp-content/plugins/edd-service-extended/includes/images/page_view.png" alt="HTML5 Icon" width="30" height="30" align="center">', 'easy-digital-downloads'); ?> </a> <?php } ?> </td> <?php } // End if ! edd_no_redownload() do_action('edd_download_history_row_end', $payment->ID, $download['id']); ?> </tr>
function edd_userpro_embed_profile_fields($hook_args) { if (!current_user_can('edit_user', $hook_args['user_id'])) { return; } echo '<div class="userpro-section userpro-column userpro-collapsible-1 userpro-collapsed-1">' . __('Purchase History', 'edd-userpro-embed') . '</div>'; echo '<div class="userpro-field userpro-field-edd-purchase-history userpro-field-view" data-key="edd-purchase-history">'; $purchases = edd_get_users_purchases($hook_args['user_id'], 99999, true, 'any'); if ($purchases) { do_action('edd_before_purchase_history'); ?> <table id="edd_user_history"> <thead> <tr class="edd_purchase_row"> <?php do_action('edd_purchase_history_header_before'); ?> <th class="edd_purchase_id"><?php _e('ID', 'easy-digital-downloads'); ?> </th> <th class="edd_purchase_date"><?php _e('Date', 'easy-digital-downloads'); ?> </th> <th class="edd_purchase_amount"><?php _e('Amount', 'easy-digital-downloads'); ?> </th> <th class="edd_purchase_details"><?php _e('Details', 'easy-digital-downloads'); ?> </th> <?php do_action('edd_purchase_history_header_after'); ?> </tr> </thead> <?php foreach ($purchases as $post) { setup_postdata($post); ?> <?php $purchase_data = edd_get_payment_meta($post->ID); ?> <tr class="edd_purchase_row"> <?php do_action('edd_purchase_history_row_start', $post->ID, $purchase_data); ?> <td class="edd_purchase_id">#<?php echo edd_get_payment_number($post->ID); ?> </td> <td class="edd_purchase_date"><?php echo date_i18n(get_option('date_format'), strtotime(get_post_field('post_date', $post->ID))); ?> </td> <td class="edd_purchase_amount"> <span class="edd_purchase_amount"><?php echo edd_currency_filter(edd_format_amount(edd_get_payment_amount($post->ID))); ?> </span> </td> <td class="edd_purchase_details"> <?php if ($post->post_status != 'publish') { ?> <span class="edd_purchase_status <?php echo $post->post_status; ?> "><?php echo edd_get_payment_status($post, true); ?> </span> <a href="<?php echo esc_url(add_query_arg('payment_key', edd_get_payment_key($post->ID), edd_get_success_page_uri())); ?> ">»</a> <?php } else { ?> <a href="<?php echo esc_url(add_query_arg('payment_key', edd_get_payment_key($post->ID), edd_get_success_page_uri())); ?> "><?php _e('View Details', 'edd-userpro-embed'); ?> </a> <?php } ?> </td> <?php do_action('edd_purchase_history_row_end', $post->ID, $purchase_data); ?> </tr> <?php } ?> </table> <?php do_action('edd_after_purchase_history'); ?> <?php wp_reset_postdata(); ?> <?php } else { ?> <p class="edd-no-purchases"><?php _e('You have not made any purchases', 'edd-userpro-embed'); ?> </p> <?php } echo '</div>'; }
$user_can_view = is_user_logged_in() && $edd_payment_user_id == get_current_user_id() || current_user_can('view_shop_sensitive_data'); if (!$user_can_view) { ?> <h2>You do not have permission to view this licence</h2> <?php } else { ?> <h2>Generate OSGi Licence</h2> <?php if (isset($edd_payment_post_id)) { ?> <p> <a href="<?php echo add_query_arg('payment_key', edd_get_payment_key($edd_payment_post_id), edd_get_success_page_uri()); ?> ">Link to Payment Receipt: <?php echo edd_get_payment_number($edd_payment_post_id); ?> </a> <p> <?php } ?> <h2>Licence Metadata</h2> <form method="post" action="" enctype="multipart/form-data"> <?php
/** * Email template tag: receipt_link * Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly * * @since 1.0.0 * @param int $payment_id * @return string receipt_link */ function edd_wallet_email_tag_receipt_link($payment_id) { if (get_post_type($payment_id) == 'edd_payment') { return sprintf(__('%1$sView it in your browser.%2$s', 'edd-wallet'), '<a href="' . esc_url(add_query_arg(array('payment_key' => edd_get_payment_key($payment_id), 'edd_action' => 'view_receipt'), home_url())) . '">', '</a>'); } else { return ''; } }
/** * Campaign Contributinos * * @since Astoundify Crowdfunding 1.4 * * @return void */ function atcf_shortcode_profile_contributions($user) { global $edd_options; $contributions = edd_get_payments(array('user' => $user->ID, 'status' => atcf_has_preapproval_gateway() ? array('preapproval', 'publish') : 'publish', 'mode' => edd_is_test_mode() ? 'test' : 'live')); if (empty($contributions)) { return; } ?> <h3 class="atcf-profile-section your-campaigns"><?php _e('Your Contributions', 'atcf'); ?> </h3> <ul class="atcf-profile-contributinos"> <?php foreach ($contributions as $contribution) { ?> <?php $payment_data = edd_get_payment_meta($contribution->ID); $cart = edd_get_payment_meta_cart_details($contribution->ID); $key = edd_get_payment_key($contribution->ID); ?> <?php if ($cart) { ?> <li> <?php foreach ($cart as $download) { ?> <?php printf(_x('<a href="%s">%s</a> pledge to <a href="%s">%s</a>', 'price for download (payment history)', 'atcf'), add_query_arg('payment_key', $key, get_permalink($edd_options['success_page'])), edd_currency_filter(edd_format_amount($download['price'])), get_permalink($download['id']), $download['name']); ?> <?php } ?> </li> <?php } ?> <?php } ?> </ul> <?php }
/** * 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); } } } } }
/** * Email template tag: receipt_link * Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly * * @param $payment_id int * * @return string receipt_link */ function edd_email_tag_receipt_link($payment_id) { $receipt_url = esc_url(add_query_arg(array('payment_key' => edd_get_payment_key($payment_id), 'edd_action' => 'view_receipt'), home_url())); $formatted = sprintf(__('%1$sView it in your browser %2$s', 'edd'), '<a href="' . $receipt_url . '">', '»</a>'); if (edd_get_option('email_template') !== 'none') { return $formatted; } else { return $receipt_url; } }
/** * Mark a payment as shipped. * * @since 2.0 * * @return void */ function frontend_toggle_shipped_status() { $payment_id = absint($_GET['order_id']); $status = !empty($_GET['new_status']) ? absint($_GET['new_status']) : '1'; $key = edd_get_payment_key($payment_id); if (function_exists('EDD_FES')) { if (!EDD_FES()->vendors->vendor_can_view_receipt(false, $key)) { wp_safe_redirect(wp_get_referer()); exit; } } update_post_meta($payment_id, '_edd_payment_shipping_status', $status); wp_safe_redirect(wp_get_referer()); exit; }
/** * Process web accept (one time) payment IPNs * * @since 1.3.4 * @global $edd_options Array of all the EDD Options * @param array $data IPN Data * @return void */ function edd_process_paypal_web_accept($data) { global $edd_options; if ($data['txn_type'] != 'web_accept') { return; } // Collect payment details $payment_id = $data['custom']; $purchase_key = $data['item_number']; $paypal_amount = $data['mc_gross']; $payment_status = strtolower($data['payment_status']); $currency_code = strtolower($data['mc_currency']); // Retrieve the meta info for this payment $payment_amount = edd_format_amount(edd_get_payment_amount($payment_id)); if (get_post_status($payment_id) == 'complete') { return; } // Only complete payments once if (edd_get_payment_gateway($payment_id) != 'paypal') { return; } // this isn't a PayPal standard IPN // Verify details if ($currency_code != strtolower(edd_get_currency())) { // The currency code is invalid edd_record_gateway_error(__('IPN Error', 'edd'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'edd'), json_encode($data)), $payment_id); edd_update_payment_status($payment_id, 'failed'); return; } if ($payment_status == 'refunded') { // Process a refund edd_process_paypal_refund($data); } else { if (number_format((double) $paypal_amount, 2) != $payment_amount) { // The prices don't match edd_record_gateway_error(__('IPN Error', 'edd'), sprintf(__('Invalid payment amount in IPN response. IPN data: ', 'edd'), json_encode($data)), $payment_id); //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: ', 'edd'), json_encode($data)), $payment_id); edd_update_payment_status($payment_id, 'failed'); return; } if ($payment_status == 'completed' || edd_is_test_mode()) { edd_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'edd'), $data['txn_id'])); edd_update_payment_status($payment_id, 'publish'); } } }