diff --git a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php index 92f44f061..72f639b64 100644 --- a/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php +++ b/modules/ppcp-api-client/src/Repository/PartnerReferralsData.php @@ -90,16 +90,15 @@ class PartnerReferralsData { ); if ( $in_acdc_country ) { + $products = array( 'PPCP', 'ADVANCED_VAULTING' ); $capabilities[] = 'PAYPAL_WALLET_VAULTING_ADVANCED'; } $first_party_features[] = 'BILLING_AGREEMENT'; - // Backwards compatibility. Keep those features in the #legacy-ui (null-value). - // Move this into the previous condition, once legacy code is removed. - if ( false !== $use_subscriptions ) { - $first_party_features[] = 'FUTURE_PAYMENT'; + if ( $use_card_payments !== false ) { $first_party_features[] = 'VAULT'; + $first_party_features[] = 'FUTURE_PAYMENT'; } $payload = array( diff --git a/modules/ppcp-button/services.php b/modules/ppcp-button/services.php index 1369b51bd..0a0cf678e 100644 --- a/modules/ppcp-button/services.php +++ b/modules/ppcp-button/services.php @@ -347,7 +347,7 @@ return array( $container->get( 'wcgateway.settings' ), $container->get( 'wcgateway.all-funding-sources' ), $container->get( 'wcgateway.configuration.card-configuration' ), - $container->get( 'settings.data.general' )->get_merchant_country() + $container->get( 'api.shop.country' ) ); }, 'button.is-logged-in' => static function ( ContainerInterface $container ): bool { diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index db63cc576..0be23ffca 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -1405,7 +1405,7 @@ return array( $container->get( 'wcgateway.settings' ), $container->get( 'api.helpers.dccapplies' ), $container->get( 'wcgateway.helper.dcc-product-status' ), - $container->get( 'settings.data.general' ) + $container->get( 'api.shop.country' ) ); }, diff --git a/modules/ppcp-wc-gateway/src/Helper/CardPaymentsConfiguration.php b/modules/ppcp-wc-gateway/src/Helper/CardPaymentsConfiguration.php index 38435c524..347f7aebb 100644 --- a/modules/ppcp-wc-gateway/src/Helper/CardPaymentsConfiguration.php +++ b/modules/ppcp-wc-gateway/src/Helper/CardPaymentsConfiguration.php @@ -71,11 +71,11 @@ class CardPaymentsConfiguration { private DCCProductStatus $dcc_status; /** - * General Settings + * Store country. * - * @var GeneralSettings + * @var string */ - private GeneralSettings $general_settings; + private string $store_country; /** * This classes lazily resolves settings on first access. This flag indicates @@ -142,20 +142,20 @@ class CardPaymentsConfiguration { * @param Settings $settings Plugin settings instance. * @param DccApplies $dcc_applies DCC eligibility helper. * @param DCCProductStatus $dcc_status Manages the Seller status. - * @param GeneralSettings $general_settings General settings instance. + * @param string $store_country The shop's country code. */ public function __construct( ConnectionState $connection_state, Settings $settings, DccApplies $dcc_applies, DCCProductStatus $dcc_status, - GeneralSettings $general_settings + string $store_country ) { $this->connection_state = $connection_state; $this->settings = $settings; $this->dcc_applies = $dcc_applies; $this->dcc_status = $dcc_status; - $this->general_settings = $general_settings; + $this->store_country = $store_country; $this->is_resolved = false; } @@ -330,7 +330,7 @@ class CardPaymentsConfiguration { * @return bool */ public function is_bcdc_enabled() : bool { - if ( 'MX' === $this->general_settings->get_merchant_country() ) { + if ( 'MX' === $this->store_country ) { $bcdc_setting = get_option( 'woocommerce_ppcp-card-button-gateway_settings' ); return 'yes' === $bcdc_setting['enabled']; } diff --git a/tests/PHPUnit/ApiClient/Repository/PartnerReferralsDataTest.php b/tests/PHPUnit/ApiClient/Repository/PartnerReferralsDataTest.php deleted file mode 100644 index d975918b3..000000000 --- a/tests/PHPUnit/ApiClient/Repository/PartnerReferralsDataTest.php +++ /dev/null @@ -1,267 +0,0 @@ -data()` method to ensure it's appended at the end of the - * return URL as-is. - */ - private const TOKEN = 'SECURE_TOKEN'; - - /** - * Expected return URL to see at in the payload, including the ppcpToken. - */ - private const RETURN_URL = 'https://example.com/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcpToken=SECURE_TOKEN'; - - private $testee; - private $dccApplies; - - public function setUp() : void { - parent::setUp(); - - $this->dccApplies = Mockery::mock( DccApplies::class ); - $this->testee = new PartnerReferralsData( $this->dccApplies ); - - when( 'admin_url' )->alias( static fn( string $path ) => self::ADMIN_URL . $path ); - when( 'add_query_arg' )->justReturn( self::RETURN_URL ); - } - - /** - * Base structure of the API payload. Each test should modify the returned - * value of the method to meet its expectations. - * - * This avoids repeating the full structure, while also highlighting the - * specific changes that different params will generate. - * - * @return array - */ - private function getBaseExpectedArray() : array { - return [ - 'partner_config_override' => [ - 'return_url' => self::RETURN_URL, - 'return_url_description' => 'Return to your shop.', - 'show_add_credit_card' => true, - ], - 'legal_consents' => [ - [ - 'type' => 'SHARE_DATA_CONSENT', - 'granted' => true, - ], - ], - 'operations' => [ - [ - 'operation' => 'API_INTEGRATION', - 'api_integration_preference' => [ - 'rest_api_integration' => [ - 'integration_method' => 'PAYPAL', - 'integration_type' => 'FIRST_PARTY', - 'first_party_details' => [ - 'features' => [ - 'PAYMENT', - 'REFUND', - 'ADVANCED_TRANSACTIONS_SEARCH', - 'TRACKING_SHIPMENT_READWRITE', - ], - 'seller_nonce' => self::DEFAULT_NONCE, - ], - ], - ], - ], - ], - ]; - } - - /** - * Data provider for testing flag combinations. - * - * @return array[] Test cases with [has_subscriptions, has_cards, is_acdc_eligible, - * expected_changes] - */ - public function flagCombinationsProvider() : array { - return [ - 'with subscriptions and cards, ACDC eligible' => [ - true, // With subscription? - true, // With cards? - true, // ACDC eligible? - [ - 'capabilities' => [ 'PAYPAL_WALLET_VAULTING_ADVANCED' ], - 'show_add_credit_card' => true, - 'has_vault_features' => true, - ], - ], - 'with subscriptions, no cards, ACDC eligible' => [ - true, // With subscription? - false, // With cards? - true, // ACDC eligible? - [ - 'capabilities' => [ 'PAYPAL_WALLET_VAULTING_ADVANCED' ], - 'show_add_credit_card' => false, - 'has_vault_features' => true, - ], - ], - 'no subscriptions, with cards, ACDC eligible' => [ - false, // With subscription? - true, // With cards? - true, // ACDC eligible? - [ - 'capabilities' => [ 'PAYPAL_WALLET_VAULTING_ADVANCED' ], - 'show_add_credit_card' => true, - 'has_vault_features' => false, - ], - ], - 'no subscriptions, no cards, ACDC eligible' => [ - false, // With subscription? - false, // With cards? - true, // ACDC eligible? - [ - 'capabilities' => [ 'PAYPAL_WALLET_VAULTING_ADVANCED' ], - 'show_add_credit_card' => false, - 'has_vault_features' => false, - ], - ], - 'with subscriptions and cards, ACDC is not eligible' => [ - true, // With subscription? - true, // With cards? - false, // ACDC eligible? - [ - 'show_add_credit_card' => true, - 'has_vault_features' => true, - ], - ], - 'with subscriptions, no cards, ACDC is not eligible' => [ - true, // With subscription? - false, // With cards? - false, // ACDC eligible? - [ - 'show_add_credit_card' => false, - 'has_vault_features' => true, - ], - ], - 'no subscriptions, with cards, ACDC is not eligible' => [ - false, // With subscription? - true, // With cards? - false, // ACDC eligible? - [ - 'show_add_credit_card' => true, - 'has_vault_features' => false, - ], - ], - 'no subscriptions, no cards, ACDC is not eligible' => [ - false, // With subscription? - false, // With cards? - false, // ACDC eligible? - [ - 'show_add_credit_card' => false, - 'has_vault_features' => false, - ], - ], - ]; - } - - /** - * Ensure the default "products" are derived from the DccApplies response. - */ - public function testDefaultValues() : void { - /** - * Case 1: The data() method gets no parameters, and the DccApplies check - * returns TRUE. Onboarding payload should indicate "PPCP". - */ - $this->dccApplies->expects( 'for_country_currency' )->andReturn( true ); - $result = $this->testee->data(); - $this->assertEquals( [ 'PPCP' ], $result['products'] ); - - /** - * Case 2: The data() method gets no parameters, and the DccApplies check - * returns FALSE. Onboarding payload should indicate "EXPRESS_CHECKOUT". - */ - $this->dccApplies->expects( 'for_country_currency' )->andReturn( false ); - $result = $this->testee->data(); - $this->assertEquals( [ 'EXPRESS_CHECKOUT' ], $result['products'] ); - } - - /** - * Ensure the generated API payload is stable and contains the expected values. - * - * The test only verifies the "products" and "token" arguments, as those are the - * core params present in the legacy and new UI. - */ - public function testDataStructure() : void { - $this->dccApplies->shouldReceive( 'for_country_currency' )->andReturn( true ); - - /** - * Undefined subscription: Keep vaulting in first-party, but don't add the capability. - */ - $result = $this->testee->data( [ 'PPCP' ], self::TOKEN ); - - $expected = $this->getBaseExpectedArray(); - - $expected['products'] = [ 'PPCP' ]; - - $expected['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['features'][] = 'BILLING_AGREEMENT'; - $expected['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['features'][] = 'FUTURE_PAYMENT'; - $expected['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['features'][] = 'VAULT'; - - $expected['capabilities'][] = 'PAYPAL_WALLET_VAULTING_ADVANCED'; - - $this->assertEquals( $expected, $result ); - } - - /** - * Test how different flag combinations affect the data structure. - * Those flags are present in the new UI. - * - * @dataProvider flagCombinationsProvider - */ - public function testDataStructureWithFlags( bool $has_subscriptions, bool $has_cards, bool $is_acdc_eligible, array $expected_changes ) : void { - $this->dccApplies->shouldReceive( 'for_country_currency' )->andReturn( $is_acdc_eligible ); - - $result = $this->testee->data( [ 'PPCP' ], self::TOKEN, $has_subscriptions, $has_cards ); - $expected = $this->getBaseExpectedArray(); - - $expected['products'] = [ 'PPCP' ]; - - if ( isset( $expected_changes['capabilities'] ) ) { - $expected['capabilities'] = $expected_changes['capabilities']; - } else { - $this->assertArrayNotHasKey( 'capabilities', $expected ); - } - - $expected['partner_config_override']['show_add_credit_card'] = $expected_changes['show_add_credit_card']; - - $expected['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['features'][] = 'BILLING_AGREEMENT'; - - if ( $expected_changes['has_vault_features'] ) { - $expected['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['features'][] = 'FUTURE_PAYMENT'; - $expected['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['features'][] = 'VAULT'; - } else { - // Double-check that the features are not present in our expected array - $this->assertNotContains( 'FUTURE_PAYMENT', $expected['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['features'] ); - $this->assertNotContains( 'VAULT', $expected['operations'][0]['api_integration_preference']['rest_api_integration']['first_party_details']['features'] ); - } - - $this->assertEquals( $expected, $result ); - } -}