PaymentAbandonedHandler.php
4 years ago
PaymentCompleteHandler.php
4 years ago
PaymentHandler.php
4 years ago
PaymentProcessingHandler.php
4 years ago
PaymentRefundedHandler.php
4 years ago
RedirectOffsiteHandler.php
4 years ago
RespondToBrowserHandler.php
4 years ago
SubscriptionCompleteHandler.php
4 years ago
PaymentHandler.php
61 lines
| 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 |