HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/wpmuhibbah/wp-content/plugins/give/src/Framework/PaymentGateways/ServiceProvider.php
<?php

namespace Give\Framework\PaymentGateways;

use Give\Donations\ValueObjects\DonationStatus;
use Give\Framework\PaymentGateways\Webhooks\EventHandlers\Actions\GetEventHandlerClassByDonationStatus;
use Give\Framework\PaymentGateways\Webhooks\EventHandlers\Actions\GetEventHandlerClassBySubscriptionStatus;
use Give\Framework\PaymentGateways\Webhooks\EventHandlers\SubscriptionFirstDonationCompleted;
use Give\Framework\PaymentGateways\Webhooks\EventHandlers\SubscriptionRenewalDonationCreated;
use Give\Helpers\Hooks;
use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;
use Give\Subscriptions\ValueObjects\SubscriptionStatus;

/**
 * @since 4.5.0
 */
class ServiceProvider implements ServiceProviderInterface
{
    /**
     * @since 4.5.0
     */
    public function register()
    {
        // TODO: Implement register() method.
    }

    /**
     * @since 4.5.0
     */
    public function boot()
    {
        $this->registerWebhookEventHandlers();
    }

    /**
     * @since 4.5.0
     */
    private function registerWebhookEventHandlers()
    {
        add_action('init', function () {
            $registeredPaymentGatewayIds = give()->gateways->getPaymentGateways();
            foreach ($registeredPaymentGatewayIds as $gatewayId => $class) {
                $this->addDonationStatusEventHandlers($gatewayId);
                $this->addSubscriptionStatusEventHandlers($gatewayId);
                $this->addSubscriptionFirstDonationEventHandler($gatewayId);
                $this->addSubscriptionRenewalDonationEventHandler($gatewayId);
            }
        }, 999);
    }

    /**
     * @since 4.5.0
     */
    private function addDonationStatusEventHandlers(string $gatewayId)
    {
        foreach (DonationStatus::values() as $status) {
            if ($eventHandlerClass = (new GetEventHandlerClassByDonationStatus())($status)) {
                Hooks::addAction(
                    sprintf('givewp_%s_webhook_event_donation_status_%s', $gatewayId, $status->getValue()),
                    $eventHandlerClass, '__invoke', 10, 3
                );
            }
        }
    }

    /**
     * @since 4.5.0
     */
    private function addSubscriptionStatusEventHandlers(string $gatewayId)
    {
        foreach (SubscriptionStatus::values() as $status) {
            if ($eventHandlerClass = (new GetEventHandlerClassBySubscriptionStatus())($status)) {
                $parameterCount = $status->isActive() ? 3 : 2;
                Hooks::addAction(
                    sprintf('givewp_%s_webhook_event_subscription_status_%s', $gatewayId, $status->getValue()),
                    $eventHandlerClass, '__invoke', 10, $parameterCount
                );
            }
        }
    }

    /**
     * @since 4.5.0
     */
    private function addSubscriptionFirstDonationEventHandler(string $gatewayId)
    {
        Hooks::addAction(
            sprintf('givewp_%s_webhook_event_subscription_first_donation', $gatewayId),
            SubscriptionFirstDonationCompleted::class, '__invoke', 10, 5
        );
    }

    /**
     * @since 4.5.0
     */
    private function addSubscriptionRenewalDonationEventHandler(string $gatewayId)
    {
        Hooks::addAction(
            sprintf('givewp_%s_webhook_event_subscription_renewal_donation', $gatewayId),
            SubscriptionRenewalDonationCreated::class, '__invoke', 10, 2
        );
    }
}