# give/4.17.0/src/Framework/PaymentGateways/Webhooks/EventHandlers/SubscriptionCompleted.php

GiveWP – Donation Plugin and Fundraising Platform, version 4.17.0. 30 lines.

- Page: https://pluginprobe.com/plugins/give/4.17.0/code/src/Framework/PaymentGateways/Webhooks/EventHandlers/SubscriptionCompleted.php
- Raw: https://pluginprobe.com/plugins/give/4.17.0/raw/src/Framework/PaymentGateways/Webhooks/EventHandlers/SubscriptionCompleted.php
- Modified: 2024-03-13T21:54:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.17.0/code/src/Framework/PaymentGateways/Webhooks/EventHandlers/SubscriptionCompleted.php#L10-L20`.

```php
<?php

namespace Give\Framework\PaymentGateways\Webhooks\EventHandlers;

use Exception;
use Give\Framework\PaymentGateways\Webhooks\EventHandlers\Actions\UpdateSubscriptionStatus;
use Give\Subscriptions\ValueObjects\SubscriptionStatus;

/**
 * @since 3.6.0
 */
class SubscriptionCompleted
{
    /**
     * @since 3.6.0
     *
     * @throws Exception
     */
    public function __invoke(string $gatewaySubscriptionId, string $message = '')
    {
        $subscription = give()->subscriptions->getByGatewaySubscriptionId($gatewaySubscriptionId);

        if ( ! $subscription || $subscription->status->isCompleted()) {
            return;
        }

        (new UpdateSubscriptionStatus())($subscription, SubscriptionStatus::COMPLETED(), $message);
    }
}

```
