Esempio n. 1
0
 /**
  * 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);
 }
 * @since 1.6
 * @return void
*/
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    wp_die(__('Payment ID not supplied. Please try again', 'edd'), __('Error', 'edd'));
}
// Setup the variables
$payment_id = absint($_GET['id']);
$number = edd_get_payment_number($payment_id);
$item = get_post($payment_id);
// Sanity check... fail if purchase ID is invalid
if (!is_object($item) || $item->post_type != 'edd_payment') {
    wp_die(__('The specified ID does not belong to a payment. Please try again', 'edd'), __('Error', 'edd'));
}
$payment_meta = edd_get_payment_meta($payment_id);
$transaction_id = esc_attr(edd_get_payment_transaction_id($payment_id));
$cart_items = edd_get_payment_meta_cart_details($payment_id);
$user_id = edd_get_payment_user_id($payment_id);
$customer_id = edd_get_payment_customer_id($payment_id);
$payment_date = strtotime($item->post_date);
$unlimited = edd_payment_has_unlimited_downloads($payment_id);
$user_info = edd_get_payment_meta_user_info($payment_id);
$address = !empty($user_info['address']) ? $user_info['address'] : array('line1' => '', 'line2' => '', 'city' => '', 'country' => '', 'state' => '', 'zip' => '');
$gateway = edd_get_payment_gateway($payment_id);
$currency_code = edd_get_payment_currency_code($payment_id);
?>
<div class="wrap edd-wrap">
	<h2><?php 
printf(__('Payment %s', 'edd'), $number);
?>
</h2>
 /**
  * Get the Export Data
  *
  * @access public
  * @since 2.4
  * @global object $wpdb Used to query the database using the WordPress
  *   Database API
  * @return array $data The data for the CSV file
  */
 public function get_data()
 {
     global $wpdb;
     $data = array();
     $args = array('number' => 30, 'page' => $this->step, 'status' => $this->status);
     if (!empty($this->start) || !empty($this->end)) {
         $args['date_query'] = array(array('after' => date('Y-n-d H:i:s', strtotime($this->start)), 'before' => date('Y-n-d H:i:s', strtotime($this->end)), 'inclusive' => true));
     }
     //echo json_encode($args ); exit;
     $payments = edd_get_payments($args);
     if ($payments) {
         foreach ($payments as $payment) {
             $payment_meta = edd_get_payment_meta($payment->ID);
             $user_info = edd_get_payment_meta_user_info($payment->ID);
             $downloads = edd_get_payment_meta_cart_details($payment->ID);
             $total = edd_get_payment_amount($payment->ID);
             $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email'];
             $products = '';
             $skus = '';
             if ($downloads) {
                 foreach ($downloads as $key => $download) {
                     // Download ID
                     $id = isset($payment_meta['cart_details']) ? $download['id'] : $download;
                     // If the download has variable prices, override the default price
                     $price_override = isset($payment_meta['cart_details']) ? $download['price'] : null;
                     $price = edd_get_download_final_price($id, $user_info, $price_override);
                     // Display the Downoad Name
                     $products .= get_the_title($id) . ' - ';
                     if (edd_use_skus()) {
                         $sku = edd_get_download_sku($id);
                         if (!empty($sku)) {
                             $skus .= $sku;
                         }
                     }
                     if (isset($downloads[$key]['item_number']) && isset($downloads[$key]['item_number']['options'])) {
                         $price_options = $downloads[$key]['item_number']['options'];
                         if (isset($price_options['price_id'])) {
                             $products .= edd_get_price_option_name($id, $price_options['price_id'], $payment->ID) . ' - ';
                         }
                     }
                     $products .= html_entity_decode(edd_currency_filter($price));
                     if ($key != count($downloads) - 1) {
                         $products .= ' / ';
                         if (edd_use_skus()) {
                             $skus .= ' / ';
                         }
                     }
                 }
             }
             if (is_numeric($user_id)) {
                 $user = get_userdata($user_id);
             } else {
                 $user = false;
             }
             $data[] = array('id' => $payment->ID, 'seq_id' => edd_get_payment_number($payment->ID), 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', 'products' => $products, 'skus' => $skus, 'amount' => html_entity_decode(edd_format_amount($total)), 'tax' => html_entity_decode(edd_format_amount(edd_get_payment_tax($payment->ID, $payment_meta))), 'discount' => isset($user_info['discount']) && $user_info['discount'] != 'none' ? $user_info['discount'] : __('none', 'edd'), 'gateway' => edd_get_gateway_admin_label(get_post_meta($payment->ID, '_edd_payment_gateway', true)), 'trans_id' => edd_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'edd'), 'status' => edd_get_payment_status($payment, true));
         }
         $data = apply_filters('edd_export_get_data', $data);
         $data = apply_filters('edd_export_get_data_' . $this->export_type, $data);
         return $data;
     }
     return false;
 }
	/**
	 * 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;
	}
 * @since 1.6
 * @return void
*/
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    wp_die(__('Payment ID not supplied. Please try again', 'edd'), __('Error', 'edd'));
}
// Setup the variables
$payment_id = absint($_GET['id']);
$number = edd_get_payment_number($payment_id);
$item = get_post($payment_id);
// Sanity check... fail if purchase ID is invalid
if (!is_object($item) || $item->post_type != 'edd_payment') {
    wp_die(__('The specified ID does not belong to a payment. Please try again', 'edd'), __('Error', 'edd'));
}
$payment_meta = edd_get_payment_meta($payment_id);
$transaction_id = edd_get_payment_transaction_id($payment_id);
$cart_items = edd_get_payment_meta_cart_details($payment_id);
$user_id = edd_get_payment_user_id($payment_id);
$payment_date = strtotime($item->post_date);
$unlimited = edd_payment_has_unlimited_downloads($payment_id);
$user_info = edd_get_payment_meta_user_info($payment_id);
$address = !empty($user_info['address']) ? $user_info['address'] : array('line1' => '', 'line2' => '', 'city' => '', 'country' => '', 'state' => '', 'zip' => '');
?>
<div class="wrap edd-wrap">
	<h2><?php 
