mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Merge pull request #187 from woocommerce/PCP-179-incorrect-api-credentials-cause-
Incorrect API credentials cause fatal error
This commit is contained in:
commit
2efb300be8
4 changed files with 45 additions and 17 deletions
12
.github/workflows/php.yml
vendored
12
.github/workflows/php.yml
vendored
|
@ -11,18 +11,24 @@ jobs:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
php-versions: ['7.1']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: ${{ matrix.php-versions }}
|
||||||
|
|
||||||
- name: Validate composer.json and composer.lock
|
- name: Validate composer.json and composer.lock
|
||||||
run: composer validate
|
run: composer validate
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: composer install --prefer-dist --no-progress --no-suggest
|
run: composer install --prefer-dist --no-progress --no-suggest
|
||||||
|
|
||||||
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
|
|
||||||
# Docs: https://getcomposer.org/doc/articles/scripts.md
|
|
||||||
|
|
||||||
- name: Run test suite
|
- name: Run test suite
|
||||||
run: ./vendor/bin/phpunit
|
run: ./vendor/bin/phpunit
|
||||||
- name: Run Woocommerce coding standards
|
- name: Run Woocommerce coding standards
|
||||||
|
|
|
@ -120,7 +120,11 @@ class PayPalBearer implements Bearer {
|
||||||
|
|
||||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
||||||
$error = new RuntimeException(
|
$error = new RuntimeException(
|
||||||
__( 'Could not create token.', 'woocommerce-paypal-payments' )
|
sprintf(
|
||||||
|
// translators: %s is the error description.
|
||||||
|
__( 'Could not create token. %s', 'woocommerce-paypal-payments' ),
|
||||||
|
isset( json_decode( $response['body'] )->error_description ) ? json_decode( $response['body'] )->error_description : ''
|
||||||
|
)
|
||||||
);
|
);
|
||||||
$this->logger->log(
|
$this->logger->log(
|
||||||
'warning',
|
'warning',
|
||||||
|
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||||
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
namespace WooCommerce\PayPalCommerce\WcGateway\Assets;
|
||||||
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SettingsPageAssets
|
* Class SettingsPageAssets
|
||||||
|
@ -111,13 +112,17 @@ class SettingsPageAssets {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$token = $bearer->bearer();
|
try {
|
||||||
wp_localize_script(
|
$token = $bearer->bearer();
|
||||||
'ppcp-gateway-settings',
|
wp_localize_script(
|
||||||
'PayPalCommerceGatewaySettings',
|
'ppcp-gateway-settings',
|
||||||
array(
|
'PayPalCommerceGatewaySettings',
|
||||||
'vaulting_features_available' => $token->vaulting_available(),
|
array(
|
||||||
)
|
'vaulting_features_available' => $token->vaulting_available(),
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Settings;
|
||||||
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
use WooCommerce\PayPalCommerce\ApiClient\Authentication\PayPalBearer;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
|
||||||
use WooCommerce\PayPalCommerce\Onboarding\State;
|
use WooCommerce\PayPalCommerce\Onboarding\State;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||||
|
@ -147,11 +148,23 @@ class SettingsListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$token = $this->bearer->bearer();
|
try {
|
||||||
if ( ! $token->vaulting_available() ) {
|
$token = $this->bearer->bearer();
|
||||||
$this->settings->set( 'vault_enabled', false );
|
if ( ! $token->vaulting_available() ) {
|
||||||
$this->settings->persist();
|
$this->settings->set( 'vault_enabled', false );
|
||||||
return;
|
$this->settings->persist();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
add_action(
|
||||||
|
'admin_notices',
|
||||||
|
function () use ( $exception ) {
|
||||||
|
printf(
|
||||||
|
'<div class="notice notice-error"><p>%s</p></div>',
|
||||||
|
esc_attr( $exception->getMessage() )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue