mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Add bancontact block checkout boilerplate
This commit is contained in:
parent
633ae1aed0
commit
60885b2ad9
10 changed files with 2472 additions and 0 deletions
14
modules/ppcp-local-alternative-payment-methods/.babelrc
Normal file
14
modules/ppcp-local-alternative-payment-methods/.babelrc
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
[
|
||||||
|
"@babel/preset-env",
|
||||||
|
{
|
||||||
|
"useBuiltIns": "usage",
|
||||||
|
"corejs": "3.25.0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"@babel/preset-react"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
3
modules/ppcp-local-alternative-payment-methods/.gitignore
vendored
Normal file
3
modules/ppcp-local-alternative-payment-methods/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
node_modules
|
||||||
|
assets/js
|
||||||
|
assets/css
|
33
modules/ppcp-local-alternative-payment-methods/package.json
Normal file
33
modules/ppcp-local-alternative-payment-methods/package.json
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"name": "ppcp-local-alternative-payment-methods",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
|
"browserslist": [
|
||||||
|
"> 0.5%",
|
||||||
|
"Safari >= 8",
|
||||||
|
"Chrome >= 41",
|
||||||
|
"Firefox >= 43",
|
||||||
|
"Edge >= 14"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"core-js": "^3.25.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.19",
|
||||||
|
"@babel/preset-env": "^7.19",
|
||||||
|
"@babel/preset-react": "^7.18.6",
|
||||||
|
"@woocommerce/dependency-extraction-webpack-plugin": "2.2.0",
|
||||||
|
"babel-loader": "^8.2",
|
||||||
|
"cross-env": "^7.0.3",
|
||||||
|
"file-loader": "^6.2.0",
|
||||||
|
"sass": "^1.42.1",
|
||||||
|
"sass-loader": "^12.1.0",
|
||||||
|
"webpack": "^5.76",
|
||||||
|
"webpack-cli": "^4.10"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
|
||||||
|
"watch": "cross-env BABEL_ENV=default NODE_ENV=production webpack --watch",
|
||||||
|
"dev": "cross-env BABEL_ENV=default webpack --watch"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
||||||
|
|
||||||
|
const config = wc.wcSettings.getSetting( 'ppcp-bancontact_data' );
|
||||||
|
console.log( config );
|
||||||
|
|
||||||
|
registerPaymentMethod( {
|
||||||
|
name: config.id,
|
||||||
|
label: <div dangerouslySetInnerHTML={ { __html: config.title } } />,
|
||||||
|
content: <div>Hi there!</div>,
|
||||||
|
edit: <div></div>,
|
||||||
|
ariaLabel: config.title,
|
||||||
|
canMakePayment: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
supports: {
|
||||||
|
features: config.supports,
|
||||||
|
},
|
||||||
|
} );
|
|
@ -12,10 +12,28 @@ namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'ppcp-local-apms.url' => static function ( ContainerInterface $container ): string {
|
||||||
|
/**
|
||||||
|
* The path cannot be false.
|
||||||
|
*
|
||||||
|
* @psalm-suppress PossiblyFalseArgument
|
||||||
|
*/
|
||||||
|
return plugins_url(
|
||||||
|
'/modules/ppcp-local-alternative-payment-methods/',
|
||||||
|
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||||
|
);
|
||||||
|
},
|
||||||
'ppcp-local-apms.bancontact.wc-gateway' => static function ( ContainerInterface $container ): BancontactGateway {
|
'ppcp-local-apms.bancontact.wc-gateway' => static function ( ContainerInterface $container ): BancontactGateway {
|
||||||
return new BancontactGateway(
|
return new BancontactGateway(
|
||||||
$container->get( 'api.endpoint.orders' ),
|
$container->get( 'api.endpoint.orders' ),
|
||||||
$container->get( 'api.factory.purchase-unit' )
|
$container->get( 'api.factory.purchase-unit' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'ppcp-local-apms.bancontact.payment-method' => static function(ContainerInterface $container): BancontactPaymentMethod {
|
||||||
|
return new BancontactPaymentMethod(
|
||||||
|
$container->get('ppcp-local-apms.url'),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get('ppcp-local-apms.bancontact.wc-gateway')
|
||||||
|
);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Bancontact payment method.
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
||||||
|
|
||||||
|
class BancontactPaymentMethod extends AbstractPaymentMethodType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL of this module.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $module_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The assets version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bancontact WC gateway.
|
||||||
|
*
|
||||||
|
* @var BancontactGateway
|
||||||
|
*/
|
||||||
|
private $gateway;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
string $module_url,
|
||||||
|
string $version,
|
||||||
|
BancontactGateway $gateway
|
||||||
|
) {
|
||||||
|
$this->module_url = $module_url;
|
||||||
|
$this->version = $version;
|
||||||
|
$this->gateway = $gateway;
|
||||||
|
|
||||||
|
$this->name = BancontactGateway::ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function initialize() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function is_active() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_script_handles() {
|
||||||
|
wp_register_script(
|
||||||
|
'ppcp-bancontact-checkout-block',
|
||||||
|
trailingslashit( $this->module_url ) . 'assets/js/bancontact-checkout-block.js',
|
||||||
|
array(),
|
||||||
|
$this->version,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( 'ppcp-bancontact-checkout-block' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function get_payment_method_data() {
|
||||||
|
return array(
|
||||||
|
'id' => $this->name,
|
||||||
|
'title' => $this->gateway->title,
|
||||||
|
'description' => $this->gateway->description,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
|
||||||
|
|
||||||
|
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||||
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
|
||||||
|
@ -35,5 +36,12 @@ class LocalAlternativePaymentMethodsModule implements ModuleInterface {
|
||||||
|
|
||||||
return $methods;
|
return $methods;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add_action(
|
||||||
|
'woocommerce_blocks_payment_method_type_registration',
|
||||||
|
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
|
||||||
|
$payment_method_registry->register( $c->get( 'ppcp-local-apms.bancontact.payment-method' ) );
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
const path = require( 'path' );
|
||||||
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
|
const DependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' );
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
devtool: isProduction ? 'source-map' : 'eval-source-map',
|
||||||
|
mode: isProduction ? 'production' : 'development',
|
||||||
|
target: 'web',
|
||||||
|
plugins: [ new DependencyExtractionWebpackPlugin() ],
|
||||||
|
entry: {
|
||||||
|
'bancontact-checkout-block': path.resolve(
|
||||||
|
'./resources/js/bancontact-checkout-block.js'
|
||||||
|
),
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.resolve( __dirname, 'assets/' ),
|
||||||
|
filename: 'js/[name].js',
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.js?$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: 'babel-loader',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.scss$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: 'file-loader',
|
||||||
|
options: {
|
||||||
|
name: 'css/[name].css',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ loader: 'sass-loader' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
2247
modules/ppcp-local-alternative-payment-methods/yarn.lock
Normal file
2247
modules/ppcp-local-alternative-payment-methods/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,7 @@
|
||||||
"install:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn install",
|
"install:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn install",
|
||||||
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install",
|
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install",
|
||||||
"install:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn install",
|
"install:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn install",
|
||||||
|
"install:modules:ppcp-local-alternative-payment-methods": "cd modules/ppcp-local-alternative-payment-methods && yarn install",
|
||||||
"install:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn install",
|
"install:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn install",
|
||||||
"install:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn install",
|
"install:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn install",
|
||||||
"install:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn install",
|
"install:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn install",
|
||||||
|
@ -30,6 +31,7 @@
|
||||||
"build:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run build",
|
"build:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run build",
|
||||||
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build",
|
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build",
|
||||||
"build:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run build",
|
"build:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run build",
|
||||||
|
"build:modules:ppcp-local-alternative-payment-methods": "cd modules/ppcp-local-alternative-payment-methods && yarn run build",
|
||||||
"build:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run build",
|
"build:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run build",
|
||||||
"build:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run build",
|
"build:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run build",
|
||||||
"build:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn run build",
|
"build:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn run build",
|
||||||
|
@ -47,6 +49,7 @@
|
||||||
"watch:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run watch",
|
"watch:modules:ppcp-paylater-configurator": "cd modules/ppcp-paylater-configurator && yarn run watch",
|
||||||
"watch:modules:ppcp-button": "cd modules/ppcp-button && yarn run watch",
|
"watch:modules:ppcp-button": "cd modules/ppcp-button && yarn run watch",
|
||||||
"watch:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run watch",
|
"watch:modules:ppcp-googlepay": "cd modules/ppcp-googlepay && yarn run watch",
|
||||||
|
"watch:modules:ppcp-local-alternative-payment-methods": "cd modules/ppcp-local-alternative-payment-methods && yarn run watch",
|
||||||
"watch:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run watch",
|
"watch:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run watch",
|
||||||
"watch:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run watch",
|
"watch:modules:ppcp-webhooks": "cd modules/ppcp-webhooks && yarn run watch",
|
||||||
"watch:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn run watch",
|
"watch:modules:ppcp-order-tracking": "cd modules/ppcp-order-tracking && yarn run watch",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue