Skip to content

Commit b3702e4

Browse files
committed
Merge remote-tracking branch 'origin/AC-1228' into gl_pr_paypal_nov11_2021
2 parents a09e4a2 + 04e9260 commit b3702e4

File tree

8 files changed

+82
-19
lines changed

8 files changed

+82
-19
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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;
1415

1516
/**
1617
* PayPal PayLater component block
@@ -38,23 +39,31 @@ class Banner extends Template
3839
*/
3940
private $position = '';
4041

42+
/**
43+
* @var PaypalConfig
44+
*/
45+
private $paypalConfig;
46+
4147
/**
4248
* @param Template\Context $context
4349
* @param PayLaterConfig $payLaterConfig
4450
* @param SdkUrl $sdkUrl
4551
* @param array $data
52+
* @param PaypalConfig $paypalConfig
4653
*/
4754
public function __construct(
4855
Template\Context $context,
4956
PayLaterConfig $payLaterConfig,
5057
SdkUrl $sdkUrl,
51-
array $data = []
58+
array $data = [],
59+
PaypalConfig $paypalConfig
5260
) {
5361
parent::__construct($context, $data);
5462
$this->payLaterConfig = $payLaterConfig;
5563
$this->sdkUrl = $sdkUrl;
5664
$this->placement = $data['placement'] ?? '';
5765
$this->position = $data['position'] ?? '';
66+
$this->paypalConfig = $paypalConfig;
5867
}
5968

6069
/**
@@ -85,6 +94,9 @@ public function getJsLayout()
8594
$displayAmount = $config['displayAmount'] ?? false;
8695
$config['displayAmount'] = !$displayAmount || $this->payLaterConfig->isPPBillingAgreementEnabled()
8796
? false : true;
97+
$config['dataAttributes'] = [
98+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
99+
];
88100

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

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
1212
use Magento\Paypal\Model\PayLaterConfig;
1313
use Magento\Paypal\Model\SdkUrl;
14+
use Magento\Paypal\Model\Config as PaypalConfig;
1415

1516
/**
1617
* PayLater Layout Processor
@@ -32,14 +33,24 @@ class LayoutProcessor implements LayoutProcessorInterface
3233
*/
3334
private $sdkUrl;
3435

36+
/**
37+
* @var PaypalConfig
38+
*/
39+
private $paypalConfig;
40+
3541
/**
3642
* @param PayLaterConfig $payLaterConfig
3743
* @param SdkUrl $sdkUrl
44+
* @param PaypalConfig $paypalConfig
3845
*/
39-
public function __construct(PayLaterConfig $payLaterConfig, SdkUrl $sdkUrl)
40-
{
41-
$this->payLaterConfig = $payLaterConfig;
42-
$this->sdkUrl = $sdkUrl;
46+
public function __construct(
47+
PayLaterConfig $payLaterConfig,
48+
SdkUrl $sdkUrl,
49+
PaypalConfig $paypalConfig
50+
) {
51+
$this->payLaterConfig = $payLaterConfig;
52+
$this->sdkUrl = $sdkUrl;
53+
$this->paypalConfig = $paypalConfig;
4354
}
4455

4556
/**
@@ -75,6 +86,9 @@ public function process($jsLayout)
7586
$displayAmount = $config['displayAmount'] ?? false;
7687
$config['displayAmount'] = !$displayAmount || $this->payLaterConfig->isPPBillingAgreementEnabled()
7788
? false : true;
89+
$config['dataAttributes'] = [
90+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
91+
];
7892

7993
$attributes = $this->payLaterConfig->getSectionConfig(
8094
PayLaterConfig::CHECKOUT_PAYMENT_PLACEMENT,

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/Test/Unit/Model/SmartButtonConfigTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class SmartButtonConfigTest extends TestCase
4242
*/
4343
protected function setUp(): void
4444
{
45-
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
46-
$this->configMock = $this->getMockBuilder(Config::class)
45+
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
46+
$this->configMock = $this->getMockBuilder(Config::class)
4747
->disableOriginalConstructor()
4848
->getMock();
4949

@@ -67,7 +67,8 @@ protected function setUp(): void
6767
$configFactoryMock,
6868
$scopeConfigMock,
6969
$sdkUrl,
70-
$this->getDefaultStyles(),
70+
$this->configMock,
71+
$this->getDefaultStyles()
7172
);
7273
}
7374

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
],
2828
'isVisibleOnProductPage' => false,
2929
'isGuestCheckoutAllowed' => true,
30-
'sdkUrl' => 'http://mock.url'
30+
'sdkUrl' => 'http://mock.url',
31+
'dataAttributes' => [
32+
'data-partner-attribution-id' => ''
33+
]
3134
]
3235
],
3336
'checkout' => [
@@ -51,7 +54,10 @@
5154
],
5255
'isVisibleOnProductPage' => false,
5356
'isGuestCheckoutAllowed' => true,
54-
'sdkUrl' => 'http://mock.url'
57+
'sdkUrl' => 'http://mock.url',
58+
'dataAttributes' => [
59+
'data-partner-attribution-id' => ''
60+
]
5561
]
5662
],
5763
'mini_cart' => [
@@ -74,7 +80,10 @@
7480
],
7581
'isVisibleOnProductPage' => false,
7682
'isGuestCheckoutAllowed' => true,
77-
'sdkUrl' => 'http://mock.url'
83+
'sdkUrl' => 'http://mock.url',
84+
'dataAttributes' => [
85+
'data-partner-attribution-id' => ''
86+
]
7887
]
7988
],
8089
'product' => [
@@ -97,7 +106,10 @@
97106
],
98107
'isVisibleOnProductPage' => false,
99108
'isGuestCheckoutAllowed' => true,
100-
'sdkUrl' => 'http://mock.url'
109+
'sdkUrl' => 'http://mock.url',
110+
'dataAttributes' => [
111+
'data-partner-attribution-id' => ''
112+
]
101113
]
102114
],
103115
];