printf(__('Payment %s', 'edd'), $number);
?>
</h2>
	<?php 
do_action('edd_view_order_details_before', $payment_id);
?>
/**
 * Create license key
 *
 * @since 1.0.0
 * @return void
 */
function edd_slm_create_license_keys($payment_id)
{
    // Collect license keys
    $licenses = array();
    // Payment meta
    $payment_meta = edd_get_payment_meta($payment_id);
    //edd_slm_print_pretty($payment_meta);
    foreach ($payment_meta['cart_details'] as $item) {
        $download_id = $item['id'];
        if (edd_slm_is_licensing_enabled($download_id)) {
            // Download data
            $download_data = edd_get_download($download_id);
            if ($download_data) {
                $download_quantity = absint($item['quantity']);
                for ($i = 1; $i <= $download_quantity; $i++) {
                    // Get price id
                    $price_id = edd_get_cart_item_price_id($item);
                    $price_name = edd_get_cart_item_price_name($item);
                    // Sites allowed
                    $sites_allowed = edd_slm_get_sites_allowed($price_id, $payment_id, $download_id);
                    if (!$sites_allowed) {
                        $sites_allowed_error = __('License could not be created: Invalid sites allowed number.', 'edd-slm');
                        $int = edd_insert_payment_note($payment_id, $sites_allowed_error);
                        break;
                    }
                    // Transaction id
                    $transaction_id = edd_get_payment_transaction_id($payment_id);
                    // Build item name
                    $item_name = !empty($price_name) ? $item['name'] . ' - ' . $price_name : $item['name'];
                    // Build parameters
                    $api_params = array();
                    $api_params['slm_action'] = 'slm_create_new';
                    $api_params['secret_key'] = EDD_SLM_API_SECRET;
                    $api_params['first_name'] = isset($payment_meta['user_info']['first_name']) ? $payment_meta['user_info']['first_name'] : '';
                    $api_params['last_name'] = isset($payment_meta['user_info']['last_name']) ? $payment_meta['user_info']['last_name'] : '';
                    $api_params['email'] = isset($payment_meta['user_info']['email']) ? $payment_meta['user_info']['email'] : '';
                    $api_params['company_name'] = '';
                    $api_params['txn_id'] = $transaction_id . ' - ' . $item_name;
                    $api_params['max_allowed_domains'] = $sites_allowed;
                    $api_params['date_created'] = date('Y-m-d');
                    $api_params['date_expiry'] = '0000-00-00';
                    // Send query to the license manager server
                    $url = EDD_SLM_API_URL . '?' . http_build_query($api_params);
                    $response = wp_remote_get($url, array('timeout' => 30));
                    edd_slm_add_log('Item: ' . $item_name);
                    edd_slm_add_log('- SLM Response Body: ' . $response['body']);
                    foreach ($response['response'] as $key => $value) {
                        edd_slm_add_log('- SLM Response ' . $key . ': ' . $value);
                    }
                    // Get license key
                    $license_key = edd_slm_get_license_key($response);
                    // Collect license keys
                    if ($license_key) {
                        $licenses[] = array('item' => $item_name, 'key' => $license_key);
                    }
                }
            }
        }
    }
    // Payment note
    edd_slm_payment_note($payment_id, $licenses);
    // Assign licenses
    edd_slm_assign_licenses($payment_id, $licenses);
}