コード例 #1
1
 /**
  * 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;
 }
 /**
  * Output column data
  *
  * @access      private
  * @since       1.4
  * @return      string
  */
 function column_default($item, $column_name)
 {
     switch ($column_name) {
         case 'error':
             return get_the_title($item['ID']) ? get_the_title($item['ID']) : __('Payment Error', 'edd');
         case 'gateway':
             return edd_get_payment_gateway($item['payment_id']);
         case 'buyer':
             $user = !empty($item['user_id']) ? $item['user_id'] : $item['buyer'];
             return '<a href="' . admin_url('edit.php?post_type=download&page=edd-payment-history&user='******'">' . $item['buyer'] . '</a>';
         default:
             return $item[$column_name];
     }
 }
コード例 #3
0
/**
 * Load our admin javascript
 *
 * @access      public
 * @since       1.8
 * @return      void
 */
function edd_stripe_admin_js($payment_id = 0)
{
    if ('stripe' !== edd_get_payment_gateway($payment_id)) {
        return;
    }
    ?>
	<script type="text/javascript">
		jQuery(document).ready(function($) {
			$('select[name=edd-payment-status]').change(function() {

				if( 'refunded' == $(this).val() ) {

					$(this).parent().parent().append( '<input type="checkbox" id="edd_refund_in_stripe" name="edd_refund_in_stripe" value="1"/>' );
					$(this).parent().parent().append( '<label for="edd_refund_in_stripe">Refund Charge in Stripe</label>' );

				}

			});
		});
	</script>
<?php 
}
コード例 #4
0
    /**
     * Render the details column
     *
     * @access      private
     * @since       1.3.4
     * @return      string
     */
    function column_details($item)
    {
        $details = "<a href='#TB_inline?width=640&amp;inlineId=purchased-files-" . $item['ID'] . "' class='thickbox' title='" . sprintf(__('Purchase Details for Payment #%s', 'edd'), $item['ID']) . "'>" . __('View Order Details', 'edd') . "</a>";
        ob_start();
        ?>
			<div id="purchased-files-<?php 
        echo $item['ID'];
        ?>
" style="display: none;">
				<?php 
        $payment_meta = edd_get_payment_meta($item['ID']);
        $cart_items = isset($payment_meta['cart_details']) ? maybe_unserialize($payment_meta['cart_details']) : false;
        if (empty($cart_items) || !$cart_items) {
            $cart_items = maybe_unserialize($payment_meta['downloads']);
        }
        ?>
				<h4><?php 
        echo _n(__('Purchased File', 'edd'), __('Purchased Files', 'edd'), count($cart_items));
        ?>
</h4>
				<ul class="purchased-files-list">
				<?php 
        if ($cart_items) {
            foreach ($cart_items as $key => $cart_item) {
                echo '<li>';
                // Retrieve the ID of the download
                $id = isset($payment_meta['cart_details']) ? $cart_item['id'] : $cart_item;
                // If download has variable prices, override the default price
                $price_override = isset($payment_meta['cart_details']) ? $cart_item['price'] : null;
                // Get the user information
                $user_info = edd_get_payment_meta_user_info($item['ID']);
                // Calculate the final item price
                $price = edd_get_download_final_price($id, $user_info, $price_override);
                // Show name of download
                echo '<a href="' . admin_url('post.php?post=' . $id . '&action=edit') . '" target="_blank">' . get_the_title($id) . '</a>';
                echo ' - ';
                if (isset($cart_items[$key]['item_number'])) {
                    $price_options = $cart_items[$key]['item_number']['options'];
                    if (isset($price_options['price_id'])) {
                        echo edd_get_price_option_name($id, $price_options['price_id']);
                        echo ' - ';
                    }
                }
                // Show the price
                echo edd_currency_filter(edd_format_amount($price));
                echo '</li>';
            }
        }
        ?>
				</ul>
				<?php 
        $payment_date = strtotime($item['date']);
        ?>
				<p><?php 
        echo __('Date and Time:', 'edd') . ' ' . date_i18n(get_option('date_format'), $payment_date) . ' ' . date_i18n(get_option('time_format'), $payment_date);
        ?>
				<p><?php 
        echo __('Discount used:', 'edd') . ' ';
        if (isset($user_info['discount']) && $user_info['discount'] != 'none') {
            echo $user_info['discount'];
        } else {
            _e('none', 'edd');
        }
        ?>
				<p><?php 
        echo __('Total:', 'edd') . ' ' . edd_currency_filter(edd_format_amount(edd_get_payment_amount($item['ID'])));
        ?>
</p>

				<div class="purcase-personal-details">
					<h4><?php 
        _e('Buyer\'s Personal Details:', 'edd');
        ?>
</h4>
					<ul>
						<li><?php 
        echo __('Name:', 'edd') . ' ' . $user_info['first_name'] . ' ' . $user_info['last_name'];
        ?>
</li>
						<li><?php 
        echo __('Email:', 'edd') . ' ' . $payment_meta['email'];
        ?>
</li>
						<?php 
        do_action('edd_payment_personal_details_list', $payment_meta, $user_info);
        ?>
					</ul>
				</div>
				<div class="payment-notes">
					<h4><?php 
        _e('Payment Notes', 'edd');
        ?>
</h4>
					<?php 
        $notes = edd_get_payment_notes($item['ID']);
        if (!empty($notes)) {
            echo '<ul id="payment-notes">';
            foreach ($notes as $note) {
                if (!empty($note->user_id)) {
                    $user = get_userdata($note->user_id);
                    $user = $user->display_name;
                } else {
                    $user = __('EDD Bot', 'edd');
                }
                echo '<div class="edd-payment-note"><strong>' . $user . '</strong>&nbsp;<em>' . $note->comment_date . '</em>&nbsp;&mdash;' . $note->comment_content . '</div>';
            }
            echo '</ul>';
        } else {
            echo '<p>' . __('No payment notes', 'edd') . '</p>';
        }
        ?>
				</div>
				<?php 
        $gateway = edd_get_payment_gateway($item['ID']);
        if ($gateway) {
            ?>
				<div class="payment-method">
					<h4><?php 
            _e('Payment Method:', 'edd');
            ?>
</h4>
					<span class="payment-method-name"><?php 
            echo edd_get_gateway_admin_label($gateway);
            ?>
</span>
				</div>
				<?php 
        }
        ?>
				<div class="purchase-key-wrap">
					<h4><?php 
        _e('Purchase Key', 'edd');
        ?>
</h4>
					<span class="purchase-key"><?php 
        echo $payment_meta['key'];
        ?>
</span>
				</div>
				<p><a id="edd-close-purchase-details" class="button-secondary" onclick="tb_remove();" title="<?php 
        _e('Close', 'edd');
        ?>
"><?php 
        _e('Close', 'edd');
        ?>
</a></p>
			</div>
<?php 
        $details .= ob_get_clean();
        return $details;
    }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
/**
 * 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);
                }
            }
        }
    }
}
コード例 #7
0
								<h3 class="hndle">
									<span><?php 
_e('Payment Meta', 'edd');
?>
</span>
								</h3>
								<div class="inside">
									<div class="edd-admin-box">

										<?php 
do_action('edd_view_order_details_payment_meta_before', $payment_id);
?>

										<?php 
$gateway = edd_get_payment_gateway($payment_id);
if ($gateway) {
    ?>
											<div class="edd-order-gateway edd-admin-box-inside">
												<p>
													<span class="label"><?php 
    _e('Gateway:', 'edd');
    ?>
</span>&nbsp;
													<?php 
    echo edd_get_gateway_admin_label($gateway);
    ?>
												</p>
											</div>
										<?php 
}
コード例 #8
0
/**
 * Retrieves the transaction ID for the given payment
 *
 * @since  2.1
 * @param int payment_id Payment ID
 * @return string The Transaction ID
 */
function edd_get_payment_transaction_id($payment_id = 0)
{
    $transaction_id = false;
    $transaction_id = edd_get_payment_meta($payment_id, '_edd_payment_transaction_id', true);
    if (empty($transaction_id)) {
        $gateway = edd_get_payment_gateway($payment_id);
        $transaction_id = apply_filters('edd_get_payment_transaction_id-' . $gateway, $payment_id);
    }
    return apply_filters('edd_get_payment_transaction_id', $transaction_id, $payment_id);
}
コード例 #9
0
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since 1.4
  * @global object $edd_logs EDD Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 public function get_logs()
 {
     global $edd_logs;
     // Prevent the queries from getting cached. Without this there are occasional memory issues for some installs
     wp_suspend_cache_addition(true);
     $logs_data = array();
     $paged = $this->get_paged();
     $log_query = array('log_type' => 'gateway_error', 'paged' => $paged);
     $logs = $edd_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $logs_data[] = array('ID' => $log->ID, 'payment_id' => $log->post_parent, 'error' => 'error', 'gateway' => edd_get_payment_gateway($log->post_parent), 'date' => $log->post_date);
         }
     }
     return $logs_data;
 }
