Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 22a2e2c

Browse files
authored
Merge pull request #3170 from magento-borg/BugFixPR
[2.3.0-regression] Bug fixes
2 parents 0c9d6d1 + ad2d79d commit 22a2e2c

File tree

5 files changed

+185
-55
lines changed

5 files changed

+185
-55
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+
(int)$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: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* Wrapper that performs Paypal Express and Checkout communication
20-
* Use current Paypal Express method instance
20+
*
2121
* @SuppressWarnings(PHPMD.TooManyFields)
2222
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2323
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -26,6 +26,7 @@ class Checkout
2626
{
2727
/**
2828
* Cache ID prefix for "pal" lookup
29+
*
2930
* @var string
3031
*/
3132
const PAL_CACHE_ID = 'paypal_express_checkout_pal';
@@ -367,6 +368,7 @@ public function __construct(
367368

368369
/**
369370
* Checkout with PayPal image URL getter
371+
*
370372
* Spares API calls of getting "pal" variable, by putting it into cache per store view
371373
*
372374
* @return string
@@ -599,8 +601,8 @@ public function canSkipOrderReviewStep()
599601

600602
/**
601603
* Update quote when returned from PayPal
602-
* rewrite billing address by paypal
603-
* save old billing address for new customer
604+
*
605+
* Rewrite billing address by paypal, save old billing address for new customer, and
604606
* export shipping address in case address absence
605607
*
606608
* @param string $token
@@ -616,14 +618,15 @@ public function returnFromPaypal($token)
616618

617619
$this->ignoreAddressValidation();
618620

621+
// check if we came from the Express Checkout button
622+
$isButton = (bool)$quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON);
623+
619624
// import shipping address
620625
$exportedShippingAddress = $this->_getApi()->getExportedShippingAddress();
621626
if (!$quote->getIsVirtual()) {
622627
$shippingAddress = $quote->getShippingAddress();
623628
if ($shippingAddress) {
624-
if ($exportedShippingAddress
625-
&& $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1
626-
) {
629+
if ($exportedShippingAddress && $isButton) {
627630
$this->_setExportedAddressData($shippingAddress, $exportedShippingAddress);
628631
// PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix
629632
$shippingAddress->setPrefix(null);
@@ -651,24 +654,29 @@ public function returnFromPaypal($token)
651654
}
652655

653656
// import billing address
654-
$portBillingFromShipping = $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1
655-
&& $this->_config->getValue(
656-
'requireBillingAddress'
657-
) != \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL
658-
&& !$quote->isVirtual();
659-
if ($portBillingFromShipping) {
657+
$requireBillingAddress = (int)$this->_config->getValue(
658+
'requireBillingAddress'
659+
) === \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL;
660+
661+
if ($isButton && !$requireBillingAddress && !$quote->isVirtual()) {
660662
$billingAddress = clone $shippingAddress;
661663
$billingAddress->unsAddressId()->unsAddressType()->setCustomerAddressId(null);
662664
$data = $billingAddress->getData();
663665
$data['save_in_address_book'] = 0;
664666
$quote->getBillingAddress()->addData($data);
665667
$quote->getShippingAddress()->setSameAsBilling(1);
666668
} else {
667-
$billingAddress = $quote->getBillingAddress();
669+
$billingAddress = $quote->getBillingAddress()->setCustomerAddressId(null);
668670
}
669671
$exportedBillingAddress = $this->_getApi()->getExportedBillingAddress();
670672

671-
$this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
673+
// Since country is required field for billing and shipping address,
674+
// we consider the address information to be empty if country is empty.
675+
$isEmptyAddress = ($billingAddress->getCountryId() === null);
676+
677+
if ($requireBillingAddress || $isEmptyAddress) {
678+
$this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
679+
}
672680
$billingAddress->setCustomerNote($exportedBillingAddress->getData('note'));
673681
$quote->setBillingAddress($billingAddress);
674682
$quote->setCheckoutMethod($this->getCheckoutMethod());
@@ -904,17 +912,6 @@ public function getCheckoutMethod()
904912
*/
905913
protected function _setExportedAddressData($address, $exportedAddress)
906914
{
907-
// Exported data is more priority if we came from Express Checkout button
908-
$isButton = (bool)$this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON);
909-
910-
// Since country is required field for billing and shipping address,
911-
// we consider the address information to be empty if country is empty.
912-
$isEmptyAddress = ($address->getCountryId() === null);
913-
914-
if (!$isButton && !$isEmptyAddress) {
915-
return;
916-
}
917-
918915
foreach ($exportedAddress->getExportedKeys() as $key) {
919916
$data = $exportedAddress->getData($key);
920917
if (!empty($data)) {
@@ -951,6 +948,8 @@ protected function _setBillingAgreementRequest()
951948
}
952949

953950
/**
951+
* Get api
952+
*
954953
* @return \Magento\Paypal\Model\Api\Nvp
955954
*/
956955
protected function _getApi()
@@ -963,8 +962,9 @@ protected function _getApi()
963962

964963
/**
965964
* Attempt to collect address shipping rates and return them for further usage in instant update API
966-
* Returns empty array if it was impossible to obtain any shipping rate
967-
* If there are shipping rates obtained, the method must return one of them as default.
965+
*
966+
* Returns empty array if it was impossible to obtain any shipping rate and
967+
* if there are shipping rates obtained, the method must return one of them as default.
968968
*
969969
* @param Address $address
970970
* @param bool $mayReturnEmpty
@@ -1048,8 +1048,8 @@ protected function _prepareShippingOptions(Address $address, $mayReturnEmpty = f
10481048
* Compare two shipping options based on their amounts
10491049
*
10501050
* This function is used as a callback comparison function in shipping options sorting process
1051-
* @see self::_prepareShippingOptions()
10521051
*
1052+
* @see self::_prepareShippingOptions()
10531053
* @param \Magento\Framework\DataObject $option1
10541054
* @param \Magento\Framework\DataObject $option2
10551055
* @return int
@@ -1064,6 +1064,7 @@ protected static function cmpShippingOptions(DataObject $option1, DataObject $op
10641064

10651065
/**
10661066
* Try to find whether the code provided by PayPal corresponds to any of possible shipping rates
1067+
*
10671068
* This method was created only because PayPal has issues with returning the selected code.
10681069
* If in future the issue is fixed, we don't need to attempt to match it. It would be enough to set the method code
10691070
* before collecting shipping rates
@@ -1089,6 +1090,7 @@ protected function _matchShippingMethodCode(Address $address, $selectedCode)
10891090

10901091
/**
10911092
* Create payment redirect url
1093+
*
10921094
* @param bool|null $button
10931095
* @param string $token
10941096
* @return void
@@ -1112,6 +1114,7 @@ public function getCustomerSession()
11121114

11131115
/**
11141116
* Set shipping options to api
1117+
*
11151118
* @param \Magento\Paypal\Model\Cart $cart
11161119
* @param \Magento\Quote\Model\Quote\Address|null $address
11171120
* @return void

0 commit comments

Comments
 (0)