Skip to content

Commit 903c611

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into B2B-582
2 parents 3be7cb1 + b4c05a4 commit 903c611

File tree

85 files changed

+2805
-718
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2805
-718
lines changed

app/code/Magento/Backend/Test/Mftf/Data/GeneralLocalConfigsData.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@
2020
<data key="scope_code">base</data>
2121
<data key="value">en_US</data>
2222
</entity>
23+
<entity name="GeneralLocalCodeConfigsForMexico">
24+
<data key="path">general/locale/code</data>
25+
<data key="scope">websites</data>
26+
<data key="scope_code">base</data>
27+
<data key="value">es_MX</data>
28+
</entity>
2329
</entities>

app/code/Magento/CurrencySymbol/Test/Mftf/Data/CurrencyRatesConfigData.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,36 @@
2020
<data key="scope">websites</data>
2121
<data key="scope_code">base</data>
2222
</entity>
23+
<entity name="SetCurrencyYENBaseConfig">
24+
<data key="path">currency/options/base</data>
25+
<data key="value">JPY</data>
26+
<data key="scope">websites</data>
27+
<data key="scope_code">base</data>
28+
</entity>
29+
<entity name="SetCurrencyCADBaseConfig">
30+
<data key="path">currency/options/base</data>
31+
<data key="value">CAD</data>
32+
<data key="scope">websites</data>
33+
<data key="scope_code">base</data>
34+
</entity>
35+
<entity name="SetCurrencyAUDBaseConfig">
36+
<data key="path">currency/options/base</data>
37+
<data key="value">AUD</data>
38+
<data key="scope">websites</data>
39+
<data key="scope_code">base</data>
40+
</entity>
41+
<entity name="SetCurrencyHKDBaseConfig">
42+
<data key="path">currency/options/base</data>
43+
<data key="value">HKD</data>
44+
<data key="scope">websites</data>
45+
<data key="scope_code">base</data>
46+
</entity>
47+
<entity name="SetCurrencyNZDBaseConfig">
48+
<data key="path">currency/options/base</data>
49+
<data key="value">NZD</data>
50+
<data key="scope">websites</data>
51+
<data key="scope_code">base</data>
52+
</entity>
2353
<entity name="SetAllowedCurrenciesConfigForUSD">
2454
<data key="path">currency/options/allow</data>
2555
<data key="value">USD</data>
@@ -32,6 +62,36 @@
3262
<data key="scope">websites</data>
3363
<data key="scope_code">base</data>
3464
</entity>
65+
<entity name="SetAllowedCurrenciesConfigForYEN">
66+
<data key="path">currency/options/allow</data>
67+
<data key="value">JPY</data>
68+
<data key="scope">websites</data>
69+
<data key="scope_code">base</data>
70+
</entity>
71+
<entity name="SetAllowedCurrenciesConfigForCAD">
72+
<data key="path">currency/options/allow</data>
73+
<data key="value">CAD</data>
74+
<data key="scope">websites</data>
75+
<data key="scope_code">base</data>
76+
</entity>
77+
<entity name="SetAllowedCurrenciesConfigForAUD">
78+
<data key="path">currency/options/allow</data>
79+
<data key="value">AUD</data>
80+
<data key="scope">websites</data>
81+
<data key="scope_code">base</data>
82+
</entity>
83+
<entity name="SetAllowedCurrenciesConfigForHKD">
84+
<data key="path">currency/options/allow</data>
85+
<data key="value">HKD</data>
86+
<data key="scope">websites</data>
87+
<data key="scope_code">base</data>
88+
</entity>
89+
<entity name="SetAllowedCurrenciesConfigForNZD">
90+
<data key="path">currency/options/allow</data>
91+
<data key="value">NZD</data>
92+
<data key="scope">websites</data>
93+
<data key="scope_code">base</data>
94+
</entity>
3595
<entity name="SetAllowedCurrenciesConfigForRUB">
3696
<data key="path">currency/options/allow</data>
3797
<data key="value">RUB</data>
@@ -44,6 +104,36 @@
44104
<data key="scope">websites</data>
45105
<data key="scope_code">base</data>
46106
</entity>
107+
<entity name="SetDefaultCurrencyYENConfig">
108+
<data key="path">currency/options/default</data>
109+
<data key="value">JPY</data>
110+
<data key="scope">websites</data>
111+
<data key="scope_code">base</data>
112+
</entity>
113+
<entity name="SetDefaultCurrencyCADConfig">
114+
<data key="path">currency/options/default</data>
115+
<data key="value">CAD</data>
116+
<data key="scope">websites</data>
117+
<data key="scope_code">base</data>
118+
</entity>
119+
<entity name="SetDefaultCurrencyAUDConfig">
120+
<data key="path">currency/options/default</data>
121+
<data key="value">AUD</data>
122+
<data key="scope">websites</data>
123+
<data key="scope_code">base</data>
124+
</entity>
125+
<entity name="SetDefaultCurrencyHKDConfig">
126+
<data key="path">currency/options/default</data>
127+
<data key="value">HKD</data>
128+
<data key="scope">websites</data>
129+
<data key="scope_code">base</data>
130+
</entity>
131+
<entity name="SetDefaultCurrencyNZDConfig">
132+
<data key="path">currency/options/default</data>
133+
<data key="value">NZD</data>
134+
<data key="scope">websites</data>
135+
<data key="scope_code">base</data>
136+
</entity>
47137
<entity name="SetDefaultCurrencyUSDConfig">
48138
<data key="path">currency/options/default</data>
49139
<data key="value">USD</data>

app/code/Magento/Paypal/Controller/Express/GetTokenData.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ public function execute(): ResultInterface
152152
$responseContent['error_message'] = __('Sorry, but something went wrong');
153153
}
154154

155+
if (!$responseContent['success']) {
156+
$this->messageManager->addErrorMessage($responseContent['error_message']);
157+
}
158+
155159
return $controllerResult->setData($responseContent);
156160
}
157161

app/code/Magento/Paypal/Controller/Express/OnAuthorization.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\Controller\ResultFactory;
1111
use Magento\Framework\App\Action\HttpPostActionInterface;
1212
use Magento\Framework\Controller\ResultInterface;
13+
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Paypal\Model\Config as PayPalConfig;
1415
use Magento\Paypal\Model\Express\Checkout as PayPalCheckout;
1516
use Magento\Paypal\Model\Api\ProcessableException as ApiProcessableException;
@@ -160,14 +161,18 @@ public function execute(): ResultInterface
160161
} catch (ApiProcessableException $e) {
161162
$responseContent['success'] = false;
162163
$responseContent['error_message'] = $e->getUserMessage();
163-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
164+
} catch (LocalizedException $e) {
164165
$responseContent['success'] = false;
165166
$responseContent['error_message'] = $e->getMessage();
166167
} catch (\Exception $e) {
167168
$responseContent['success'] = false;
168169
$responseContent['error_message'] = __('We can\'t process Express Checkout approval.');
169170
}
170171

172+
if (!$responseContent['success']) {
173+
$this->messageManager->addErrorMessage($responseContent['error_message']);
174+
}
175+
171176
return $controllerResult->setData($responseContent);
172177
}
173178
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,10 @@ protected function _mapExpressFieldset($fieldName)
15121512
case 'allow_ba_signup':
15131513
case 'in_context':
15141514
case 'merchant_id':
1515+
case 'client_id':
1516+
case 'sandbox_client_id':
15151517
case 'supported_locales':
1518+
case 'smart_buttons_supported_locales':
15161519
return "payment/{$this->_methodCode}/{$fieldName}";
15171520
default:
15181521
return $this->_mapMethodFieldset($fieldName);