コード例 #10
0
/**
 * Email template tag: payment_method
 * The method of payment used for this purchase
 *
 * @param int $payment_id
 *
 * @return string gateway
 */
function edd_email_tag_payment_method($payment_id)
{
    return edd_get_gateway_checkout_label(edd_get_payment_gateway($payment_id));
}
コード例 #11
0
 /**
  * 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;
 }
コード例 #12
0
/**
 * 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');
        }
    }
}
コード例 #13
0
 /**
  * Get the payment method used for the given $payment_id. Returns a link to the transaction in Stripe or PayPal if possible.
  *
  * @param int $payment_id
  *
  * @return string
  */
 private function get_payment_method($payment_id)
 {
     $payment_method = edd_get_payment_gateway($payment_id);
     switch ($payment_method) {
         case 'paypal':
             $notes = edd_get_payment_notes($payment_id);
             foreach ($notes as $note) {
                 if (preg_match('/^PayPal Transaction ID: ([^\\s]+)/', $note->comment_content, $match)) {
                     $transaction_id = $match[1];
                     $payment_method = '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . esc_attr($transaction_id) . '" target="_blank">PayPal</a>';
                     break 2;
                 }
             }
             break;
         case 'stripe':
             $notes = edd_get_payment_notes($payment_id);
             foreach ($notes as $note) {
                 if (preg_match('/^Stripe Charge ID: ([^\\s]+)/', $note->comment_content, $match)) {
                     $transaction_id = $match[1];
                     $payment_method = '<a href="https://dashboard.stripe.com/payments/' . esc_attr($transaction_id) . '" target="_blank">Stripe</a>';
                     break 2;
                 }
             }
             break;
         case 'manual_purchases':
             $payment_method = 'Manual';
             break;
     }
     return $payment_method;
 }
コード例 #14
0
/**
 * Record Commissions
 *
 * @access      private
 * @since       1.0
 * @return      void
 */
