Skip to content

Commit 2fd31d4

Browse files
committed
AC-1225 Sandbox Testing ONLY Add buyer-country param
1 parent 60637c2 commit 2fd31d4

File tree

5 files changed

+529
-218
lines changed

5 files changed

+529
-218
lines changed

app/code/Magento/Paypal/Model/Config.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* Config model that is aware of all \Magento\Paypal payment methods
1313
*
1414
* Works with PayPal-specific system configuration
15-
1615
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
1716
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
1817
*/
@@ -620,7 +619,8 @@ public function __construct(
620619
\Magento\Payment\Model\Source\CctypeFactory $cctypeFactory,
621620
\Magento\Paypal\Model\CertFactory $certFactory,
622621
$params = []
623-
) {
622+
)
623+
{
624624
parent::__construct($scopeConfig);
625625
$this->directoryHelper = $directoryHelper;
626626
$this->_storeManager = $storeManager;
@@ -840,7 +840,7 @@ public function getCountryMethods($countryCode = null)
840840
public function getPayPalBasicStartUrl($token)
841841
{
842842
$params = [
843-
'cmd' => '_express-checkout',
843+
'cmd' => '_express-checkout',
844844
'token' => $token,
845845
];
846846

@@ -1519,6 +1519,7 @@ protected function _mapExpressFieldset($fieldName)
15191519
case 'merchant_id':
15201520
case 'client_id':
15211521
case 'sandbox_client_id':
1522+
case 'buyer_country':
15221523
case 'supported_locales':
15231524
case 'smart_buttons_supported_locales':
15241525
return "payment/{$this->_methodCode}/{$fieldName}";
@@ -1615,8 +1616,8 @@ protected function _mapWpukFieldset($fieldName)
16151616
if ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS && $this->isMethodAvailable(self::METHOD_PAYFLOWLINK)) {
16161617
$pathPrefix = 'payment/payflow_link';
16171618
} elseif ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS && $this->isMethodAvailable(
1618-
self::METHOD_PAYFLOWADVANCED
1619-
)
1619+
self::METHOD_PAYFLOWADVANCED
1620+
)
16201621
) {
16211622
$pathPrefix = 'payment/payflow_advanced';
16221623
} elseif ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS) {

app/code/Magento/Paypal/Model/SdkUrl.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public function __construct(
8282
StoreManagerInterface $storeManager,
8383
$disallowedFundingMap = [],
8484
$unsupportedPaymentMethods = []
85-
) {
85+
)
86+
{
8687
$this->localeResolver = $localeResolver;
8788
$this->config = $configFactory->create();
8889
$this->config->setMethod(Config::METHOD_EXPRESS);
@@ -116,6 +117,7 @@ public function getUrl(): string
116117
$params['intent'] = $this->getIntent();
117118
$params['merchant-id'] = $this->config->getValue('merchant_id');
118119
$params['disable-funding'] = $this->getDisallowedFunding();
120+
$params['buyer-country'] = $this->getBuyerCountry();
119121
$params = array_replace($params, $this->queryParams);
120122
}
121123
$params['components'] = implode(',', $components);
@@ -156,7 +158,7 @@ private function areMessagesEnabled()
156158
*/
157159
private function areButtonsEnabled()
158160
{
159-
return (bool)(int) $this->config->getValue('in_context');
161+
return (bool)(int)$this->config->getValue('in_context');
160162
}
161163

162164
/**
@@ -171,6 +173,17 @@ private function getClientId()
171173
$this->config->getValue('client_id');
172174
}
173175

176+
/**
177+
* get Configured value for paypal buyer country
178+
* @return string
179+
*/
180+
private function getBuyerCountry()
181+
{
182+
return (int)$this->config->getValue('sandbox_flag') ?
183+
$this->config->getValue('buyer_country') :
184+
'';
185+
}
186+
174187
/**
175188
* Returns disallowed funding from configuration after updating values
176189
*

app/code/Magento/Paypal/Test/Unit/Model/SdkUrlTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ protected function setUp(): void
8585
* @param string $locale
8686
* @param string $intent
8787
* @param string|null $disallowedFunding
88+
* @param bool $isBuyerCountryEnabled
8889
* @param bool $isPaypalGuestCheckoutEnabled
8990
* @param array $expected
9091
* @dataProvider getConfigDataProvider
@@ -93,16 +94,19 @@ public function testGetConfig(
9394
string $locale,
9495
string $intent,
9596
?string $disallowedFunding,
97+
bool $isBuyerCountryEnabled,
9698
bool $isPaypalGuestCheckoutEnabled,
9799
array $expected
98-
) {
100+
)
101+
{
99102
$this->localeResolverMock->method('getLocale')->willReturn($locale);
100103
$this->configMock->method('getValue')->willReturnMap(
101104
[
102105
['merchant_id', null, 'merchant'],
103106
['sandbox_client_id', null, 'sb'],
104107
['sandbox_flag', null, true],
105108
['disable_funding_options', null, $disallowedFunding],
109+
['buyer_country', null, $isBuyerCountryEnabled ? 'US' : ''],
106110
['paymentAction', null, $intent],
107111
['in_context', null, true],
108112
[
@@ -112,7 +116,6 @@ public function testGetConfig(
112116
],
113117
]
114118
);
115-
116119
self::assertEquals($expected['sdkUrl'], $this->model->getUrl());
117120
}
118121

@@ -150,7 +153,7 @@ private function getDisallowedFundingMap()
150153
private function getUnsupportedPaymentMethods()
151154
{
152155
return [
153-
'venmo'=> 'venmo',
156+
'venmo' => 'venmo',
154157
'bancontact' => 'bancontact',
155158
'eps' => 'eps',
156159
'giropay' => 'giropay',

app/code/Magento/Paypal/Test/Unit/Model/_files/expected_url_config.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @param array $params
1111
* @return String
1212
*/
13-
function generateExpectedPaypalSdkUrl(array $params) : String
13+
function generateExpectedPaypalSdkUrl(array $params): string
1414
{
1515
return 'https://www.paypal.com/sdk/js?' . http_build_query($params);
1616
}
@@ -20,6 +20,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
2020
'es_MX',
2121
'Authorization',
2222
'CREDIT,ELV,CARD',
23+
false,
2324
true,
2425
[
2526
'sdkUrl' => generateExpectedPaypalSdkUrl(
@@ -55,6 +56,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
5556
'en_BR',
5657
'Sale',
5758
null,
59+
false,
5860
true,
5961
[
6062
'sdkUrl' => generateExpectedPaypalSdkUrl(
@@ -78,6 +80,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
7880
'en_US',
7981
'Order',
8082
null,
83+
false,
8184
true,
8285
[
8386
'sdkUrl' => generateExpectedPaypalSdkUrl(
@@ -102,6 +105,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
102105
'Authorization',
103106
'CREDIT,ELV',
104107
false,
108+
false,
105109
[
106110
'sdkUrl' => generateExpectedPaypalSdkUrl(
107111
[
@@ -136,6 +140,56 @@ function generateExpectedPaypalSdkUrl(array $params) : String
136140
'en_BR',
137141
'Authorization',
138142
'CREDIT,ELV',
143+
false,
144+
true,
145+
[
146+
'sdkUrl' => generateExpectedPaypalSdkUrl(
147+
[
148+
'client-id' => 'sb',
149+
'locale' => 'en_BR',
150+
'currency' => 'USD',
151+
'commit' => 'false',
152+
'intent' => 'authorize',
153+
'merchant-id' => 'merchant',
154+
'disable-funding' => implode(
155+
',',
156+
['credit', 'sepa', 'venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
157+
),
158+
'components' => implode(',', ['messages', 'buttons'])
159+
]
160+
)
161+
]
162+
],
163+
'buyer_country_enabled' => [
164+
'en_BR',
165+
'Authorization',
166+
'CREDIT,ELV',
167+
true,
168+
true,
169+
[
170+
'sdkUrl' => generateExpectedPaypalSdkUrl(
171+
[
172+
'client-id' => 'sb',
173+
'locale' => 'en_BR',
174+
'currency' => 'USD',
175+
'commit' => 'false',
176+
'intent' => 'authorize',
177+
'merchant-id' => 'merchant',
178+
'disable-funding' => implode(
179+
',',
180+
['credit', 'sepa', 'venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
181+
),
182+
'buyer-country' => 'US',
183+
'components' => implode(',', ['messages', 'buttons'])
184+
]
185+
)
186+
]
187+
],
188+
'buyer_country_disabled' => [
189+
'en_BR',
190+
'Authorization',
191+
'CREDIT,ELV',
192+
false,
139193
true,
140194
[
141195
'sdkUrl' => generateExpectedPaypalSdkUrl(

0 commit comments

Comments
 (0)