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-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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 {
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'wp',
|
|
|
|
static function () use ( $c ) {
|
|
|
|
if ( is_admin() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$button = $c->get( 'googlepay.button' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Button.
|
|
|
|
*
|
|
|
|
* @var ButtonInterface $button
|
|
|
|
*/
|
|
|
|
$button->render_buttons();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
add_action(
|
|
|
|
'wp_enqueue_scripts',
|
|
|
|
static function () use ( $c ) {
|
|
|
|
$button = $c->get( 'googlepay.button' );
|
|
|
|
assert( $button instanceof ButtonInterface );
|
|
|
|
|
|
|
|
if ( $button->should_load_script() ) {
|
|
|
|
$button->enqueue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-08-25 16:25:20 +01:00
|
|
|
add_action(
|
|
|
|
'woocommerce_blocks_payment_method_type_registration',
|
|
|
|
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
|
|
|
|
$payment_method_registry->register( $c->get( 'googlepay.blocks-payment-method' ) );
|
|
|
|
}
|
|
|
|
);
|
2023-08-22 08:44:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the key for the module.
|
|
|
|
*
|
|
|
|
* @return string|void
|
|
|
|
*/
|
|
|
|
public function getKey() {
|
|
|
|
}
|
|
|
|
}
|