Ejemplo n.º 1
0
 /**
  * Retrieves Recent Sales
  *
  * @access public
  * @since  1.1
  * @return array
  */
 public function get_recent_donations()
 {
     global $wp_query;
     $sales = array();
     if (!user_can($this->user_id, 'view_give_reports') && !$this->override) {
         return $sales;
     }
     if (isset($wp_query->query_vars['id'])) {
         $query = array();
         $query[] = give_get_payment_by('id', $wp_query->query_vars['id']);
     } elseif (isset($wp_query->query_vars['purchasekey'])) {
         $query = array();
         $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']);
     } elseif (isset($wp_query->query_vars['email'])) {
         $query = give_get_payments(array('meta_key' => '_give_payment_user_email', 'meta_value' => $wp_query->query_vars['email'], 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish'));
     } else {
         $query = give_get_payments(array('number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish'));
     }
     if ($query) {
         $i = 0;
         foreach ($query as $payment) {
             $payment_meta = give_get_payment_meta($payment->ID);
             $user_info = give_get_payment_meta_user_info($payment->ID);
             $first_name = isset($user_info['first_name']) ? $user_info['first_name'] : '';
             $last_name = isset($user_info['last_name']) ? $user_info['last_name'] : '';
             $sales['donations'][$i]['ID'] = give_get_payment_number($payment->ID);
             $sales['donations'][$i]['transaction_id'] = give_get_payment_transaction_id($payment->ID);
             $sales['donations'][$i]['key'] = give_get_payment_key($payment->ID);
             $sales['donations'][$i]['total'] = give_get_payment_amount($payment->ID);
             $sales['donations'][$i]['gateway'] = give_get_payment_gateway($payment->ID);
             $sales['donations'][$i]['name'] = $first_name . ' ' . $last_name;
             $sales['donations'][$i]['fname'] = $first_name;
             $sales['donations'][$i]['lname'] = $last_name;
             $sales['donations'][$i]['email'] = give_get_payment_user_email($payment->ID);
             $sales['donations'][$i]['date'] = $payment->post_date;
             $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta;
             $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false;
             $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null;
             $sales['donations'][$i]['form']['id'] = $form_id;
             $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']);
             $sales['donations'][$i]['form']['price'] = $price;
             if (give_has_variable_prices($form_id)) {
                 if (isset($payment_meta['price_id'])) {
                     $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID);
                     $sales['donations'][$i]['form']['price_name'] = $price_name;
                     $sales['donations'][$i]['form']['price_id'] = $price_id;
                     $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id);
                 }
             }
             //Add custom meta to API
             foreach ($payment_meta as $meta_key => $meta_value) {
                 $exceptions = array('form_title', 'form_id', 'price_id', 'user_info', 'key', 'email', 'date');
                 //Don't clutter up results with dupes
                 if (in_array($meta_key, $exceptions)) {
                     continue;
                 }
                 $sales['donations'][$i]['payment_meta'][$meta_key] = $meta_value;
             }
             $i++;
         }
     }
     return apply_filters('give_api_donations_endpoint', $sales);
 }
Ejemplo n.º 2
0
								<h3 class="hndle">
									<span><?php 
_e('Payment Meta', 'give');
?>
</span>
								</h3>

								<div class="inside">
									<div class="give-admin-box">

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

										<?php 
$gateway = give_get_payment_gateway($payment_id);
if ($gateway) {
    ?>
											<div class="give-order-gateway give-admin-box-inside">
												<p>
													<span class="label"><?php 
    _e('Gateway:', 'give');
    ?>
</span>&nbsp;
													<?php 
    echo give_get_gateway_admin_label($gateway);
    ?>
												</p>
											</div>
										<?php 
}
 /**
  * Gets the log entries for the current view
  *
  * @access public
  * @since  1.0
  * @global object $give_logs Give Logs Object
  * @return array $logs_data Array of all the Log entires
  */
 public function get_logs()
 {
     $give_logs = new Give_Logging();
     // 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 = $give_logs->get_connected_logs($log_query);
     if ($logs) {
         foreach ($logs as $log) {
             $logs_data[] = array('ID' => $log->ID, 'ID_label' => '<span class=\'give-item-label give-item-label-gray\'>' . $log->ID . '</span>', 'payment_id' => $log->post_parent, 'error' => 'error', 'gateway' => give_get_payment_gateway($log->post_parent), 'date' => $log->post_date);
         }
     }
     return $logs_data;
 }