function eddc_record_commission($payment_id, $new_status, $old_status)
{
    // Check if the payment was already set to complete
    if ($old_status == 'publish' || $old_status == 'complete') {
        return;
    }
    // Make sure that payments are only completed once
    // Make sure the commission is only recorded when new status is complete
    if ($new_status != 'publish' && $new_status != 'complete') {
        return;
    }
    if (edd_get_payment_gateway($payment_id) == 'manual_purchases' && !isset($_POST['commission'])) {
        return;
    }
    // do not record commission on manual payments unless specified
    $payment_data = edd_get_payment_meta($payment_id);
    $user_info = maybe_unserialize($payment_data['user_info']);
    $cart_details = maybe_unserialize($payment_data['cart_details']);
    // loop through each purchased download and award commissions, if needed
    foreach ($cart_details as $download) {
        $download_id = absint($download['id']);
        $commissions_enabled = get_post_meta($download_id, '_edd_commisions_enabled', true);
        if ('subtotal' == edd_get_option('edd_commissions_calc_base', 'subtotal')) {
            $price = $download['subtotal'];
        } else {
            $price = $download['price'];
        }
        // if we need to award a commission, and the price is greater than zero
        if ($commissions_enabled && floatval($price) > '0') {
            // set a flag so downloads with commissions awarded are easy to query
            update_post_meta($download_id, '_edd_has_commission', true);
            $commission_settings = get_post_meta($download_id, '_edd_commission_settings', true);
            if ($commission_settings) {
                $type = eddc_get_commission_type($download_id);
                // but if we have price variations, then we need to get the name of the variation
                if (edd_has_variable_prices($download_id)) {
                    $price_id = edd_get_cart_item_price_id($download);
                    $variation = edd_get_price_option_name($download_id, $price_id);
                }
                $recipients = eddc_get_recipients($download_id);
                // Record a commission for each user
                foreach ($recipients as $recipient) {
                    $rate = eddc_get_recipient_rate($download_id, $recipient);
                    // percentage amount of download price
                    $commission_amount = eddc_calc_commission_amount($price, $rate, $type);
                    // calculate the commission amount to award
                    $currency = $payment_data['currency'];
                    $commission = array('post_type' => 'edd_commission', 'post_title' => $user_info['email'] . ' - ' . get_the_title($download_id), 'post_status' => 'publish');
                    $commission_id = wp_insert_post(apply_filters('edd_commission_post_data', $commission));
                    $commission_info = apply_filters('edd_commission_info', array('user_id' => $recipient, 'rate' => $rate, 'amount' => $commission_amount, 'currency' => $currency), $commission_id);
                    update_post_meta($commission_id, '_edd_commission_info', $commission_info);
                    update_post_meta($commission_id, '_commission_status', 'unpaid');
                    update_post_meta($commission_id, '_download_id', $download_id);
                    update_post_meta($commission_id, '_user_id', $recipient);
                    update_post_meta($commission_id, '_edd_commission_payment_id', $payment_id);
                    //if we are dealing with a variation, then save variation info
                    if (isset($variation)) {
                        update_post_meta($commission_id, '_edd_commission_download_variation', $variation);
                    }
                    do_action('eddc_insert_commission', $recipient, $commission_amount, $rate, $download_id, $commission_id, $payment_id);
                }
            }
        }
    }
}
コード例 #15
0
 public function cryptocoin_payment($payment)
 {
     global $gourl;
     if (!is_object($payment) || edd_get_payment_gateway($payment->ID) != "gourl") {
         return true;
     }
     // Current Order Details
     $status = $payment->post_status;
     $amount = edd_get_payment_amount($payment->ID);
     $currency = edd_get_payment_currency_code($payment->ID);
     $userID = edd_get_payment_user_id($payment->ID);
     $orderID = "order" . $payment->ID;
     // file shortcode-receipt.php
     // filter 'edd_payment_receipt_before' inside <table>
     echo '</thead></table>';
     if (!$payment || !$payment->ID) {
         echo '<h3>' . __('Information', GOURLEDD) . '</h3>' . PHP_EOL;
         echo "<div class='edd-alert edd-alert-error'>" . __('The GoUrl payment plugin was called to process a payment but could not retrieve the order details. Cannot continue!', GOURLEDD) . "</div>";
     } elseif (!in_array($status, array("pending", "publish"))) {
         echo '<h3>' . __('Information', GOURLEDD) . '</h3>' . PHP_EOL;
         echo "<div class='edd-alert edd-alert-error'>" . sprintf(__("This order's status is '%s' - it cannot be paid for. Please contact us if you need assistance.", GOURLEDD), $status) . "</div>";
     } elseif (!class_exists('gourlclass') || !defined('GOURL') || !is_object($gourl)) {
         echo '<h3>' . __('Information', GOURLEDD) . '</h3>' . PHP_EOL;
         echo "<div class='edd-alert edd-alert-error'>" . sprintf(__("Please try a different payment method. Admin need to install and activate wordpress plugin <a href='%s'>GoUrl Bitcoin Gateway for Wordpress</a> to accept Bitcoin/Altcoin Payments online.", GOURLEDD), "https://gourl.io/bitcoin-wordpress-plugin.html") . "</div>";
     } elseif (!$this->payments || !$this->defcoin || true === version_compare(EDD_VERSION, '2.4.2', '<') || true === version_compare(GOURL_VERSION, '1.3.4', '<') || array_key_exists($currency, $this->coin_names) && !array_key_exists($currency, $this->payments)) {
         echo '<h3>' . __('Information', GOURLEDD) . '</h3>' . PHP_EOL;
         echo "<div class='edd-alert edd-alert-error'>" . sprintf(__('Sorry, but there was an error processing your order. Please try a different payment method or contact us if you need assistance (GoUrl Bitcoin Plugin not configured / %s not activated).', GOURLEDD), !$this->payments || !$this->defcoin || !isset($this->coin_names[$currency]) ? $this->title : $this->coin_names[$currency]) . "</div>";
     } else {
         $plugin = "gourledd";
         $period = "NOEXPIRY";
         $language = $this->deflang;
         $coin = $this->coin_names[$this->defcoin];
         $affiliate_key = 'gourl';
         $crypto = array_key_exists($currency, $this->coin_names);
         if (!$userID) {
             $userID = "guest";
         }
         // allow guests to make checkout (payments)
         if (!$userID) {
             echo '<h3>' . __('Information', GOURLEDD) . '</h3>' . PHP_EOL;
             echo "<div align='center'><a href='" . wp_login_url(get_permalink()) . "'>\n\t\t\t\t\t\t\t<img style='border:none;box-shadow:none;' title='" . __('You need first to login or register on the website to make Bitcoin/Altcoin Payments', GOURLEDD) . "' vspace='10'\n\t\t\t\t\t\t\tsrc='" . $gourl->box_image() . "' border='0'></a></div>";
         } elseif ($amount <= 0) {
             echo '<h3>' . __('Information', GOURLEDD) . '</h3>' . PHP_EOL;
             echo "<div class='edd-alert edd-alert-error'>" . sprintf(__("This order's amount is %s - it cannot be paid for. Please contact us if you need assistance.", GOURLEDD), $amount . " " . $currency) . "</div>";
         } else {
             // Exchange (optional)
             // --------------------
             if ($currency != "USD" && !$crypto) {
                 $amount = gourl_convert_currency($currency, "USD", $amount);
                 if ($amount <= 0) {
                     echo '<h3>' . __('Information', GOURLEDD) . '</h3>' . PHP_EOL;
                     echo "<div class='edd-alert edd-alert-error'>" . sprintf(__('Sorry, but there was an error processing your order. Please try later or use a different payment method. System cannot receive exchange rates for %s/USD from Google Finance', GOURLEDD), $currency) . "</div>";
                 } else {
                     $currency = "USD";
                 }
             }
             if (!$crypto) {
                 $amount = $amount * $this->emultiplier;
             }
             // Payment Box
             // ------------------
             if ($amount > 0) {
                 // crypto payment gateway
                 $result = $gourl->cryptopayments($plugin, $amount, $currency, $orderID, $period, $language, $coin, $affiliate_key, $userID, $this->iconwidth);
                 if (!isset($result["is_paid"]) || !$result["is_paid"]) {
                     echo '<h3>' . __('Pay Now -', GOURLEDD) . '</h3>' . PHP_EOL;
                 }
                 if ($result["error"]) {
                     echo "<div class='edd-alert edd-alert-error'>" . __("Sorry, but there was an error processing your order. Please try a different payment method.", GOURLEDD) . "<br/>" . $result["error"] . "</div>";
                 } else {
                     // display payment box or successful payment result
                     echo $result["html_payment_box"];
                     // payment received
                     if ($result["is_paid"]) {
                         if (false) {
                             echo "<div align='center'>" . sprintf(__('%s Payment ID: #%s', GOURLEDD), ucfirst($result["coinname"]), $result["paymentID"]) . "</div>";
                         }
                         echo "<br/>";
                         if ($status == 'pending') {
                             header('Location: ' . $_SERVER['REQUEST_URI']);
                         }
                     }
                 }
             }
         }
     }
     echo '<br/><br/><table id="edd_purchase_receipt"><thead>';
     return true;
 }
