HEX
Server: Apache/2
System: Linux bq-e705.pointdnshere.com 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User: wellmix (1103)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/wellmix/public_html/wp-content/plugins/pymntpl-paypal-woocommerce/updates/1.0.13.php
<?php

defined( 'ABSPATH' ) || exit();

if ( \function_exists( 'WC' ) ) {
	$container = \PaymentPlugins\WooCommerce\PPCP\Main::container();
	$settings  = $container->get( \PaymentPlugins\WooCommerce\PPCP\Admin\Settings\APISettings::class );
	/**
	 * @var \PaymentPlugins\WooCommerce\PPCP\Logger $logger
	 */
	$logger = $container->get( \PaymentPlugins\WooCommerce\PPCP\Logger::class );
	/**
	 * @var \PaymentPlugins\PayPalSDK\PayPalClient $client
	 */
	$client       = $container->get( \PaymentPlugins\PayPalSDK\PayPalClient::class );
	$environments = [ 'production', 'sandbox' ];
	foreach ( $environments as $environment ) {
		$webhook_id = $settings->get_webhook_id( $environment );
		if ( $webhook_id ) {
			// update the events that the webhook is subscribed to
			$patches  = [
				[
					'op'    => \PaymentPlugins\PayPalSDK\PatchRequest::REPLACE,
					'path'  => '/event_types',
					'value' => [
						[ 'name' => 'PAYMENT.CAPTURE.COMPLETED' ],
						[ 'name' => 'PAYMENT.CAPTURE.REFUNDED' ],
						[ 'name' => 'CHECKOUT.ORDER.APPROVED' ],
						[ 'name' => 'CHECKOUT.ORDER.PROCESSED' ],
						[ 'name' => 'CUSTOMER.DISPUTE.CREATED' ],
						[ 'name' => 'CUSTOMER.DISPUTE.RESOLVED' ]
					]
				]
			];
			$response = $client->environment( $environment )->webhooks->update( $webhook_id, $patches );
			if ( is_wp_error( $response ) ) {
				$logger->error( sprintf( 'Error updating webhook. ID: %1$s. Reason: %2$s', $webhook_id, $response->get_error_message() ) );
			} else {
				$logger->info( sprintf( 'Webhook %1$s updated.', $webhook_id ) );
			}
		}
	}
}