/** * Static method that is fired right after a donation is completed, sending the donation receipt. * * @param int $donation_id * @return boolean * @access public * @static * @since 1.0.0 */ public static function send_with_donation_id($donation_id) { if (!charitable_get_helper('emails')->is_enabled_email(self::get_email_id())) { return false; } if (!charitable_is_approved_status(get_post_status($donation_id))) { return false; } $donation = charitable_get_donation($donation_id); if (!is_object($donation) || 0 == count($donation->get_campaign_donations())) { return false; } if (!apply_filters('charitable_send_' . self::get_email_id(), true, $donation)) { return false; } $email = new Charitable_Email_New_Donation(array('donation' => $donation)); /** * Don't resend the email. */ if ($email->is_sent_already($donation_id)) { return false; } $sent = $email->send(); /** * Log that the email was sent. */ if (apply_filters('charitable_log_email_send', true, self::get_email_id(), $email)) { $email->log($donation_id, $sent); } return true; }
/** * Return list of donation IDs together with the number of donations they have made. * * @return object[] * @access public * @since 1.4.0 */ public function get_donations() { $records = $this->query(); if ('donations' != $this->get('output')) { return $records; } $objects = array(); foreach ($records as $row) { $objects[] = charitable_get_donation($row->ID); } return $objects; }
/** * @covers charitable_cancel_donation * @depends test_cancel_donation */ public function test_do_not_cancel_donation() { /** * Temporary workaround for issue noted below. * @see https://core.trac.wordpress.org/ticket/37207 */ Charitable_Post_Types::get_instance()->add_endpoints(); $donation_id = $this->create_donation('charitable-pending'); $campaign_donation = current(charitable_get_donation($donation_id)->get_campaign_donations()); $donate_url = charitable_get_campaign_donation_page_permalink(false, array('campaign_id' => $campaign_donation->campaign_id)); $this->go_to($donate_url); $this->assertFalse(charitable_cancel_donation()); }
/** * Static method that is fired right after a donation is completed, sending the donation receipt. * * @param int $donation_id * @return boolean * @access public * @static * @since 1.0.0 */ public static function send_with_donation_id($donation_id) { if (!charitable_get_helper('emails')->is_enabled_email(self::get_email_id())) { return false; } if (!charitable_is_approved_status(get_post_status($donation_id))) { return false; } $email = new Charitable_Email_Donation_Receipt(array('donation' => charitable_get_donation($donation_id))); /** * Don't resend the email. */ if ($email->is_sent_already($donation_id)) { return false; } $sent = $email->send(); /** * Log that the email was sent. */ if (apply_filters('charitable_log_email_send', true, self::get_email_id(), $email)) { $email->log($donation_id, $sent); } return true; }
/** * Process the bulk actions * * @access public * @since 1.0.0 * @return void */ public function process_bulk_action() { $ids = isset($_GET['donation']) ? $_GET['donation'] : array(); $action = $this->current_action(); if (empty($action) || empty($ids)) { return; } /* Bulk delete donations */ if ('delete' == $action) { foreach ($ids as $id) { wp_delete_post($id); } } /* Check for status change */ foreach ($this->donation_statuses as $status_key => $label) { if ('set-' . $status_key != $action) { continue; } foreach ($ids as $id) { charitable_get_donation($id)->update_status($status_key); do_action('charitable_donations_table_do_bulk_action', $id, $action); } } }
?> </p> </div> </div> <?php if (count($donations)) { ?> <div class="recent-donations"> <table> <caption><h3><?php _e('Recent Donations', 'charitable'); ?> </h3></caption> <?php foreach ($donations as $donation_id) { $donation = charitable_get_donation($donation_id); ?> <tr> <td class="donation-date"><?php echo $donation->get_date(); ?> </td> <td class="donation-id">#<?php echo $donation->get_number(); ?> </td> <td class="donation-status"><?php echo $donation->get_status(true); ?> </td> <td class="donation-total"><?php
<?php /** * Renders the donation details meta box for the Donation post type. * * @author Studio 164a * @since 1.0.0 */ global $post; $meta = charitable_get_donation($post->ID)->get_donation_meta(); ?> <div id="charitable-donation-details-metabox" class="charitable-metabox"> <dl> <?php foreach ($meta as $key => $details) { ?> <dt><?php echo $details['label']; ?> </dt> <dd><?php echo $details['value']; ?> </dd> <?php } ?> </dl> </div>
/** * Process the donation with the gateway. * * @param mixed $return * @param int $donation_id * @param Charitable_Donation_Processor $processor * @return boolean|array * @access public * @static * @since 1.0.0 */ public static function process_donation($return, $donation_id, $processor) { $gateway = new Charitable_Gateway_Extension_Boilerplate(); $donation = charitable_get_donation($donation_id); $donor = $donation->get_donor(); $values = $processor->get_donation_data(); // API keys // $keys = $gateway->get_keys(); // Donation fields // $donation_key = $donation->get_donation_key(); // $item_name = sprintf( __( 'Donation %d', 'charitable-payu-money' ), $donation->ID );; // $description = $donation->get_campaigns_donated_to(); // $amount = $donation->get_total_donation_amount( true ); // Donor fields // $first_name = $donor->get_donor_meta( 'first_name' ); // $last_name = $donor->get_donor_meta( 'last_name' ); // $address = $donor->get_donor_meta( 'address' ); // $address_2 = $donor->get_donor_meta( 'address_2' ); // $email = $donor->get_donor_meta( 'email' ); // $city = $donor->get_donor_meta( 'city' ); // $state = $donor->get_donor_meta( 'state' ); // $country = $donor->get_donor_meta( 'country' ); // $postcode = $donor->get_donor_meta( 'postcode' ); // $phone = $donor->get_donor_meta( 'phone' ); // URL fields // $return_url = charitable_get_permalink( 'donation_receipt_page', array( 'donation_id' => $donation->ID ) ); // $cancel_url = charitable_get_permalink( 'donation_cancel_page', array( 'donation_id' => $donation->ID ) ); // $notify_url = function_exists( 'charitable_get_ipn_url' ) // ? charitable_get_ipn_url( Charitable_Gateway_Sparrow::ID ) // : Charitable_Donation_Processor::get_instance()->get_ipn_url( Charitable_Gateway_Sparrow::ID ); // Credit card fields // $cc_expiration = $this->get_gateway_value( 'cc_expiration', $values ); // $cc_number = $this->get_gateway_value( 'cc_number', $values ); // $cc_year = $cc_expiration['year']; // $cc_month = $cc_expiration['month']; // $cc_cvc = $this->get_gateway_value( 'cc_cvc', $values ); /** * @todo Create donation charge through gateway. * * You should return one of three values. * * 1. If the donation fails to be processed and the user should be * returned to the donation page, return false. * 2. If the donation succeeds and the user should be directed to * the donation receipt, return true. * 3. If the user should be redirected elsewhere (for example, * a gateway-hosted payment page), you should return an array * like this: array( 'redirect' => $redirect_url, 'safe' => false // Set to false if you are redirecting away from the site. ); * */ return true; }
/** * Returns the current donation object. If there is no current donation, return false. * * @return Charitable_Donation|false * @access public * @since 1.0.0 */ public function get_current_donation() { if (!isset($this->donation)) { $donation_id = $this->get_current_donation_id(); $this->donation = $donation_id ? charitable_get_donation($donation_id) : false; } return $this->donation; }
<?php /** * Renders the donation details meta box for the Donation post type. * * @author Studio 164a * @since 1.0.0 */ global $post; $donation = charitable_get_donation($post->ID); $donor = $donation->get_donor(); ?> <div id="charitable-donation-overview-metabox" class="charitable-metabox"> <div id="donor" class="charitable-media-block"> <div class="donor-avatar charitable-media-image"> <?php echo $donor->get_avatar(80); ?> </div> <div class="donor-facts charitable-media-body"> <h3 class="donor-name"><?php echo $donor->get_name(); ?> </h3> <span class="donor-email"><?php echo $donor->get_email(); ?> </span> <?php /** * @hook charitable_donation_details_donor_facts
/** * Automatically mark all offline donations as Paid. * * @param boolean $return * @param int $donation_id * @return boolean */ function ed_auto_complete_offline_donation($return, $donation_id) { charitable_get_donation($donation_id)->update_status('charitable-completed'); return $return; }
/** * Filter the date and time fields. * * @param mixed $value * @param string $key * @param array $data * @return mixed * @access public * @since 1.0.0 */ public function set_custom_field_data($value, $key, $data) { switch ($key) { case 'date': if (isset($data['post_date'])) { $value = mysql2date('l, F j, Y', $data['post_date']); } break; case 'time': if (isset($data['post_date'])) { $value = mysql2date('H:i A', $data['post_date']); } break; case 'status': if (isset($data['post_status'])) { $value = $this->statuses[$data['post_status']]; } break; case 'address': $value = charitable_get_donation($data['donation_id'])->get_donor()->get_donor_meta('address'); break; case 'address_2': $value = charitable_get_donation($data['donation_id'])->get_donor()->get_donor_meta('address_2'); break; case 'city': $value = charitable_get_donation($data['donation_id'])->get_donor()->get_donor_meta('city'); break; case 'state': $value = charitable_get_donation($data['donation_id'])->get_donor()->get_donor_meta('state'); break; case 'postcode': $value = charitable_get_donation($data['donation_id'])->get_donor()->get_donor_meta('postcode'); break; case 'country': $value = charitable_get_donation($data['donation_id'])->get_donor()->get_donor_meta('country'); break; case 'phone': $value = charitable_get_donation($data['donation_id'])->get_donor()->get_donor_meta('phone'); break; case 'address_formatted': $value = str_replace('<br/>', PHP_EOL, charitable_get_donation($data['donation_id'])->get_donor_address()); break; case 'donation_gateway': $gateway = charitable_get_donation($data['donation_id'])->get_gateway_object(); $value = is_a($gateway, 'Charitable_Gateway') ? $gateway->get_name() : ''; break; } return $value; }
/** * Get a donation's log. * * @return array * @since 1.0.0 */ function charitable_get_donation_log($donation_id) { charitable_get_donation($donation_id)->get_donation_log(); }
/** * Add a message to the donation log. * * @param string $message * @return void * @access public * @since 1.0.0 */ public function update_donation_log($donation_id, $message) { $donation = charitable_get_donation($donation_id); if ($donation) { $donation->update_donation_log($message); } }
/** * Returns the URL for the campaign donation page. * * This is used when you call charitable_get_permalink( 'donation_cancel_page' ). In * general, you should use charitable_get_permalink() instead since it will * take into account permalinks that have been filtered by plugins/themes. * * @global WP_Rewrite $wp_rewrite * * @param string $url The default URL. * @param array $args An array of arguments. * @return string * @since 1.4.0 */ function charitable_get_donation_cancel_page_permalink($url, $args = array()) { global $wp_rewrite; /* A donation ID must be provided. */ if (!isset($args['donation_id'])) { return $url; } /* Grab the first campaign donation. */ $campaign_donation = current(charitable_get_donation($args['donation_id'])->get_campaign_donations()); $donation_page = charitable_get_permalink('campaign_donation_page', array('campaign_id' => $campaign_donation->campaign_id)); return esc_url_raw(add_query_arg(array('donation_id' => $args['donation_id'], 'cancel' => true), $donation_page)); }
/** * Receives verified IPN data from PayPal and processes the donation. * * @return void * @access public * @static * @since 1.0.0 */ public static function process_web_accept($data, $donation_id) { if (!isset($data['invoice'])) { return; } $gateway = new Charitable_Gateway_Paypal(); $donation = charitable_get_donation($donation_id); if ('paypal' != $donation->get_gateway()) { return; } $donation_key = $data['invoice']; $amount = $data['mc_gross']; $payment_status = strtolower($data['payment_status']); $currency_code = strtoupper($data['mc_currency']); $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); /* Verify that the business email matches the PayPal email in the settings */ if (strcasecmp($business_email, trim($gateway->get_value('paypal_email'))) != 0) { $message = sprintf('%s %s', __('Invalid Business email in the IPN response. IPN data:', 'charitable'), json_encode($data)); $donation->update_donation_log($message); $donation->update_status('charitable-failed'); return; } /* Verify that the currency matches. */ if (charitable_get_currency() != $currency_code) { $message = sprintf('%s %s', __('The currency in the IPN response does not match the site currency. IPN data:', 'charitable'), json_encode($data)); $donation->update_donation_log($message); $donation->update_status('charitable-failed'); return; } /* Process a refunded donation. */ if (in_array($payment_status, array('refunded', 'reversed'))) { /* It's a partial refund. */ if ($amount < $donation->get_total_donation_amount(true)) { $message = sprintf('%s: #%s', __('Partial PayPal refund processed', 'charitable'), isset($data['parent_txn_id']) ? $data['parent_txn_id'] : ''); } else { $message = sprintf('%s #%s %s: %s', __('PayPal Payment', 'charitable'), isset($data['parent_txn_id']) ? $data['parent_txn_id'] : '', __('refunded with reason', 'charitable'), isset($data['reason_code']) ? $data['reason_code'] : ''); } $donation->process_refund($amount, $message); return; } /* Mark a payment as failed. */ if (in_array($payment_status, array('declined', 'failed', 'denied', 'expired', 'voided'))) { $message = sprintf('%s: %s', __('The donation has failed with the following status', 'charitable'), $payment_status); $donation->update_donation_log($message); $donation->update_status('charitable-failed'); return; } /* If we have already processed this donation, stop here. */ if ('charitable-completed' == get_post_status($donation_id)) { return; } /* Verify that the donation key matches the one stored for the donation. */ if ($donation_key != $donation->get_donation_key()) { $message = sprintf('%s %s', __('Donation key in the IPN response does not match the donation. IPN data:', 'charitable'), json_encode($data)); $donation->update_donation_log($message); $donation->update_status('charitable-failed'); return; } /* Verify that the amount in the IPN matches the amount we expected. */ if ($amount < $donation->get_total_donation_amount(true)) { $message = sprintf('%s %s', __('The amount in the IPN response does not match the expected donation amount. IPN data:', 'charitable'), json_encode($data)); $donation->update_donation_log($message); $donation->update_status('charitable-failed'); return; } /* Process a completed donation. */ if ('completed' == $payment_status) { $message = sprintf('%s: %s', __('PayPal Transaction ID', 'charitable'), $data['txn_id']); $donation->update_donation_log($message); $donation->update_status('charitable-completed'); return; } /* If the donation is set to pending but has a pending_reason provided, save that to the log. */ if ('pending' == $payment_status) { if (isset($data['pending_reason'])) { $message = $gateway->get_pending_reason_note(strtolower($data['pending_reason'])); $donation->update_donation_log($message); } $donation->update_status('charitable-pending'); } }
public function test_get_campaigns_donated_to() { $donation_id = Charitable_Donation_Helper::create_donation(array('campaigns' => array(array('campaign_id' => $this->campaign_1->ID, 'campaign_name' => 'Test Campaign 1', 'amount' => 10), array('campaign_id' => $this->campaign_2->ID, 'campaign_name' => 'Test Campaign 2', 'amount' => 10)), 'status' => 'charitable-pending')); $donation = charitable_get_donation($donation_id); $this->assertEquals('Test Campaign 1, Test Campaign 2', $donation->get_campaigns_donated_to()); }
/** * Returns the set value for a particular user field. * * @param string $key * @param string $default Optional. The value that will be used if none is set. * @return mixed * @access public * @since 1.0.0 */ public function get_user_value($key, $default = '') { if (isset($_POST[$key])) { return $_POST[$key]; } if (isset($_GET['donation_id'])) { $donation = charitable_get_donation($_GET['donation_id']); $value = $donation->get_donor()->get_donor_meta($key); if ($value) { return $value; } } if (!$this->get_user() || !$this->get_user()->has_prop($key)) { return $default; } return $this->get_user()->get($key); }
/** * Load the donation template if we're looking at the donate page. * * @param string $template * @return string * @access protected * @since 1.0.0 */ protected function get_donate_template($template) { /* If a donation ID is included, make sure it belongs to the current user. */ $donation_id = get_query_var('donation_id', false); if ($donation_id) { $donation = charitable_get_donation($donation_id); if (!$donation || !$donation->is_from_current_user()) { wp_safe_redirect(charitable_get_permalink('campaign_donation_page')); exit; } } /* If the campaign has exired, redirect the user to the campaign page. */ $campaign = charitable_get_current_campaign(); if (!$campaign || $campaign->has_ended()) { wp_safe_redirect(get_permalink($campaign->ID)); exit; } do_action('charitable_is_donate_page'); $new_template = apply_filters('charitable_donate_page_template', array('campaign-donation-page.php', 'page.php', 'index.php')); return charitable_get_template_path($new_template, $template); }
/** * Respond to changes in donation status. * * @param string $new_status * @param string $old_status * @param WP_Post $post * @return void * @access public * @since 1.2.0 * * @deprecated 1.4.0 */ public function handle_donation_status_change($new_status, $old_status, $post) { charitable_get_deprecated()->deprecated_function(__METHOD__, '1.4.0', __('Handled automatically when $donation->update_status() is called.', 'reach')); if (Charitable::DONATION_POST_TYPE != $post->post_type) { return; } $valid_statuses = charitable_get_valid_donation_statuses(); if ('new' == $old_status) { $message = sprintf(__('Donation status set to %s.', 'charitable'), $valid_statuses[$new_status]); } else { $message = sprintf(__('Donation status updated from %s to %s.', 'charitable'), $valid_statuses[$old_status], $valid_statuses[$new_status]); } charitable_get_donation($post->ID)->update_donation_log($message); }
/** * Returns the donation object. Caches the object to avoid re-creating this for each column. * * @return Charitable_Donation * @access private * @since 1.0.0 */ private function get_donation($post_id) { $donation = wp_cache_get($post_id, 'charitable_donation'); if (false === $donation) { $donation = charitable_get_donation($post_id); wp_cache_set($post_id, $donation, 'charitable_donation'); } return $donation; }
/** * Add the National ID Number value for donation. * * @param mixed $value * @param string $key * @param array $data * @return mixed */ function ed_donation_export_add_national_id_number_value($value, $key, $data) { if ('national_id_number' != $key) { return $value; } return ed_donation_get_national_id_number(charitable_get_donation($data['donation_id'])); }
<?php /** * Partial template displaying donations in the activity feed shown on user profiles. * * @package Reach */ if (!reach_has_charitable()) { return; } $donation = charitable_get_donation(get_the_ID()); $campaign_id = current($donation->get_campaign_donations())->campaign_id; ?> <li class="activity-type-donation cf"> <p class="activity-summary"> <?php printf(_x('%1$s backed %2$s', 'user backed campaign(s)', 'reach'), '<span class="display-name">' . reach_get_current_author()->display_name . '</span>', $donation->get_campaigns_donated_to(true)); ?> <br /> <span class="time-ago"><?php printf(_x('%s ago', 'time ago', 'reach'), human_time_diff(get_the_time('U'), current_time('timestamp'))); ?> </span> </p> <?php if (has_post_thumbnail($campaign_id)) { echo get_the_post_thumbnail($campaign_id, 'thumbnail'); } ?> </li><!-- .activity-type-donation -->
/** * Return the parent donation, if exists * * @return false|Charitable_Donation * @access public * @since 1.4.5 */ public function get_donation_plan() { if (!isset($this->parent_donation)) { if ($this->donation_data->post_parent > 0) { $this->parent_donation = charitable_get_donation($this->donation_data->post_parent); } else { $this->parent_donation = false; } } return $this->parent_donation; }