Skip to content

Commit efa6c6f

Browse files
authored
Merge pull request #7210 from magento-gl/gl_pr_paypal_nov11_2021
GL PR for Paypal raised on Nov11, 2021
2 parents 40ceb70 + 81d4361 commit efa6c6f

22 files changed

+387
-80
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\View\Element\Template;
1212
use Magento\Paypal\Model\PayLaterConfig;
1313
use Magento\Paypal\Model\SdkUrl;
14+
use Magento\Paypal\Model\Config as PaypalConfig;
15+
use Magento\Framework\App\ObjectManager;
1416

1517
/**
1618
* PayPal PayLater component block
@@ -38,23 +40,32 @@ class Banner extends Template
3840
*/
3941
private $position = '';
4042

43+
/**
44+
* @var PaypalConfig
45+
*/
46+
private $paypalConfig;
47+
4148
/**
4249
* @param Template\Context $context
4350
* @param PayLaterConfig $payLaterConfig
4451
* @param SdkUrl $sdkUrl
4552
* @param array $data
53+
* @param PaypalConfig $paypalConfig
4654
*/
4755
public function __construct(
4856
Template\Context $context,
4957
PayLaterConfig $payLaterConfig,
5058
SdkUrl $sdkUrl,
51-
array $data = []
59+
array $data = [],
60+
PaypalConfig $paypalConfig = null
5261
) {
5362
parent::__construct($context, $data);
5463
$this->payLaterConfig = $payLaterConfig;
5564
$this->sdkUrl = $sdkUrl;
5665
$this->placement = $data['placement'] ?? '';
5766
$this->position = $data['position'] ?? '';
67+
$this->paypalConfig = $paypalConfig ?: ObjectManager::getInstance()
68+
->get(PaypalConfig::class);
5869
}
5970

6071
/**
@@ -85,6 +96,9 @@ public function getJsLayout()
8596
$displayAmount = $config['displayAmount'] ?? false;
8697
$config['displayAmount'] = !$displayAmount || $this->payLaterConfig->isPPBillingAgreementEnabled()
8798
? false : true;
99+
$config['dataAttributes'] = [
100+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
101+
];
88102

89103
//Extend block component attributes with defaults
90104
$componentAttributes = $this->jsLayout['components']['payLater']['config']['attributes'] ?? [];

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
namespace Magento\Paypal\Block\PayLater;
1010

1111
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
12+
use Magento\Framework\App\ObjectManager;
1213
use Magento\Paypal\Model\PayLaterConfig;
1314
use Magento\Paypal\Model\SdkUrl;
15+
use Magento\Paypal\Model\Config as PaypalConfig;
1416

1517
/**
1618
* PayLater Layout Processor
@@ -32,25 +34,35 @@ class LayoutProcessor implements LayoutProcessorInterface
3234
*/
3335
private $sdkUrl;
3436

37+
/**
38+
* @var PaypalConfig
39+
*/
40+
private $paypalConfig;
41+
3542
/**
3643
* @param PayLaterConfig $payLaterConfig
3744
* @param SdkUrl $sdkUrl
45+
* @param PaypalConfig $paypalConfig
3846
*/
39-
public function __construct(PayLaterConfig $payLaterConfig, SdkUrl $sdkUrl)
40-
{
47+
public function __construct(
48+
PayLaterConfig $payLaterConfig,
49+
SdkUrl $sdkUrl,
50+
PaypalConfig $paypalConfig
51+
) {
4152
$this->payLaterConfig = $payLaterConfig;
4253
$this->sdkUrl = $sdkUrl;
54+
$this->paypalConfig = $paypalConfig;
4355
}
4456

4557
/**
46-
* {@inheritdoc}
58+
* @inheritdoc
4759
*/
4860
public function process($jsLayout)
4961
{
5062
if (!$this->payLaterConfig->isEnabled(PayLaterConfig::CHECKOUT_PAYMENT_PLACEMENT)) {
5163
unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
52-
['children']['payment']['children']['payments-list']['children']['paypal-method-extra-content']['children']
53-
['paylater-place-order']);
64+
['children']['payment']['children']['payments-list']['children']['paypal-method-extra-content']
65+
['children']['paylater-place-order']);
5466

5567
return $jsLayout;
5668
}
@@ -75,6 +87,9 @@ public function process($jsLayout)
7587
$displayAmount = $config['displayAmount'] ?? false;
7688
$config['displayAmount'] = !$displayAmount || $this->payLaterConfig->isPPBillingAgreementEnabled()
7789
? false : true;
90+
$config['dataAttributes'] = [
91+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
92+
];
7893

