Skip to content

Move 3D Secure settings from Payment Methods to Settings tab (4521) #3340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
use WooCommerce\PayPalCommerce\Settings\Data\AbstractDataModel;
use WooCommerce\PayPalCommerce\Settings\Data\PaymentSettings;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;

/**
Expand All @@ -22,25 +21,15 @@
*/
class PaymentMethodSettingsMapHelper {

/**
* A map of new to old 3d secure values.
*/
protected const THREE_D_SECURE_VALUES_MAP = array(
'no-3d-secure' => 'NO_3D_SECURE',
'only-required-3d-secure' => 'SCA_WHEN_REQUIRED',
'always-3d-secure' => 'SCA_ALWAYS',
);

/**
* Maps old setting keys to new payment method settings names.
*
* @psalm-return array<oldSettingsKey, newSettingsKey>
*/
public function map(): array {
return array(
'dcc_enabled' => CreditCardGateway::ID,
'axo_enabled' => AxoGateway::ID,
'3d_secure_contingency' => 'three_d_secure',
'dcc_enabled' => CreditCardGateway::ID,
'axo_enabled' => AxoGateway::ID,
);
}

Expand All @@ -52,25 +41,13 @@ public function map(): array {
* @return mixed The value of the mapped setting, (null if not found).
*/
public function mapped_value( string $old_key, ?AbstractDataModel $payment_settings ) {
switch ( $old_key ) {
case '3d_secure_contingency':
if ( is_null( $payment_settings ) ) {
return null;
}

assert( $payment_settings instanceof PaymentSettings );
$selected_three_d_secure = $payment_settings->get_three_d_secure();
return self::THREE_D_SECURE_VALUES_MAP[ $selected_three_d_secure ] ?? null;
$payment_method = $this->map()[ $old_key ] ?? false;

default:
$payment_method = $this->map()[ $old_key ] ?? false;

if ( ! $payment_method ) {
return null;
}

return $this->is_gateway_enabled( $payment_method );
if ( ! $payment_method ) {
return null;
}

return $this->is_gateway_enabled( $payment_method );
}

/**
Expand Down
31 changes: 31 additions & 0 deletions modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ class SettingsTabMapHelper {

use ContextTrait;

/**
* A map of new to old 3d secure values.
*
* @var array<string, string>
*/
protected const THREE_D_SECURE_VALUES_MAP = array(
'no-3d-secure' => 'NO_3D_SECURE',
'only-required-3d-secure' => 'SCA_WHEN_REQUIRED',
'always-3d-secure' => 'SCA_ALWAYS',
);

/**
* Maps old setting keys to new setting keys.
*
Expand All @@ -43,6 +54,7 @@ public function map(): array {
'blocks_final_review_enabled' => 'enable_pay_now',
'logging_enabled' => 'enable_logging',
'vault_enabled' => 'save_paypal_and_venmo',
'3d_secure_contingency' => 'threeDSecure',
);
}

Expand All @@ -69,11 +81,30 @@ public function mapped_value( string $old_key, array $settings_model ) {
case 'blocks_final_review_enabled':
return $this->mapped_pay_now_value( $settings_model );

case '3d_secure_contingency':
return $this->mapped_3d_secure_value( $settings_model );

default:
return $settings_model[ $new_key ] ?? null;
}
}

/**
* Retrieves the mapped value for the '3d_secure_contingency' from the new settings.
*
* @param array $settings_model The new settings model data.
* @return string|null The mapped '3d_secure_contingency' setting value.
*/
protected function mapped_3d_secure_value( array $settings_model ): ?string {
$three_d_secure = $settings_model['threeDSecure'] ?? null;

if ( ! is_string( $three_d_secure ) ) {
return null;
}

return self::THREE_D_SECURE_VALUES_MAP[ $three_d_secure ] ?? null;
}

/**
* Retrieves the mapped value for the 'mismatch_behavior' from the new settings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ import { PaymentHooks } from '../../../../../data';

const Modal = ( { method, setModalIsVisible, onSave } ) => {
const { all: paymentMethods } = PaymentHooks.usePaymentMethods();
const {
paypalShowLogo,
threeDSecure,
fastlaneCardholderName,
fastlaneDisplayWatermark,
} = PaymentHooks.usePaymentMethodsModal();
const { paypalShowLogo, fastlaneCardholderName, fastlaneDisplayWatermark } =
PaymentHooks.usePaymentMethodsModal();

const [ settings, setSettings ] = useState( () => {
if ( ! method?.id ) {
Expand All @@ -44,7 +40,6 @@ const Modal = ( { method, setModalIsVisible, onSave } ) => {
} );

initialSettings.paypalShowLogo = paypalShowLogo;
initialSettings.threeDSecure = threeDSecure;
initialSettings.fastlaneCardholderName = fastlaneCardholderName;
initialSettings.fastlaneDisplayWatermark = fastlaneDisplayWatermark;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { __ } from '@wordpress/i18n';

import Accordion from '../../../../../ReusableComponents/AccordionSection';
import SettingsBlock from '../../../../../ReusableComponents/SettingsBlock';
import { ControlSelect } from '../../../../../ReusableComponents/Controls';
import {
ControlSelect,
ControlRadioGroup,
} from '../../../../../ReusableComponents/Controls';
import { SettingsHooks } from '../../../../../../data';

const OtherSettings = () => {
const { disabledCards, setDisabledCards } = SettingsHooks.useSettings();
const { disabledCards, setDisabledCards, threeDSecure, setThreeDSecure } =
SettingsHooks.useSettings();

const disabledCardChoices = window.ppcpSettings.disabledCardsChoices;
const threeDSecureOptions = window.ppcpSettings.threeDSecureOptions;

return (
<Accordion
title={ __(
Expand Down Expand Up @@ -40,6 +46,19 @@ const OtherSettings = () => {
) }
/>
</SettingsBlock>
<SettingsBlock
title={ __( '3D Secure', 'woocommerce-paypal-payments' ) }
description={ __(
'Authenticate cardholders through their card issuers to reduce fraud and improve transaction security. Successful 3D Secure authentication can shift liability for fraudulent chargebacks to the card issuer.',
'woocommerce-paypal-payments'
) }
>
<ControlRadioGroup
options={ threeDSecureOptions }
value={ threeDSecure }
onChange={ setThreeDSecure }
/>
</SettingsBlock>
</Accordion>
);
};
Expand Down
2 changes: 0 additions & 2 deletions modules/ppcp-settings/resources/js/data/payment/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export const usePaymentMethodsModal = () => {
const { usePersistent } = useStoreData();

const [ paypalShowLogo ] = usePersistent( 'paypalShowLogo' );
const [ threeDSecure ] = usePersistent( 'threeDSecure' );
const [ fastlaneCardholderName ] = usePersistent(
'fastlaneCardholderName'
);
Expand All @@ -139,7 +138,6 @@ export const usePaymentMethodsModal = () => {

return {
paypalShowLogo,
threeDSecure,
fastlaneCardholderName,
fastlaneDisplayWatermark,
};
Expand Down
8 changes: 8 additions & 0 deletions modules/ppcp-settings/resources/js/data/settings/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const useHooks = () => {
const [ disabledCards, setDisabledCards ] =
usePersistent( 'disabledCards' );

const [ threeDSecure, setThreeDSecure ] = usePersistent( 'threeDSecure' );

return {
invoicePrefix,
setInvoicePrefix,
Expand Down Expand Up @@ -94,6 +96,8 @@ const useHooks = () => {
setButtonLanguage,
disabledCards,
setDisabledCards,
threeDSecure,
setThreeDSecure,
};
};

Expand Down Expand Up @@ -138,6 +142,8 @@ export const useSettings = () => {
setButtonLanguage,
disabledCards,
setDisabledCards,
threeDSecure,
setThreeDSecure,
} = useHooks();

return {
Expand Down Expand Up @@ -167,5 +173,7 @@ export const useSettings = () => {
setButtonLanguage,
disabledCards,
setDisabledCards,
threeDSecure,
setThreeDSecure,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const defaultPersistent = Object.freeze( {
subtotalAdjustment: 'no_details', // [correction|no_details] Handling for subtotal mismatches
landingPage: 'any', // [any|login|guest_checkout] PayPal checkout landing page
buttonLanguage: '', // Language for PayPal buttons
threeDSecure: 'only-required-3d-secure', // [no-3d-secure|only-required-3d-secure|always-3d-secure] 3D Secure settings

// Boolean flags.
authorizeOnly: false, // Whether to only authorize payments initially
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,40 +240,7 @@ public function group_card_methods() : array {
'title' => __( 'Advanced Credit and Debit Card Payments', 'woocommerce-paypal-payments' ),
'description' => __( "Present custom credit and debit card fields to your payers so they can pay with credit and debit cards using your site's branding.", 'woocommerce-paypal-payments' ),
'icon' => 'payment-method-advanced-cards',
'fields' => array(
'threeDSecure' => array(
'type' => 'radio',
'default' => $this->settings->get_three_d_secure(),
'label' => __( '3D Secure', 'woocommerce-paypal-payments' ),
'description' => __(
'Authenticate cardholders through their card issuers to reduce fraud and improve transaction security. Successful 3D Secure authentication can shift liability for fraudulent chargebacks to the card issuer.',
'woocommerce-paypal-payments'
),
'options' => array(
array(
'label' => __(
'No 3D Secure',
'woocommerce-paypal-payments'
),
'value' => 'no-3d-secure',
),
array(
'label' => __(
'Only when required',
'woocommerce-paypal-payments'
),
'value' => 'only-required-3d-secure',
),
array(
'label' => __(
'Always require 3D Secure',
'woocommerce-paypal-payments'
),
'value' => 'always-3d-secure',
),
),
),
),
'fields' => array(),
);
$group[] = array(
'id' => AxoGateway::ID,
Expand Down
26 changes: 26 additions & 0 deletions modules/ppcp-settings/src/Data/SettingsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class SettingsModel extends AbstractDataModel {
*/
public const LANDING_PAGE_OPTIONS = array( 'any', 'login', 'guest_checkout' );

/**
* Valid options for 3D Secure.
*
* @var array
*/
public const THREE_D_SECURE_OPTIONS = array( 'no-3d-secure', 'only-required-3d-secure', 'always-3d-secure' );

/**
* Data sanitizer service.
*
Expand Down Expand Up @@ -74,6 +81,7 @@ protected function get_defaults() : array {
'subtotal_adjustment' => 'correction', // Options: [correction|no_details].
'landing_page' => 'any', // Options: [any|login|guest_checkout].
'button_language' => '', // empty or a language locale code.
'three_d_secure' => 'only-required-3d-secure', // Options: [no-3d-secure|only-required-3d-secure|always-3d-secure].

// Boolean flags.
'authorize_only' => false,
Expand Down Expand Up @@ -199,6 +207,24 @@ public function set_button_language( string $language ) : void {
$this->data['button_language'] = $this->sanitizer->sanitize_text( $language );
}

/**
* Gets the 3D Secure setting.
*
* @return string The 3D Secure setting.
*/
public function get_three_d_secure() : string {
return $this->data['three_d_secure'];
}

/**
* Sets the 3D Secure setting.
*
* @param string $setting The 3D Secure setting to set.
*/
public function set_three_d_secure( string $setting ) : void {
$this->data['three_d_secure'] = $this->sanitizer->sanitize_enum( $setting, self::THREE_D_SECURE_OPTIONS );
}

/**
* Gets the authorize only setting.
*
Expand Down
5 changes: 0 additions & 5 deletions modules/ppcp-settings/src/Endpoint/PaymentRestEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ class PaymentRestEndpoint extends RestEndpoint {
'js_name' => 'paypalShowLogo',
'sanitize' => 'to_boolean',
),
'three_d_secure' => array(
'js_name' => 'threeDSecure',
'sanitize' => 'sanitize_text_field',
),
'fastlane_cardholder_name' => array(
'js_name' => 'fastlaneCardholderName',
'sanitize' => 'to_boolean',
Expand Down Expand Up @@ -203,7 +199,6 @@ public function get_details() : WP_REST_Response {
}

$gateway_settings['paypalShowLogo'] = $this->payment_settings->get_paypal_show_logo();
$gateway_settings['threeDSecure'] = $this->payment_settings->get_three_d_secure();
$gateway_settings['fastlaneCardholderName'] = $this->payment_settings->get_fastlane_cardholder_name();
$gateway_settings['fastlaneDisplayWatermark'] = $this->payment_settings->get_fastlane_display_watermark();

Expand Down
4 changes: 4 additions & 0 deletions modules/ppcp-settings/src/Endpoint/SettingsRestEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class SettingsRestEndpoint extends RestEndpoint {
'disabled_cards' => array(
'js_name' => 'disabledCards',
),
'three_d_secure' => array(
'js_name' => 'threeDSecure',
'sanitize' => 'sanitize_text_field',
),
);

/**
Expand Down
Loading
Loading