PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 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 All 255 releases
give / src / Framework / PaymentGateways / CommandHandlers / PaymentHandler.php

PaymentHandler.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Framework/PaymentGateways/CommandHandlers/PaymentHandler.php

61 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\PaymentGateways\CommandHandlers;
4
5 use Give\Donations\Models\Donation;
6 use Give\Donations\Models\DonationNote;
7 use Give\Donations\ValueObjects\DonationStatus;
8 use Give\Framework\Exceptions\Primitives\Exception;
9 use Give\Framework\PaymentGateways\Commands\PaymentCommand;
10
11 abstract class PaymentHandler
12 {
13 /**
14 * @var PaymentCommand
15 */
16 protected $paymentCommand;
17
18 /**
19 * @since 2.21.0 change return type to DonationStatus
20 *
21 * @since 2.18.0
22 */
23 abstract protected function getPaymentStatus(): DonationStatus;
24
25 /**
26 * @param PaymentCommand $paymentCommand
27 */
28 public function __construct(PaymentCommand $paymentCommand)
29 {
30 $this->paymentCommand = $paymentCommand;
31 }
32
33 /**
34 * @since 2.18.0
35 */
36 public static function make(PaymentCommand $paymentCommand): PaymentHandler
37 {
38 return new static($paymentCommand);
39 }
40
41 /**
42 * @since 2.21.0 replace $donationId with Donation model
43 * @since 2.18.0
44 *
45 * @throws Exception
46 */
47 public function handle(Donation $donation)
48 {
49 $donation->status = $this->getPaymentStatus();
50 $donation->gatewayTransactionId = $this->paymentCommand->gatewayTransactionId;
51 $donation->save();
52
53 foreach ($this->paymentCommand->paymentNotes as $paymentNote) {
54 DonationNote::create([
55 'donationId' => $donation->id,
56 'content' => $paymentNote
57 ]);
58 }
59 }
60 }
61