7994
$attributes = $this->payLaterConfig->getSectionConfig(
8095
PayLaterConfig::CHECKOUT_PAYMENT_PLACEMENT,

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: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ class SdkUrl
4242
private $queryParams = [];
4343

4444
/**
45-
* Maps the old checkout SDK configuration values to the current ones
46-
*
4745
* @var array
4846
*/
4947
private $disallowedFundingMap;
@@ -55,14 +53,19 @@ class SdkUrl
5553
*/
5654
private $unsupportedPaymentMethods;
5755

56+
/**
57+
* These payment methods will be added as parameters to the SDK url to enable them.
58+
*
59+
* @var array
60+
*/
61+
private $supportedPaymentMethods;
62+
5863
/**
5964
* @var ResolverInterface
6065
*/
6166
private $localeResolver;
6267

6368
/**
64-
* Generated Url to PayPAl SDK
65-
*
6669
* @var string
6770
*/
6871
private $url;
@@ -74,14 +77,16 @@ class SdkUrl
7477
* @param StoreManagerInterface $storeManager
7578
* @param array $disallowedFundingMap
7679
* @param array $unsupportedPaymentMethods
80+
* @param array $supportedPaymentMethods
7781
*/
7882
public function __construct(
7983
ResolverInterface $localeResolver,
8084
ConfigFactory $configFactory,
8185
ScopeConfigInterface $scopeConfig,
8286
StoreManagerInterface $storeManager,
8387
$disallowedFundingMap = [],
84-
$unsupportedPaymentMethods = []
88+
$unsupportedPaymentMethods = [],
89+
$supportedPaymentMethods = []
8590
) {
8691
$this->localeResolver = $localeResolver;
8792
$this->config = $configFactory->create();
@@ -90,6 +95,7 @@ public function __construct(
9095
$this->storeManager = $storeManager;
9196
$this->disallowedFundingMap = $disallowedFundingMap;
9297
$this->unsupportedPaymentMethods = $unsupportedPaymentMethods;
98+
$this->supportedPaymentMethods = $supportedPaymentMethods;
9399
}
94100

95101
/**
@@ -105,6 +111,8 @@ public function getUrl(): string
105111
'client-id' => $this->getClientId(),
106112
'locale' => $this->localeResolver->getLocale(),
107113
'currency' => $this->storeManager->getStore()->getBaseCurrencyCode(),
114+
'buyer-country' => $this->getBuyerCountry(),
115+
'enable-funding' => $this->getAllowedFunding(),
108116
];
109117

110118
if ($this->areMessagesEnabled()) {
@@ -156,7 +164,7 @@ private function areMessagesEnabled()
156164
*/
157165
private function areButtonsEnabled()
158166
{
159-
return (bool)(int) $this->config->getValue('in_context');
167+
return (bool)(int)$this->config->getValue('in_context');
160168
}
161169

162170
/**
@@ -171,6 +179,16 @@ private function getClientId()
171179
$this->config->getValue('client_id');
172180
}
173181

182+
/**
183+
* Get Configured value for paypal buyer country
184+
*
185+
* @return string
186+
*/
187+
private function getBuyerCountry(): ?string
188+
{
189+
return (int)$this->config->getValue('sandbox_flag') ? $this->config->getValue('buyer_country') : '';
190+
}
191+
174192
/**
175193
* Returns disallowed funding from configuration after updating values
176194
*
@@ -198,6 +216,23 @@ private function getDisallowedFunding()
198216
return implode(',', $result);
199217
}
200218

219+
/**
220+
* Returns allowed funding from configuration after validating
221+
*
222+
* @return string
223+
*/
224+
private function getAllowedFunding(): string
225+
{
226+
$payLaterActive = (bool)$this->config->getPayLaterConfigValue('experience_active');
227+
228+
// If Pay Later is disabled, paylater parameter will be removed from enable-funding parameter list
229+
if (!$payLaterActive) {
230+
unset($this->supportedPaymentMethods['paylater']);
231+
232+
}
233+
return implode(',', $this->supportedPaymentMethods);
234+
}
235+
201236
/**
202237
* Returns if is allowed PayPal Guest Checkout.
203238
*

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Locale\ResolverInterface;
1313
use Magento\Store\Model\ScopeInterface;
1414
use Magento\Store\Model\StoreManagerInterface;
15+
use Magento\Paypal\Model\Config as PaypalConfig;
1516

1617
/**
1718
* Provides configuration values for PayPal in-context checkout
@@ -43,18 +44,25 @@ class SmartButtonConfig
4344
*/
4445
private $sdkUrl;
4546

47+
/**
48+
* @var PaypalConfig
49+
*/
50+
private $paypalConfig;
51+
4652
/**
4753
* @param ResolverInterface $localeResolver
4854
* @param ConfigFactory $configFactory
4955
* @param ScopeConfigInterface $scopeConfig
5056
* @param SdkUrl $sdkUrl
57+
* @param PaypalConfig $paypalConfig
5158
* @param array $defaultStyles
5259
*/
5360
public function __construct(
5461
ResolverInterface $localeResolver,
5562
ConfigFactory $configFactory,
5663
ScopeConfigInterface $scopeConfig,
5764
SdkUrl $sdkUrl,
65+
PaypalConfig $paypalConfig,
5866
$defaultStyles = []
5967
) {
6068
$this->localeResolver = $localeResolver;
@@ -63,6 +71,7 @@ public function __construct(
6371
$this->scopeConfig = $scopeConfig;
6472
$this->defaultStyles = $defaultStyles;
6573
$this->sdkUrl = $sdkUrl;
74+
$this->paypalConfig = $paypalConfig;
6675
}
6776

6877
/**
@@ -81,7 +90,10 @@ public function getConfig(string $page): array
8190
'styles' => $this->getButtonStyles($page),
8291
'isVisibleOnProductPage' => (bool)$this->config->getValue('visible_on_product'),
8392
'isGuestCheckoutAllowed' => $isGuestCheckoutAllowed,
84-
'sdkUrl' => $this->sdkUrl->getUrl()
93+
'sdkUrl' => $this->sdkUrl->getUrl(),
94+
'dataAttributes' => [
95+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
96+
]
8597
];
8698
}
8799

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

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

@@ -46,7 +46,7 @@ public function getPositionsHP(): array
4646
public function getPositionsCheckout(): array
4747
{
4848
return [
49-
'near_pp_button' => __('Near PayPal Credit checkout button')
49+
'near_pp_button' => __('Under PayPal Checkout buttons')
5050
];
5151
}
5252

@@ -72,7 +72,7 @@ public function getPositionsCart(): array
7272
{
7373
return [
7474
'header' => __('Header (center)'),
75-
'near_pp_button' => __('Near PayPal Credit checkout button')
75+
'near_pp_button' => __('Under PayPal Checkout buttons')
7676
];
7777
}
7878
}

0 commit comments

Comments
 (0)