woocommerce-paypal-payments/modules/ppcp-googlepay/src/GooglepayModule.php

103 lines
2.4 KiB
PHP
Raw Normal View History

2023-08-22 08:44:32 +01:00
<?php
/**
* The Googlepay module.
*
* @package WooCommerce\PayPalCommerce\Googlepay
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Googlepay;
2023-08-25 16:25:20 +01:00
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
2023-08-24 17:30:29 +01:00
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
2023-09-08 18:43:33 +01:00
use WooCommerce\PayPalCommerce\Googlepay\Helper\ApmProductStatus;
2023-08-22 08:44:32 +01:00
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
2023-09-11 10:04:38 +01:00
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
2023-08-22 08:44:32 +01:00
/**
* Class GooglepayModule
*/
class GooglepayModule implements ModuleInterface {
/**
* {@inheritDoc}
*/
public function setup(): ServiceProviderInterface {
return new ServiceProvider(
require __DIR__ . '/../services.php',
require __DIR__ . '/../extensions.php'
);
}
/**
* {@inheritDoc}
*/
public function run( ContainerInterface $c ): void {
2023-09-01 11:32:26 +01:00
if ( ! $c->get( 'googlepay.eligible' ) ) {
return;
}
2023-09-08 18:43:33 +01:00
$button = $c->get( 'googlepay.button' );
assert( $button instanceof ButtonInterface );
2023-09-01 11:32:26 +01:00
$button->initialize();
if ( ! $c->get( 'googlepay.available' ) ) {
return;
}
2023-08-22 08:44:32 +01:00
add_action(
'wp',
2023-09-01 11:32:26 +01:00
static function () use ( $c, $button ) {
2023-08-22 08:44:32 +01:00
if ( is_admin() ) {
return;
}
2023-09-01 11:32:26 +01:00
$button->render();
2023-08-22 08:44:32 +01:00
}
);
add_action(
'wp_enqueue_scripts',
2023-09-01 11:32:26 +01:00
static function () use ( $c, $button ) {
$button->enqueue();
2023-08-22 08:44:32 +01:00
}
);
2023-08-25 16:25:20 +01:00
add_action(
'woocommerce_blocks_payment_method_type_registration',
2023-09-01 11:32:26 +01:00
function( PaymentMethodRegistry $payment_method_registry ) use ( $c, $button ): void {
if ( $button->is_enabled() ) {
$payment_method_registry->register( $c->get( 'googlepay.blocks-payment-method' ) );
}
2023-08-25 16:25:20 +01:00
}
);
2023-09-08 18:43:33 +01:00
// Clear product status handling.
add_action(
'woocommerce_paypal_payments_clear_apm_product_status',
2023-09-11 10:04:38 +01:00
function( Settings $settings = null ) use ( $c ): void {
2023-09-08 18:43:33 +01:00
$apm_status = $c->get( 'googlepay.helpers.apm-product-status' );
assert( $apm_status instanceof ApmProductStatus );
2023-09-11 10:04:38 +01:00
if ( ! $settings instanceof Settings ) {
$settings = null;
}
$apm_status->clear( $settings );
2023-09-08 18:43:33 +01:00
}
);
2023-08-22 08:44:32 +01:00
}
/**
* Returns the key for the module.
*
* @return string|void
*/
public function getKey() {
}
}