Skip to content

Commit f72dffc

Browse files
MAGETWO-94402: [2.3.0] PayPal Billing Address for Registered Customers
- make sure the require billing address setting is set before getting billing address from PayPal
1 parent ed8b676 commit f72dffc

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

app/code/Magento/Braintree/Model/Ui/PayPal/ConfigProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public function __construct(Config $config, ResolverInterface $resolver)
4747
*/
4848
public function getConfig()
4949
{
50+
$requireBillingAddressAll = \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL;
51+
5052
return [
5153
'payment' => [
5254
self::PAYPAL_CODE => [
@@ -60,6 +62,8 @@ public function getConfig()
6062
'vaultCode' => self::PAYPAL_VAULT_CODE,
6163
'skipOrderReview' => $this->config->isSkipOrderReview(),
6264
'paymentIcon' => $this->config->getPayPalIcon(),
65+
'isRequiredBillingAddress' =>
66+
$this->config->isRequiredBillingAddress() == $requireBillingAddressAll
6367
]
6468
]
6569
];

app/code/Magento/Braintree/Test/Unit/Model/Ui/PayPal/ConfigProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public function testGetConfig($expected)
7777
'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url'
7878
]);
7979

80+
$this->config->method('isRequiredBillingAddress')
81+
->willReturn(1);
82+
8083
self::assertEquals($expected, $this->configProvider->getConfig());
8184
}
8285

@@ -101,7 +104,8 @@ public function getConfigDataProvider()
101104
'skipOrderReview' => false,
102105
'paymentIcon' => [
103106
'width' => 30, 'height' => 26, 'url' => 'https://icon.test.url'
104-
]
107+
],
108+
'isRequiredBillingAddress' => true
105109
]
106110
]
107111
]

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ define([
206206
beforePlaceOrder: function (data) {
207207
this.setPaymentMethodNonce(data.nonce);
208208

209-
if (quote.billingAddress() === null && typeof data.details.billingAddress !== 'undefined') {
209+
if ((this.isRequiredBillingAddress() || quote.billingAddress() === null)
210+
&& typeof data.details.billingAddress !== 'undefined'
211+
) {
210212
this.setBillingAddress(data.details, data.details.billingAddress);
211213
}
212214

@@ -264,6 +266,14 @@ define([
264266
return window.checkoutConfig.payment[this.getCode()].isAllowShippingAddressOverride;
265267
},
266268

269+
/**
270+
* Is billing address required from PayPal side
271+
* @returns {Boolean}
272+
*/
273+
isRequiredBillingAddress: function () {
274+
return window.checkoutConfig.payment[this.getCode()].isRequiredBillingAddress;
275+
},
276+
267277
/**
268278
* Get configuration for PayPal
269279
* @returns {Object}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,14 +904,16 @@ public function getCheckoutMethod()
904904
*/
905905
protected function _setExportedAddressData($address, $exportedAddress)
906906
{
907-
// Exported data is more priority if we came from Express Checkout button
908-
$isButton = (bool)$this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON);
907+
// Exported data is more priority if require billing address setting is yes
908+
$requireBillingAddress = $this->_config->getValue(
909+
'requireBillingAddress'
910+
) == \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL;
909911

910912
// Since country is required field for billing and shipping address,
911913
// we consider the address information to be empty if country is empty.
912914
$isEmptyAddress = ($address->getCountryId() === null);
913915

914-
if (!$isButton && !$isEmptyAddress) {
916+
if (!$requireBillingAddress && !$isEmptyAddress) {
915917
return;
916918
}
917919

0 commit comments

Comments
 (0)