From 42f3e575bc9789b3b611e7ff9a182fc17e24a921 Mon Sep 17 00:00:00 2001
From: Pedro Silva
Date: Fri, 2 Feb 2024 17:16:42 +0000
Subject: [PATCH] Fix inconsistent instance of AppleProductStatus
---
modules/ppcp-applepay/services.php | 19 +++++++++++--------
.../src/Settings/SettingsListener.php | 3 ++-
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/modules/ppcp-applepay/services.php b/modules/ppcp-applepay/services.php
index e12298179..2a2fb7abd 100644
--- a/modules/ppcp-applepay/services.php
+++ b/modules/ppcp-applepay/services.php
@@ -18,6 +18,7 @@
use WooCommerce\PayPalCommerce\Applepay\Assets\PropertiesDictionary;
use WooCommerce\PayPalCommerce\Applepay\Helper\ApmApplies;
use WooCommerce\PayPalCommerce\Applepay\Helper\AvailabilityNotice;
+use WooCommerce\PayPalCommerce\Common\Pattern\SingletonDecorator;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
@@ -72,14 +73,16 @@
return $settings->has( 'applepay_validated' ) ? $settings->get( 'applepay_validated' ) === true : false;
},
- 'applepay.apple-product-status' => static function( ContainerInterface $container ): AppleProductStatus {
- return new AppleProductStatus(
- $container->get( 'wcgateway.settings' ),
- $container->get( 'api.endpoint.partners' ),
- $container->get( 'onboarding.state' ),
- $container->get( 'api.helper.failure-registry' )
- );
- },
+ 'applepay.apple-product-status' => SingletonDecorator::make(
+ static function( ContainerInterface $container ): AppleProductStatus {
+ return new AppleProductStatus(
+ $container->get( 'wcgateway.settings' ),
+ $container->get( 'api.endpoint.partners' ),
+ $container->get( 'onboarding.state' ),
+ $container->get( 'api.helper.failure-registry' )
+ );
+ }
+ ),
'applepay.available' => static function ( ContainerInterface $container ): bool {
if ( apply_filters( 'woocommerce_paypal_payments_applepay_validate_product_status', true ) ) {
$status = $container->get( 'applepay.apple-product-status' );
diff --git a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
index 5f1bd38ad..35ff96fff 100644
--- a/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
+++ b/modules/ppcp-wc-gateway/src/Settings/SettingsListener.php
@@ -346,9 +346,10 @@ private function onboarding_redirect( bool $success = true ): void {
/**
* Prevent enabling both Pay Later messaging and PayPal vaulting
*
+ * @return void
* @throws RuntimeException When API request fails.
*/
- public function listen_for_vaulting_enabled() {
+ public function listen_for_vaulting_enabled(): void {
if ( ! $this->is_valid_site_request() || State::STATE_ONBOARDED !== $this->state->current_state() ) {
return;
}