Skip to content

Commit 3aac7ea

Browse files
committed
Merge remote-tracking branch 'origin/ac1225' into gl_pr_paypal_nov11_2021
2 parents 2399c8c + 68f8727 commit 3aac7ea

File tree

10 files changed

+117
-17
lines changed

10 files changed

+117
-17
lines changed

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

Lines changed: 5 additions & 8 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
*/
@@ -180,7 +179,6 @@ class Config extends AbstractConfig
180179
const PAYLATER = 'paypal_paylater';
181180

182181
/**
183-
* Instructions for generating proper BN code
184182
*
185183
* @var array
186184
*/
@@ -191,7 +189,6 @@ class Config extends AbstractConfig
191189
];
192190

193191
/**
194-
* Style system config map (Express Checkout)
195192
*
196193
* @var array
197194
*/
@@ -204,7 +201,6 @@ class Config extends AbstractConfig
204201
];
205202

206203
/**
207-
* Currency codes supported by PayPal methods
208204
*
209205
* @var string[]
210206
*/
@@ -234,7 +230,6 @@ class Config extends AbstractConfig
234230
];
235231

236232
/**
237-
* Merchant country supported by PayPal
238233
*
239234
* @var string[]
240235
*/
@@ -310,7 +305,6 @@ class Config extends AbstractConfig
310305
];
311306

312307
/**
313-
* Buyer country supported by PayPal
314308
*
315309
* @var string[]
316310
*/
@@ -837,10 +831,10 @@ public function getCountryMethods($countryCode = null)
837831
* @param string $token
838832
* @return string
839833
*/
840-
public function getPayPalBasicStartUrl($token)
834+
public function getPayPalBasicStartUrl($token): string
841835
{
842836
$params = [
843-
'cmd' => '_express-checkout',
837+
'cmd' => '_express-checkout',
844838
'token' => $token,
845839
];
846840

@@ -1519,6 +1513,7 @@ protected function _mapExpressFieldset($fieldName)
15191513
case 'merchant_id':
15201514
case 'client_id':
15211515
case 'sandbox_client_id':
1516+
case 'buyer_country':
15221517
case 'supported_locales':
15231518
case 'smart_buttons_supported_locales':
15241519
return "payment/{$this->_methodCode}/{$fieldName}";
@@ -1591,6 +1586,7 @@ protected function _mapWppFieldset($fieldName)
15911586
case 'api_signature':
15921587
case 'api_cert':
15931588
case 'sandbox_flag':
1589+
case 'buyer_country':
15941590
case 'use_proxy':
15951591
case 'proxy_host':
15961592
case 'proxy_port':
@@ -1631,6 +1627,7 @@ protected function _mapWpukFieldset($fieldName)
16311627
case 'vendor':
16321628
case 'pwd':
16331629
case 'sandbox_flag':
1630+
case 'buyer_country':
16341631
case 'use_proxy':
16351632
case 'proxy_host':
16361633
case 'proxy_port':

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class SdkUrl
4242
private $queryParams = [];
4343

4444
/**
45-
* Maps the old checkout SDK configuration values to the current ones
4645
*
4746
* @var array
4847
*/
@@ -61,7 +60,6 @@ class SdkUrl
6160
private $localeResolver;
6261

6362
/**
64-
* Generated Url to PayPAl SDK
6563
*
6664
* @var string
6765
*/
@@ -105,6 +103,7 @@ public function getUrl(): string
105103
'client-id' => $this->getClientId(),
106104
'locale' => $this->localeResolver->getLocale(),
107105
'currency' => $this->storeManager->getStore()->getBaseCurrencyCode(),
106+
'buyer-country' => $this->getBuyerCountry(),
108107
];
109108

110109
if ($this->areMessagesEnabled()) {
@@ -156,7 +155,7 @@ private function areMessagesEnabled()
156155
*/
157156
private function areButtonsEnabled()
158157
{
159-
return (bool)(int) $this->config->getValue('in_context');
158+
return (bool)(int)$this->config->getValue('in_context');
160159
}
161160

162161
/**
@@ -171,6 +170,16 @@ private function getClientId()
171170
$this->config->getValue('client_id');
172171
}
173172

173+
/**
174+
* Get Configured value for paypal buyer country
175+
*
176+
* @return string
177+
*/
178+
private function getBuyerCountry(): ?string
179+
{
180+
return (int)$this->config->getValue('sandbox_flag') ? $this->config->getValue('buyer_country') : '';
181+
}
182+
174183
/**
175184
* Returns disallowed funding from configuration after updating values
176185
*

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

Lines changed: 4 additions & 2 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,6 +94,7 @@ public function testGetConfig(
9394
string $locale,
9495
string $intent,
9596
?string $disallowedFunding,
97+
bool $isBuyerCountryEnabled,
9698
bool $isPaypalGuestCheckoutEnabled,
9799
array $expected
98100
) {
@@ -102,6 +104,7 @@ public function testGetConfig(
102104
['merchant_id', null, 'merchant'],
103105
['sandbox_client_id', null, 'sb'],
104106
['sandbox_flag', null, true],
107+
['buyer_country', null, $isBuyerCountryEnabled ? 'US' : ''],
105108
['disable_funding_options', null, $disallowedFunding],
106109
['paymentAction', null, $intent],
107110
['in_context', null, true],
@@ -112,7 +115,6 @@ public function testGetConfig(
112115
],
113116
]
114117
);
115-
116118
self::assertEquals($expected['sdkUrl'], $this->model->getUrl());
117119
}
118120

@@ -150,7 +152,7 @@ private function getDisallowedFundingMap()
150152
private function getUnsupportedPaymentMethods()
151153
{
152154
return [
153-
'venmo'=> 'venmo',
155+
'venmo' => 'venmo',
154156
'bancontact' => 'bancontact',
155157
'eps' => 'eps',
156158
'giropay' => 'giropay',

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

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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(
@@ -46,7 +47,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
4647
'sofort'
4748
]
4849
),
49-
'components' => implode(',', ['messages', 'buttons'])
50+
'components' => implode(',', ['messages', 'buttons']),
5051
]
5152
)
5253
]
@@ -55,6 +56,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
5556
'en_BR',
5657
'Sale',
5758
null,
59+
false,
5860
true,
5961
[
6062
'sdkUrl' => generateExpectedPaypalSdkUrl(
@@ -69,7 +71,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
6971
',',
7072
['venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
7173
),
72-
'components' => implode(',', ['messages', 'buttons'])
74+
'components' => implode(',', ['messages', 'buttons']),
7375
]
7476
)
7577
]
@@ -78,6 +80,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
7880
'en_US',
7981
'Order',
8082
null,
83+
false,
8184
true,
8285
[
8386
'sdkUrl' => generateExpectedPaypalSdkUrl(
@@ -92,7 +95,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
9295
',',
9396
['venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
9497
),
95-
'components' => implode(',', ['messages', 'buttons'])
98+
'components' => implode(',', ['messages', 'buttons']),
9699
]
97100
)
98101
]
@@ -102,6 +105,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
102105
'Authorization',
103106
'CREDIT,ELV',
104107
false,
108+
false,
105109
[
106110
'sdkUrl' => generateExpectedPaypalSdkUrl(
107111
[
@@ -127,7 +131,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
127131
'sofort'
128132
]
129133
),
130-
'components' => implode(',', ['messages', 'buttons'])
134+
'components' => implode(',', ['messages', 'buttons']),
131135
]
132136
)
133137
]
@@ -136,6 +140,7 @@ function generateExpectedPaypalSdkUrl(array $params) : String
136140
'en_BR',
137141
'Authorization',
138142
'CREDIT,ELV',
143+
false,
139144
true,
140145
[
141146
'sdkUrl' => generateExpectedPaypalSdkUrl(
@@ -150,9 +155,58 @@ function generateExpectedPaypalSdkUrl(array $params) : String
150155
',',
151156
['credit', 'sepa', 'venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
152157
),
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+
'buyer-country' => 'US',
176+
'commit' => 'false',
177+
'intent' => 'authorize',
178+
'merchant-id' => 'merchant',
179+
'disable-funding' => implode(
180+
',',
181+
['credit', 'sepa', 'venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
182+
),
153183
'components' => implode(',', ['messages', 'buttons'])
154184
]
155185
)
156186
]
157187
],
188+
'buyer_country_disabled' => [
189+
'en_BR',
190+
'Authorization',
191+
'CREDIT,ELV',
192+
false,
193+
true,
194+
[
195+
'sdkUrl' => generateExpectedPaypalSdkUrl(
196+
[
197+
'client-id' => 'sb',
198+
'locale' => 'en_BR',
199+
'currency' => 'USD',
200+
'commit' => 'false',
201+
'intent' => 'authorize',
202+
'merchant-id' => 'merchant',
203+
'disable-funding' => implode(
204+
',',
205+
['credit', 'sepa', 'venmo', 'bancontact', 'eps', 'giropay', 'ideal', 'mybank', 'p24', 'sofort']
206+
),
207+
'components' => implode(',', ['messages', 'buttons']),
208+
]
209+
)
210+
]
211+
],
158212
];

app/code/Magento/Paypal/etc/adminhtml/system/express_checkout.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@
103103
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
104104
<attribute type="shared">1</attribute>
105105
</field>
106+
<field id="buyer_country" translate="label" type="select" sortOrder="85" showInDefault="1" showInWebsite="1">
107+
<label>Buyer Country</label>
108+
<config_path>payment/paypal_express/buyer_country</config_path>
109+
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
110+
<attribute type="shared">1</attribute>
111+
<depends>
112+
<field id="sandbox_flag">1</field>
113+
</depends>
114+
</field>
106115
<field id="use_proxy" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="1">
107116
<label>API Uses Proxy</label>
108117
<config_path>paypal/wpp/use_proxy</config_path>

app/code/Magento/Paypal/etc/adminhtml/system/payflow_advanced.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
5656
<attribute type="shared">1</attribute>
5757
</field>
58+
<field id="buyer_country" translate="label" type="select" sortOrder="65" showInDefault="1" showInWebsite="1">
59+
<label>Buyer Country</label>
60+
<config_path>payment/payflow_advanced/buyer_country</config_path>
61+
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
62+
<attribute type="shared">1</attribute>
63+
<depends>
64+
<field id="sandbox_flag">1</field>
65+
</depends>
66+
</field>
5867
<field id="use_proxy" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1">
5968
<label>Use Proxy</label>
6069
<config_path>payment/payflow_advanced/use_proxy</config_path>

app/code/Magento/Paypal/etc/adminhtml/system/payflow_link.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@
5656
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
5757
<attribute type="shared">1</attribute>
5858
</field>
59+
<field id="buyer_country" translate="label" type="select" sortOrder="55" showInDefault="1" showInWebsite="1">
60+
<label>Buyer Country</label>
61+
<config_path>payment/payflow_link/buyer_country</config_path>
62+
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
63+
<attribute type="shared">1</attribute>
64+
<depends>
65+
<field id="sandbox_flag">1</field>
66+
</depends>
67+
</field>
5968
<field id="use_proxy" translate="label" type="select" sortOrder="60" showInDefault="1" showInWebsite="1">
6069
<label>Use Proxy</label>
6170
<config_path>payment/payflow_link/use_proxy</config_path>

app/code/Magento/Paypal/etc/adminhtml/system/payments_pro_hosted_solution.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<field id="api_cert" extends="payment_all_paypal/express_checkout/express_checkout_required/express_checkout_required_express_checkout/api_cert" />
3232
<field id="api_wizard" extends="payment_all_paypal/express_checkout/express_checkout_required/express_checkout_required_express_checkout/api_wizard" />
3333
<field id="sandbox_flag" extends="payment_all_paypal/express_checkout/express_checkout_required/express_checkout_required_express_checkout/sandbox_flag" />
34+
<field id="buyer_country" extends="payment_all_paypal/express_checkout/express_checkout_required/express_checkout_required_express_checkout/buyer_country" />
3435
<field id="use_proxy" extends="payment_all_paypal/express_checkout/express_checkout_required/express_checkout_required_express_checkout/use_proxy" />
3536
<field id="proxy_host" extends="payment_all_paypal/express_checkout/express_checkout_required/express_checkout_required_express_checkout/proxy_host" />
3637
<field id="proxy_port" extends="payment_all_paypal/express_checkout/express_checkout_required/express_checkout_required_express_checkout/proxy_port" />

app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@
5151
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
5252
<attribute type="shared">1</attribute>
5353
</field>
54+
<field id="buyer_country" translate="label" type="select" sortOrder="65" showInDefault="1" showInWebsite="1">
55+
<label>Buyer Country</label>
56+
<config_path>payment/payflowpro/buyer_country</config_path>
57+
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
58+
<attribute type="shared">1</attribute>
59+
<depends>
60+
<field id="sandbox_flag">1</field>
61+
</depends>
62+
</field>
5463
<field id="use_proxy" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1">
5564
<label>Use Proxy</label>
5665
<config_path>payment/payflowpro/use_proxy</config_path>

app/code/Magento/Paypal/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ Manage,Manage
468468
"API Password","API Password"
469469
"Get Credentials from PayPal","Get Credentials from PayPal"
470470
"Sandbox Mode","Sandbox Mode"
471+
"Buyer Country","Buyer Country"
471472
"API Uses Proxy","API Uses Proxy"
472473
"Proxy Host","Proxy Host"
473474
"Proxy Port","Proxy Port"

0 commit comments

Comments
 (0)