mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Fix merge conflicts
This commit is contained in:
commit
f5a2fca5fb
10 changed files with 289 additions and 33 deletions
21
modules/ppcp-wc-gateway/package.json
Normal file
21
modules/ppcp-wc-gateway/package.json
Normal 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"
|
||||
}
|
||||
}
|
34
modules/ppcp-wc-gateway/resources/js/gateway-settings.js
Normal file
34
modules/ppcp-wc-gateway/resources/js/gateway-settings.js
Normal 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-save_paypal_account"
|
||||
)
|
||||
|
||||
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));
|
||||
}
|
||||
);
|
|
@ -9,7 +9,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway;
|
||||
|
||||
use Dhii\Data\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
|
@ -1886,10 +1885,19 @@ return array(
|
|||
},
|
||||
'wcgateway.url' => static function ( $container ): string {
|
||||
return plugins_url(
|
||||
'/modules/ppcp-wc-gateway/',
|
||||
$container->get( 'wcgateway.relative-path' ),
|
||||
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
'wcgateway.relative-path' => static function( $container ): string {
|
||||
return 'modules/ppcp-wc-gateway/';
|
||||
},
|
||||
'wcgateway.absolute-path' => static function( $container ): string {
|
||||
return plugin_dir_path(
|
||||
dirname( __FILE__, 3 ) . '/woocommerce-paypal-payments.php'
|
||||
) .
|
||||
$container->get( 'wcgateway.relative-path' );
|
||||
},
|
||||
'wcgateway.endpoint.return-url' => static function ( $container ) : ReturnUrlEndpoint {
|
||||
$gateway = $container->get( 'wcgateway.paypal-gateway' );
|
||||
$endpoint = $container->get( 'api.endpoint.order' );
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Register and configure assets provided by this module.
|
||||
*
|
||||
* @package WooCommerce\PayPalCommerce\WcGateway\Assets
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
||||
|
||||
/**
|
||||
* Class SettingsPageAssets
|
||||
*/
|
||||
class SettingsPageAssets {
|
||||
|
||||
/**
|
||||
* The URL of this module.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $module_url;
|
||||
/**
|
||||
* The filesystem path to the module dir.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $module_path;
|
||||
|
||||
/**
|
||||
* Assets constructor.
|
||||
*
|
||||
* @param string $module_url The url of this module.
|
||||
* @param string $module_path The filesystem path to this module.
|
||||
*/
|
||||
public function __construct( string $module_url, string $module_path ) {
|
||||
$this->module_url = $module_url;
|
||||
$this->module_path = $module_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register assets provided by this module.
|
||||
*/
|
||||
public function register_assets() {
|
||||
if ( is_admin() && ! is_ajax() ) {
|
||||
$this->register_admin_assets();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register assets for admin pages.
|
||||
*/
|
||||
private function register_admin_assets() {
|
||||
$gateway_settings_script_path = trailingslashit( $this->module_path ) . 'assets/js/gateway-settings.js';
|
||||
|
||||
add_action(
|
||||
'admin_enqueue_scripts',
|
||||
function() use ( $gateway_settings_script_path ) {
|
||||
wp_enqueue_script(
|
||||
'ppcp-gateway-settings',
|
||||
trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js',
|
||||
array(),
|
||||
file_exists( $gateway_settings_script_path ) ? (string) filemtime( $gateway_settings_script_path ) : null,
|
||||
true
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
|
@ -125,23 +125,33 @@ class SettingsListener {
|
|||
exit;
|
||||
}
|
||||
|
||||
public function listen_for_vaulting_enabled() {
|
||||
if ( ! $this->is_valid_site_request() ) {
|
||||
return;
|
||||
}
|
||||
if ( ! isset( $_POST['ppcp']['vault_enabled'] ) && ! isset( $_POST['ppcp']['save_paypal_account'] ) && ! isset( $_POST['ppcp']['dcc_vault_enabled'] ) && ! isset( $_POST['ppcp']['dcc_save_card'] ) ) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Prevent enabling both Pay Later messaging and PayPal vaulting
|
||||
*/
|
||||
public function listen_for_vaulting_enabled() {
|
||||
if ( ! $this->is_valid_site_request() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->settings->set( 'message_enabled', false );
|
||||
$this->settings->set( 'message_product_enabled', false );
|
||||
$this->settings->set( 'message_cart_enabled', false );
|
||||
$this->settings->persist();
|
||||
/**
|
||||
* No need to verify nonce here.
|
||||
*
|
||||
* phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
* phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
*/
|
||||
if ( ! isset( $_POST['ppcp']['vault_enabled'] ) && ! isset( $_POST['ppcp']['save_paypal_account'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' );
|
||||
wp_safe_redirect( $redirect_url, 302 );
|
||||
exit;
|
||||
}
|
||||
$this->settings->set( 'message_enabled', false );
|
||||
$this->settings->set( 'message_product_enabled', false );
|
||||
$this->settings->set( 'message_cart_enabled', false );
|
||||
$this->settings->persist();
|
||||
|
||||
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' );
|
||||
wp_safe_redirect( $redirect_url, 302 );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to the request.
|
||||
|
|
|
@ -10,7 +10,6 @@ declare(strict_types=1);
|
|||
namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
|
||||
use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesApply;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
|
@ -93,33 +92,89 @@ class SettingsRenderer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the notice, when onboarding failed.
|
||||
* Returns notices list.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages() : array {
|
||||
|
||||
$messages = array();
|
||||
|
||||
if ( $this->paypal_vaulting_is_enabled() || $this->pay_later_messaging_is_enabled() ) {
|
||||
$vaulting_title = __( 'PayPal vaulting', 'woocommerce-paypal-payments' );
|
||||
$pay_later_messages_title = __( 'Pay Later Messaging', 'woocommerce-paypal-payments' );
|
||||
|
||||
$enabled = $this->paypal_vaulting_is_enabled() ? $vaulting_title : $pay_later_messages_title;
|
||||
$disabled = $this->pay_later_messaging_is_enabled() ? $vaulting_title : $pay_later_messages_title;
|
||||
|
||||
$pay_later_messages_or_vaulting_text = sprintf(
|
||||
// translators: %1$s and %2$s is translated PayPal vaulting and Pay Later Messaging strings.
|
||||
__(
|
||||
'You have %1$s enabled, that\'s why %2$s options are unavailable now. You cannot use both features at the same time',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
$enabled,
|
||||
$disabled
|
||||
);
|
||||
$messages[] = new Message( $pay_later_messages_or_vaulting_text, 'warning' );
|
||||
}
|
||||
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Recommended
|
||||
//phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
if ( ! isset( $_GET['ppcp-onboarding-error'] ) || ! empty( $_POST ) ) {
|
||||
return array();
|
||||
return $messages;
|
||||
}
|
||||
//phpcs:enable WordPress.Security.NonceVerification.Recommended
|
||||
//phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
|
||||
$messages = array(
|
||||
new Message(
|
||||
__(
|
||||
'We could not complete the onboarding process. Some features, such as card processing, will not be available. To fix this, please try again.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'error',
|
||||
false
|
||||
$messages[] = new Message(
|
||||
__(
|
||||
'We could not complete the onboarding process. Some features, such as card processing, will not be available. To fix this, please try again.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'error',
|
||||
false
|
||||
);
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether PayPal vaulting is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function paypal_vaulting_is_enabled(): bool {
|
||||
$saving_paypal_account_is_enabled = $this->settings->has( 'save_paypal_account' ) &&
|
||||
(bool) $this->settings->get( 'save_paypal_account' );
|
||||
|
||||
$vault_is_enabled = $this->settings->has( 'vault_enabled' ) &&
|
||||
(bool) $this->settings->get( 'vault_enabled' );
|
||||
|
||||
return $saving_paypal_account_is_enabled || $vault_is_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether Pay Later message is enabled either for checkout, cart or product page.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function pay_later_messaging_is_enabled(): bool {
|
||||
$pay_later_message_enabled_for_checkout = $this->settings->has( 'message_enabled' )
|
||||
&& (bool) $this->settings->get( 'message_enabled' );
|
||||
|
||||
$pay_later_message_enabled_for_cart = $this->settings->has( 'message_cart_enabled' )
|
||||
&& (bool) $this->settings->get( 'message_cart_enabled' );
|
||||
|
||||
$pay_later_message_enabled_for_product = $this->settings->has( 'message_product_enabled' )
|
||||
&& (bool) $this->settings->get( 'message_product_enabled' );
|
||||
|
||||
return $pay_later_message_enabled_for_checkout ||
|
||||
$pay_later_message_enabled_for_cart ||
|
||||
$pay_later_message_enabled_for_product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the multiselect field.
|
||||
*
|
||||
|
@ -295,7 +350,7 @@ class SettingsRenderer {
|
|||
$key = 'ppcp[' . $field . ']';
|
||||
$id = 'ppcp-' . $field;
|
||||
$config['id'] = $id;
|
||||
$th_td = 'ppcp-heading' !== $config['type'] ? 'td' : 'td';
|
||||
$th_td = 'ppcp-heading' !== $config['type'] ? 'td' : 'th';
|
||||
$colspan = 'ppcp-heading' !== $config['type'] ? 1 : 2;
|
||||
$classes = isset( $config['classes'] ) ? $config['classes'] : array();
|
||||
$classes[] = sprintf( 'ppcp-settings-field-%s', str_replace( 'ppcp-', '', $config['type'] ) );
|
||||
|
|
|
@ -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,14 @@ class WcGatewayModule implements ModuleInterface {
|
|||
}
|
||||
);
|
||||
|
||||
if ( $container->has( 'wcgateway.url' ) ) {
|
||||
$assets = new SettingsPageAssets(
|
||||
$container->get( 'wcgateway.url' ),
|
||||
$container->get( 'wcgateway.absolute-path' )
|
||||
);
|
||||
$assets->register_assets();
|
||||
}
|
||||
|
||||
add_filter(
|
||||
Repository::NOTICES_FILTER,
|
||||
static function ( $notices ) use ( $container ): array {
|
||||
|
|
22
modules/ppcp-wc-gateway/webpack.config.js
Normal file
22
modules/ppcp-wc-gateway/webpack.config.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const path = require('path');
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
|
||||
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',
|
||||
}]
|
||||
}
|
||||
};
|
10
package.json
10
package.json
|
@ -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",
|
||||
|
|
26
tests/PHPUnit/WcGateway/Assets/SettingsPagesAssetsTest.php
Normal file
26
tests/PHPUnit/WcGateway/Assets/SettingsPagesAssetsTest.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
||||
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
class SettingsPagesAssetsTest extends TestCase
|
||||
{
|
||||
public function testRegisterAssets()
|
||||
{
|
||||
$moduleUrl = 'http://example.com/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway';
|
||||
$modulePath = '/var/www/html/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway';
|
||||
|
||||
$testee = new SettingsPageAssets($moduleUrl, $modulePath);
|
||||
|
||||
when('is_admin')
|
||||
->justReturn(true);
|
||||
when('is_ajax')
|
||||
->justReturn(false);
|
||||
|
||||
$testee->register_assets();
|
||||
|
||||
self::assertSame(has_action('admin_enqueue_scripts', "function()"), 10);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue