woocommerce-paypal-payments/modules/ppcp-blocks/src/BlocksModule.php

70 lines
1.8 KiB
PHP
Raw Normal View History

2022-12-20 16:04:11 +02:00
<?php
/**
* The blocks module.
*
* @package WooCommerce\PayPalCommerce\Blocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Blocks;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
2023-04-07 15:58:59 +03:00
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
2022-12-20 16:04:11 +02: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 BlocksModule
*/
class BlocksModule 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 {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
$payment_method_registry->register( $c->get( 'blocks.method' ) );
}
);
2023-04-07 15:58:59 +03:00
woocommerce_store_api_register_payment_requirements(
array(
'data_callback' => function() use ( $c ): array {
$smart_button = $c->get( 'button.smart-button' );
assert( $smart_button instanceof SmartButton );
if ( isset( $smart_button->script_data()['continuation'] ) ) {
return array( 'ppcp_continuation' );
}
return array();
},
)
);
2022-12-20 16:04:11 +02:00
}
}
/**
* Returns the key for the module.
*
* @return string|void
*/
public function getKey() {
}
}