/**
  * Return the total amount donated.
  *
  * @return  string
  * @access  public
  * @since   1.4.2
  */
 public function get_donation_total($value)
 {
     if (!$this->has_valid_donation()) {
         return $value;
     }
     return charitable_format_money($this->donation->get_total_donation_amount());
 }
 /**
  * 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 = new Charitable_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));
         Charitable_Donation::update_donation_log($donation_id, $message);
         $donation->update_status('charitable-failed');
         return;
     }
     /* Verify that the currency matches. */
     if ($currency_code != charitable_get_currency()) {
         $message = sprintf('%s %s', __('The currency in the IPN response does not match the site currency. IPN data:', 'charitable'), json_encode($data));
         Charitable_Donation::update_donation_log($donation_id, $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()) {
             $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);
         Charitable_Donation::update_donation_log($donation_id, $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));
         Charitable_Donation::update_donation_log($donation_id, $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()) {
         $message = sprintf('%s %s', __('The amount in the IPN response does not match the expected donation amount. IPN data:', 'charitable'), json_encode($data));
         Charitable_Donation::update_donation_log($donation_id, $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']);
         Charitable_Donation::update_donation_log($donation_id, $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']));
             Charitable_Donation::update_donation_log($donation_id, $message);
         }
         $donation->update_status('charitable-pending');
     }
 }
Ejemplo n.º 3
0
    ?>
</h3></caption>
            <?php 
    foreach ($donations as $post) {
        $donation = new Charitable_Donation($post);
        ?>
            <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 
        echo charitable_format_money($donation->get_total_donation_amount());
        ?>
</td>
            </tr>
            <?php 
    }
    ?>
        </table>
    </div>
<?php 
}
Ejemplo n.º 4
0
 /**
  * @depends test_add_donation
  * @depends test_get_total_donation_amount
  */
 public function test_get_total_donation_amount_multi_donation()
 {
     $donation_id = Charitable_Donation_Helper::create_donation(array('campaigns' => array(array('campaign_id' => $this->campaign_1->ID, 'campaign_name' => 'Test Campaign', 'amount' => 50), array('campaign_id' => $this->campaign_2->ID, 'campaign_name' => 'Test Campaign 2', 'amount' => 75))));
     $donation = new Charitable_Donation($donation_id);
     $this->assertEquals(125, $donation->get_total_donation_amount());
 }
Ejemplo n.º 5
0
 /**
  * Get items
  *
  * @see Pronamic_Pay_PaymentDataInterface::get_items()
  * @return Pronamic_IDeal_Items
  */
 public function get_items()
 {
     $donation = new Charitable_Donation($this->donation_id);
     // Items
     $items = new Pronamic_IDeal_Items();
     // Item
     // We only add one total item, because iDEAL cant work with negative price items (discount)
     $item = new Pronamic_IDeal_Item();
     $item->setNumber($this->get_order_id());
     $item->setDescription($this->get_description());
     // @see http://plugins.trac.wordpress.org/browser/woocommerce/tags/1.5.2.1/classes/class-wc-order.php#L50
     $item->setPrice($donation->get_total_donation_amount());
     $item->setQuantity(1);
     $items->addItem($item);
     return $items;
 }