Skip to content

Commit 04e9260

Browse files
committed
AC-1228::Add BN Code for PayLater Paypal SDK
1 parent 49e721d commit 04e9260

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
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/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)