/** * Set it Up */ public function setUp() { parent::setUp(); $payment_id = Give_Helper_Payment::create_simple_payment(); $this->_payment_key = give_get_payment_key($payment_id); $this->_payment_id = $payment_id; $this->_key = $this->_payment_key; $this->_transaction_id = 'FIR3SID3'; give_set_payment_transaction_id($payment_id, $this->_transaction_id); give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Transaction ID: %s', 'give'), $this->_transaction_id)); // Make sure we're working off a clean object caching in WP Core. // Prevents some payment_meta from not being present. clean_post_cache($payment_id); update_postmeta_cache(array($payment_id)); }
/** * 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); }
/** * Email template tag: receipt_link. * * Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly. * * @param int $payment_id * * @return string receipt_link */ function give_email_tag_receipt_link($payment_id) { $receipt_url = esc_url(add_query_arg(array('payment_key' => give_get_payment_key($payment_id), 'give_action' => 'view_receipt'), home_url())); $formatted = sprintf('<a href="%1$s">%2$s</a>', $receipt_url, esc_html__('View it in your browser', 'give')); if (give_get_option('email_template') !== 'none') { return $formatted; } else { return $receipt_url; } }
echo give_get_gateway_admin_label($gateway); ?> </p> </div> <?php } ?> <div class="give-order-payment-key give-admin-box-inside"> <p> <span class="label"><?php _e('Key:', 'give'); ?> </span> <span><?php echo give_get_payment_key($payment_id); ?> </span> </p> </div> <div class="give-order-ip give-admin-box-inside"> <p> <span class="label"><?php _e('IP:', 'give'); ?> </span> <span><?php echo esc_html(give_get_payment_user_ip($payment_id)); ?> </span>
/** * Email template tag: receipt_link * Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly * * @param int $payment_id * * @return string receipt_link */ function give_email_tag_receipt_link($payment_id) { return sprintf(__('%1$sView it in your browser.%2$s', 'give'), '<a href="' . esc_url(add_query_arg(array('payment_key' => give_get_payment_key($payment_id), 'give_action' => 'view_receipt'), home_url())) . '">', '</a>'); }
/** * 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; }
/** * 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; }
/** * Get Payment Meta for a specific Payment * * @since 1.0 * * @param int $payment_id Payment ID * @param string $meta_key The meta key to pull * @param bool $single Pull single meta entry or as an object * * @return mixed $meta Payment Meta */ function give_get_payment_meta($payment_id = 0, $meta_key = '_give_payment_meta', $single = true) { $meta = get_post_meta($payment_id, $meta_key, $single); if ($meta_key === '_give_payment_meta') { if (empty($meta['key'])) { $meta['key'] = give_get_payment_key($payment_id); } if (empty($meta['email'])) { $meta['email'] = give_get_payment_user_email($payment_id); } if (empty($meta['date'])) { $meta['date'] = get_post_field('post_date', $payment_id); } } $meta = apply_filters('give_get_payment_meta_' . $meta_key, $meta, $payment_id); return apply_filters('give_get_payment_meta', $meta, $payment_id, $meta_key); }
<span class="give_purchase_status <?php echo $post->post_status; ?> "><?php echo give_get_payment_status($post, true); ?> </span> <a href="<?php echo esc_url(add_query_arg('payment_key', give_get_payment_key($post->ID), give_get_success_page_uri())); ?> ">»</a> <?php } else { ?> <a href="<?php echo esc_url(add_query_arg('payment_key', give_get_payment_key($post->ID), give_get_success_page_uri())); ?> "><?php _e('View Details', 'give'); ?> </a> <?php } ?> </td> <?php do_action('give_purchase_history_row_end', $post->ID, $donation_data); ?> </tr> <?php }