コード例 #16
0
 /**
  * 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;
 }
コード例 #17
0
ファイル: slackedd.php プロジェクト: deviodigital/Slackedd
/**
 * Slackedd Notification Codes
 *
 * @since	   1.0.0
 */
function slackedd_notification($payment_id)
{
    $edd_options = edd_get_settings();
    /* Check that the user has all required information added for the plugin to work */
    $enable_slack = isset($edd_options['slackedd_enable_notification']) ? $edd_options['slackedd_enable_notification'] : '';
    $hide_order_number = isset($edd_options['slackedd_hide_order_number']) ? $edd_options['slackedd_hide_order_number'] : '';
    $hide_order_items = isset($edd_options['slackedd_hide_order_items']) ? $edd_options['slackedd_hide_order_items'] : '';
    $hide_payment_gateway = isset($edd_options['slackedd_hide_payment_gateway']) ? $edd_options['slackedd_hide_payment_gateway'] : '';
    $hide_buyer_information = isset($edd_options['slackedd_hide_buyer_information']) ? $edd_options['slackedd_hide_buyer_information'] : '';
    $slack_channel = isset($edd_options['slackedd_channel']) ? $edd_options['slackedd_channel'] : '';
    $webhook_url = isset($edd_options['slackedd_webhook_url']) ? $edd_options['slackedd_webhook_url'] : '';
    if (!($enable_slack && $slack_channel && $webhook_url)) {
        return;
    }
    $enable_slack = isset($edd_options['slackedd_enable_notification']) ? $edd_options['slackedd_enable_notification'] : '';
    $emoji = !empty($edd_options['slackedd_icon_emoji']) ? $edd_options['slackedd_icon_emoji'] : ':moneybag:';
    $bot_name = !empty($edd_options['slackedd_bot_name']) ? $edd_options['slackedd_bot_name'] : 'Slackedd';
    $order_amount = esc_attr(edd_format_amount(edd_get_payment_amount($payment_id)));
    $currency_symbol = edd_currency_symbol($payment_meta['currency']);
    $currency_symbol = html_entity_decode($currency_symbol, ENT_QUOTES, 'UTF-8');
    $payment_meta = edd_get_payment_meta($payment_id);
    $cart_items = edd_get_payment_meta_cart_details($payment_id);
    $items_sold = '';
    $order_id = edd_get_payment_number($payment_id);
    foreach ($cart_items as $key => $cart_item) {
        $name = $cart_item['name'];
        $price = $cart_item['price'];
        $items_sold .= "*Name:* " . $name . " | *Price:* " . $currency_symbol . "" . $price . " \n";
    }
    $gateway = edd_get_payment_gateway($payment_id);
    $payment_method = edd_get_gateway_admin_label($gateway);
    $user_data = $payment_meta['user_info'];
    /* Display the new sale introduction */
    $message = "A new sale has occurred at " . get_bloginfo('name') . " \n\n";
    /* Show or hide order number based on user preference in settings page */
    if (!$hide_order_number) {
        $message .= "*Order* <" . get_bloginfo('home') . "/wp-admin/edit.php?post_type=download&page=edd-payment-history&view=view-order-details&id=" . $order_id . "|#" . $order_id . "> \n";
    }
    /* Show the order total */
    $message .= "*Order Total:* " . $currency_symbol . "" . $order_amount . " \n\n";
    /* Show or hide payment gateway based on user preference in settings page */
    if (!$hide_payment_gateway) {
        $message .= "*Payment Method:* " . $payment_method . " \n\n";
    }
    /* Show or hide order items based on user preference in settings page */
    if (!$hide_order_items) {
        $message .= "*" . edd_get_cart_quantity() . " ITEM(S):* \n";
        $message .= $items_sold;
    }
    /* Show or hide order number based on user preference in settings page */
    if (!$hide_buyer_information) {
        $message .= "\n\n *Customer:* " . $user_data['first_name'] . " " . $user_data['last_name'] . " " . $user_data['email'] . "\n";
    }
    $attachment = array();
    $attachment[] = array('color' => 'good', 'fallback' => 'New sale notification of ' . $currency_symbol . '' . $price . ' at ' . get_bloginfo('name'), 'mrkdwn_in' => array('text'), 'text' => $message, 'title' => 'New Sale Notification!');
    $payload = array('attachments' => $attachment, 'channel' => $slack_channel, 'icon_emoji' => $emoji, 'username' => $bot_name);
    $args = array('body' => json_encode($payload), 'timeout' => 30);
    $response = wp_remote_post($webhook_url, $args);
    return;
}
コード例 #18
0
</td>
		</tr>
		<?php 
}
?>

		<?php 