/**
 * Email template tag: payment_method
 * The method of payment used for this donation
 *
 * @param int $payment_id
 *
 * @return string gateway
 */
function give_email_tag_payment_method($payment_id)
{
    return give_get_gateway_checkout_label(give_get_payment_gateway($payment_id));
}
Ejemplo n.º 5
0
/**
 * Process web accept (one time) payment IPNs.
 *
 * @since 1.0
 *
 * @param array $data       IPN Data
 * @param int   $payment_id The payment ID from Give.
 *
 * @return void
 */
function give_process_paypal_web_accept_and_cart($data, $payment_id)
{
    //Only allow through these transaction types.
    if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && strtolower($data['payment_status']) != 'refunded') {
        return;
    }
    //Need $payment_id to continue.
    if (empty($payment_id)) {
        return;
    }
    // Collect donation payment details.
    $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 = give_get_payment_meta($payment_id);
    // Must be a PayPal standard IPN.
    if (give_get_payment_gateway($payment_id) != 'paypal') {
        return;
    }
    // Verify payment recipient
    if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) {
        give_record_gateway_error(esc_html__('IPN Error', 'give'), sprintf(esc_html__('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid PayPal business email.', 'give'));
        return;
    }
    // Verify payment currency.
    if ($currency_code != strtolower($payment_meta['currency'])) {
        give_record_gateway_error(esc_html__('IPN Error', 'give'), sprintf(esc_html__('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid currency in PayPal IPN.', 'give'));
        return;
    }
    //Process refunds & reversed.
    if ($payment_status == 'refunded' || $payment_status == 'reversed') {
        give_process_paypal_refund($data, $payment_id);
        return;
    }
    // Only complete payments once.
    if (get_post_status($payment_id) == 'publish') {
        return;
    }
    // Retrieve the total donation amount (before PayPal).
    $payment_amount = give_get_payment_amount($payment_id);
    //Check that the donation PP and local db amounts match.
    if (number_format((double) $paypal_amount, 2) < number_format((double) $payment_amount, 2)) {
        // The prices don't match
        give_record_gateway_error(esc_html__('IPN Error', 'give'), sprintf(esc_html__('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid amount in PayPal IPN.', 'give'));
        return;
    }
    //Process completed donations.
    if ($payment_status == 'completed' || give_is_test_mode()) {
        give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Transaction ID: %s', 'give'), $data['txn_id']));
        give_set_payment_transaction_id($payment_id, $data['txn_id']);
        give_update_payment_status($payment_id, 'publish');
    } elseif ('pending' == $payment_status && isset($data['pending_reason'])) {
        // Look for possible pending reasons, such as an echeck.
        $note = give_paypal_get_pending_donation_note(strtolower($data['pending_reason']));
        if (!empty($note)) {
            give_insert_payment_note($payment_id, $note);
        }
    }
}
Ejemplo n.º 6
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.0
  * @return object
  */
 public function get_payments()
 {
     do_action('give_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 = give_get_payment_amount($payment_id);
             $details->fees = give_get_payment_fees($payment_id);
             $details->key = give_get_payment_key($payment_id);
             $details->gateway = give_get_payment_gateway($payment_id);
             $details->user_info = give_get_payment_meta_user_info($payment_id);
             if (give_get_option('enable_sequential')) {
                 $details->payment_number = give_get_payment_number($payment_id);
             }
             $this->payments[] = apply_filters('give_payment', $details, $payment_id, $this);
         }
         wp_reset_postdata();
     }
     do_action('give_post_get_payments', $this);
     return $this->payments;
 }
Ejemplo n.º 7
0
</td>
			</tr>
		<?php 
}
?>

		<?php 
if (filter_var($give_receipt_args['payment_method'], FILTER_VALIDATE_BOOLEAN)) {
    ?>
			<tr>
				<td><strong><?php 
    _e('Payment Method', 'give');
    ?>
:</strong></td>
				<td><?php 
    echo give_get_gateway_checkout_label(give_get_payment_gateway($payment->ID));
    ?>
</td>
			</tr>
		<?php 
}
?>
		<?php 
