diff --git a/changelog/fix-fatals-on-plugin-update b/changelog/fix-fatals-on-plugin-update new file mode 100644 index 00000000000..a63e19bdb3c --- /dev/null +++ b/changelog/fix-fatals-on-plugin-update @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Avoid warnings about fatal error during plugin update due to problems with plugin initialization. diff --git a/includes/admin/class-wc-rest-payments-settings-controller.php b/includes/admin/class-wc-rest-payments-settings-controller.php index ffd941feee8..9664d5a54a5 100644 --- a/includes/admin/class-wc-rest-payments-settings-controller.php +++ b/includes/admin/class-wc-rest-payments-settings-controller.php @@ -8,7 +8,6 @@ use WCPay\Constants\Country_Code; use WCPay\Fraud_Prevention\Fraud_Risk_Tools; use WCPay\Constants\Track_Events; -use WCPay\Duplicates_Detection_Service; defined( 'ABSPATH' ) || exit; @@ -37,34 +36,22 @@ class WC_REST_Payments_Settings_Controller extends WC_Payments_REST_Controller { */ protected $account; - - /** - * Duplicates detection service. - * - * @var Duplicates_Detection_Service - */ - private $duplicates_detection_service; - - /** * WC_REST_Payments_Settings_Controller constructor. * - * @param WC_Payments_API_Client $api_client WC_Payments_API_Client instance. - * @param WC_Payment_Gateway_WCPay $wcpay_gateway WC_Payment_Gateway_WCPay instance. - * @param WC_Payments_Account $account Account class instance. - * @param Duplicates_Detection_Service $duplicates_detection_service Duplicates detection service. + * @param WC_Payments_API_Client $api_client WC_Payments_API_Client instance. + * @param WC_Payment_Gateway_WCPay $wcpay_gateway WC_Payment_Gateway_WCPay instance. + * @param WC_Payments_Account $account Account class instance. */ public function __construct( WC_Payments_API_Client $api_client, WC_Payment_Gateway_WCPay $wcpay_gateway, - WC_Payments_Account $account, - Duplicates_Detection_Service $duplicates_detection_service + WC_Payments_Account $account ) { parent::__construct( $api_client ); - $this->wcpay_gateway = $wcpay_gateway; - $this->account = $account; - $this->duplicates_detection_service = $duplicates_detection_service; + $this->wcpay_gateway = $wcpay_gateway; + $this->account = $account; } /** @@ -486,7 +473,7 @@ public function get_settings(): WP_REST_Response { 'enabled_payment_method_ids' => $enabled_payment_methods, 'available_payment_method_ids' => $available_upe_payment_methods, 'payment_method_statuses' => $this->wcpay_gateway->get_upe_enabled_payment_method_statuses(), - 'duplicated_payment_method_ids' => $this->duplicates_detection_service->find_duplicates(), + 'duplicated_payment_method_ids' => $this->wcpay_gateway->find_duplicates(), 'is_wcpay_enabled' => $this->wcpay_gateway->is_enabled(), 'is_manual_capture_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'manual_capture' ), 'is_test_mode_enabled' => WC_Payments::mode()->is_test(), diff --git a/includes/class-duplicates-detection-service.php b/includes/class-duplicates-detection-service.php index 3c49a0ab4fe..abf47a4c382 100644 --- a/includes/class-duplicates-detection-service.php +++ b/includes/class-duplicates-detection-service.php @@ -11,7 +11,6 @@ exit; // Exit if accessed directly. } -use Exception; use WC_Payments; use WCPay\Payment_Methods\Affirm_Payment_Method; use WCPay\Payment_Methods\Afterpay_Payment_Method; diff --git a/includes/class-wc-payment-gateway-wcpay.php b/includes/class-wc-payment-gateway-wcpay.php index 48e1399e146..12c72c479f3 100644 --- a/includes/class-wc-payment-gateway-wcpay.php +++ b/includes/class-wc-payment-gateway-wcpay.php @@ -30,6 +30,7 @@ use WCPay\Core\Server\Request\List_Charge_Refunds; use WCPay\Core\Server\Request\Refund_Charge; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Fraud_Prevention\Fraud_Prevention_Service; use WCPay\Fraud_Prevention\Fraud_Risk_Tools; use WCPay\Internal\Payment\State\AuthenticationRequiredState; @@ -196,6 +197,13 @@ class WC_Payment_Gateway_WCPay extends WC_Payment_Gateway_CC { */ protected $duplicate_payment_prevention_service; + /** + * Duplicate payment methods detection service + * + * @var Duplicates_Detection_Service + */ + protected $duplicate_payment_methods_detection_service; + /** * WC_Payments_Localization_Service instance. * @@ -246,6 +254,7 @@ class WC_Payment_Gateway_WCPay extends WC_Payment_Gateway_CC { * @param Duplicate_Payment_Prevention_Service $duplicate_payment_prevention_service - Service for preventing duplicate payments. * @param WC_Payments_Localization_Service $localization_service - Localization service instance. * @param WC_Payments_Fraud_Service $fraud_service - Fraud service instance. + * @param Duplicates_Detection_Service $duplicate_payment_methods_detection_service - Service for finding duplicate enabled payment methods. */ public function __construct( WC_Payments_API_Client $payments_api_client, @@ -259,22 +268,24 @@ public function __construct( WC_Payments_Order_Service $order_service, Duplicate_Payment_Prevention_Service $duplicate_payment_prevention_service, WC_Payments_Localization_Service $localization_service, - WC_Payments_Fraud_Service $fraud_service + WC_Payments_Fraud_Service $fraud_service, + Duplicates_Detection_Service $duplicate_payment_methods_detection_service ) { $this->payment_methods = $payment_methods; $this->payment_method = $payment_method; $this->stripe_id = $payment_method->get_id(); - $this->payments_api_client = $payments_api_client; - $this->account = $account; - $this->customer_service = $customer_service; - $this->token_service = $token_service; - $this->action_scheduler_service = $action_scheduler_service; - $this->failed_transaction_rate_limiter = $failed_transaction_rate_limiter; - $this->order_service = $order_service; - $this->duplicate_payment_prevention_service = $duplicate_payment_prevention_service; - $this->localization_service = $localization_service; - $this->fraud_service = $fraud_service; + $this->payments_api_client = $payments_api_client; + $this->account = $account; + $this->customer_service = $customer_service; + $this->token_service = $token_service; + $this->action_scheduler_service = $action_scheduler_service; + $this->failed_transaction_rate_limiter = $failed_transaction_rate_limiter; + $this->order_service = $order_service; + $this->duplicate_payment_prevention_service = $duplicate_payment_prevention_service; + $this->localization_service = $localization_service; + $this->fraud_service = $fraud_service; + $this->duplicate_payment_methods_detection_service = $duplicate_payment_methods_detection_service; $this->id = static::GATEWAY_ID; $this->icon = $this->get_theme_icon(); @@ -4346,6 +4357,15 @@ public function get_method_description() { return $description; } + /** + * Calls duplicate payment methods detection service to find duplicates. + * This method acts as a wrapper. The approach should be reverted once + * https://github.com/Automattic/woocommerce-payments/issues/7464 is resolved. + */ + public function find_duplicates() { + return $this->duplicate_payment_methods_detection_service->find_duplicates(); + } + // Start: Deprecated functions. /** diff --git a/includes/class-wc-payments.php b/includes/class-wc-payments.php index 9dbd87c85df..e465834adc0 100644 --- a/includes/class-wc-payments.php +++ b/includes/class-wc-payments.php @@ -538,7 +538,7 @@ public static function init() { foreach ( $payment_methods as $payment_method ) { self::$payment_method_map[ $payment_method->get_id() ] = $payment_method; - $split_gateway = new WC_Payment_Gateway_WCPay( self::$api_client, self::$account, self::$customer_service, self::$token_service, self::$action_scheduler_service, $payment_method, $payment_methods, self::$failed_transaction_rate_limiter, self::$order_service, self::$duplicate_payment_prevention_service, self::$localization_service, self::$fraud_service ); + $split_gateway = new WC_Payment_Gateway_WCPay( self::$api_client, self::$account, self::$customer_service, self::$token_service, self::$action_scheduler_service, $payment_method, $payment_methods, self::$failed_transaction_rate_limiter, self::$order_service, self::$duplicate_payment_prevention_service, self::$localization_service, self::$fraud_service, self::$duplicates_detection_service ); // Card gateway hooks are registered once below. if ( 'card' !== $payment_method->get_id() ) { @@ -1020,7 +1020,7 @@ public static function init_rest_api() { $reporting_controller->register_routes(); include_once WCPAY_ABSPATH . 'includes/admin/class-wc-rest-payments-settings-controller.php'; - $settings_controller = new WC_REST_Payments_Settings_Controller( self::$api_client, self::get_gateway(), self::$account, self::$duplicates_detection_service ); + $settings_controller = new WC_REST_Payments_Settings_Controller( self::$api_client, self::get_gateway(), self::$account ); $settings_controller->register_routes(); include_once WCPAY_ABSPATH . 'includes/admin/class-wc-rest-payments-reader-controller.php'; diff --git a/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php b/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php index 7c152626ad0..6bfaff2b816 100644 --- a/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php +++ b/tests/unit/admin/test-class-wc-rest-payments-settings-controller.php @@ -175,9 +175,10 @@ public function set_up() { $order_service, $mock_dpps, $this->mock_localization_service, - $this->mock_fraud_service + $this->mock_fraud_service, + $this->mock_duplicates_detection_service ); - $this->controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->gateway, $this->mock_wcpay_account, $this->mock_duplicates_detection_service ); + $this->controller = new WC_REST_Payments_Settings_Controller( $this->mock_api_client, $this->gateway, $this->mock_wcpay_account ); $this->mock_api_client ->method( 'is_server_connected' ) diff --git a/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php b/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php index 9597390a9a0..f2f5b4274f7 100644 --- a/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php +++ b/tests/unit/admin/test-class-wc-rest-payments-tos-controller.php @@ -9,6 +9,7 @@ use WCPay\Core\Server\Request\Add_Account_Tos_Agreement; use WCPay\Database_Cache; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; @@ -55,16 +56,17 @@ public function set_up() { ->disableOriginalConstructor() ->getMock(); - $mock_wcpay_account = $this->createMock( WC_Payments_Account::class ); - $mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); - $mock_db_cache = $this->createMock( Database_Cache::class ); - $mock_session_service = $this->createMock( WC_Payments_Session_Service::class ); - $customer_service = new WC_Payments_Customer_Service( $mock_api_client, $mock_wcpay_account, $mock_db_cache, $mock_session_service ); - $token_service = new WC_Payments_Token_Service( $mock_api_client, $customer_service ); - $order_service = new WC_Payments_Order_Service( $this->createMock( WC_Payments_API_Client::class ) ); - $action_scheduler_service = new WC_Payments_Action_Scheduler_Service( $mock_api_client, $order_service ); - $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $mock_payment_method = $this->createMock( CC_Payment_Method::class ); + $mock_wcpay_account = $this->createMock( WC_Payments_Account::class ); + $mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $mock_db_cache = $this->createMock( Database_Cache::class ); + $mock_session_service = $this->createMock( WC_Payments_Session_Service::class ); + $customer_service = new WC_Payments_Customer_Service( $mock_api_client, $mock_wcpay_account, $mock_db_cache, $mock_session_service ); + $token_service = new WC_Payments_Token_Service( $mock_api_client, $customer_service ); + $order_service = new WC_Payments_Order_Service( $this->createMock( WC_Payments_API_Client::class ) ); + $action_scheduler_service = new WC_Payments_Action_Scheduler_Service( $mock_api_client, $order_service ); + $mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); + $mock_payment_method = $this->createMock( CC_Payment_Method::class ); + $mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class ); $this->gateway = new WC_Payment_Gateway_WCPay( $mock_api_client, @@ -78,7 +80,8 @@ public function set_up() { $order_service, $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), - $mock_fraud_service + $mock_fraud_service, + $mock_duplicates_detection_service ); $this->controller = new WC_REST_Payments_Tos_Controller( $mock_api_client, $this->gateway, $mock_wcpay_account ); diff --git a/tests/unit/payment-methods/test-class-upe-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-payment-gateway.php index 8260f8707b5..137a283a944 100644 --- a/tests/unit/payment-methods/test-class-upe-payment-gateway.php +++ b/tests/unit/payment-methods/test-class-upe-payment-gateway.php @@ -33,6 +33,7 @@ use WC_Payments_Localization_Service; use WCPay\Core\Server\Request\Create_And_Confirm_Intention; use WCPay\Database_Cache; +use WCPay\Duplicates_Detection_Service; use WCPay\Internal\Service\Level3Service; use WCPay\Internal\Service\OrderService; @@ -170,6 +171,13 @@ class UPE_Payment_Gateway_Test extends WCPAY_UnitTestCase { */ private $mock_fraud_service; + /** + * Mock Duplicates Detection Service. + * + * @var Duplicates_Detection_Service + */ + private $mock_duplicates_detection_service; + /** * Pre-test setup */ @@ -230,8 +238,9 @@ public function set_up() { $this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class ); - $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class ); + $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class ); $this->mock_payment_methods = []; $payment_method_classes = [ @@ -294,6 +303,7 @@ public function set_up() { $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ] ) ->setMethods( @@ -961,7 +971,8 @@ public function test_get_upe_available_payment_methods( $payment_methods, $expec $this->mock_order_service, $this->mock_dpps, $this->mock_localization_service, - $this->mock_fraud_service + $this->mock_fraud_service, + $this->mock_duplicates_detection_service ); $this->assertEquals( $expected_result, $gateway->get_upe_available_payment_methods() ); diff --git a/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php b/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php index 22653a4cba9..8ac1db139a5 100644 --- a/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php +++ b/tests/unit/payment-methods/test-class-upe-split-payment-gateway.php @@ -35,6 +35,7 @@ use WC_Payments_Localization_Service; use WCPay\Core\Server\Request\Create_And_Confirm_Intention; use WCPay\Database_Cache; +use WCPay\Duplicates_Detection_Service; use WCPay\Internal\Service\Level3Service; use WCPay\Internal\Service\OrderService; /** @@ -158,6 +159,13 @@ class UPE_Split_Payment_Gateway_Test extends WCPAY_UnitTestCase { */ private $mock_fraud_service; + /** + * Mock Duplicates Detection Service. + * + * @var Duplicates_Detection_Service + */ + private $mock_duplicates_detection_service; + /** * Mapping for payment ID to payment method. * @@ -247,8 +255,9 @@ public function set_up() { $this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class ); - $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class ); + $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class ); // Arrange: Define a $_POST array which includes the payment method, // so that get_payment_method_from_request() does not throw error. @@ -281,6 +290,7 @@ public function set_up() { $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ] ) ->setMethods( @@ -1060,6 +1070,7 @@ public function test_get_payment_methods_with_request_context() { $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ] ) ->setMethods( [ 'get_payment_methods_from_gateway_id' ] ) @@ -1105,6 +1116,7 @@ public function test_get_payment_methods_without_request_context() { $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ] ) ->setMethods( [ 'get_payment_methods_from_gateway_id' ] ) @@ -1149,6 +1161,7 @@ public function test_get_payment_methods_without_request_context_or_token() { $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ] ) ->setMethods( @@ -1202,6 +1215,7 @@ public function test_get_payment_methods_from_gateway_id_upe() { $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ] ) ->onlyMethods( diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php b/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php index 8caaadb9ea4..c4ae5f729ee 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-payment-types.php @@ -9,6 +9,7 @@ use WCPay\Core\Server\Request\Create_And_Confirm_Intention; use WCPay\Constants\Payment_Method; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Session_Rate_Limiter; use WCPay\Fraud_Prevention\Fraud_Prevention_Service; use WCPay\Payment_Methods\CC_Payment_Method; @@ -153,6 +154,7 @@ public function set_up() { $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ), ] ) ->setMethods( diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php b/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php index 79f6cd75d9b..3962272376d 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-process-payment.php @@ -15,6 +15,7 @@ use WCPay\Exceptions\Connection_Exception; use WCPay\Session_Rate_Limiter; use WCPay\Constants\Payment_Method; +use WCPay\Duplicates_Detection_Service; use WCPay\Payment_Methods\CC_Payment_Method; // Need to use WC_Mock_Data_Store. @@ -167,6 +168,7 @@ public function set_up() { $this->mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ), ] ) ->setMethods( diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php b/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php index 49746ef3ca3..24f06d99933 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-process-refund.php @@ -12,6 +12,7 @@ use WCPay\Core\Server\Request\Refund_Charge; use WCPay\Core\Server\Response; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Exceptions\API_Exception; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; @@ -104,7 +105,8 @@ public function set_up() { $this->mock_order_service, $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), - $this->createMock( WC_Payments_Fraud_Service::class ) + $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ) ); } diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php index 9715d61a193..fd4352ac0b2 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-payment-method-order-note.php @@ -6,6 +6,7 @@ */ use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; @@ -139,7 +140,8 @@ public function set_up() { $this->mock_order_service, $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), - $this->createMock( WC_Payments_Fraud_Service::class ) + $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ), ); $this->wcpay_gateway->init_hooks(); diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php index 434bbd971fd..622e7cbe1d9 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions-process-payment.php @@ -10,6 +10,7 @@ use WCPay\Constants\Order_Status; use WCPay\Constants\Intent_Status; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; @@ -160,6 +161,7 @@ public function set_up() { $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ), ] ) ->setMethods( diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php index a5b33c1581c..151b3b919fe 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay-subscriptions.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\MockObject\MockObject; use WCPay\Core\Server\Request\Create_And_Confirm_Intention; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Exceptions\API_Exception; use WCPay\Internal\Service\Level3Service; use WCPay\Internal\Service\OrderService; @@ -102,6 +103,13 @@ class WC_Payment_Gateway_WCPay_Subscriptions_Test extends WCPAY_UnitTestCase { */ private $mock_fraud_service; + /** + * Mock Duplicates Detection Service. + * + * @var Duplicates_Detection_Service + */ + private $mock_duplicates_detection_service; + public function set_up() { parent::set_up(); @@ -136,8 +144,9 @@ public function set_up() { $this->mock_dpps = $this->createMock( Duplicate_Payment_Prevention_Service::class ); - $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class ); - $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $this->mock_localization_service = $this->createMock( WC_Payments_Localization_Service::class ); + $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class ); $mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) ->setConstructorArgs( [ $this->mock_token_service ] ) @@ -156,7 +165,8 @@ public function set_up() { $this->order_service, $this->mock_dpps, $this->mock_localization_service, - $this->mock_fraud_service + $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ); $this->wcpay_gateway->init_hooks(); WC_Payments::set_gateway( $this->wcpay_gateway ); @@ -830,7 +840,8 @@ public function test_adds_custom_payment_meta_input_fallback_until_subs_3_0_7() $this->order_service, $this->mock_dpps, $this->mock_localization_service, - $this->mock_fraud_service + $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ); // Ensure the has_attached_integration_hooks property is set to false so callbacks can be attached in maybe_init_subscriptions(). @@ -864,7 +875,8 @@ public function test_does_not_add_custom_payment_meta_input_fallback_for_subs_3_ $this->order_service, $this->mock_dpps, $this->mock_localization_service, - $this->mock_fraud_service + $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ); $this->assertFalse( has_action( 'woocommerce_admin_order_data_after_billing_address' ) ); diff --git a/tests/unit/test-class-wc-payment-gateway-wcpay.php b/tests/unit/test-class-wc-payment-gateway-wcpay.php index 38b299129d8..c485a19ecb3 100644 --- a/tests/unit/test-class-wc-payment-gateway-wcpay.php +++ b/tests/unit/test-class-wc-payment-gateway-wcpay.php @@ -17,6 +17,7 @@ use WCPay\Constants\Intent_Status; use WCPay\Constants\Payment_Method; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Exceptions\Amount_Too_Small_Exception; use WCPay\Exceptions\API_Exception; use WCPay\Exceptions\Process_Payment_Exception; @@ -177,6 +178,13 @@ class WC_Payment_Gateway_WCPay_Test extends WCPAY_UnitTestCase { */ private $mock_fraud_service; + /** + * Mock Duplicates Detection Service. + * + * @var Duplicates_Detection_Service + */ + private $mock_duplicates_detection_service; + /** * Pre-test setup */ @@ -229,7 +237,8 @@ public function set_up() { 'currency_code' => 'usd', ] ); - $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $this->mock_fraud_service = $this->createMock( WC_Payments_Fraud_Service::class ); + $this->mock_duplicates_detection_service = $this->createMock( Duplicates_Detection_Service::class ); $this->mock_payment_method = $this->getMockBuilder( CC_Payment_Method::class ) ->setConstructorArgs( [ $this->mock_token_service ] ) @@ -897,6 +906,7 @@ public function test_process_redirect_setup_intent_succeded() { $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ] ) ->onlyMethods( @@ -1004,6 +1014,7 @@ public function test_process_redirect_payment_save_payment_token() { $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ] ) ->onlyMethods( @@ -3203,6 +3214,7 @@ private function get_partial_mock_for_gateway( array $methods = [], array $const $this->mock_dpps, $this->mock_localization_service, $this->mock_fraud_service, + $this->mock_duplicates_detection_service, ]; foreach ( $constructor_replacement as $key => $value ) { @@ -3688,7 +3700,8 @@ private function init_gateways() { $this->order_service, $this->mock_dpps, $this->mock_localization_service, - $this->mock_fraud_service + $this->mock_fraud_service, + $this->mock_duplicates_detection_service ); } diff --git a/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php b/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php index 1bd4dbeeafc..8a6a1b7f4f3 100644 --- a/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php +++ b/tests/unit/test-class-wc-payments-express-checkout-button-display-handler.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\MockObject\MockObject; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; use WCPay\WooPay\WooPay_Utilities; @@ -177,7 +178,8 @@ private function make_wcpay_gateway() { $mock_order_service, $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), - $this->createMock( WC_Payments_Fraud_Service::class ) + $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ) ); } diff --git a/tests/unit/test-class-wc-payments-express-checkout-button-helper.php b/tests/unit/test-class-wc-payments-express-checkout-button-helper.php index 8b3312dcf30..3dc7878ba39 100644 --- a/tests/unit/test-class-wc-payments-express-checkout-button-helper.php +++ b/tests/unit/test-class-wc-payments-express-checkout-button-helper.php @@ -6,6 +6,7 @@ */ use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; @@ -91,7 +92,8 @@ private function make_wcpay_gateway() { $mock_order_service, $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), - $this->createMock( WC_Payments_Fraud_Service::class ) + $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ) ); } diff --git a/tests/unit/test-class-wc-payments-payment-request-button-handler.php b/tests/unit/test-class-wc-payments-payment-request-button-handler.php index fe703f8ee94..672a4cdaeac 100644 --- a/tests/unit/test-class-wc-payments-payment-request-button-handler.php +++ b/tests/unit/test-class-wc-payments-payment-request-button-handler.php @@ -7,6 +7,7 @@ use WCPay\Constants\Country_Code; use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; @@ -223,7 +224,8 @@ private function make_wcpay_gateway() { $mock_order_service, $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), - $this->createMock( WC_Payments_Fraud_Service::class ) + $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ) ); } diff --git a/tests/unit/test-class-wc-payments-woopay-button-handler.php b/tests/unit/test-class-wc-payments-woopay-button-handler.php index 1c87f05a4b7..dbb5cefe960 100644 --- a/tests/unit/test-class-wc-payments-woopay-button-handler.php +++ b/tests/unit/test-class-wc-payments-woopay-button-handler.php @@ -6,6 +6,7 @@ */ use WCPay\Duplicate_Payment_Prevention_Service; +use WCPay\Duplicates_Detection_Service; use WCPay\Payment_Methods\CC_Payment_Method; use WCPay\Session_Rate_Limiter; use WCPay\WooPay\WooPay_Utilities; @@ -163,7 +164,8 @@ private function make_wcpay_gateway() { $mock_order_service, $mock_dpps, $this->createMock( WC_Payments_Localization_Service::class ), - $this->createMock( WC_Payments_Fraud_Service::class ) + $this->createMock( WC_Payments_Fraud_Service::class ), + $this->createMock( Duplicates_Detection_Service::class ) ); }