This commit is contained in:
Pedro Silva 2023-09-25 11:26:37 +01:00
parent 561d43baf6
commit 26a2b80b1b
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
6 changed files with 22 additions and 12 deletions

View file

@ -848,7 +848,7 @@ return array(
$purchase_unit_sanitizer = $container->get( 'api.helper.purchase-unit-sanitizer' ); $purchase_unit_sanitizer = $container->get( 'api.helper.purchase-unit-sanitizer' );
return new OrderTransient( $cache, $purchase_unit_sanitizer ); return new OrderTransient( $cache, $purchase_unit_sanitizer );
}, },
'api.helper.failure-registry' => static function( ContainerInterface $container ): FailureRegistry { 'api.helper.failure-registry' => static function( ContainerInterface $container ): FailureRegistry {
$cache = new Cache( 'ppcp-paypal-api-status-cache' ); $cache = new Cache( 'ppcp-paypal-api-status-cache' );
return new FailureRegistry( $cache ); return new FailureRegistry( $cache );
}, },

View file

@ -39,12 +39,14 @@ class FailureRegistry {
} }
/** /**
* @param string $key * Returns if there was a failure within a given timeframe.
* @param int $seconds *
* @param string $key The cache key.
* @param int $seconds The timeframe in seconds.
* @return bool * @return bool
*/ */
public function has_failure_in_timeframe( string $key, int $seconds ): bool { public function has_failure_in_timeframe( string $key, int $seconds ): bool {
$cache_key = $this->cache_key( $key ); $cache_key = $this->cache_key( $key );
$failure_time = $this->cache->get( $cache_key ); $failure_time = $this->cache->get( $cache_key );
if ( ! $failure_time ) { if ( ! $failure_time ) {
@ -56,7 +58,9 @@ class FailureRegistry {
} }
/** /**
* @param string $key * Registers a failure.
*
* @param string $key The cache key.
* @return void * @return void
*/ */
public function add_failure( string $key ) { public function add_failure( string $key ) {
@ -65,7 +69,9 @@ class FailureRegistry {
} }
/** /**
* @param string $key * Clear a given failure.
*
* @param string $key The cache key.
* @return void * @return void
*/ */
public function clear_failures( string $key ) { public function clear_failures( string $key ) {
@ -79,9 +85,9 @@ class FailureRegistry {
* Build cache key. * Build cache key.
* *
* @param string $key The cache key. * @param string $key The cache key.
* @return string|null * @return string
*/ */
private function cache_key( string $key ): ?string { private function cache_key( string $key ): string {
return implode( '_', array( self::CACHE_KEY, $key ) ); return implode( '_', array( self::CACHE_KEY, $key ) );
} }

View file

@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\Applepay\Assets;
use Throwable; use Throwable;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PartnersEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\SellerStatusProduct;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry; use WooCommerce\PayPalCommerce\ApiClient\Helper\FailureRegistry;
use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\Onboarding\State;
@ -128,7 +127,7 @@ class AppleProductStatus {
try { try {
$seller_status = $this->partners_endpoint->seller_status(); $seller_status = $this->partners_endpoint->seller_status();
} catch ( Throwable $error ) { } catch ( Throwable $error ) {
$this->has_request_failure = true; $this->has_request_failure = true;
$this->current_status_cache = false; $this->current_status_cache = false;
return false; return false;
} }

View file

@ -140,7 +140,7 @@ class DCCProductStatus {
try { try {
$seller_status = $this->partners_endpoint->seller_status(); $seller_status = $this->partners_endpoint->seller_status();
} catch ( Throwable $error ) { } catch ( Throwable $error ) {
$this->has_request_failure = true; $this->has_request_failure = true;
$this->current_status_cache = false; $this->current_status_cache = false;
return false; return false;
} }

View file

@ -128,7 +128,7 @@ class PayUponInvoiceProductStatus {
try { try {
$seller_status = $this->partners_endpoint->seller_status(); $seller_status = $this->partners_endpoint->seller_status();
} catch ( Throwable $error ) { } catch ( Throwable $error ) {
$this->has_request_failure = true; $this->has_request_failure = true;
$this->current_status_cache = false; $this->current_status_cache = false;
return false; return false;
} }

View file

@ -264,6 +264,11 @@
<code>DAY_IN_SECONDS</code> <code>DAY_IN_SECONDS</code>
</UndefinedConstant> </UndefinedConstant>
</file> </file>
<file src="modules/ppcp-api-client/src/Helper/FailureRegistry.php">
<UndefinedConstant occurrences="1">
<code>DAY_IN_SECONDS</code>
</UndefinedConstant>
</file>
<file src="modules/ppcp-button/services.php"> <file src="modules/ppcp-button/services.php">
<PossiblyFalseArgument occurrences="1"> <PossiblyFalseArgument occurrences="1">
<code>realpath( __FILE__ )</code> <code>realpath( __FILE__ )</code>