app/code/Magento/Paypal/view/frontend/web/js/in-context/express-checkout-smart-buttons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ define([
6464
}
6565

6666
return function (clientConfig, element) {
67-
paypalSdk(clientConfig.sdkUrl).done(function (paypal) {
67+
paypalSdk(clientConfig.sdkUrl, clientConfig.dataAttributes).done(function (paypal) {
6868
paypal.Buttons({
6969
style: clientConfig.styles,
7070

app/code/Magento/Paypal/view/frontend/web/js/in-context/paypal-sdk.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ define([
1212
/**
1313
* Loads the PayPal SDK object
1414
* @param {String} paypalUrl - the url of the PayPal SDK
15+
* @param {Array} dataAttributes - Array of the Attributes for PayPal SDK Script tag
1516
*/
16-
return function loadPaypalScript(paypalUrl) {
17+
return function loadPaypalScript(paypalUrl, dataAttributes) {
1718
//configuration for loaded PayPal script
1819
require.config({
1920
paths: {
@@ -23,6 +24,15 @@ define([
2324
paypalSdk: {
2425
exports: 'paypal'
2526
}
27+
},
28+
29+
/**
30+
* Add attributes under Paypal SDK Script tag
31+
*/
32+
onNodeCreated: function (node) {
33+
$.each(dataAttributes, function (index, elem) {
34+
node.setAttribute(index, elem);
35+
});
2636
}
2737
});
2838

app/code/Magento/Paypal/view/frontend/web/js/view/paylater.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ define([
2727
attributes: {
2828
class: 'pay-later-message'
2929
},
30+
dataAttributes: {},
3031
refreshSelector: '',
3132
displayAmount: false,
3233
amountComponentConfig: {
@@ -51,7 +52,7 @@ define([
5152
}
5253

5354
if (this.sdkUrl !== '') {
54-
this.loadPayPalSdk(this.sdkUrl)
55+
this.loadPayPalSdk(this.sdkUrl, this.dataAttributes)
5556
.then(this._setPayPalObject.bind(this));
5657
}
5758

@@ -76,10 +77,11 @@ define([
7677
/**
7778
* Load PP SDK with preconfigured options
7879
*
79-
* @param {String} sdkUrl
80+
* @param {String} sdkUrl - the url of the PayPal SDK
81+
* @param {Array} dataAttributes - Array of the Attributes for PayPal SDK Script tag
8082
*/
81-
loadPayPalSdk: function (sdkUrl) {
82-
return paypalSdk(sdkUrl);
83+
loadPayPalSdk: function (sdkUrl, dataAttributes) {
84+
return paypalSdk(sdkUrl, dataAttributes);
8385
},
8486

8587
/**

0 commit comments

Comments
 (0)