PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.3
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
charitable / includes / donations / class-charitable-donation.php

class-charitable-donation.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.3, at includes/donations/class-charitable-donation.php

97 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Donation model.
4 *
5 * @package Charitable/Classes/Charitable_Donation
6 * @author David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.6.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Donation' ) ) :
19
20 /**
21 * Donation Model.
22 *
23 * @since 1.0.0
24 */
25 class Charitable_Donation extends Charitable_Abstract_Donation {
26
27 /**
28 * The type of donation.
29 *
30 * @since 1.4.0
31 *
32 * @var string
33 */
34 public $donation_type = 'simple';
35
36 /**
37 * Process a refund.
38 *
39 * @since 1.0.0
40 *
41 * @param float $refund_amount The amount to be refunded.
42 * @param string $message The message to add to the donation log.
43 * @return void
44 */
45 public function process_refund( $refund_amount, $message = '' ) {
46 $refund_log = get_post_meta( $this->ID, 'donation_refund', true );
47 $total_refund = isset( $refund_log['total_refund'] ) ? $refund_log['total_refund'] : 0;
48 $refunds_per_campaign = isset( $refund_log['campaign_refunds'] ) ? $refund_log['campaign_refunds'] : array();
49
50 foreach ( $this->get_campaign_donations() as $campaign_donation ) {
51
52 if ( 0 == $refund_amount ) {
53 break;
54 }
55
56 if ( ! isset( $refunds_per_campaign[ $campaign_donation->campaign_id ] ) ) {
57 $refunds_per_campaign[ $campaign_donation->campaign_id ] = array();
58 }
59
60 /**
61 * Calculate the amount to be refunded out of this particular campaign's amount.
62 *
63 * This takes into account any amounts that have already been refunded, to find the
64 * amount that remains credited towards to the campaign.
65 */
66 $campaign_remaining_amount = $campaign_donation->amount - array_sum( $refunds_per_campaign[ $campaign_donation->campaign_id ] );
67
68 if ( $campaign_remaining_amount > $refund_amount ) {
69 $campaign_refund_amount = $refund_amount;
70 } else {
71 $campaign_refund_amount = $campaign_remaining_amount;
72 }
73
74 $refunds_per_campaign[ $campaign_donation->campaign_id ][] = $campaign_refund_amount;
75
76 /* Reduce the remaining amount to refund. */
77 $refund_amount -= $campaign_refund_amount;
78
79 /* Increase the total refund amount. */
80 $total_refund += $campaign_refund_amount;
81 }
82
83 $refund_log = array(
84 'time' => time(),
85 'message' => $message,
86 'campaign_refunds' => $refunds_per_campaign,
87 'total_refund' => $total_refund,
88 );
89
90 update_post_meta( $this->ID, 'donation_refund', $refund_log );
91
92 $this->update_status( 'charitable-refunded' );
93 }
94 }
95
96 endif;
97