if (filter_var($give_receipt_args['date'], FILTER_VALIDATE_BOOLEAN)) {
    ?>
			<tr>
				<td><strong><?php 
    _e('Date', 'give');
    ?>
:</strong></td>
				<td><?php 
Ejemplo n.º 8
0
/**
 * Mark Abandoned Donations
 *
 * Updates over a week-old 'pending' donations to 'abandoned' status.
 *
 * @since  1.0
 *
 * @return void
 */
function give_mark_abandoned_donations()
{
    $args = array('status' => 'pending', 'number' => -1, 'output' => 'give_payments');
    add_filter('posts_where', 'give_filter_where_older_than_week');
    $payments = give_get_payments($args);
    remove_filter('posts_where', 'give_filter_where_older_than_week');
    if ($payments) {
        /**
         * Filter payment gateways:  Used to set payment gateways which can be skip while transferring pending payment to abandon.
         *
         * @since 1.6
         *
         * @param array $skip_payment_gateways Array of payment gateways
         */
        $skip_payment_gateways = apply_filters('give_mark_abandoned_donation_gateways', array('offline'));
        foreach ($payments as $payment) {
            $gateway = give_get_payment_gateway($payment);
            // Skip payment gateways.
            if (in_array($gateway, $skip_payment_gateways)) {
                continue;
            }
            $payment->status = 'abandoned';
            $payment->save();
        }
    }
}
Ejemplo n.º 9
0
/**
 * Updates week-old+ 'pending' orders to 'abandoned'
 *
 * @since 1.0
 * @return void
 */
function give_mark_abandoned_donations()
{
    $args = array('status' => 'pending', 'number' => -1, 'fields' => 'ids');
    add_filter('posts_where', 'give_filter_where_older_than_week');
    $payments = give_get_payments($args);
    remove_filter('posts_where', 'give_filter_where_older_than_week');
    if ($payments) {
        foreach ($payments as $payment) {
            $gateway = give_get_payment_gateway($payment);
            //Skip offline gateway payments
            if ($gateway == 'offline') {
                continue;
            }
            //Non-offline get marked as 'abandoned'
            give_update_payment_status($payment, 'abandoned');
        }
    }
}
Ejemplo n.º 10
0
/**
 * Process web accept (one time) payment IPNs
 *
 * @since 1.0
 *
 * @param array $data IPN Data
 *
 * @return void
 */
function give_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 = give_get_payment_meta($payment_id);
    if (give_get_payment_gateway($payment_id) != 'paypal') {
        return;
        // this isn't a PayPal standard IPN
    }
    // Verify payment recipient
    if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) {
        give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'give'));
        return;
    }
    // Verify payment currency
    if ($currency_code != strtolower($payment_meta['currency'])) {
        give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'give'));
        return;
    }
    if (!give_get_payment_user_email($payment_id)) {
        // No email associated with purchase, so store from PayPal
        give_update_payment_meta($payment_id, '_give_payment_user_email', $data['payer_email']);
        // Setup and store the donors'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;
        give_update_payment_meta($payment_id, '_give_payment_meta', $payment_meta);
    }
    if ($payment_status == 'refunded' || $payment_status == 'reversed') {
        // Process a refund
        give_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 = give_get_payment_amount($payment_id);
        if (number_format((double) $paypal_amount, 2) < number_format((double) $payment_amount, 2)) {
            // The prices don't match
            give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
            give_update_payment_status($payment_id, 'failed');
            give_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'give'));
            return;
        }
        if ($purchase_key != give_get_payment_key($payment_id)) {
            // Purchase keys don't match
            give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
            give_update_payment_status($payment_id, 'failed');
            give_insert_payment_note($payment_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'give'));
            return;
        }
        if ($payment_status == 'completed' || give_is_test_mode()) {
            give_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'give'), $data['txn_id']));
            give_set_payment_transaction_id($payment_id, $data['txn_id']);
            give_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', 'give');
                        break;
                    case 'address':
                        $note = __('Payment requires a confirmed donor address and must be accepted manually through PayPal', 'give');
                        break;
                    case 'intl':
                        $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'give');
                        break;
                    case 'multi-currency':
                        $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'give');
                        break;
                    case 'paymentreview':
                    case 'regulatory_review':
                        $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'give');
                        break;
                    case 'unilateral':
                        $note = __('Payment was sent to non-confirmed or non-registered email address.', 'give');
                        break;
                    case 'upgrade':
                        $note = __('PayPal account must be upgraded before this payment can be accepted', 'give');
                        break;
                    case 'verify':
                        $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'give');
                        break;
                    case 'other':
                        $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'give');
                        break;
                }
                if (!empty($note)) {
                    give_insert_payment_note($payment_id, $note);
                }
            }
        }
    }
}
Ejemplo n.º 11
0
 /**
  * Retrieves Recent Sales
  *
  * @access public
  * @since  1.1
  * @return array
  */
 public function get_recent_donations()
 {
     global $wp_query;
     $sales = array();
     if (!user_can($this->user_id, 'view_give_reports') && !$this->override) {
         return $sales;
     }
     if (isset($wp_query->query_vars['id'])) {
         $query = array();
         $query[] = give_get_payment_by('id', $wp_query->query_vars['id']);
     } elseif (isset($wp_query->query_vars['purchasekey'])) {
         $query = array();
         $query[] = give_get_payment_by('key', $wp_query->query_vars['purchasekey']);
     } elseif (isset($wp_query->query_vars['email'])) {
         $query = give_get_payments(array('meta_key' => '_give_payment_user_email', 'meta_value' => $wp_query->query_vars['email'], 'number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish'));
     } else {
         $query = give_get_payments(array('number' => $this->per_page(), 'page' => $this->get_paged(), 'status' => 'publish'));
     }
     if ($query) {
         $i = 0;
         foreach ($query as $payment) {
             $payment_meta = give_get_payment_meta($payment->ID);
             $user_info = give_get_payment_meta_user_info($payment->ID);
             $sales['donations'][$i]['ID'] = give_get_payment_number($payment->ID);
             $sales['donations'][$i]['transaction_id'] = give_get_payment_transaction_id($payment->ID);
             $sales['donations'][$i]['key'] = give_get_payment_key($payment->ID);
             $sales['donations'][$i]['total'] = give_get_payment_amount($payment->ID);
             $sales['donations'][$i]['gateway'] = give_get_payment_gateway($payment->ID);
             $sales['donations'][$i]['email'] = give_get_payment_user_email($payment->ID);
             $sales['donations'][$i]['date'] = $payment->post_date;
             $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : $payment_meta;
             $price = isset($payment_meta['form_id']) ? give_get_form_price($payment_meta['form_id']) : false;
             $price_id = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null;
             $sales['donations'][$i]['form']['id'] = $form_id;
             $sales['donations'][$i]['form']['name'] = get_the_title($payment_meta['form_id']);
             $sales['donations'][$i]['form']['price'] = $price;
             if (give_has_variable_prices($form_id)) {
                 if (isset($payment_meta['price_id'])) {
                     $price_name = give_get_price_option_name($form_id, $payment_meta['price_id'], $payment->ID);
                     $sales['donations'][$i]['form']['price_name'] = $price_name;
                     $sales['donations'][$i]['form']['price'] = give_get_price_option_amount($form_id, $price_id);
                 }
             }
             $i++;
         }
     }
     return $sales;
 }
Ejemplo n.º 12
0
/**
 * Retrieves the transaction ID for the given payment
 *
 * @since  1.0
 *
 * @param int $payment_id Payment ID
 *
 * @return string The Transaction ID
 */
function give_get_payment_transaction_id($payment_id = 0)
{
    $transaction_id = false;
    $transaction_id = give_get_payment_meta($payment_id, '_give_payment_transaction_id', true);
    if (empty($transaction_id)) {
        $gateway = give_get_payment_gateway($payment_id);
        $transaction_id = apply_filters('give_get_payment_transaction_id-' . $gateway, $payment_id);
    }
    return apply_filters('give_get_payment_transaction_id', $transaction_id, $payment_id);
}