app/code/Magento/Paypal/Model/Express/LocaleResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public function setLocale($locale = null)
8989
public function getLocale(): string
9090
{
9191
$locale = $this->localeMap[$this->resolver->getLocale()] ?? $this->resolver->getLocale();
92-
$allowedLocales = $this->config->getValue('supported_locales');
92+
$allowedLocales =(bool)(int) $this->config->getValue('in_context')
93+
? $this->config->getValue('smart_buttons_supported_locales')
94+
: $this->config->getValue('supported_locales');
9395

9496
return strpos($allowedLocales, $locale) !== false ? $locale : 'en_US';
9597
}

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

Lines changed: 84 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Framework\Locale\ResolverInterface;
1313
use Magento\Store\Model\ScopeInterface;
14+
use Magento\Paypal\Model\Config as PayPalConfig;
1415

1516
/**
16-
* Smart button configuration.
17+
* Provides configuration values for PayPal in-context checkout
1718
*/
1819
class SmartButtonConfig
1920
{
@@ -33,35 +34,50 @@ class SmartButtonConfig
3334
private $defaultStyles;
3435

3536
/**
37+
* @var ScopeConfigInterface
38+
*/
39+
private $scopeConfig;
40+
41+
/**
42+
* Maps the old checkout SDK configuration values to the current ones
3643
* @var array
3744
*/
38-
private $allowedFunding;
45+
private $disallowedFundingMap;
3946

4047
/**
41-
* @var ScopeConfigInterface
48+
* These payment methods will be added as parameters to the SDK url to disable them.
49+
* @var array
4250
*/
43-
private $scopeConfig;
51+
private $unsupportedPaymentMethods;
52+
53+
/**
54+
* Base url for Paypal SDK
55+
*/
56+
private const BASE_URL = 'https://www.paypal.com/sdk/js?';
4457

4558
/**
4659
* @param ResolverInterface $localeResolver
4760
* @param ConfigFactory $configFactory
4861
* @param ScopeConfigInterface $scopeConfig
4962
* @param array $defaultStyles
50-
* @param array $allowedFunding
63+
* @param array $disallowedFundingMap
64+
* @param array $unsupportedPaymentMethods
5165
*/
5266
public function __construct(
5367
ResolverInterface $localeResolver,
5468
ConfigFactory $configFactory,
5569
ScopeConfigInterface $scopeConfig,
5670
$defaultStyles = [],
57-
$allowedFunding = []
71+
$disallowedFundingMap = [],
72+
$unsupportedPaymentMethods = []
5873
) {
5974
$this->localeResolver = $localeResolver;
6075
$this->config = $configFactory->create();
6176
$this->config->setMethod(Config::METHOD_EXPRESS);
6277
$this->scopeConfig = $scopeConfig;
6378
$this->defaultStyles = $defaultStyles;
64-
$this->allowedFunding = $allowedFunding;
79+
$this->disallowedFundingMap = $disallowedFundingMap;
80+
$this->unsupportedPaymentMethods = $unsupportedPaymentMethods;
6581
}
6682

6783
/**
@@ -76,20 +92,63 @@ public function getConfig(string $page): array
7692
Data::XML_PATH_GUEST_CHECKOUT,
7793
ScopeInterface::SCOPE_STORE
7894
);
95+
7996
return [
80-
'merchantId' => $this->config->getValue('merchant_id'),
81-
'environment' => ((int)$this->config->getValue('sandbox_flag') ? 'sandbox' : 'production'),
82-
'locale' => $this->localeResolver->getLocale(),
83-
'allowedFunding' => $this->getAllowedFunding($page),
84-
'disallowedFunding' => $this->getDisallowedFunding(),
8597
'styles' => $this->getButtonStyles($page),
8698
'isVisibleOnProductPage' => (bool)$this->config->getValue('visible_on_product'),
87-
'isGuestCheckoutAllowed' => $isGuestCheckoutAllowed
99+
'isGuestCheckoutAllowed' => $isGuestCheckoutAllowed,
100+
'sdkUrl' => $this->generatePaypalSdkUrl($page)
88101
];
89102
}
90103

91104
/**
92-
* Returns disallowed funding from configuration
105+
* Generate the url to download the Paypal SDK
106+
*
107+
* @param string $page
108+
*
109+
* @return string
110+
*/
111+
private function generatePaypalSdkUrl(string $page): string
112+
{
113+
$clientId = (int)$this->config->getValue('sandbox_flag') ?
114+
$this->config->getValue('sandbox_client_id') : $this->config->getValue('client_id');
115+
$disallowedFunding = implode(',', $this->getDisallowedFunding());
116+
117+
$commit = $page === 'checkout' ? 'true' : 'false';
118+
119+
$params =
120+
[
121+
'client-id' => $clientId,
122+
'commit' => $commit,
123+
'merchant-id' => $this->config->getValue('merchant_id'),
124+
'locale' => $this->localeResolver->getLocale(),
125+
'intent' => $this->getIntent(),
126+
];
127+
if ($disallowedFunding) {
128+
$params['disable-funding'] = $disallowedFunding;
129+
}
130+
131+
return self::BASE_URL . http_build_query($params);
132+
}
133+
134+
/**
135+
* Return intent value from the configuration payment_action value
136+
*
137+
* @return string
138+
*/
139+
private function getIntent(): string
140+
{
141+
$paymentAction = $this->config->getValue('paymentAction');
142+
$mappedIntentValues = [
143+
Config::PAYMENT_ACTION_AUTH => 'authorize',
144+
Config::PAYMENT_ACTION_SALE => 'capture',
145+
Config::PAYMENT_ACTION_ORDER => 'order'
146+
];
147+
return $mappedIntentValues[$paymentAction];
148+
}
149+
150+
/**
151+
* Returns disallowed funding from configuration after updating values
93152
*
94153
* @return array
95154
*/
@@ -103,18 +162,17 @@ private function getDisallowedFunding(): array
103162
array_push($result, 'CARD');
104163
}
105164

