PaymentAbandonedHandler.php
4 years ago
PaymentCompleteHandler.php
4 years ago
PaymentHandler.php
4 years ago
PaymentPendingHandler.php
2 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
SubscriptionProcessingHandler.php
3 years ago
SubscriptionSyncedHandler.php
2 years ago
SubscriptionProcessingHandler.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\PaymentGateways\CommandHandlers; |
| 4 | |
| 5 | use Exception; |
| 6 | use Give\Donations\Models\Donation; |
| 7 | use Give\Donations\ValueObjects\DonationStatus; |
| 8 | use Give\Framework\PaymentGateways\Commands\SubscriptionProcessing; |
| 9 | use Give\Subscriptions\Models\Subscription; |
| 10 | use Give\Subscriptions\ValueObjects\SubscriptionStatus; |
| 11 | |
| 12 | /** |
| 13 | * @since 2.23.2 |
| 14 | */ |
| 15 | class SubscriptionProcessingHandler |
| 16 | { |
| 17 | /** |
| 18 | * @since 2.23.2 |
| 19 | * @var SubscriptionProcessing |
| 20 | */ |
| 21 | private $subscriptionComplete; |
| 22 | /** |
| 23 | * @since 2.23.2 |
| 24 | * @var Subscription |
| 25 | */ |
| 26 | private $subscription; |
| 27 | /** |
| 28 | * @since 2.23.2 |
| 29 | * @var Donation |
| 30 | */ |
| 31 | private $donation; |
| 32 | |
| 33 | /** |
| 34 | * @since 2.23.2 |
| 35 | */ |
| 36 | public function __construct( |
| 37 | SubscriptionProcessing $subscriptionComplete, |
| 38 | Subscription $subscription, |
| 39 | Donation $donation |
| 40 | ) { |
| 41 | $this->subscriptionComplete = $subscriptionComplete; |
| 42 | $this->subscription = $subscription; |
| 43 | $this->donation = $donation; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @since 2.23.2 |
| 48 | * @return void |
| 49 | * @throws Exception |
| 50 | */ |
| 51 | public function __invoke() |
| 52 | { |
| 53 | $this->donation->status = DonationStatus::PROCESSING(); |
| 54 | $this->subscription->status = SubscriptionStatus::PENDING(); |
| 55 | $this->subscription->gatewaySubscriptionId = $this->subscriptionComplete->gatewaySubscriptionId; |
| 56 | |
| 57 | // Only save no-empty gateway transaction ids. |
| 58 | if ($this->subscriptionComplete->gatewayTransactionId) { |
| 59 | $this->donation->gatewayTransactionId = $this->subscriptionComplete->gatewayTransactionId; |
| 60 | $this->subscription->transactionId = $this->subscriptionComplete->gatewayTransactionId; |
| 61 | } |
| 62 | |
| 63 | $this->donation->save(); |
| 64 | $this->subscription->save(); |
| 65 | } |
| 66 | } |
| 67 |