if ($edd_receipt_args['payment_method']) {
    ?>
		<tr>
			<td><strong><?php 
    _e('Payment Method', 'edd');
    ?>
:</strong></td>
			<td><?php 
    echo edd_get_payment_gateway($payment->ID);
    ?>
</td>
		</tr>
		<?php 
}
?>

		<?php 
if ($edd_receipt_args['payment_key']) {
    ?>
		<tr>
			<td><strong><?php 
    _e('Payment Key', 'edd');
    ?>
:</strong></td>
コード例 #19
0
 /**
  * Process refunds
  *
  * @access      public
  * @since       1.0.0
  * @param       int $payment_id The ID of a payment
  * @param       string $new_status The new status of the payment
  * @param       string $old_status The old status of the payment
  * @return      void
  */
 public function process_refund($payment_id, $new_status, $old_status)
 {
     if ($old_status != 'publish' && $old_status != 'revoked') {
         return;
     }
     if ($new_status != 'refunded') {
         return;
     }
     if (edd_get_payment_gateway($payment_id) !== 'wallet') {
         return;
     }
     $user_id = edd_get_payment_user_id($payment_id);
     $refund_amount = edd_get_payment_amount($payment_id);
     // Deposit the funds
     edd_wallet()->wallet->deposit($user_id, $refund_amount, 'refund');
     // Insert payment note
     edd_insert_payment_note($payment_id, __('Refund completed to Wallet.', 'edd-wallet'));
 }
コード例 #20
0
/**
 * Record Commissions
 *
 * @access      private
 * @since       1.0
 * @return      void
 */
function eddc_record_commission($payment_id, $new_status, $old_status)
{
    // Check if the payment was already set to complete
    if ($old_status == 'publish' || $old_status == 'complete') {
        return;
    }
    // Make sure that payments are only completed once
    // Make sure the commission is only recorded when new status is complete
    if ($new_status != 'publish' && $new_status != 'complete') {
        return;
    }
    if (edd_get_payment_gateway($payment_id) == 'manual_purchases' && !isset($_POST['commission'])) {
        return;
    }
    // do not record commission on manual payments unless specified
    if (edd_get_payment_meta($payment_id, '_edd_completed_date')) {
        return;
    }
    $payment_data = edd_get_payment_meta($payment_id);
    $user_info = maybe_unserialize($payment_data['user_info']);
    $cart_details = edd_get_payment_meta_cart_details($payment_id);
    $calc_base = edd_get_option('edd_commissions_calc_base', 'subtotal');
    $shipping = edd_get_option('edd_commissions_shipping', 'ignored');
    // loop through each purchased download and award commissions, if needed
    foreach ($cart_details as $download) {
        $download_id = absint($download['id']);
        $commissions_enabled = get_post_meta($download_id, '_edd_commisions_enabled', true);
        if ('subtotal' == $calc_base) {
            $price = $download['subtotal'];
        } else {
            if ('total_pre_tax' == $calc_base) {
                $price = $download['price'] - $download['tax'];
            } else {
                $price = $download['price'];
            }
        }
        if (!empty($download['fees'])) {
            foreach ($download['fees'] as $fee_id => $fee) {
                if (false !== strpos($fee_id, 'shipping')) {
                    // If we're adjusting the commission for shipping, we need to remove it from the calculation and then add it after the commission amount has been determined
                    if ('ignored' !== $shipping) {
                        continue;
                    }
                }
                $price += $fee['amount'];
            }
        }
        // if we need to award a commission, and the price is greater than zero
        if ($commissions_enabled && floatval($price) > '0') {
            // set a flag so downloads with commissions awarded are easy to query
            update_post_meta($download_id, '_edd_has_commission', true);
            $commission_settings = get_post_meta($download_id, '_edd_commission_settings', true);
            if ($commission_settings) {
                $type = eddc_get_commission_type($download_id);
                // but if we have price variations, then we need to get the name of the variation
                $has_variable_prices = edd_has_variable_prices($download_id);
                if ($has_variable_prices) {
                    $price_id = edd_get_cart_item_price_id($download);
                    $variation = edd_get_price_option_name($download_id, $price_id);
                }
                $recipients = eddc_get_recipients($download_id);
                // Record a commission for each user
                foreach ($recipients as $recipient) {
                    $rate = eddc_get_recipient_rate($download_id, $recipient);
                    // percentage amount of download price
                    $args = array('price' => $price, 'rate' => $rate, 'type' => $type, 'download_id' => $download_id, 'recipient' => $recipient, 'payment_id' => $payment_id);
                    $commission_amount = eddc_calc_commission_amount($args);
                    // calculate the commission amount to award
                    $currency = $payment_data['currency'];
                    // If shipping is included or not included, we need to adjust the amount
                    if (!empty($download['fees']) && 'ignored' !== $shipping) {
                        foreach ($download['fees'] as $fee_id => $fee) {
                            if (false !== strpos($fee_id, 'shipping')) {
                                // If we're adjusting the commission for shipping, we need to remove it from the calculation and then add it after the commission amount has been determined
                                if ('include_shipping' == $shipping) {
                                    $commission_amount += $fee['amount'];
                                }
                            }
                        }
                    }
                    $commission = array('post_type' => 'edd_commission', 'post_title' => $user_info['email'] . ' - ' . get_the_title($download_id), 'post_status' => 'publish');
                    $commission_id = wp_insert_post(apply_filters('edd_commission_post_data', $commission));
                    $commission_info = apply_filters('edd_commission_info', array('user_id' => $recipient, 'rate' => $rate, 'amount' => $commission_amount, 'currency' => $currency), $commission_id, $payment_id, $download_id);
                    eddc_set_commission_status($commission_id, 'unpaid');
                    update_post_meta($commission_id, '_edd_commission_info', $commission_info);
                    update_post_meta($commission_id, '_download_id', $download_id);
                    update_post_meta($commission_id, '_user_id', $recipient);
                    update_post_meta($commission_id, '_edd_commission_payment_id', $payment_id);
                    // If we are dealing with a variation, then save variation info
                    if ($has_variable_prices && isset($variation)) {
                        update_post_meta($commission_id, '_edd_commission_download_variation', $variation);
                    }
                    // If it's a renewal, save that detail
                    if (!empty($download['item_number']['options']['is_renewal'])) {
                        update_post_meta($commission_id, '_edd_commission_is_renewal', true);
                    }
                    do_action('eddc_insert_commission', $recipient, $commission_amount, $rate, $download_id, $commission_id, $payment_id);
                }
            }
        }
    }
}
コード例 #21
0
	/**
	 * 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;
	}
コード例 #22
0
/**
 * Mark commissions as paid immediately since they are paid at the time of purchase
 *
 * @since 2.7
 * @return void
 */
function eddc_override_commission_status($recipient, $commission_amount, $rate, $download_id, $commission_id, $payment_id)
{
    if (!edd_get_option('edd_commissions_autopay_pa') || 'paypal_adaptive_payments' != edd_get_payment_gateway($payment_id)) {
        return;
    }
    eddc_set_commission_status($commission_id, 'paid');
}
コード例 #23
0
 /**
  * Detect a refund action from EDD
  *
  * @access public
  * @since  2.4
  * @param  $payment_id int The ID number of the payment being refunded
  * @param  $new_status string The new status assigned to the payment
  * @param  $old_status string The previous status of the payment
  * @return void
  */
 public function process_refund($payment_id, $new_status, $old_status)
 {
     if ('publish' != $old_status && 'revoked' != $old_status) {
         return;
     }
     if ('refunded' != $new_status) {
         return;
     }
     if ($this->doing_ipn) {
         return;
     }
     if ('amazon' !== edd_get_payment_gateway($payment_id)) {
         return;
     }
     $this->refund($payment_id);
 }
コード例 #24
0
/**
 * Sales Summary Dashboard Widget
 *
 * @access      private
 * @author      Sunny Ratilal
 * @since       1.2.2
*/
function edd_dashboard_sales_widget()
{
    $top_selling_args = array('post_type' => 'download', 'posts_per_page' => 1, 'post_status' => 'publish', 'meta_key' => '_edd_download_sales', 'meta_compare' => '>', 'meta_value' => 0, 'orderby' => 'meta_value_num', 'cache_results' => false, 'update_post_term_cache' => false, 'no_found_rows' => true, 'order' => 'DESC');
    $top_selling = get_posts($top_selling_args);
    ?>
	<div class="table table_current_month">
		<p class="sub"><?php 
    _e('Current Month', 'edd');
    ?>
</p>
		<table>
			<tbody>
				<tr class="first">
					<td class="first b"><?php 
    echo edd_currency_filter(edd_format_amount(edd_get_earnings_by_date(null, date('n'), date('Y'))));
    ?>
</td>
					<td class="t monthly_earnings"><?php 
    _e('Earnings', 'edd');
    ?>
</td>
				</tr>
				<tr>
					<?php 
    $monthly_sales = edd_get_sales_by_date(null, date('n'), date('Y'));
    ?>
					<td class="first b"><?php 
    echo $monthly_sales;
    ?>
</td>
					<td class="t monthly_sales"><?php 
    echo _n('Sale', 'Sales', $monthly_sales, 'edd');
    ?>
</td>
				</tr>
			</tbody>
		</table>
		<p class="label_heading"><?php 
    _e('Last Month', 'edd');
    ?>
</p>
		<div>
			<?php 
    echo __('Earnings', 'edd') . ':&nbsp;<span class="edd_price_label">' . edd_currency_filter(edd_format_amount(edd_get_earnings_by_date(null, date('n') - 1, date('Y')))) . '</span>';
    ?>
		</div>
		<div>
			<?php 
    $last_month_sales = edd_get_sales_by_date(null, date('n') - 1, date('Y'));
    ?>
			<?php 
    echo _n('Sale', 'Sales', $last_month_sales, 'edd') . ':&nbsp;' . '<span class="edd_price_label">' . $last_month_sales . '</span>';
    ?>
		</div>
	</div>
	<div class="table table_totals">
		<p class="sub"><?php 
    _e('Totals', 'edd');
    ?>
</p>
		<table>
			<tbody>
				<tr class="first">
					<td class="b b-earnings"><?php 
    echo edd_currency_filter(edd_format_amount(edd_get_total_earnings()));
    ?>
</td>
					<td class="last t earnings"><?php 
    _e('Total Earnings', 'edd');
    ?>
</td>
				</tr>
				<tr>
					<td class="b b-sales"><?php 
    echo edd_get_total_sales();
    ?>
</td>
					<td class="last t sales"><?php 
    _e('Total Sales', 'edd');
    ?>
</td>
				</tr>
			</tbody>
		</table>
		<?php 
    if ($top_selling) {
        foreach ($top_selling as $list) {
            ?>
				<p class="lifetime_best_selling label_heading"><?php 
            _e('Lifetime Best Selling', 'edd');
            ?>
</p>
				<p><span class="lifetime_best_selling_label"><?php 
            echo edd_get_download_sales_stats($list->ID);
            ?>
</span> <a href="<?php 
            echo get_permalink($list->ID);
            ?>
"><?php 
            echo get_the_title($list->ID);
            ?>
</a></p>
		<?php 
        }
    }
    ?>
	</div>
	<div style="clear: both"></div>
	<?php 
    $payments = edd_get_payments(array('number' => 5, 'mode' => 'live', 'orderby' => 'post_date', 'order' => 'DESC', 'user' => null, 'status' => 'publish', 'meta_key' => null));
    if ($payments) {
        ?>
	<p class="edd_dashboard_widget_subheading"><?php 
        _e('Recent Purchases', 'edd');
        ?>
</p>
	<div class="table recent_purchases">
		<table>
			<tbody>
				<?php 
        foreach ($payments as $payment) {
            $payment_meta = edd_get_payment_meta($payment->ID);
            ?>
				<tr>
					<td><?php 
            echo get_the_title($payment->ID);
            ?>
 - (<?php 
            echo $payment_meta['email'];
            ?>
) - <span class="edd_price_label"><?php 
            echo edd_currency_filter(edd_format_amount(edd_get_payment_amount($payment->ID)));
            ?>
</span> - <a href="#TB_inline?width=640&amp;inlineId=purchased-files-<?php 
            echo $payment->ID;
            ?>
" class="thickbox" title="<?php 
            printf(__('Purchase Details for Payment #%s', 'edd'), $payment->ID);
            ?>
 "><?php 
            _e('View Order Details', 'edd');
            ?>
</a>
						<div id="purchased-files-<?php 
            echo $payment->ID;
            ?>
" style="display:none;">
							<?php 
            $cart_items = edd_get_payment_meta_cart_details($payment->ID);
            if (empty($cart_items) || !$cart_items) {
                $cart_items = maybe_unserialize($payment_meta['downloads']);
            }
            ?>
							<h4><?php 
            echo _n(__('Purchased File', 'edd'), __('Purchased Files', 'edd'), count($cart_items));
            ?>
</h4>
							<ul class="purchased-files-list">
							<?php 
            if ($cart_items) {
                foreach ($cart_items as $key => $cart_item) {
                    echo '<li>';
                    $id = isset($payment_meta['cart_details']) ? $cart_item['id'] : $cart_item;
                    $price_override = isset($payment_meta['cart_details']) ? $cart_item['price'] : null;
                    $user_info = edd_get_payment_meta_user_info($payment->ID);
                    $price = edd_get_download_final_price($id, $user_info, $price_override);
                    echo '<a href="' . admin_url('post.php?post=' . $id . '&action=edit') . '" target="_blank">' . get_the_title($id) . '</a>';
                    echo ' - ';
                    if (isset($cart_items[$key]['item_number'])) {
                        $price_options = $cart_items[$key]['item_number']['options'];
                        if (isset($price_options['price_id'])) {
                            echo edd_get_price_option_name($id, $price_options['price_id']);
                            echo ' - ';
                        }
                    }
                    echo edd_currency_filter(edd_format_amount($price));
                    echo '</li>';
                }
            }
            ?>
							</ul>
							<?php 
            $payment_date = strtotime($payment->post_date);
            ?>
							<p><?php 
            echo __('Date and Time:', 'edd') . ' ' . date_i18n(get_option('date_format'), $payment_date) . ' ' . date_i18n(get_option('time_format'), $payment_date);
            ?>
							<p><?php 
            echo __('Discount used:', 'edd') . ' ';
            if (isset($user_info['discount']) && $user_info['discount'] != 'none') {
                echo $user_info['discount'];
            } else {
                _e('none', 'edd');
            }
            ?>
							<p><?php 
            echo __('Total:', 'edd') . ' ' . edd_currency_filter(edd_format_amount(edd_get_payment_amount($payment->ID)));
            ?>
</p>

							<div class="purcase-personal-details">
								<h4><?php 
            _e('Buyer\'s Personal Details:', 'edd');
            ?>
</h4>
								<ul>
									<li><?php 
            echo __('Name:', 'edd') . ' ' . $user_info['first_name'] . ' ' . $user_info['last_name'];
            ?>
</li>
									<li><?php 
            echo __('Email:', 'edd') . ' ' . $payment_meta['email'];
            ?>
</li>
									<?php 
            do_action('edd_payment_personal_details_list', $payment_meta, $user_info);
            ?>
								</ul>
							</div>
							<?php 
            $gateway = edd_get_payment_gateway($payment->ID);
            if ($gateway) {
                ?>
							<div class="payment-method">
								<h4><?php 
                _e('Payment Method:', 'edd');
                ?>
</h4>
								<span class="payment-method-name"><?php 
                echo edd_get_gateway_admin_label($gateway);
                ?>
</span>
							</div>
							<?php 
            }
            ?>
							<div class="purchase-key-wrap">
								<h4><?php 
            _e('Purchase Key', 'edd');
            ?>
</h4>
								<span class="purchase-key"><?php 
            echo $payment_meta['key'];
            ?>
</span>
							</div>
							<p><a id="edd-close-purchase-details" class="button-secondary" onclick="tb_remove();" title="<?php 
            _e('Close', 'edd');
            ?>
"><?php 
            _e('Close', 'edd');
            ?>
</a></p>
						</div>
					</td>
				</tr>
				<?php 
        }
        // end foreach
        ?>
			</tbody>
		</table>
	</div>
	<?php 
    }
    // end if
}
コード例 #25
0
/**
 * Email template tag: payment_method
 * The method of payment used for this purchase
 *
 * @since       1.0.0
 * @param       int $payment_id
 * @return      string gateway
 */
function edd_wallet_email_tag_payment_method($payment_id)
{
    if (get_post_type($payment_id) == 'edd_payment') {
        return edd_get_gateway_checkout_label(edd_get_payment_gateway($payment_id));
    } else {
        return '';
    }
}
コード例 #26
0
/**
 * Shows checkbox to automatically refund payments made in PayPal.
 *
 * @access public
 * @since  2.6.0
 *
 * @param int $payment_id The current payment ID.
 * @return void
 */
function edd_paypal_refund_admin_js($payment_id = 0)
{
    // If not the proper gateway, return early.
    if ('paypal' !== edd_get_payment_gateway($payment_id)) {
        return;
    }
    // If our credentials are not set, return early.
    $key = edd_get_payment_meta($payment_id, '_edd_payment_mode', true);
    $username = edd_get_option('paypal_' . $key . '_api_username');
    $password = edd_get_option('paypal_' . $key . '_api_password');
    $signature = edd_get_option('paypal_' . $key . '_api_signature');
    if (empty($username) || empty($password) || empty($signature)) {
        return;
    }
    // Localize the refund checkbox label.
    $label = __('Refund Payment in PayPal', 'easy-digital-downloads');
    ?>
	<script type="text/javascript">
		jQuery(document).ready(function($) {
			$('select[name=edd-payment-status]').change(function() {
				if ( 'refunded' == $(this).val() ) {
					$(this).parent().parent().append('<input type="checkbox" id="edd-paypal-refund" name="edd-paypal-refund" value="1" style="margin-top:0">');
					$(this).parent().parent().append('<label for="edd-paypal-refund"><?php 
    echo $label;
    ?>
</label>');
				} else {
					$('#edd-paypal-refund').remove();
					$('label[for="edd-paypal-refund"]').remove();
				}
			});
		});
	</script>
	<?php 
}
コード例 #27
0
 /**
  * process voguepay response and then redirect to purchase confirmation page.
  * @global $edd_options Array of all the EDD Options
  * @return void
  */
 public function process_voguepay_response()
 {
     global $edd_options;
     // Get all response data coming from voguepay.
     $post_data = $_POST;
     // Get payment id.
     $payment_id = $_GET['payment-id'];
     // Get Payment status code.
     $payment_status_code = intval($post_data['status']);
     if (empty($payment_id)) {
         return;
     }
     if ('voguepay' != edd_get_payment_gateway($payment_id)) {
         return;
         // this isn't a voguepay response.
     }
     // create payment note.
     $payment_note = sprintf(__('voguepay Reference ID: %s <br> Merchant Reference ID: %s', 'edd-voguepay'), $post_data['voguepay_refID'], $post_data['merchant_ref']);
     $payment_note .= '<br> Message: ' . $post_data['status_msg'];
     if (0 == $payment_status_code) {
         edd_insert_payment_note($payment_id, $payment_note);
         edd_set_payment_transaction_id($payment_id, $post_data['voguepay_refID']);
         edd_update_payment_status($payment_id, 'publish');
         $confirm_url = add_query_arg(array('payment-confirmation' => 'voguepay', 'payment-id' => $payment_id), get_permalink($edd_options['success_page']));
         wp_redirect($confirm_url);
     } else {
         edd_insert_payment_note($payment_id, $payment_note);
         edd_set_payment_transaction_id($payment_id, $post_data['voguepay_refID']);
         edd_update_payment_status($payment_id, 'failed');
         wp_redirect(edd_get_failed_transaction_uri('?payment-id=' . $payment_id));
     }
     die;
 }
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since 1.4
  * @global object $edd_logs EDD Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 public function get_logs()
 {
     global $edd_logs;
     $logs_data = array();
     $paged = $this->get_paged();
     $log_query = array('log_type' => 'gateway_error', 'paged' => $paged);
     $logs = $edd_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $logs_data[] = array('ID' => $log->ID, 'payment_id' => $log->post_parent, 'error' => 'error', 'gateway' => edd_get_payment_gateway($log->post_parent), 'date' => $log->post_date);
         }
     }
     return $logs_data;
 }
コード例 #29
0
</td>
			</tr>
		<?php 
}
?>

		<?php 
if ($edd_receipt_args['payment_method']) {
    ?>
			<tr>
				<td><strong><?php 
    _e('Payment Method', 'easy-digital-downloads');
    ?>
:</strong></td>
				<td><?php 
    echo edd_get_gateway_checkout_label(edd_get_payment_gateway($payment->ID));
    ?>
</td>
			</tr>
		<?php 
}
?>
		<?php 
if ($edd_receipt_args['date']) {
    ?>
		<tr>
			<td><strong><?php 
    _e('Date', 'easy-digital-downloads');
    ?>
:</strong></td>
			<td><?php 
コード例 #30
0
/**
 * 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');
        }
    }
}