| 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 SubscriptionCompleted |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @since 3.6.0 |
| 16 |
* |
| 17 |
* @throws Exception |
| 18 |
*/ |
| 19 |
public function __invoke(string $gatewaySubscriptionId, string $message = '') |
| 20 |
{ |
| 21 |
$subscription = give()->subscriptions->getByGatewaySubscriptionId($gatewaySubscriptionId); |
| 22 |
|
| 23 |
if ( ! $subscription || $subscription->status->isCompleted()) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
(new UpdateSubscriptionStatus())($subscription, SubscriptionStatus::COMPLETED(), $message); |
| 28 |
} |
| 29 |
} |
| 30 |
|