Actions
2 years ago
DonationAbandoned.php
2 years ago
DonationCancelled.php
2 years ago
DonationCompleted.php
2 years ago
DonationFailed.php
2 years ago
DonationPending.php
2 years ago
DonationPreapproval.php
2 years ago
DonationProcessing.php
2 years ago
DonationRefunded.php
2 years ago
DonationRevoked.php
2 years ago
SubscriptionActive.php
2 years ago
SubscriptionCancelled.php
2 years ago
SubscriptionCompleted.php
2 years ago
SubscriptionExpired.php
2 years ago
SubscriptionFailing.php
2 years ago
SubscriptionFirstDonationCompleted.php
2 years ago
SubscriptionRenewalDonationCreated.php
2 years ago
SubscriptionSuspended.php
2 years ago
SubscriptionActive.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\PaymentGateways\Webhooks\EventHandlers; |
| 4 | |
| 5 | use Exception; |
| 6 | use Give\Framework\PaymentGateways\Webhooks\EventHandlers\Actions\UpdateSubscriptionStatus; |
| 7 | use Give\Subscriptions\ValueObjects\SubscriptionStatus; |
| 8 | |
| 9 | /** |
| 10 | * @since 3.6.0 |
| 11 | */ |
| 12 | class SubscriptionActive |
| 13 | { |
| 14 | /** |
| 15 | * @since 3.6.0 |
| 16 | * |
| 17 | * @throws Exception |
| 18 | */ |
| 19 | public function __invoke( |
| 20 | string $gatewaySubscriptionId, |
| 21 | string $message = '', |
| 22 | bool $initialDonationShouldBeCompleted = false |
| 23 | ) |
| 24 | { |
| 25 | $subscription = give()->subscriptions->getByGatewaySubscriptionId($gatewaySubscriptionId); |
| 26 | |
| 27 | if ( ! $subscription || $subscription->status->isActive()) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | if ($initialDonationShouldBeCompleted && ! $subscription->initialDonation()->status->isComplete()) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | (new UpdateSubscriptionStatus())($subscription, SubscriptionStatus::ACTIVE(), $message); |
| 36 | } |
| 37 | } |
| 38 |