mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-03 08:37:53 +08:00
Merge branch 'trunk' into PCP-417-new-feature---pay-upon-invoice
This commit is contained in:
commit
cee42e7d4e
6 changed files with 97 additions and 87 deletions
|
@ -9,6 +9,18 @@
|
|||
"#ppcp-vault_enabled"
|
||||
)
|
||||
|
||||
const payLaterEnabledLabels = document.querySelectorAll(
|
||||
".ppcp-pay-later-enabled-label"
|
||||
)
|
||||
|
||||
const payLaterDisabledLabels = document.querySelectorAll(
|
||||
".ppcp-pay-later-disabled-label"
|
||||
)
|
||||
|
||||
const disabledCheckboxes = document.querySelectorAll(
|
||||
'.ppcp-disabled-checkbox'
|
||||
)
|
||||
|
||||
function atLeastOneChecked(checkboxesNodeList) {
|
||||
return Array.prototype.slice.call(checkboxesNodeList).filter(node => !node.disabled && node.checked).length > 0
|
||||
}
|
||||
|
@ -21,18 +33,41 @@
|
|||
nodeList.forEach(node => node.removeAttribute('disabled'))
|
||||
}
|
||||
|
||||
function updateCheckboxes() {
|
||||
atLeastOneChecked(payLaterMessagingCheckboxes) ? disableAll(vaultingCheckboxes) : enableAll(vaultingCheckboxes)
|
||||
atLeastOneChecked(vaultingCheckboxes) ? disableAll(payLaterMessagingCheckboxes) : enableAll(payLaterMessagingCheckboxes)
|
||||
|
||||
if(typeof PayPalCommerceGatewaySettings === 'undefined' || PayPalCommerceGatewaySettings.vaulting_features_available !== '1' ) {
|
||||
disableAll(vaultingCheckboxes)
|
||||
}
|
||||
function hideAll(nodeList) {
|
||||
nodeList.forEach(node => node.style.display = 'none')
|
||||
}
|
||||
|
||||
updateCheckboxes()
|
||||
function displayAll(nodeList) {
|
||||
nodeList.forEach(node => node.style.display = '')
|
||||
}
|
||||
|
||||
payLaterMessagingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes))
|
||||
vaultingCheckboxes.forEach(node => node.addEventListener('change', updateCheckboxes));
|
||||
function uncheckAll(nodeList){
|
||||
nodeList.forEach(node => {
|
||||
node.checked = false
|
||||
node.dispatchEvent(new Event('change'))
|
||||
})
|
||||
}
|
||||
|
||||
function disablePayLater() {
|
||||
uncheckAll(payLaterMessagingCheckboxes)
|
||||
disableAll(payLaterMessagingCheckboxes)
|
||||
hideAll(payLaterEnabledLabels)
|
||||
displayAll(payLaterDisabledLabels)
|
||||
}
|
||||
|
||||
function enablePayLater() {
|
||||
enableAll(payLaterMessagingCheckboxes)
|
||||
displayAll(payLaterEnabledLabels)
|
||||
hideAll(payLaterDisabledLabels)
|
||||
}
|
||||
|
||||
function togglePayLater() {
|
||||
atLeastOneChecked(vaultingCheckboxes) ? disablePayLater() : enablePayLater()
|
||||
}
|
||||
|
||||
disableAll( disabledCheckboxes )
|
||||
togglePayLater()
|
||||
|
||||
vaultingCheckboxes.forEach(node => node.addEventListener('change', togglePayLater));
|
||||
}
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway;
|
|||
use Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\MessagesDisclaimers;
|
||||
|
@ -797,15 +798,7 @@ return array(
|
|||
'title' => __( 'Vaulting', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
'label' => sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
|
||||
__( 'Enable saved cards and subscription features on your store. To use vaulting features, you must %1$senable vaulting on your account%2$s.', 'woocommerce-paypal-payments' ),
|
||||
'<a
|
||||
href="https://docs.woocommerce.com/document/woocommerce-paypal-payments/#enable-vaulting-on-your-live-account"
|
||||
target="_blank"
|
||||
>',
|
||||
'</a>'
|
||||
),
|
||||
'label' => $container->get( 'button.helper.vaulting-label' ),
|
||||
'description' => __( 'Allow registered buyers to save PayPal and Credit Card accounts. Allow Subscription renewals.', 'woocommerce-paypal-payments' ),
|
||||
'default' => false,
|
||||
'screens' => array(
|
||||
|
@ -813,6 +806,7 @@ return array(
|
|||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => array( 'paypal', 'dcc' ),
|
||||
'input_class' => $container->get( 'wcgateway.helper.vaulting-scope' ) ? array() : array( 'ppcp-disabled-checkbox' ),
|
||||
),
|
||||
'logging_enabled' => array(
|
||||
'title' => __( 'Logging', 'woocommerce-paypal-payments' ),
|
||||
|
@ -1003,7 +997,7 @@ return array(
|
|||
'message_enabled' => array(
|
||||
'title' => __( 'Enable message on Checkout', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable on Checkout', 'woocommerce-paypal-payments' ),
|
||||
'label' => sprintf( $container->get( 'wcgateway.settings.fields.pay-later-label' ), __( 'Enable on Checkout', 'woocommerce-paypal-payments' ) ),
|
||||
'default' => true,
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
|
@ -1309,7 +1303,7 @@ return array(
|
|||
'message_product_enabled' => array(
|
||||
'title' => __( 'Enable message on Single Product', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable on Single Product', 'woocommerce-paypal-payments' ),
|
||||
'label' => sprintf( $container->get( 'wcgateway.settings.fields.pay-later-label' ), __( 'Enable on Single Product', 'woocommerce-paypal-payments' ) ),
|
||||
'default' => true,
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
|
@ -1615,7 +1609,7 @@ return array(
|
|||
'message_cart_enabled' => array(
|
||||
'title' => __( 'Enable message on Cart', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable on Cart', 'woocommerce-paypal-payments' ),
|
||||
'label' => sprintf( $container->get( 'wcgateway.settings.fields.pay-later-label' ), __( 'Enable on Cart', 'woocommerce-paypal-payments' ) ),
|
||||
'default' => true,
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
|
@ -2061,17 +2055,6 @@ return array(
|
|||
$fields['disable_cards']['options'] = $card_options;
|
||||
$fields['card_icons']['options'] = array_merge( $dark_versions, $card_options );
|
||||
|
||||
/**
|
||||
* Display vault message on Pay Later label if vault is enabled.
|
||||
*/
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
if ( $settings->has( 'vault_enabled' ) && $settings->get( 'vault_enabled' ) ) {
|
||||
$message = __( "You have PayPal vaulting enabled, that's why Pay Later Messaging options are unavailable now. You cannot use both features at the same time.", 'woocommerce-paypal-payments' );
|
||||
$fields['message_enabled']['label'] = $message;
|
||||
$fields['message_product_enabled']['label'] = $message;
|
||||
$fields['message_cart_enabled']['label'] = $message;
|
||||
}
|
||||
|
||||
return $fields;
|
||||
},
|
||||
|
||||
|
@ -2231,4 +2214,44 @@ return array(
|
|||
$settings->has( 'logging_enabled' ) && $settings->get( 'logging_enabled' )
|
||||
);
|
||||
},
|
||||
|
||||
'wcgateway.helper.vaulting-scope' => static function ( ContainerInterface $container ): bool {
|
||||
try {
|
||||
$token = $container->get( 'api.bearer' )->bearer();
|
||||
return $token->vaulting_available();
|
||||
} catch ( RuntimeException $exception ) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
'button.helper.vaulting-label' => static function ( ContainerInterface $container ): string {
|
||||
$vaulting_label = __( 'Enable saved cards and subscription features on your store.', 'woocommerce-paypal-payments' );
|
||||
|
||||
if ( ! $container->get( 'wcgateway.helper.vaulting-scope' ) ) {
|
||||
$vaulting_label .= sprintf(
|
||||
// translators: %1$s and %2$s are the opening and closing of HTML <a> tag.
|
||||
__( ' To use vaulting features, you must %1$senable vaulting on your account%2$s.', 'woocommerce-paypal-payments' ),
|
||||
'<a
|
||||
href="https://docs.woocommerce.com/document/woocommerce-paypal-payments/#enable-vaulting-on-your-live-account"
|
||||
target="_blank"
|
||||
>',
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
|
||||
$vaulting_label .= '<p class="description">';
|
||||
$vaulting_label .= __( 'This will disable all Pay Later messaging on your site.', 'woocommerce-paypal-payments' );
|
||||
$vaulting_label .= '</p>';
|
||||
|
||||
return $vaulting_label;
|
||||
},
|
||||
|
||||
'wcgateway.settings.fields.pay-later-label' => static function ( ContainerInterface $container ): string {
|
||||
$pay_later_label = '<span class="ppcp-pay-later-enabled-label">%s</span>';
|
||||
$pay_later_label .= '<span class="ppcp-pay-later-disabled-label">';
|
||||
$pay_later_label .= __( "You have PayPal vaulting enabled, that's why Pay Later Messaging options are unavailable now. You cannot use both features at the same time.", 'woocommerce-paypal-payments' );
|
||||
$pay_later_label .= '</span>';
|
||||
|
||||
return $pay_later_label;
|
||||
},
|
||||
);
|
||||
|
|
|
@ -9,7 +9,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
|
@ -31,34 +30,24 @@ class SettingsPageAssets {
|
|||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* The bearer.
|
||||
*
|
||||
* @var Bearer
|
||||
*/
|
||||
private $bearer;
|
||||
|
||||
/**
|
||||
* Assets constructor.
|
||||
*
|
||||
* @param string $module_url The url of this module.
|
||||
* @param string $version The assets version.
|
||||
* @param Bearer $bearer The bearer.
|
||||
*/
|
||||
public function __construct( string $module_url, string $version, Bearer $bearer ) {
|
||||
public function __construct( string $module_url, string $version ) {
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->bearer = $bearer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register assets provided by this module.
|
||||
*/
|
||||
public function register_assets() {
|
||||
$bearer = $this->bearer;
|
||||
add_action(
|
||||
'admin_enqueue_scripts',
|
||||
function() use ( $bearer ) {
|
||||
function() {
|
||||
if ( ! is_admin() || wp_doing_ajax() ) {
|
||||
return;
|
||||
}
|
||||
|
@ -67,7 +56,7 @@ class SettingsPageAssets {
|
|||
return;
|
||||
}
|
||||
|
||||
$this->register_admin_assets( $bearer );
|
||||
$this->register_admin_assets();
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -98,10 +87,8 @@ class SettingsPageAssets {
|
|||
|
||||
/**
|
||||
* Register assets for admin pages.
|
||||
*
|
||||
* @param Bearer $bearer The bearer.
|
||||
*/
|
||||
private function register_admin_assets( Bearer $bearer ) {
|
||||
private function register_admin_assets() {
|
||||
wp_enqueue_script(
|
||||
'ppcp-gateway-settings',
|
||||
trailingslashit( $this->module_url ) . 'assets/js/gateway-settings.js',
|
||||
|
@ -109,18 +96,5 @@ class SettingsPageAssets {
|
|||
$this->version,
|
||||
true
|
||||
);
|
||||
|
||||
try {
|
||||
$token = $bearer->bearer();
|
||||
wp_localize_script(
|
||||
'ppcp-gateway-settings',
|
||||
'PayPalCommerceGatewaySettings',
|
||||
array(
|
||||
'vaulting_features_available' => $token->vaulting_available(),
|
||||
)
|
||||
);
|
||||
} catch ( RuntimeException $exception ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,26 +124,6 @@ class SettingsRenderer {
|
|||
|
||||
$messages = array();
|
||||
|
||||
if ( $this->can_display_vaulting_admin_message() ) {
|
||||
|
||||
$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->settings_status->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 ) ) {
|
||||
|
|
|
@ -148,8 +148,7 @@ class WCGatewayModule implements ModuleInterface {
|
|||
if ( $c->has( 'wcgateway.url' ) ) {
|
||||
$assets = new SettingsPageAssets(
|
||||
$c->get( 'wcgateway.url' ),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
$c->get( 'api.bearer' )
|
||||
$c->get( 'ppcp.asset-version' )
|
||||
);
|
||||
$assets->register_assets();
|
||||
}
|
||||
|
|
|
@ -13,9 +13,8 @@ class SettingsPagesAssetsTest extends TestCase
|
|||
{
|
||||
$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';
|
||||
$bearer = Mockery::mock(Bearer::class);
|
||||
|
||||
$testee = new SettingsPageAssets($moduleUrl, $modulePath, $bearer);
|
||||
$testee = new SettingsPageAssets($moduleUrl, $modulePath);
|
||||
|
||||
when('is_admin')
|
||||
->justReturn(true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue