mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Do not redirect when handling vault_enabled
settings, also return false if there is no scope yet
This commit is contained in:
parent
61397bc798
commit
1725d2da18
3 changed files with 65 additions and 6 deletions
|
@ -104,7 +104,11 @@ class Token {
|
|||
*
|
||||
* @return bool Whether vaulting features are enabled or not.
|
||||
*/
|
||||
public function vaulting_available() {
|
||||
public function vaulting_available(): bool {
|
||||
if ( ! isset( $this->json->scope ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( strpos(
|
||||
$this->json->scope,
|
||||
'https://uri.paypal.com/services/vault/payment-tokens/readwrite'
|
||||
|
|
|
@ -147,15 +147,11 @@ class SettingsListener {
|
|||
return;
|
||||
}
|
||||
|
||||
$redirect_url = admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway' );
|
||||
|
||||
$token = $this->bearer->bearer();
|
||||
if ( ! $token->vaulting_available() ) {
|
||||
$this->settings->set( 'vault_enabled', false );
|
||||
$this->settings->persist();
|
||||
|
||||
wp_safe_redirect( $redirect_url, 302 );
|
||||
exit;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
59
tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php
Normal file
59
tests/PHPUnit/WcGateway/Settings/SettingsListenerTest.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||
use WooCommerce\PayPalCommerce\TestCase;
|
||||
use Mockery;
|
||||
use WooCommerce\PayPalCommerce\Webhooks\WebhookRegistrar;
|
||||
use function Brain\Monkey\Functions\when;
|
||||
|
||||
class SettingsListenerTest extends TestCase
|
||||
{
|
||||
public function testListen()
|
||||
{
|
||||
$settings = Mockery::mock(Settings::class);
|
||||
$setting_fields = [];
|
||||
$webhook_registrar = Mockery::mock(WebhookRegistrar::class);
|
||||
$cache = Mockery::mock(Cache::class);
|
||||
$state = Mockery::mock(State::class);
|
||||
|
||||
$testee = new SettingsListener(
|
||||
$settings,
|
||||
$setting_fields,
|
||||
$webhook_registrar,
|
||||
$cache,
|
||||
$state
|
||||
);
|
||||
|
||||
$_REQUEST['section'] = 'ppcp-gateway';
|
||||
$_POST['ppcp-nonce'] = 'foo';
|
||||
$_POST['ppcp'] = [
|
||||
'client_id' => 'client_id',
|
||||
];
|
||||
when('sanitize_text_field')->justReturn('ppcp-gateway');
|
||||
when('wp_unslash')->justReturn('ppcp-gateway');
|
||||
when('current_user_can')->justReturn(true);
|
||||
when('wp_verify_nonce')->justReturn(true);
|
||||
|
||||
$settings->shouldReceive('has')
|
||||
->with('client_id')
|
||||
->andReturn('client_id');
|
||||
$settings->shouldReceive('get')
|
||||
->with('client_id')
|
||||
->andReturn('client_id');
|
||||
$settings->shouldReceive('has')
|
||||
->with('client_secret')
|
||||
->andReturn('client_secret');
|
||||
$settings->shouldReceive('get')
|
||||
->with('client_secret')
|
||||
->andReturn('client_secret');
|
||||
|
||||
// run
|
||||
$testee->listen();
|
||||
|
||||
// assert
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue