Add boilerplate for advanced card block integration

This commit is contained in:
Emili Castells Guasch 2024-04-16 12:05:06 +02:00
parent ffe3a0b958
commit 7c90031c4f
5 changed files with 103 additions and 0 deletions

View file

@ -0,0 +1,12 @@
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
const config = wc.wcSettings.getSetting('ppcp-credit-card-gateway_data');
registerPaymentMethod({
name: config.id,
label: <div dangerouslySetInnerHTML={{__html: config.title}}/>,
content: <p>content</p>,
edit: <p>edit...</p>,
ariaLabel: config.title,
canMakePayment: () => {return true},
})

View file

@ -45,6 +45,13 @@ return array(
$container->get( 'wcgateway.all-funding-sources' ) $container->get( 'wcgateway.all-funding-sources' )
); );
}, },
'blocks.advanced-card-method' => static function( ContainerInterface $container ): AdvancedCardPaymentMethod {
return new AdvancedCardPaymentMethod(
$container->get( 'blocks.url' ),
$container->get( 'ppcp.asset-version' ),
$container->get( 'wcgateway.credit-card-gateway' )
);
},
'blocks.settings.final_review_enabled' => static function ( ContainerInterface $container ): bool { 'blocks.settings.final_review_enabled' => static function ( ContainerInterface $container ): bool {
$settings = $container->get( 'wcgateway.settings' ); $settings = $container->get( 'wcgateway.settings' );
assert( $settings instanceof ContainerInterface ); assert( $settings instanceof ContainerInterface );

View file

@ -0,0 +1,82 @@
<?php
/**
* Advanced card payment method.
*
* @package WooCommerce\PayPalCommerce\Blocks
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Blocks;
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
class AdvancedCardPaymentMethod extends AbstractPaymentMethodType {
/**
* The URL of this module.
*
* @var string
*/
private $module_url;
/**
* The assets version.
*
* @var string
*/
private $version;
/**
* Credit card gateway.
*
* @var CreditCardGateway
*/
private $gateway;
public function __construct(
string $module_url,
string $version,
CreditCardGateway $gateway
) {
$this->name = CreditCardGateway::ID;
$this->module_url = $module_url;
$this->version = $version;
$this->gateway = $gateway;
}
public function initialize() {}
/**
* {@inheritDoc}
*/
public function is_active() {
return true;
}
/**
* {@inheritDoc}
*/
public function get_payment_method_script_handles() {
wp_register_script(
'ppcp-advanced-card-checkout-block',
trailingslashit( $this->module_url ) . 'assets/js/advanced-card-checkout-block.js',
array(),
$this->version,
true
);
return array( 'ppcp-advanced-card-checkout-block' );
}
/**
* {@inheritDoc}
*/
public function get_payment_method_data() {
return array(
'id' => $this->name,
'title' => $this->gateway->title,
'description' => $this->gateway->description,
);
}
}

View file

@ -61,6 +61,7 @@ class BlocksModule implements ModuleInterface {
'woocommerce_blocks_payment_method_type_registration', 'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void { function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
$payment_method_registry->register( $c->get( 'blocks.method' ) ); $payment_method_registry->register( $c->get( 'blocks.method' ) );
$payment_method_registry->register( $c->get( 'blocks.advanced-card-method' ) );
} }
); );

View file

@ -10,6 +10,7 @@ module.exports = {
plugins: [ new DependencyExtractionWebpackPlugin() ], plugins: [ new DependencyExtractionWebpackPlugin() ],
entry: { entry: {
'checkout-block': path.resolve('./resources/js/checkout-block.js'), 'checkout-block': path.resolve('./resources/js/checkout-block.js'),
'advanced-card-checkout-block': path.resolve('./resources/js/advanced-card-checkout-block.js'),
"gateway": path.resolve('./resources/css/gateway.scss') "gateway": path.resolve('./resources/css/gateway.scss')
}, },
output: { output: {