/** * 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); }
* @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 do_action('give_view_order_details_before', $payment_id); ?>
/** * Render the User Column * * @access public * @since 1.0 * * @param array $payment Contains all the data of the payment * * @return string Data shown in the User column */ public function column_user($payment) { $user_id = give_get_payment_user_id($payment->ID); if ($user_id && $user_id > 0) { $user = get_userdata($user_id); $display_name = is_object($user) ? $user->display_name : __('guest', 'give'); } else { $display_name = __('guest', 'give'); } $value = '<a href="' . esc_url(add_query_arg(array('user' => urlencode($payment->user_info['email']), 'paged' => false))) . '">' . $display_name . '</a>'; return apply_filters('give_payments_table_column', $value, $payment->ID, 'user'); }
/** * Receipt Shortcode * * Shows an order receipt. * * @since 1.0 * * @param array $atts Shortcode attributes * @param string $content * * @return string */ function give_receipt_shortcode($atts, $content = null) { global $give_receipt_args, $payment; //set $session var $session = give_get_purchase_session(); //set payment key var if (isset($_GET['payment_key'])) { $payment_key = urldecode($_GET['payment_key']); } elseif ($give_receipt_args['payment_key']) { $payment_key = $give_receipt_args['payment_key']; } else { if ($session) { $payment_key = $session['purchase_key']; } } ob_start(); //Check for payment key if (empty($payment_key)) { ?> <div class="give_errors"> <p class="give_error"><?php echo apply_filters('give_receipt_no_payment_key', __('Sorry, there was a problem identifying this donation. Please contact the site owner for more information.', 'give')); ?> </p> </div> <?php return ob_get_clean(); //return error } //Set our important payment information variables $give_receipt_args['id'] = give_get_purchase_id_by_key($payment_key); $donor_id = give_get_payment_user_id($give_receipt_args['id']); $payment = get_post($give_receipt_args['id']); $give_receipt_args = shortcode_atts(array('error' => __('Sorry, it appears the viewing window for this donation receipt has expired or you do not have the permission to view this donation receipt.', 'give'), 'price' => true, 'date' => true, 'notes' => true, 'payment_key' => false, 'payment_method' => true, 'payment_id' => true), $atts, 'give_receipt'); //Is registration open? If so, add better error messaging to tell user their session expired if (get_option('users_can_register')) { $email = get_post_meta($payment->ID, '_give_payment_user_email', true); $donation_history = get_permalink(give_get_option('history_page')); $give_receipt_args['error'] .= sprintf(__(' To view your receipt, please <a href="%s">create an account</a> using the following email %s (the email attached to this donation) and visit the <a href="%s">donation history page</a>'), wp_registration_url(), '<strong>' . $email . '</strong>', $donation_history); } /* * Check if the user has permission to view the receipt * * If user is logged in, user ID is compared to user ID of ID stored in payment meta * * Or if user is logged out and donation was made as a guest, the donation session is checked for * * Or if user is logged in and the user can view sensitive donor data */ $user_can_view = is_user_logged_in() && $donor_id == get_current_user_id() || ($donor_id == 0 || $donor_id == '-1') && !is_user_logged_in() && give_get_purchase_session() || current_user_can('view_give_sensitive_data'); if (!apply_filters('give_user_can_view_receipt', $user_can_view, $give_receipt_args)) { ?> <div class="give_errors"> <p class="give_error"><?php echo $give_receipt_args['error']; ?> </p> </div> <?php return ob_get_clean(); // ?> <?php } give_get_template_part('shortcode', 'receipt'); $display = ob_get_clean(); return $display; }
/** * 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); } } }
/** * Is the payment provided associated with a user account * * @since 1.3 * * @param int $payment_id The payment ID * * @return bool If the payment is associated with a user (false) or not (true) */ function give_is_guest_payment($payment_id) { $payment_user_id = give_get_payment_user_id($payment_id); $is_guest_payment = !empty($payment_user_id) && $payment_user_id > 0 ? false : true; return (bool) apply_filters('give_is_guest_payment', $is_guest_payment, $payment_id); }