allow to enable either vault or pay later message

This commit is contained in:
Kirill Braslavsky 2021-03-25 10:21:28 +02:00
parent 092a808066
commit 77efce52db
6 changed files with 144 additions and 4 deletions

View file

@ -0,0 +1,21 @@
{
"name": "ppcp-wc-gateway",
"version": "1.0.0",
"license": "GPL-3.0-or-later",
"main": "resources/js/gateway-settings.js",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"babel-loader": "^8.1.0",
"cross-env": "^5.0.1",
"file-loader": "^4.2.0",
"webpack": "^4.42.1",
"webpack-cli": "^3.1.2",
"babel-plugin-transform-object-rest-spread": "^6.26.0"
},
"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"
}
}

View file

@ -0,0 +1,34 @@
;document.addEventListener(
'DOMContentLoaded',
() => {
const payLaterMessagingCheckboxes = document.querySelectorAll(
"#ppcp-message_enabled, #ppcp-message_cart_enabled, #ppcp-message_product_enabled"
)
const vaultingCheckboxes = document.querySelectorAll(
"#ppcp-vault_enabled, #ppcp-dcc_vault_enabled"
)
function atLeastOneChecked(checkboxesNodeList) {
return Array.prototype.slice.call(checkboxesNodeList).filter(node => !node.disabled && node.checked).length > 0
}
function disableAll(nodeList){
nodeList.forEach(node => node.setAttribute('disabled', 'true'))
}
function enableAll(nodeList){
nodeList.forEach(node => node.removeAttribute('disabled'))
}
function updateCheckboxes() {
atLeastOneChecked(payLaterMessagingCheckboxes) ? disableAll(vaultingCheckboxes) : enableAll(vaultingCheckboxes)
atLeastOneChecked(vaultingCheckboxes) ? disableAll(payLaterMessagingCheckboxes) : enableAll(payLaterMessagingCheckboxes)
}
updateCheckboxes()
payLaterMessagingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes))
vaultingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes));
}
);

View file

@ -0,0 +1,52 @@
<?php
/**
* Register and configure assets provided by this module.
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
class SettingsPageAssets
{
/**
* @var string
*/
private $module_url;
/**
* Assets constructor.
* @param string $module_url The url of this module.
*/
public function __construct(string $module_url)
{
$this->module_url = $module_url;
}
/**
* Register assets provided by this module.
*/
public function register_assets(): void
{
if(is_admin() && ! is_ajax()){
$this->register_admin_assets();
}
}
/**
* Register assets for admin pages.
*/
private function register_admin_assets(): void
{
add_action('admin_enqueue_scripts', function(){
wp_enqueue_script(
'ppcp-gateway-settings',
trailingslashit($this->module_url) . 'assets/js/gateway-settings.js',
[],
null,
true
);
});
}
}

View file

@ -17,6 +17,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use WooCommerce\PayPalCommerce\WcGateway\Admin\OrderTablePaymentStatusColumn;
use WooCommerce\PayPalCommerce\WcGateway\Admin\PaymentStatusOrderDetail;
use WooCommerce\PayPalCommerce\WcGateway\Admin\RenderAuthorizeAction;
use WooCommerce\PayPalCommerce\WcGateway\Assets\SettingsPageAssets;
use WooCommerce\PayPalCommerce\WcGateway\Checkout\CheckoutPayPalAddressPreset;
use WooCommerce\PayPalCommerce\WcGateway\Checkout\DisableGateways;
use WooCommerce\PayPalCommerce\WcGateway\Endpoint\ReturnUrlEndpoint;
@ -72,6 +73,12 @@ class WcGatewayModule implements ModuleInterface {
}
);
if($container->has('wcgateway.url')) {
$assets = new SettingsPageAssets($container->get('wcgateway.url'));
$assets->register_assets();
}
add_filter(
Repository::NOTICES_FILTER,
static function ( $notices ) use ( $container ): array {

View file

@ -0,0 +1,24 @@
const path = require('path');
const isProduction = process.env.NODE_ENV === 'production';
debugger
module.exports = {
devtool: 'sourcemap',
mode: isProduction ? 'production' : 'development',
target: 'web',
entry: {
'gateway-settings': path.resolve('./resources/js/gateway-settings.js'),
},
output: {
path: path.resolve(__dirname, 'assets/'),
filename: 'js/[name].js',
},
module: {
rules: [{
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader',
}]
}
};

View file

@ -6,10 +6,12 @@
"license": "GPL-2.0",
"author": "WooCommerce",
"scripts": {
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install",
"install:modules": "yarn run install:modules:ppcp-button",
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build",
"build:modules": "yarn run build:modules:ppcp-button",
"install:modules:ppcp-button": "cd modules/ppcp-button && yarn install && cd -",
"install:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn install && cd -",
"install:modules": "yarn run install:modules:ppcp-button && yarn run install:modules:ppcp-wc-gateway",
"build:modules:ppcp-button": "cd modules/ppcp-button && yarn run build && cd -",
"build:modules:ppcp-wc-gateway": "cd modules/ppcp-wc-gateway && yarn run build && cd -",
"build:modules": "yarn run build:modules:ppcp-button && yarn build:modules:ppcp-wc-gateway",
"build:dev": "yarn run install:modules && yarn run build:modules",
"prebuild": "rm -rf ./vendor",