Skip to content

Commit

Permalink
Ensure WooPay eligibility is taken into account when retrieving WooPa…
Browse files Browse the repository at this point in the history
…y enable state in the settings (#9841)
  • Loading branch information
cesarcosta99 authored Dec 4, 2024
1 parent af82606 commit 9169717
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-9787-woopay-enable-state-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Consider WooPay eligibility when retrieving WooPay enable state in the settings.
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public function get_settings(): WP_REST_Response {
'payment_request_button_border_radius' => $this->wcpay_gateway->get_option( 'payment_request_button_border_radius', WC_Payments_Express_Checkout_Button_Handler::DEFAULT_BORDER_RADIUS_IN_PX ),
'is_saved_cards_enabled' => $this->wcpay_gateway->is_saved_cards_enabled(),
'is_card_present_eligible' => $this->wcpay_gateway->is_card_present_eligible() && isset( WC()->payment_gateways()->get_available_payment_gateways()['cod'] ),
'is_woopay_enabled' => 'yes' === $this->wcpay_gateway->get_option( 'platform_checkout' ),
'is_woopay_enabled' => WC_Payments_Features::is_woopay_eligible() && 'yes' === $this->wcpay_gateway->get_option( 'platform_checkout' ),
'show_woopay_incompatibility_notice' => get_option( 'woopay_invalid_extension_found', false ),
'woopay_custom_message' => $this->wcpay_gateway->get_option( 'platform_checkout_custom_message' ),
'woopay_store_logo' => $this->wcpay_gateway->get_option( 'platform_checkout_store_logo' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class WC_REST_Payments_Settings_Controller_Test extends WCPAY_UnitTestCase {
/**
* @var Database_Cache|MockObject
*/
private $mock_db_cache;
private $mock_cache;

/**
* WC_Payments_Localization_Service instance.
Expand Down Expand Up @@ -117,15 +117,19 @@ public function set_up() {
// Set the user so that we can pass the authentication.
wp_set_current_user( 1 );

// Mock the main class's cache service.
$this->_cache = WC_Payments::get_database_cache();
$this->mock_cache = $this->createMock( Database_Cache::class );
WC_Payments::set_database_cache( $this->mock_cache );

$this->mock_api_client = $this->getMockBuilder( WC_Payments_API_Client::class )
->disableOriginalConstructor()
->getMock();

$this->mock_wcpay_account = $this->createMock( WC_Payments_Account::class );
$this->mock_db_cache = $this->createMock( Database_Cache::class );
$this->mock_session_service = $this->createMock( WC_Payments_Session_Service::class );
$order_service = new WC_Payments_Order_Service( $this->mock_api_client );
$customer_service = new WC_Payments_Customer_Service( $this->mock_api_client, $this->mock_wcpay_account, $this->mock_db_cache, $this->mock_session_service, $order_service );
$customer_service = new WC_Payments_Customer_Service( $this->mock_api_client, $this->mock_wcpay_account, $this->mock_cache, $this->mock_session_service, $order_service );
$token_service = new WC_Payments_Token_Service( $this->mock_api_client, $customer_service );
$compatibility_service = new Compatibility_Service( $this->mock_api_client );
$action_scheduler_service = new WC_Payments_Action_Scheduler_Service( $this->mock_api_client, $order_service, $compatibility_service );
Expand Down Expand Up @@ -205,6 +209,8 @@ public function set_up() {
public function tear_down() {
parent::tear_down();
WC_Blocks_REST_API_Registration_Preventer::stop_preventing();
// Restore the cache service in the main class.
WC_Payments::set_database_cache( $this->_cache );
}

public function test_get_settings_request_returns_status_code_200() {
Expand Down Expand Up @@ -745,6 +751,32 @@ public function test_get_settings_domestic_currency_fallbacks_to_default_currenc
$this->assertSame( $this->domestic_currency, $response->get_data()['account_domestic_currency'] );
}

public function test_get_settings_is_woopay_enabled_returns_true(): void {
$current_platform_checkout = $this->gateway->get_option( 'platform_checkout' );

$this->gateway->update_option( 'platform_checkout', 'yes' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => true ] );

$response = $this->controller->get_settings();

$this->assertArrayHasKey( 'is_woopay_enabled', $response->get_data() );
$this->assertTrue( $response->get_data()['is_woopay_enabled'] );
$this->gateway->update_option( 'platform_checkout', $current_platform_checkout );
}

public function test_get_settings_is_woopay_enabled_returns_false_if_it_is_not_eligible(): void {
$current_platform_checkout = $this->gateway->get_option( 'platform_checkout' );

$this->gateway->update_option( 'platform_checkout', 'yes' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => false ] );

$response = $this->controller->get_settings();

$this->assertArrayHasKey( 'is_woopay_enabled', $response->get_data() );
$this->assertFalse( $response->get_data()['is_woopay_enabled'] );
$this->gateway->update_option( 'platform_checkout', $current_platform_checkout );
}

/**
* Tests account business support address validator
*
Expand Down

0 comments on commit 9169717

Please sign in to comment.