Skip to content

Commit 8ee5cd2

Browse files
authored
Merge pull request #4309 from woocommerce/dev/PCP-6280-remove-redundant-cache-from-reference-transaction-status
Remove redundant cache from ReferenceTransactionStatus (6280)
2 parents 07babdb + 6441670 commit 8ee5cd2

11 files changed

Lines changed: 110 additions & 64 deletions

File tree

modules/ppcp-api-client/services.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@
300300
);
301301
},
302302
'api.reference-transaction-status' => static fn ( ContainerInterface $container ): ReferenceTransactionStatus => new ReferenceTransactionStatus(
303-
$container->get( 'api.endpoint.partners' ),
304-
$container->get( 'api.reference-transaction-status-cache' )
303+
$container->get( 'api.endpoint.partners' )
305304
),
306305
'api.endpoint.catalog-products' => static function ( ContainerInterface $container ): CatalogProducts {
307306
return new CatalogProducts(
@@ -866,9 +865,6 @@ static function ( ContainerInterface $container ): PurchaseUnitSanitizer {
866865
'api.user-id-token-cache' => static function ( ContainerInterface $container ): Cache {
867866
return new Cache( 'ppcp-id-token-cache' );
868867
},
869-
'api.reference-transaction-status-cache' => static function ( ContainerInterface $container ): Cache {
870-
return new Cache( 'ppcp-reference-transaction-status-cache' );
871-
},
872868
'api.user-id-token' => static function ( ContainerInterface $container ): UserIdToken {
873869
return new UserIdToken(
874870
$container->get( 'api.host' ),

modules/ppcp-api-client/src/Helper/ReferenceTransactionStatus.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,10 @@
1919
*/
2020
class ReferenceTransactionStatus {
2121

22-
public const CACHE_KEY = 'ppcp_reference_transaction_enabled';
23-
24-
2522
protected PartnersEndpoint $partners_endpoint;
26-
protected Cache $cache;
2723

28-
public function __construct( PartnersEndpoint $partners_endpoint, Cache $cache ) {
24+
public function __construct( PartnersEndpoint $partners_endpoint ) {
2925
$this->partners_endpoint = $partners_endpoint;
30-
$this->cache = $cache;
3126
}
3227

3328
/**
@@ -39,29 +34,19 @@ public function __construct( PartnersEndpoint $partners_endpoint, Cache $cache )
3934
* @return bool True if reference transactions are enabled, false otherwise.
4035
*/
4136
public function reference_transaction_enabled(): bool {
42-
if ( $this->cache->has( self::CACHE_KEY ) ) {
43-
$cached = $this->cache->get( self::CACHE_KEY );
44-
if ( is_string( $cached ) || is_bool( $cached ) ) {
45-
return wc_string_to_bool( $cached );
46-
}
47-
}
48-
4937
try {
5038
foreach ( $this->partners_endpoint->seller_status()->capabilities() as $capability ) {
5139
if (
5240
$capability->name() === 'PAYPAL_WALLET_VAULTING_ADVANCED' &&
5341
$capability->status() === 'ACTIVE'
5442
) {
55-
$this->cache->set( self::CACHE_KEY, wc_bool_to_string( true ), MONTH_IN_SECONDS );
5643
return true;
5744
}
5845
}
5946
} catch ( RuntimeException $exception ) {
60-
$this->cache->set( self::CACHE_KEY, wc_bool_to_string( false ), HOUR_IN_SECONDS );
6147
return false;
6248
}
6349

64-
$this->cache->set( self::CACHE_KEY, wc_bool_to_string( false ), HOUR_IN_SECONDS );
6550
return false;
6651
}
6752
}

modules/ppcp-api-client/src/Repository/PartnerReferralsData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PartnerReferralsData {
2626
protected FeaturesDefinition $features_definition;
2727

2828
public function __construct( DccApplies $dcc_applies, FeaturesDefinition $features_definition ) {
29-
$this->dcc_applies = $dcc_applies; // @phpstan-ignore property.deprecated
29+
$this->dcc_applies = $dcc_applies; // @phpstan-ignore property.deprecated
3030
$this->features_definition = $features_definition;
3131
}
3232

modules/ppcp-button/services.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
$data_store = \WC_Data_Store::load( 'product' );
337337
return new CartProductsHelper( $data_store );
338338
},
339-
'button.helper.isolated-cart-simulator' => static function ( ContainerInterface $container ): IsolatedCartSimulator {
339+
'button.helper.isolated-cart-simulator' => static function ( ContainerInterface $container ): IsolatedCartSimulator {
340340
return new IsolatedCartSimulator(
341341
$container->get( 'button.helper.cart-products' ),
342342
$container->get( 'woocommerce.logger.woocommerce' )

modules/ppcp-button/src/Endpoint/SimulateCartEndpoint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public function __construct(
2525
IsolatedCartSimulator $cart_simulator,
2626
LoggerInterface $logger
2727
) {
28-
$this->smart_button = $smart_button;
29-
$this->request_data = $request_data;
30-
$this->cart_products = $cart_products;
28+
$this->smart_button = $smart_button;
29+
$this->request_data = $request_data;
30+
$this->cart_products = $cart_products;
3131
$this->cart_simulator = $cart_simulator;
32-
$this->logger = $logger;
32+
$this->logger = $logger;
3333

3434
$this->logger_tag = 'simulation';
3535
}

modules/ppcp-compat/services.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
return array(
1919

20-
'compat.ppec.mock-gateway' => static function ( $container ) {
20+
'compat.ppec.mock-gateway' => static function ( $container ) {
2121
$settings = $container->get( 'settings.settings-provider' );
2222
assert( $settings instanceof SettingsProvider );
2323

@@ -30,15 +30,15 @@
3030
return new PPEC\MockGateway( $title );
3131
},
3232

33-
'compat.ppec.billing-agreement-converter' => static function ( ContainerInterface $container ) {
33+
'compat.ppec.billing-agreement-converter' => static function ( ContainerInterface $container ) {
3434
return new PPEC\BillingAgreementTokenConverter(
3535
$container->get( 'api.endpoint.payment-method-tokens' ),
3636
$container->get( 'api.repository.customer' ),
3737
$container->get( 'woocommerce.logger.woocommerce' )
3838
);
3939
},
4040

41-
'compat.ppec.subscriptions-handler' => static function ( ContainerInterface $container ) {
41+
'compat.ppec.subscriptions-handler' => static function ( ContainerInterface $container ) {
4242
return new PPEC\SubscriptionsHandler(
4343
$container->get( 'wc-subscriptions.renewal-handler' ),
4444
$container->get( 'compat.ppec.mock-gateway' ),
@@ -47,7 +47,7 @@
4747
);
4848
},
4949

50-
'compat.plugin-script-names' => static function ( ContainerInterface $container ): array {
50+
'compat.plugin-script-names' => static function ( ContainerInterface $container ): array {
5151
return array(
5252
'ppcp-smart-button',
5353
'ppcp-oxxo',
@@ -61,7 +61,7 @@
6161
);
6262
},
6363

64-
'compat.plugin-script-file-names' => static function ( ContainerInterface $container ): array {
64+
'compat.plugin-script-file-names' => static function ( ContainerInterface $container ): array {
6565
return array(
6666
'button.js',
6767
'gateway-settings.js',
@@ -71,18 +71,18 @@
7171
);
7272
},
7373

74-
'compat.shiptastic.is_supported_plugin_version_active' => function (): bool {
74+
'compat.shiptastic.is_supported_plugin_version_active' => function (): bool {
7575
return function_exists( 'wc_stc_get_shipments' );
7676
},
7777

7878
'compat.wc_shipment_tracking.is_supported_plugin_version_active' => function (): bool {
7979
return class_exists( 'WC_Shipment_Tracking' );
8080
},
8181

82-
'compat.ywot.is_supported_plugin_version_active' => function (): bool {
82+
'compat.ywot.is_supported_plugin_version_active' => function (): bool {
8383
return function_exists( 'yith_ywot_init' );
8484
},
85-
'compat.dhl.is_supported_plugin_version_active' => function (): bool {
85+
'compat.dhl.is_supported_plugin_version_active' => function (): bool {
8686
return function_exists( 'PR_DHL' );
8787
},
8888
'compat.shipstation.is_supported_plugin_version_active' => function (): bool {
@@ -91,21 +91,21 @@
9191
'compat.wc_shipping_tax.is_supported_plugin_version_active' => function (): bool {
9292
return class_exists( 'WC_Connect_Loader' );
9393
},
94-
'compat.nyp.is_supported_plugin_version_active' => function (): bool {
94+
'compat.nyp.is_supported_plugin_version_active' => function (): bool {
9595
return function_exists( 'wc_nyp_init' );
9696
},
9797
'compat.wc_bookings.is_supported_plugin_version_active' => function (): bool {
9898
return class_exists( 'WC_Bookings' );
9999
},
100100

101-
'compat.asset_getter' => static function ( ContainerInterface $container ): AssetGetter {
101+
'compat.asset_getter' => static function ( ContainerInterface $container ): AssetGetter {
102102
$factory = $container->get( 'assets.asset_getter_factory' );
103103
assert( $factory instanceof AssetGetterFactory );
104104

105105
return $factory->for_module( 'ppcp-compat' );
106106
},
107107

108-
'compat.assets' => function ( ContainerInterface $container ): CompatAssets {
108+
'compat.assets' => function ( ContainerInterface $container ): CompatAssets {
109109
return new CompatAssets(
110110
$container->get( 'compat.asset_getter' ),
111111
$container->get( 'ppcp.asset-version' ),

modules/ppcp-settings/src/Endpoint/PaymentRestEndpoint.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ class PaymentRestEndpoint extends RestEndpoint {
7373
* @var array
7474
*/
7575
private array $field_map = array(
76-
'paypal_show_logo' => array(
76+
'paypal_show_logo' => array(
7777
'js_name' => 'paypalShowLogo',
7878
'sanitize' => 'to_boolean',
7979
),
80-
'cardholder_name' => array(
80+
'cardholder_name' => array(
8181
'js_name' => 'cardholderName',
8282
'sanitize' => 'to_boolean',
8383
),
84-
'fastlane_display_watermark' => array(
84+
'fastlane_display_watermark' => array(
8585
'js_name' => 'fastlaneDisplayWatermark',
8686
'sanitize' => 'to_boolean',
8787
),
88-
'pui_brand_name' => array(
88+
'pui_brand_name' => array(
8989
'js_name' => 'puiBrandName',
9090
'sanitize' => 'sanitize_text_field',
9191
),
92-
'pui_logo_url' => array(
92+
'pui_logo_url' => array(
9393
'js_name' => 'puiLogoUrl',
9494
'sanitize' => 'esc_url_raw',
9595
),
@@ -215,11 +215,11 @@ public function get_details(): WP_REST_Response {
215215
}
216216
}
217217

218-
$gateway_settings['paypalShowLogo'] = $this->payment_settings->get_paypal_show_logo();
219-
$gateway_settings['cardholderName'] = $this->payment_settings->get_cardholder_name();
220-
$gateway_settings['fastlaneDisplayWatermark'] = $this->payment_settings->get_fastlane_display_watermark();
221-
$gateway_settings['puiBrandName'] = $this->payment_settings->get_pui_brand_name();
222-
$gateway_settings['puiLogoUrl'] = $this->payment_settings->get_pui_logo_url();
218+
$gateway_settings['paypalShowLogo'] = $this->payment_settings->get_paypal_show_logo();
219+
$gateway_settings['cardholderName'] = $this->payment_settings->get_cardholder_name();
220+
$gateway_settings['fastlaneDisplayWatermark'] = $this->payment_settings->get_fastlane_display_watermark();
221+
$gateway_settings['puiBrandName'] = $this->payment_settings->get_pui_brand_name();
222+
$gateway_settings['puiLogoUrl'] = $this->payment_settings->get_pui_logo_url();
223223
$gateway_settings['puiCustomerServiceInstructions'] = $this->payment_settings->get_pui_customer_service_instructions();
224224

225225
return $this->return_success( apply_filters( 'woocommerce_paypal_payments_payment_methods', $gateway_settings ) );

modules/ppcp-settings/src/Service/FeaturesEligibilityService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ public function get_eligibility_checks(): array {
127127
FeaturesDefinition::FEATURE_SAVE_PAYPAL_AND_VENMO => fn() => $this->is_save_paypal_eligible,
128128
FeaturesDefinition::FEATURE_ADVANCED_CREDIT_AND_DEBIT_CARDS => $this->check_acdc_eligible,
129129
FeaturesDefinition::FEATURE_ALTERNATIVE_PAYMENT_METHODS => fn() => $this->is_apm_eligible,
130-
FeaturesDefinition::FEATURE_GOOGLE_PAY => $this->check_google_pay_eligible,
131-
FeaturesDefinition::FEATURE_APPLE_PAY => $this->check_apple_pay_eligible,
130+
FeaturesDefinition::FEATURE_GOOGLE_PAY => $this->check_google_pay_eligible,
131+
FeaturesDefinition::FEATURE_APPLE_PAY => $this->check_apple_pay_eligible,
132132
FeaturesDefinition::FEATURE_PAY_LATER_MESSAGING => fn() => $this->is_pay_later_eligible,
133-
FeaturesDefinition::FEATURE_INSTALLMENTS => fn() => $this->is_installments_eligible,
134-
FeaturesDefinition::FEATURE_PAY_WITH_CRYPTO => fn() => $this->is_pwc_eligibility_checked,
133+
FeaturesDefinition::FEATURE_INSTALLMENTS => fn() => $this->is_installments_eligible,
134+
FeaturesDefinition::FEATURE_PAY_WITH_CRYPTO => fn() => $this->is_pwc_eligibility_checked,
135135
FeaturesDefinition::FEATURE_PAY_UPON_INVOICE => fn() => $this->is_pui_eligible,
136136
);
137137
}

modules/ppcp-wc-gateway/src/Endpoint/ReturnUrlEndpoint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ public function __construct(
6969
SessionHandler $session_handler,
7070
LoggerInterface $logger
7171
) {
72-
$this->gateway = $gateway;
73-
$this->order_endpoint = $order_endpoint;
74-
$this->session_handler = $session_handler;
75-
$this->logger = $logger;
72+
$this->gateway = $gateway;
73+
$this->order_endpoint = $order_endpoint;
74+
$this->session_handler = $session_handler;
75+
$this->logger = $logger;
7676
}
7777

7878
/**

modules/ppcp-wc-gateway/src/WCGatewayModule.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture;
2020
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
2121
use WooCommerce\PayPalCommerce\ApiClient\Helper\ReferenceTransactionStatus;
22-
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
2322
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
2423
use WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods\LocalApmProductStatus;
2524
use WooCommerce\PayPalCommerce\Settings\Data\Definition\FeaturesDefinition;
@@ -449,13 +448,6 @@ static function () use ( $c ): void {
449448
if ( $pwc_product_status instanceof PWCProductStatus ) {
450449
$pwc_product_status->clear();
451450
}
452-
453-
$reference_transaction_status_cache = $c->get( 'api.reference-transaction-status-cache' );
454-
assert( $reference_transaction_status_cache instanceof Cache );
455-
// Clear Reference Transaction status.
456-
if ( $reference_transaction_status_cache->has( ReferenceTransactionStatus::CACHE_KEY ) ) {
457-
$reference_transaction_status_cache->delete( ReferenceTransactionStatus::CACHE_KEY );
458-
}
459451
}
460452
);
461453

0 commit comments

Comments
 (0)