mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Merge pull request #3418 from woocommerce/PCP-4254-mexico-installments-new-ux-updates-fix-unavailable-settings-service
Replace the unavailable country code service (4254)
This commit is contained in:
commit
088cd982e8
5 changed files with 12 additions and 280 deletions
|
@ -90,16 +90,15 @@ class PartnerReferralsData {
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $in_acdc_country ) {
|
if ( $in_acdc_country ) {
|
||||||
|
$products = array( 'PPCP', 'ADVANCED_VAULTING' );
|
||||||
$capabilities[] = 'PAYPAL_WALLET_VAULTING_ADVANCED';
|
$capabilities[] = 'PAYPAL_WALLET_VAULTING_ADVANCED';
|
||||||
}
|
}
|
||||||
|
|
||||||
$first_party_features[] = 'BILLING_AGREEMENT';
|
$first_party_features[] = 'BILLING_AGREEMENT';
|
||||||
|
|
||||||
// Backwards compatibility. Keep those features in the #legacy-ui (null-value).
|
if ( $use_card_payments !== false ) {
|
||||||
// Move this into the previous condition, once legacy code is removed.
|
|
||||||
if ( false !== $use_subscriptions ) {
|
|
||||||
$first_party_features[] = 'FUTURE_PAYMENT';
|
|
||||||
$first_party_features[] = 'VAULT';
|
$first_party_features[] = 'VAULT';
|
||||||
|
$first_party_features[] = 'FUTURE_PAYMENT';
|
||||||
}
|
}
|
||||||
|
|
||||||
$payload = array(
|
$payload = array(
|
||||||
|
|
|
@ -347,7 +347,7 @@ return array(
|
||||||
$container->get( 'wcgateway.settings' ),
|
$container->get( 'wcgateway.settings' ),
|
||||||
$container->get( 'wcgateway.all-funding-sources' ),
|
$container->get( 'wcgateway.all-funding-sources' ),
|
||||||
$container->get( 'wcgateway.configuration.card-configuration' ),
|
$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 {
|
'button.is-logged-in' => static function ( ContainerInterface $container ): bool {
|
||||||
|
|
|
@ -1405,7 +1405,7 @@ return array(
|
||||||
$container->get( 'wcgateway.settings' ),
|
$container->get( 'wcgateway.settings' ),
|
||||||
$container->get( 'api.helpers.dccapplies' ),
|
$container->get( 'api.helpers.dccapplies' ),
|
||||||
$container->get( 'wcgateway.helper.dcc-product-status' ),
|
$container->get( 'wcgateway.helper.dcc-product-status' ),
|
||||||
$container->get( 'settings.data.general' )
|
$container->get( 'api.shop.country' )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -71,11 +71,11 @@ class CardPaymentsConfiguration {
|
||||||
private DCCProductStatus $dcc_status;
|
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
|
* This classes lazily resolves settings on first access. This flag indicates
|
||||||
|
@ -142,20 +142,20 @@ class CardPaymentsConfiguration {
|
||||||
* @param Settings $settings Plugin settings instance.
|
* @param Settings $settings Plugin settings instance.
|
||||||
* @param DccApplies $dcc_applies DCC eligibility helper.
|
* @param DccApplies $dcc_applies DCC eligibility helper.
|
||||||
* @param DCCProductStatus $dcc_status Manages the Seller status.
|
* @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(
|
public function __construct(
|
||||||
ConnectionState $connection_state,
|
ConnectionState $connection_state,
|
||||||
Settings $settings,
|
Settings $settings,
|
||||||
DccApplies $dcc_applies,
|
DccApplies $dcc_applies,
|
||||||
DCCProductStatus $dcc_status,
|
DCCProductStatus $dcc_status,
|
||||||
GeneralSettings $general_settings
|
string $store_country
|
||||||
) {
|
) {
|
||||||
$this->connection_state = $connection_state;
|
$this->connection_state = $connection_state;
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->dcc_applies = $dcc_applies;
|
$this->dcc_applies = $dcc_applies;
|
||||||
$this->dcc_status = $dcc_status;
|
$this->dcc_status = $dcc_status;
|
||||||
$this->general_settings = $general_settings;
|
$this->store_country = $store_country;
|
||||||
|
|
||||||
$this->is_resolved = false;
|
$this->is_resolved = false;
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ class CardPaymentsConfiguration {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function is_bcdc_enabled() : 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' );
|
$bcdc_setting = get_option( 'woocommerce_ppcp-card-button-gateway_settings' );
|
||||||
return 'yes' === $bcdc_setting['enabled'];
|
return 'yes' === $bcdc_setting['enabled'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,267 +0,0 @@
|
||||||
<?php
|
|
||||||
declare( strict_types = 1 );
|
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\ApiClient\Repository;
|
|
||||||
|
|
||||||
use Mockery;
|
|
||||||
use WooCommerce\PayPalCommerce\TestCase;
|
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
|
|
||||||
use function Brain\Monkey\Functions\when;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group api
|
|
||||||
* @group onboarding
|
|
||||||
*/
|
|
||||||
class PartnerReferralsDataTest extends TestCase {
|
|
||||||
/**
|
|
||||||
* Expected nonce that should appear in the payload.
|
|
||||||
*/
|
|
||||||
private const DEFAULT_NONCE = 'a1233wtergfsdt4365tzrshgfbaewa36AGa1233wtergfsdt4365tzrshgfbaewa36AG';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sample URL which is used to mock the `admin_url()` response, used to build the return URL.
|
|
||||||
* Specifically, we want to verify the $path which is appended to the admin URL.
|
|
||||||
*/
|
|
||||||
private const ADMIN_URL = 'https://example.com/wp-admin/';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A sample token that we add to the return URL.
|
|
||||||
* We pass this const to the `->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 );
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue