/** * Get the Export Data. * * @access public * @since 1.5 * @global object $wpdb Used to query the database using the WordPress database API. * @return array $data The data for the CSV file. */ public function get_data() { global $wpdb; $data = array(); $args = array('number' => 30, 'page' => $this->step, 'status' => $this->status); if (!empty($this->start) || !empty($this->end)) { $args['date_query'] = array(array('after' => date('Y-n-d 00:00:00', strtotime($this->start)), 'before' => date('Y-n-d 23:59:59', strtotime($this->end)), 'inclusive' => true)); } //echo json_encode($args ); exit; $payments = give_get_payments($args); if ($payments) { foreach ($payments as $payment) { $payment_meta = give_get_payment_meta($payment->ID); $user_info = give_get_payment_meta_user_info($payment->ID); $total = give_get_payment_amount($payment->ID); $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email']; $products = ''; $skus = ''; if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user = false; } $data[] = array('id' => $payment->ID, 'seq_id' => give_get_payment_number($payment->ID), 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', 'form_id' => isset($payment_meta['form_id']) ? $payment_meta['form_id'] : '', 'form_name' => isset($payment_meta['form_title']) ? $payment_meta['form_title'] : '', 'skus' => $skus, 'amount' => html_entity_decode(give_format_amount($total)), 'gateway' => give_get_gateway_admin_label(get_post_meta($payment->ID, '_give_payment_gateway', true)), 'trans_id' => give_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'give'), 'status' => give_get_payment_status($payment, true)); } $data = apply_filters('give_export_get_data', $data); $data = apply_filters('give_export_get_data_' . $this->export_type, $data); return $data; } return false; }
/** * Get Magic Tag Conditional Data * * @description Example function that returns Custom field data if present, for any form ID * @param $payment_id * * @return string|void */ function rum_wohh_get_wohh_magic_tag_data($payment_id) { $form_id = give_get_payment_form_id($payment_id); $payment_meta = give_get_payment_meta($payment_id); $meta_vals = get_post_custom($payment_id); $output = ''; // Check if this payment's donation form ID matches the donation form we want custom email body copy if ($form_id == '1650') { // Online Donation form $donation_reason = ''; // get the custom field data for this donation if (isset($meta_vals['donation_reason'])) { $donation_reason = $meta_vals['donation_reason'][0]; } if ($donation_reason != '') { $output = '<strong>Reason for Donation:</strong> ' . $donation_reason; } } // Check if this payment's donation form ID matches the donation form we want custom email body copy if ($form_id == '1865') { // Annual Memorial Walk Butterfly Campaign $in_memory_of = ''; // get the custom field data for this donation if (isset($meta_vals['my_donation_is_in_memory_of'])) { $in_memory_of = $meta_vals['my_donation_is_in_memory_of'][0]; } if ($in_memory_of != '') { $output = '<strong>In Memory Of:</strong> ' . $in_memory_of; } } return $output; }
/** * Prevent the donor notification email but keep the admin notification email functionality. * * @param $payment_id */ function my123_give_remove_donor_notification($payment_id) { remove_action('give_complete_donation', 'give_trigger_donation_receipt', 999, 1); //Remove these lines to stop triggering the admin notification. $payment_data = give_get_payment_meta($payment_id); if (!give_admin_notices_disabled($payment_id)) { do_action('give_admin_donation_email', $payment_id, $payment_data); } }
/** * Get the Export Data * * @access public * @since 1.0 * @global object $wpdb Used to query the database using the WordPress * Database API * @return array $data The data for the CSV file */ public function get_data() { global $wpdb, $give_options; $data = array(); $payments = give_get_payments(array('offset' => 0, 'number' => -1, 'mode' => give_is_test_mode() ? 'test' : 'live', 'status' => isset($_POST['give_export_payment_status']) ? $_POST['give_export_payment_status'] : 'any', 'month' => isset($_POST['month']) ? absint($_POST['month']) : date('n'), 'year' => isset($_POST['year']) ? absint($_POST['year']) : date('Y'))); foreach ($payments as $payment) { $payment_meta = give_get_payment_meta($payment->ID); $user_info = give_get_payment_meta_user_info($payment->ID); $total = give_get_payment_amount($payment->ID); $user_id = isset($user_info['id']) && $user_info['id'] != -1 ? $user_info['id'] : $user_info['email']; $form_id = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : ''; $form_title = isset($payment_meta['form_title']) ? $payment_meta['form_title'] : ''; if (is_numeric($user_id)) { $user = get_userdata($user_id); } else { $user = false; } $data[] = array('id' => $payment->ID, 'seq_id' => give_get_payment_number($payment->ID), 'email' => $payment_meta['email'], 'first' => $user_info['first_name'], 'last' => $user_info['last_name'], 'address1' => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '', 'address2' => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '', 'city' => isset($user_info['address']['city']) ? $user_info['address']['city'] : '', 'state' => isset($user_info['address']['state']) ? $user_info['address']['state'] : '', 'country' => isset($user_info['address']['country']) ? $user_info['address']['country'] : '', 'zip' => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '', 'amount' => html_entity_decode(give_format_amount($total)), 'form_id' => $form_id, 'form' => $form_title, 'gateway' => give_get_gateway_admin_label(get_post_meta($payment->ID, '_give_payment_gateway', true)), 'trans_id' => give_get_payment_transaction_id($payment->ID), 'key' => $payment_meta['key'], 'date' => $payment->post_date, 'user' => $user ? $user->display_name : __('guest', 'give'), 'status' => give_get_payment_status($payment, true)); } $data = apply_filters('give_export_get_data', $data); $data = apply_filters('give_export_get_data_' . $this->export_type, $data); return $data; }
/** * Email the payment confirmation to the buyer in a customizable Donation Receipt * * @since 1.0 * * @param int $payment_id Payment ID * @param bool $admin_notice Whether to send the admin email notification or not (default: true) * * @return void */ function give_email_donation_receipt($payment_id, $admin_notice = true) { $payment_data = give_get_payment_meta($payment_id); $from_name = give_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); $from_name = apply_filters('give_purchase_from_name', $from_name, $payment_id, $payment_data); $from_email = give_get_option('from_email', get_bloginfo('admin_email')); $from_email = apply_filters('give_purchase_from_address', $from_email, $payment_id, $payment_data); $to_email = give_get_payment_user_email($payment_id); $subject = give_get_option('donation_subject', __('Donation Receipt', 'give')); $subject = apply_filters('give_donation_subject', wp_strip_all_tags($subject), $payment_id); $subject = give_do_email_tags($subject, $payment_id); $attachments = apply_filters('give_receipt_attachments', array(), $payment_id, $payment_data); $message = give_do_email_tags(give_get_email_body_content($payment_id, $payment_data), $payment_id); $emails = Give()->emails; $emails->__set('from_name', $from_name); $emails->__set('from_email', $from_email); $emails->__set('heading', __('Donation Receipt', 'give')); $headers = apply_filters('give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data); $emails->__set('headers', $headers); $emails->send($to_email, $subject, $message, $attachments); if ($admin_notice && !give_admin_notices_disabled($payment_id)) { do_action('give_admin_sale_notice', $payment_id, $payment_data); } }
/** * Send Offline Donation Instructions * * @description Sends a notice to the donor with offline instructions; can be customized per form * * @param int $payment_id * * @since 1.0 * @return void */ function give_offline_send_donor_instructions($payment_id = 0) { $payment_data = give_get_payment_meta($payment_id); $post_offline_customization_option = get_post_meta($payment_data['form_id'], '_give_customize_offline_donations', true); //Customize email content depending on whether the single form has been customized $email_content = give_get_option('global_offline_donation_email'); if ($post_offline_customization_option === 'yes') { $email_content = get_post_meta($payment_data['form_id'], '_give_offline_donation_email', true); } $from_name = give_get_option('from_name', wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES)); $from_name = apply_filters('give_purchase_from_name', $from_name, $payment_id, $payment_data); $from_email = give_get_option('from_email', get_bloginfo('admin_email')); $from_email = apply_filters('give_purchase_from_address', $from_email, $payment_id, $payment_data); $to_email = give_get_payment_user_email($payment_id); $subject = give_get_option('offline_donation_subject', __('Offline Donation Instructions', 'give')); if ($post_offline_customization_option === 'yes') { $subject = get_post_meta($payment_data['form_id'], '_give_offline_donation_subject', true); } $subject = apply_filters('give_offline_donation_subject', wp_strip_all_tags($subject), $payment_id); $subject = give_do_email_tags($subject, $payment_id); $attachments = apply_filters('give_offline_donation_attachments', array(), $payment_id, $payment_data); $message = give_do_email_tags($email_content, $payment_id); $emails = Give()->emails; $emails->__set('from_name', $from_name); $emails->__set('from_email', $from_email); $emails->__set('heading', __('Offline Donation Instructions', 'give')); $headers = apply_filters('give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data); $emails->__set('headers', $headers); $emails->send($to_email, $subject, $message, $attachments); }
* * @since 1.0 * @return void */ if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { wp_die(__('Donation ID not supplied. Please try again', 'give'), __('Error', 'give')); } // Setup the variables $payment_id = absint($_GET['id']); $number = give_get_payment_number($payment_id); $item = get_post($payment_id); // Sanity check... fail if purchase ID is invalid if (!is_object($item) || $item->post_type != 'give_payment') { wp_die(__('The specified ID does not belong to a payment. Please try again', 'give'), __('Error', 'give')); } $payment_meta = give_get_payment_meta($payment_id); $transaction_id = esc_attr(give_get_payment_transaction_id($payment_id)); $user_id = give_get_payment_user_id($payment_id); $donor_id = give_get_payment_customer_id($payment_id); $payment_date = strtotime($item->post_date); $user_info = give_get_payment_meta_user_info($payment_id); $address = !empty($user_info['address']) ? $user_info['address'] : array('line1' => '', 'line2' => '', 'city' => '', 'country' => '', 'state' => '', 'zip' => ''); $gateway = give_get_payment_gateway($payment_id); $currency_code = give_get_payment_currency_code($payment_id); ?> <div class="wrap give-wrap"> <h2><?php printf(__('Payment %s', 'give'), $number); ?> </h2> <?php
/** * 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); } } }
/** * Email template tag: donation * The form submitted to make the donation * * @param int $payment_id * * @return string $form_title */ function give_email_tag_donation($payment_id) { $payment_data = give_get_payment_meta($payment_id); $form_title = !empty($payment_data['form_title']) ? $payment_data['form_title'] : __('There was an error retrieving this donation title', 'give'); return $form_title; }
</th> <th class="give_purchase_details"><?php _e('Details', 'give'); ?> </th> <?php do_action('give_purchase_history_header_after'); ?> </tr> </thead> <?php foreach ($donations as $post) { setup_postdata($post); ?> <?php $donation_data = give_get_payment_meta($post->ID); ?> <tr class="give_purchase_row"> <?php do_action('give_purchase_history_row_start', $post->ID, $donation_data); ?> <td class="give_purchase_id">#<?php echo give_get_payment_number($post->ID); ?> </td> <td class="give_purchase_date"><?php echo date_i18n(get_option('date_format'), strtotime(get_post_field('post_date', $post->ID))); ?> </td> <td class="give_purchase_amount"> <span class="give_purchase_amount"><?php
/** * Determines the receipt visibility status * * @since 1.3.2 * * @param string $payment_key * * @return bool Whether the receipt is visible or not. */ function give_can_view_receipt($payment_key = '') { $return = false; if (empty($payment_key)) { return $return; } global $give_receipt_args; $give_receipt_args['id'] = give_get_purchase_id_by_key($payment_key); $user_id = (int) give_get_payment_user_id($give_receipt_args['id']); $payment_meta = give_get_payment_meta($give_receipt_args['id']); if (is_user_logged_in()) { if ($user_id === (int) get_current_user_id()) { $return = true; } elseif (wp_get_current_user()->user_email === give_get_payment_user_email($give_receipt_args['id'])) { $return = true; } elseif (current_user_can('view_give_sensitive_data')) { $return = true; } } $session = give_get_purchase_session(); if (!empty($session) && !is_user_logged_in()) { if ($session['purchase_key'] === $payment_meta['key']) { $return = true; } } return (bool) apply_filters('give_can_view_receipt', $return, $payment_key); }
/** * Search content for email tags and filter email tags through their hooks. * * @param string $content Content to search for email tags. * @param int $payment_id The payment id. * * @since 1.0 * * @return string Content with email tags filtered out. */ function give_do_email_tags($content, $payment_id) { // Replace all tags $content = Give()->email_tags->do_tags($content, $payment_id); // Maintaining backwards compatibility $content = apply_filters('give_email_template_tags', $content, give_get_payment_meta($payment_id), $payment_id); // Return content return $content; }
/** * Looks up purchases by email that match the registering user * * This is for users that purchased as a guest and then came * back and created an account. * * @access public * @since 1.0 * * @param $user_id INT - the new user's ID * * @return void */ function give_add_past_purchases_to_new_user($user_id) { $email = get_the_author_meta('user_email', $user_id); $payments = give_get_payments(array('s' => $email)); if ($payments) { foreach ($payments as $payment) { if (intval(give_get_payment_user_id($payment->ID)) > 0) { continue; } // This payment already associated with an account $meta = give_get_payment_meta($payment->ID); $meta['user_info'] = maybe_unserialize($meta['user_info']); $meta['user_info']['id'] = $user_id; $meta['user_info'] = $meta['user_info']; // Store the updated user ID in the payment meta give_update_payment_meta($payment->ID, '_give_payment_meta', $meta); give_update_payment_meta($payment->ID, '_give_payment_user_id', $user_id); } } }
/** * Updates all old payments, prior to 1.2, with new * meta for the total purchase amount * * This is so that payments can be queried by their totals * * @since 1.0 * * @param array $data Arguments passed * * @return void */ function give_update_old_payments_with_totals($data) { if (!wp_verify_nonce($data['_wpnonce'], 'give_upgrade_payments_nonce')) { return; } if (get_option('give_payment_totals_upgraded')) { return; } $payments = give_get_payments(array('offset' => 0, 'number' => -1, 'mode' => 'all')); if ($payments) { foreach ($payments as $payment) { $meta = give_get_payment_meta($payment->ID); give_update_payment_meta($payment->ID, '_give_payment_total', $meta['amount']); } } add_option('give_payment_totals_upgraded', 1); }
/** * Get Donation Referral Data * * @description Example function that returns Custom field data if present in payment_meta; the example used here is in conjunction with the Give documentation tutorials * @param $payment_id * * @return string|void */ function my_custom_prefix_get_donation_referral_data($payment_id, $payment_meta) { $payment_meta = give_get_payment_meta($payment_id); $output = __('No referral data found.', 'give'); if (!empty($payment_meta['message'])) { $output = $payment_meta['message']; } return $output; }
/** * 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); } } } } }
/** * 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; }
/** * Retrieves arbitrary fees for the donation (Currently not in use!!) * @TODO - Incorporate a fee-based functionality similar to below * @since 1.0 * * @param int $payment_id Payment ID * @param string $type Fee type * * @return mixed array if payment fees found, false otherwise */ function give_get_payment_fees($payment_id = 0, $type = 'all') { $payment_meta = give_get_payment_meta($payment_id); $fees = array(); $payment_fees = isset($payment_meta['fees']) ? $payment_meta['fees'] : false; if (!empty($payment_fees) && is_array($payment_fees)) { foreach ($payment_fees as $fee_id => $fee) { if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { unset($payment_fees[$fee_id]); } else { $fees[] = array('id' => $fee_id, 'amount' => $fee['amount'], 'label' => $fee['label']); } } } return apply_filters('give_get_payment_fees', $fees, $payment_id); }
/** * 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() { global $give_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(); $give_form = empty($_GET['s']) ? $this->get_filtered_give_form() : null; $user = $this->get_filtered_user(); $log_query = array('post_parent' => $give_form, 'log_type' => 'sale', 'paged' => $paged, 'meta_query' => $this->get_meta_query()); $logs = $give_logs->get_connected_logs($log_query); if ($logs) { foreach ($logs as $log) { $payment_id = get_post_meta($log->ID, '_give_log_payment_id', true); // Make sure this payment hasn't been deleted if (get_post($payment_id)) { $user_info = give_get_payment_meta_user_info($payment_id); $payment_meta = give_get_payment_meta($payment_id); $payment_amount = give_get_payment_amount($payment_id); $logs_data[] = array('ID' => '<span class="give-item-label give-item-label-gray">' . $log->ID . '</span>', 'payment_id' => $payment_id, 'form' => $log->post_parent, 'amount' => $payment_amount, 'user_id' => $user_info['id'], 'user_name' => $user_info['first_name'] . ' ' . $user_info['last_name'], 'date' => get_post_field('post_date', $payment_id)); } } } return $logs_data; }
<?php /** * This template is used to display the purchase summary with [give_receipt] */ global $give_receipt_args, $give_options, $payment; //Validation: Ensure $payment var is set if (empty($payment) && isset($give_receipt_args['id'])) { $payment = get_post($give_receipt_args['id']); } //Double-Validation: Check for $payment global if (empty($payment)) { give_output_error(__('The specified receipt ID appears to be invalid', 'give')); return; } $meta = give_get_payment_meta($payment->ID); $donation = $meta['form_title']; $user = give_get_payment_meta_user_info($payment->ID); $email = give_get_payment_user_email($payment->ID); $status = give_get_payment_status($payment, true); ?> <?php do_action('give_payment_receipt_before_table', $payment, $give_receipt_args); ?> <table id="give_donation_receipt" class="give-table"> <thead> <?php do_action('give_payment_receipt_before', $payment, $give_receipt_args); ?>
/** * 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); }
/** * * Process the payment details edit * * @access private * * @param $data * * @since 1.0 * @return void * */ function give_update_payment_details($data) { if (!current_user_can('edit_give_payments', $data['give_payment_id'])) { wp_die(__('You do not have permission to edit this payment record', 'give'), __('Error', 'give'), array('response' => 403)); } check_admin_referer('give_update_payment_details_nonce'); // Retrieve the payment ID $payment_id = absint($data['give_payment_id']); // Retrieve existing payment meta $meta = give_get_payment_meta($payment_id); $user_info = give_get_payment_meta_user_info($payment_id); $status = $data['give-payment-status']; $user_id = isset($data['give-payment-user-id']) ? intval($data['give-payment-user-id']) : ''; $date = sanitize_text_field($data['give-payment-date']); $hour = sanitize_text_field($data['give-payment-time-hour']); $form_id = give_get_payment_form_id($payment_id); // Restrict to our high and low if ($hour > 23) { $hour = 23; } elseif ($hour < 0) { $hour = 00; } $minute = sanitize_text_field($data['give-payment-time-min']); // Restrict to our high and low if ($minute > 59) { $minute = 59; } elseif ($minute < 0) { $minute = 00; } $address = array_map('trim', $data['give-payment-address'][0]); $date = date('Y-m-d', strtotime($date)) . ' ' . $hour . ':' . $minute . ':00'; $curr_total = give_sanitize_amount(give_get_payment_amount($payment_id)); $new_total = give_sanitize_amount($_POST['give-payment-total']); $curr_customer_id = sanitize_text_field($data['give-current-customer']); $new_customer_id = sanitize_text_field($data['customer-id']); do_action('give_update_edited_purchase', $payment_id); // Update main payment record $updated = wp_update_post(array('ID' => $payment_id, 'edit_date' => true, 'post_date' => $date)); if (0 === $updated) { wp_die(esc_attr__('Error Updating Payment', 'give'), esc_attr__('Error', 'give'), array('response' => 400)); } $customer_changed = false; if (isset($data['give-new-customer']) && $data['give-new-customer'] == '1') { $email = isset($data['give-new-customer-email']) ? sanitize_text_field($data['give-new-customer-email']) : ''; $names = isset($data['give-new-customer-name']) ? sanitize_text_field($data['give-new-customer-name']) : ''; if (empty($email) || empty($names)) { wp_die(esc_attr__('New Customers require a name and email address', 'give')); } $customer = new Give_Customer($email); if (empty($customer->id)) { $customer_data = array('name' => $names, 'email' => $email); $user_id = email_exists($email); if (false !== $user_id) { $customer_data['user_id'] = $user_id; } if (!$customer->create($customer_data)) { // Failed to crete the new customer, assume the previous customer $customer_changed = false; $customer = new Give_Customer($curr_customer_id); give_set_error('give-payment-new-customer-fail', __('Error creating new customer', 'give')); } } $new_customer_id = $customer->id; $previous_customer = new Give_Customer($curr_customer_id); $customer_changed = true; } elseif ($curr_customer_id !== $new_customer_id) { $customer = new Give_Customer($new_customer_id); $email = $customer->email; $names = $customer->name; $previous_customer = new Give_Customer($curr_customer_id); $customer_changed = true; } else { $customer = new Give_Customer($curr_customer_id); $email = $customer->email; $names = $customer->name; } // Setup first and last name from input values $names = explode(' ', $names); $first_name = !empty($names[0]) ? $names[0] : ''; $last_name = ''; if (!empty($names[1])) { unset($names[0]); $last_name = implode(' ', $names); } if ($customer_changed) { // Remove the stats and payment from the previous customer and attach it to the new customer $previous_customer->remove_payment($payment_id, false); $customer->attach_payment($payment_id, false); // If purchase was completed and not ever refunded, adjust stats of customers if ('revoked' == $status || 'publish' == $status) { $previous_customer->decrease_purchase_count(); $previous_customer->decrease_value($new_total); $customer->increase_purchase_count(); $customer->increase_value($new_total); } update_post_meta($payment_id, '_give_payment_customer_id', $customer->id); } // Set new meta values $user_info['id'] = $customer->user_id; $user_info['email'] = $customer->email; $user_info['first_name'] = $first_name; $user_info['last_name'] = $last_name; $user_info['address'] = $address; $meta['user_info'] = $user_info; // Check for payment notes if (!empty($data['give-payment-note'])) { $note = wp_kses($data['give-payment-note'], array()); give_insert_payment_note($payment_id, $note); } // Set new status give_update_payment_status($payment_id, $status); give_update_payment_meta($payment_id, '_give_payment_user_id', $customer->user_id); give_update_payment_meta($payment_id, '_give_payment_user_email', $customer->email); give_update_payment_meta($payment_id, '_give_payment_meta', $meta); give_update_payment_meta($payment_id, '_give_payment_total', $new_total); // Adjust total store earnings if the payment total has been changed if ($new_total !== $curr_total && ('publish' == $status || 'revoked' == $status)) { if ($new_total > $curr_total) { // Increase if our new total is higher $difference = $new_total - $curr_total; give_increase_total_earnings($difference); $form = new Give_Donate_Form($form_id); $form->increase_earnings($difference); } elseif ($curr_total > $new_total) { // Decrease if our new total is lower $difference = $curr_total - $new_total; give_decrease_total_earnings($difference); $form = new Give_Donate_Form($form_id); $form->decrease_earnings($difference); } } do_action('give_updated_edited_purchase', $payment_id); wp_safe_redirect(admin_url('edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&give-message=payment-updated&id=' . $payment_id)); exit; }