106-
return $result;
107-
}
165+
// Map old configuration values to current ones
166+
$result = array_map(function ($oldValue) {
167+
return $this->disallowedFundingMap[$oldValue] ?? $oldValue;
168+
},
169+
$result);
108170

109-
/**
110-
* Returns allowed funding
111-
*
112-
* @param string $page
113-
* @return array
114-
*/
115-
private function getAllowedFunding(string $page): array
116-
{
117-
return array_values(array_diff($this->allowedFunding[$page], $this->getDisallowedFunding()));
171+
//disable unsupported payment methods
172+
$result = array_combine($result, $result);
173+
$result = array_merge($result, $this->unsupportedPaymentMethods);
174+
175+
return $result;
118176
}
119177

120178
/**
@@ -165,7 +223,7 @@ private function updateStyles(array $styles, string $page): array
165223
// Installment label is only available for specific locales
166224
if ($styles['label'] === 'installment') {
167225
if (array_key_exists($locale, $installmentPeriodLocale)) {
168-
$styles['installmentperiod'] = (int)$this->config->getValue(
226+
$styles['period'] = (int)$this->config->getValue(
169227
$page .'_page_button_' . $installmentPeriodLocale[$locale] . '_installment_period'
170228
);
171229
} else {

app/code/Magento/Paypal/Model/System/Config/Source/ButtonStyles.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@ public function getShape(): array
5353
];
5454
}
5555

56-
/**
57-
* Button size source getter
58-
*
59-
* @return array
60-
*/
61-
public function getSize(): array
62-
{
63-
return [
64-
'medium' => __('Medium'),
65-
'large' => __('Large'),
66-
'responsive' => __('Responsive')
67-
];
68-
}
69-
7056
/**
7157
* Button label source getter
7258
*
@@ -80,7 +66,6 @@ public function getLabel(): array
8066
'buynow' => __('Buy Now'),
8167
'paypal' => __('PayPal'),
8268
'installment' => __('Installment'),
83-
'credit' => __('Credit')
8469
];
8570
}
8671

0 commit comments

Comments
 (0)