Skip to content

Commit 12ba7c6

Browse files
committed
Merge branch 'MC-41654' into MC-41701
2 parents 0e2d1e1 + f1ff5de commit 12ba7c6

File tree

10 files changed

+626
-104
lines changed

10 files changed

+626
-104
lines changed

app/code/Magento/Paypal/Block/PayLater/Banner.php

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ class Banner extends Template
2121
* @var PayLaterConfig
2222
*/
2323
private $payLaterConfig;
24-
private $position;
25-
private $placement;
26-
private $sdkUrl;
24+
25+
/**
26+
* @var string
27+
*/
28+
private $placement = '';
29+
30+
/**
31+
* @var string
32+
*/
33+
private $position = '';
2734

2835
/**
2936
* @param Template\Context $context
3037
* @param PayLaterConfig $payLaterConfig
31-
* @param SdkUrl $sdkUrl
3238
* @param array $data
3339
*/
3440
public function __construct(
@@ -38,18 +44,18 @@ public function __construct(
3844
array $data = []
3945
) {
4046
parent::__construct($context, $data);
41-
$this->placement = $data['placement'] ?? '';
42-
$this->position = $data['position'] ?? '';
4347
$this->payLaterConfig = $payLaterConfig;
4448
$this->sdkUrl = $sdkUrl;
49+
$this->placement = $data['placement'] ?? '';
50+
$this->position = $data['position'] ?? '';
4551
}
4652

4753
/**
4854
* Disable block output
4955
*
5056
* @return string
5157
*/
52-
protected function _toHtml()
58+
protected function _toHtml(): string
5359
{
5460
if (!$this->isEnabled()) {
5561
return '';
@@ -62,10 +68,30 @@ protected function _toHtml()
6268
*/
6369
public function getJsLayout()
6470
{
65-
$this->jsLayout['components']['payLater']['config']['sdkUrl'] = $this->getPayPalSdkUrl();
71+
$jsLayout = [
72+
'components' => [
73+
'payLater' => [
74+
'component' =>
75+
$this->jsLayout['components']['payLater']['component'] ?? 'Magento_Paypal/js/view/paylater',
76+
'config' => [
77+
'sdkUrl' => $this->getPayPalSdkUrl(),
78+
]
79+
]
80+
]
81+
];
82+
83+
//Merge config
84+
$config = $this->jsLayout['components']['payLater']['config'] ?? [];
85+
$config = array_replace($jsLayout['components']['payLater']['config'], $config);
86+
87+
//Merge attributes
6688
$attributes = $this->jsLayout['components']['payLater']['config']['attributes'] ?? [];
67-
$attributes = array_replace($this->getStyleAttributesConfig(), $attributes);
68-
$this->jsLayout['components']['payLater']['config']['attributes'] = $attributes;
89+
$config['attributes'] = array_replace($this->getStyleAttributesConfig(), $attributes);
90+
$config['attributes']['data-pp-placement'] = $this->placement;
91+
$jsLayout['components']['payLater']['config'] = $config;
92+
93+
$this->jsLayout = $jsLayout;
94+
6995
return parent::getJsLayout();
7096
}
7197

@@ -74,30 +100,27 @@ public function getJsLayout()
74100
*
75101
* @return string
76102
*/
77-
private function getPayPalSdkUrl()
103+
private function getPayPalSdkUrl(): string
78104
{
79105
return $this->sdkUrl->getUrl();
80106
}
81107

82108
/**
83109
* Retrieve style configuration
84110
*
85-
* @return string[]
111+
* @return array
86112
*/
87-
private function getStyleAttributesConfig()
113+
private function getStyleAttributesConfig(): array
88114
{
89-
return array_replace(
90-
['data-pp-style-logo-position' => 'center'],
91-
$this->payLaterConfig->getStyleConfig($this->placement)
92-
);
115+
return $this->payLaterConfig->getStyleConfig($this->placement);
93116
}
94117

95118
/**
96119
* Check if block should be displayed
97120
*
98121
* @return bool
99122
*/
100-
private function isEnabled()
123+
private function isEnabled(): bool
101124
{
102125
$enabled = $this->payLaterConfig->isEnabled($this->placement);
103126
return $enabled && $this->payLaterConfig->getPositionConfig($this->placement) == $this->position;

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,33 @@ public function isMethodActive($method)
292292
break;
293293
case Config::METHOD_WPS_BML:
294294
case Config::METHOD_WPP_BML:
295-
$disabledFunding = $this->_scopeConfig->getValue(
296-
'paypal/style/disable_funding_options',
297-
ScopeInterface::SCOPE_STORE,
298-
$this->_storeId
299-
);
300-
$isExpressCreditEnabled = $disabledFunding
301-
? strpos($disabledFunding, 'CREDIT') === false
302-
: true;
303-
$isEnabled = $isExpressCreditEnabled
304-
|| $this->_scopeConfig->isSetFlag(
305-
'payment/' . Config::METHOD_WPP_BML .'/active',
295+
$isWpsEnabled = $this->_scopeConfig->isSetFlag(
296+
'payment/' . Config::METHOD_WPS_EXPRESS .'/active',
306297
ScopeInterface::SCOPE_STORE,
307298
$this->_storeId
308299
);
300+
if ($isWpsEnabled) {
301+
$isEnabled = $this->_scopeConfig->isSetFlag(
302+
'payment/' . Config::METHOD_WPS_BML .'/active',
303+
ScopeInterface::SCOPE_STORE,
304+
$this->_storeId
305+
);
306+
} else {
307+
$disabledFunding = $this->_scopeConfig->getValue(
308+
'paypal/style/disable_funding_options',
309+
ScopeInterface::SCOPE_STORE,
310+
$this->_storeId
311+
);
312+
$isExpressCreditEnabled = $disabledFunding
313+
? strpos($disabledFunding, 'CREDIT') === false
314+
: true;
315+
$isEnabled = $isExpressCreditEnabled
316+
|| $this->_scopeConfig->isSetFlag(
317+
'payment/' . Config::METHOD_WPP_BML .'/active',
318+
ScopeInterface::SCOPE_STORE,
319+
$this->_storeId
320+
);
321+
}
309322
$method = Config::METHOD_WPP_BML;
310323
break;
311324
case Config::METHOD_PAYMENT_PRO:

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ class Config extends AbstractConfig
174174
*/
175175
const XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG = 'payment/paypal_express/skip_order_review_step';
176176

177+
/**
178+
* PayPal PayLater
179+
*/
180+
const PAYLATER = 'paypal_paylater';
181+
177182
/**
178183
* Instructions for generating proper BN code
179184
*
@@ -1828,4 +1833,19 @@ public function getBmlSize($section)
18281833
$this->_storeId
18291834
);
18301835
}
1836+
1837+
/**
1838+
* Get PayLater config values
1839+
*
1840+
* @param string $fieldName
1841+
* @return mixed
1842+
*/
1843+
public function getPayLaterConfigValue($fieldName)
1844+
{
1845+
return $this->_scopeConfig->getValue(
1846+
'payment/' . self::PAYLATER . '/' . $fieldName,
1847+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1848+
$this->_storeId
1849+
);
1850+
}
18311851
}

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

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,44 @@
77

88
namespace Magento\Paypal\Model;
99

10-
use Magento\Checkout\Helper\Data;
1110
use Magento\Framework\App\Config\ScopeConfigInterface;
12-
use Magento\Framework\Locale\ResolverInterface;
13-
use Magento\Store\Model\ScopeInterface;
14-
use Magento\Store\Model\StoreManagerInterface;
1511

1612
/**
1713
* Provides configuration values for PayPal PayLater Banners
1814
*/
1915
class PayLaterConfig
2016
{
21-
const PLACEMENT_PRODUCT = 'product';
17+
/**
18+
* @var Config
19+
*/
20+
private $config;
2221

2322
/**
2423
* @var ScopeConfigInterface
2524
*/
26-
private ScopeConfigInterface $scopeConfig;
25+
private $scopeConfig;
26+
27+
/**
28+
* @var array
29+
*/
30+
private $configData = [];
2731

2832
/**
2933
* @param ScopeConfigInterface $scopeConfig
34+
* @param Config $config
3035
*/
3136
public function __construct(
32-
ScopeConfigInterface $scopeConfig
37+
ScopeConfigInterface $scopeConfig,
38+
Config $config
3339
) {
3440
$this->scopeConfig = $scopeConfig;
41+
$this->config = $config;
3542
}
3643

3744
/**
3845
* Get configured styles for specified page
3946
*
47+
* @param string $placement
4048
* @return array
4149
*/
4250
public function getStyleConfig(string $placement): array
@@ -48,9 +56,9 @@ public function getStyleConfig(string $placement): array
4856
* Get configured Banner position on specified page
4957
*
5058
* @param string $placement
51-
* @return mixed|string
59+
* @return string
5260
*/
53-
public function getPositionConfig(string $placement)
61+
public function getPositionConfig(string $placement): string
5462
{
5563
return $this->getSectionConfig($placement, 'position') ?? '';
5664
}
@@ -61,23 +69,67 @@ public function getPositionConfig(string $placement)
6169
* @param string $placement
6270
* @return bool
6371
*/
64-
public function isEnabled(string $placement)
72+
public function isEnabled(string $placement): bool
73+
{
74+
$enabled = false;
75+
if ($this->isPPCreditEnabled()) {
76+
$isPayLaterEnabled = (boolean)$this->config->getPayLaterConfigValue('enabled');
77+
$enabled = $isPayLaterEnabled && $this->getSectionConfig($placement, 'display');
78+
}
79+
return $enabled;
80+
}
81+
82+
/**
83+
* Check that PayPal Credit enabled with any PayPal express method
84+
*
85+
* @return
86+
*/
87+
private function isPPCreditEnabled()
6588
{
66-
$isPayLaterEnabled = true; //read from config
67-
return $isPayLaterEnabled && $this->getSectionConfig($placement, 'display');
89+
return $this->config->isMethodAvailable(Config::METHOD_WPP_BML)
90+
|| $this->config->isMethodAvailable(Config::METHOD_WPS_BML)
91+
|| $this->config->isMethodAvailable(Config::METHOD_WPP_PE_BML);
6892
}
6993

94+
/**
95+
* Get config for a specific section and key
96+
*
97+
* @param string $section
98+
* @param string $key
99+
* @return mixed
100+
*/
70101
private function getSectionConfig($section, $key)
71102
{
72-
$configMock = [
73-
self::PLACEMENT_PRODUCT => [
74-
'display' => 1,
75-
'position' => 'header', // 'sidebar'
103+
if (!array_key_exists($section, $this->configData)) {
104+
$this->configData[$section] = [
105+
'display' => (boolean)$this->config->getPayLaterConfigValue("${section}page_display"),
106+
'position' => $this->config->getPayLaterConfigValue("${section}page_position"),
76107
'style' => [
77-
'data-pp-style-logo-position' => 'right'
108+
'data-pp-style-layout' => $this->config->getPayLaterConfigValue(
109+
"${section}page_stylelayout"
110+
),
111+
'data-pp-style-logo-type' => $this->config->getPayLaterConfigValue(
112+
"${section}page_logotype"
113+
),
114+
'data-pp-style-logo-position' => $this->config->getPayLaterConfigValue(
115+
"${section}page_logoposition"
116+
),
117+
'data-pp-style-text-color' => $this->config->getPayLaterConfigValue(
118+
"${section}page_textcolor"
119+
),
120+
'data-pp-style-text-size' => $this->config->getPayLaterConfigValue(
121+
"${section}page_textsize"
122+
),
123+
'data-pp-style-color' => $this->config->getPayLaterConfigValue(
124+
"${section}page_color"
125+
),
126+
'data-pp-style-ratio' => $this->config->getPayLaterConfigValue(
127+
"${section}page_ratio"
128+
)
78129
]
79-
],
80-
];
81-
return $configMock[$section][$key] ?? [];
130+
];
131+
}
132+
133+
return $this->configData[$section][$key];
82134
}
83135
}

app/code/Magento/Paypal/Model/System/Config/Source/PayLater/Position.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function getPositionsCPP(): array
2121
{
2222
return [
2323
'header' => __('Header (center)'),
24-
'sidebar' => __('Near PayPal Credit checkout button')
24+
'near_pp_button' => __('Near PayPal Credit checkout button')
2525
];
2626
}
2727
}

0 commit comments

Comments
 (0)