Skip to content

Commit 22fb5e4

Browse files
MAGETWO-94402: [2.3.0] PayPal Billing Address for Registered Customers
- fix express checkout for logged in customer and code formatting
1 parent f72dffc commit 22fb5e4

File tree

2 files changed

+17
-25
lines changed
  • app/code/Magento

2 files changed

+17
-25
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ define([
206206
beforePlaceOrder: function (data) {
207207
this.setPaymentMethodNonce(data.nonce);
208208

209-
if ((this.isRequiredBillingAddress() || quote.billingAddress() === null)
210-
&& typeof data.details.billingAddress !== 'undefined'
209+
if ((this.isRequiredBillingAddress() || quote.billingAddress() === null) &&
210+
typeof data.details.billingAddress !== 'undefined'
211211
) {
212212
this.setBillingAddress(data.details, data.details.billingAddress);
213213
}

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -616,14 +616,14 @@ public function returnFromPaypal($token)
616616

617617
$this->ignoreAddressValidation();
618618

619+
$isButton = $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1;
620+
619621
// import shipping address
620622
$exportedShippingAddress = $this->_getApi()->getExportedShippingAddress();
621623
if (!$quote->getIsVirtual()) {
622624
$shippingAddress = $quote->getShippingAddress();
623625
if ($shippingAddress) {
624-
if ($exportedShippingAddress
625-
&& $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1
626-
) {
626+
if ($exportedShippingAddress && $isButton) {
627627
$this->_setExportedAddressData($shippingAddress, $exportedShippingAddress);
628628
// PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix
629629
$shippingAddress->setPrefix(null);
@@ -651,24 +651,29 @@ public function returnFromPaypal($token)
651651
}
652652

653653
// import billing address
654-
$portBillingFromShipping = $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1
655-
&& $this->_config->getValue(
654+
$requireBillingAddress = $this->_config->getValue(
656655
'requireBillingAddress'
657-
) != \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL
658-
&& !$quote->isVirtual();
659-
if ($portBillingFromShipping) {
656+
) == \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL;
657+
658+
if ($isButton && !$requireBillingAddress && !$quote->isVirtual()) {
660659
$billingAddress = clone $shippingAddress;
661660
$billingAddress->unsAddressId()->unsAddressType()->setCustomerAddressId(null);
662661
$data = $billingAddress->getData();
663662
$data['save_in_address_book'] = 0;
664663
$quote->getBillingAddress()->addData($data);
665664
$quote->getShippingAddress()->setSameAsBilling(1);
666665
} else {
667-
$billingAddress = $quote->getBillingAddress();
666+
$billingAddress = $quote->getBillingAddress()->setCustomerAddressId(null);
668667
}
669668
$exportedBillingAddress = $this->_getApi()->getExportedBillingAddress();
670669

671-
$this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
670+
// Since country is required field for billing and shipping address,
671+
// we consider the address information to be empty if country is empty.
672+
$isEmptyAddress = ($billingAddress->getCountryId() === null);
673+
674+
if ($requireBillingAddress || $isEmptyAddress) {
675+
$this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
676+
}
672677
$billingAddress->setCustomerNote($exportedBillingAddress->getData('note'));
673678
$quote->setBillingAddress($billingAddress);
674679
$quote->setCheckoutMethod($this->getCheckoutMethod());
@@ -904,19 +909,6 @@ public function getCheckoutMethod()
904909
*/
905910
protected function _setExportedAddressData($address, $exportedAddress)
906911
{
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;
911-
912-
// Since country is required field for billing and shipping address,
913-
// we consider the address information to be empty if country is empty.
914-
$isEmptyAddress = ($address->getCountryId() === null);
915-
916-
if (!$requireBillingAddress && !$isEmptyAddress) {
917-
return;
918-
}
919-
920912
foreach ($exportedAddress->getExportedKeys() as $key) {
921913
$data = $exportedAddress->getData($key);
922914
if (!empty($data)) {

0 commit comments

Comments
 (0)