Skip to content
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

Ensure 3ds contingency uses SCA_ALWAYS instead of 3D_SECURE (521) #464

Merged
merged 9 commits into from
Feb 7, 2022
4 changes: 4 additions & 0 deletions modules/ppcp-button/src/Assets/SmartButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,10 @@ private function get_3ds_contingency(): string {
if ( $this->settings->has( '3d_secure_contingency' ) ) {
$value = $this->settings->get( '3d_secure_contingency' );
if ( $value ) {
if ( '3D_SECURE' === $value ) {
$value = 'SCA_ALWAYS';
}

return $value;
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/ppcp-wc-gateway/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -1914,12 +1914,12 @@ static function ( ContainerInterface $container ): AuthorizeOrderActionNotice {
),
'class' => array(),
'input_class' => array( 'wc-enhanced-select' ),
'default' => $container->get( 'api.shop.is-psd2-country' ) ? '3D_SECURE' : 'NO_3D_SECURE',
'default' => $container->get( 'api.shop.is-psd2-country' ) ? 'SCA_WHEN_REQUIRED' : 'NO_3D_SECURE',
'desc_tip' => true,
'options' => array(
'NO_3D_SECURE' => __( 'No 3D Secure (transaction will be denied if 3D Secure is required)', 'woocommerce-paypal-payments' ),
'SCA_WHEN_REQUIRED' => __( '3D Secure when required', 'woocommerce-paypal-payments' ),
'3D_SECURE' => __( 'Always trigger 3D Secure', 'woocommerce-paypal-payments' ),
'SCA_ALWAYS' => __( 'Always trigger 3D Secure', 'woocommerce-paypal-payments' ),
),
'screens' => array(
State::STATE_ONBOARDED,
Expand Down
21 changes: 20 additions & 1 deletion modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\Webhooks\WebhookRegistrar;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;

/**
* Class SettingsListener
Expand Down Expand Up @@ -208,6 +208,25 @@ function () use ( $exception ) {
exit;
}

/**
* Ensure 3DS contingency use `SCA_ALWAYS` instead of `3D_SECURE`.
*
* @return void
* @throws NotFoundException When a setting was not found.
*/
public function listen_for_3d_secure_contingency(): void {
if ( ! $this->is_valid_site_request() || $this->settings->get( '3d_secure_contingency' ) !== '3D_SECURE' ) {
return;
}

$this->settings->set( '3d_secure_contingency', 'SCA_ALWAYS' );
$this->settings->persist();

$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should redirect to the cards tab? admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway&ppcp-tab=ppcp-credit-card-gateway

Or maybe redirect not needed here at all.

Also as I understand it is executed only if the merchant saves settings. Maybe better to do that simply on some kind of plugin init/upgrade, such as woocommerce_paypal_payments_gateway_migrate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, much better on plugin upgrade, thanks!

wp_safe_redirect( $redirect_url, 302 );
exit;
}

/**
* Listens to the request.
*
Expand Down
1 change: 1 addition & 0 deletions modules/ppcp-wc-gateway/src/WCGatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static function () use ( $container ) {
*/
$listener->listen_for_merchant_id();
$listener->listen_for_vaulting_enabled();
$listener->listen_for_3d_secure_contingency();
}
);

Expand Down