PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / TestData / Repositories / DonationRepository.php
DonationRepository.php
93 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\TestData\Repositories;
4
5 use Give\TestData\Factories\DonationFactory;
6 use Give\TestData\Framework\MetaRepository;
7 use Give\ValueObjects\Money;
8 use Give_Donor;
9
10 class DonationRepository
11 {
12 /**
13 * @var DonationFactory
14 */
15 private $donationFactory;
16 /**
17 * @var RevenueRepository
18 */
19 private $revenueRepository;
20
21 /**
22 * @param DonationFactory $donationFactory
23 * @param RevenueRepository $revenueRepository
24 */
25 public function __construct(DonationFactory $donationFactory, RevenueRepository $revenueRepository)
26 {
27 $this->donationFactory = $donationFactory;
28 $this->revenueRepository = $revenueRepository;
29 }
30
31 /**
32 * @param array $donation
33 * @param array $params
34 */
35 public function insertDonation($donation, $params)
36 {
37 global $wpdb;
38
39 $donation = wp_parse_args(
40 apply_filters('give-test-data-donation-definition', $donation, $params),
41 $this->donationFactory->definition()
42 );
43
44 // Insert donation
45 $wpdb->insert(
46 "{$wpdb->prefix}posts",
47 [
48 'post_type' => 'give_payment',
49 'post_date' => $donation['completed_date'],
50 'post_status' => $donation['payment_status'],
51 ]
52 );
53
54 $donationID = $wpdb->insert_id;
55
56 // Insert donation in revenue table
57 $this->revenueRepository->insertRevenue(
58 [
59 'donation_id' => $donationID,
60 'form_id' => $donation['payment_form_id'],
61 'amount' => Money::of($donation['payment_total'], $donation['payment_currency'])->getMinorAmount(),
62 ]
63 );
64
65 $metaRepository = new MetaRepository('give_donationmeta', 'donation_id');
66
67 $metaRepository->persist(
68 $donationID,
69 [
70 '_give_payment_form_id' => $donation['payment_form_id'],
71 '_give_payment_form_title' => $donation['payment_form_title'],
72 '_give_payment_donor_id' => $donation['donor_id'],
73 '_give_payment_total' => $donation['payment_total'],
74 '_give_payment_currency' => $donation['payment_currency'],
75 '_give_payment_gateway' => $donation['payment_gateway'],
76 '_give_payment_mode' => $donation['payment_mode'],
77 '_give_payment_purchase_key' => $donation['payment_purchase_key'],
78 '_give_completed_date' => $donation['completed_date'],
79 '_give_donor_billing_first_name' => $donation['donor_name'],
80 '_give_donor_billing_last_name' => '',
81 '_give_payment_donor_email' => $donation['donor_email'],
82 ]
83 );
84
85 // Increase donor donated amount and count
86 $donor = new Give_Donor($donation['donor_id']);
87 $donor->increase_value(floatval($donation['payment_total']));
88 $donor->increase_purchase_count();
89
90 do_action('give-test-data-insert-donation', $donationID, $donation, $params);
91 }
92 }
93