Skip to content

Commit 8a73e53

Browse files
committed
MC-31196: [2.4.0] Paypal issue with region on 2.3.4
1 parent 36722d9 commit 8a73e53

File tree

2 files changed

+33
-17
lines changed
  • app/code/Magento/Paypal/Model/Api
  • dev/tests/integration/testsuite/Magento/Paypal/Model/Express

2 files changed

+33
-17
lines changed

app/code/Magento/Paypal/Model/Api/Nvp.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,13 +1512,11 @@ protected function _applyStreetAndRegionWorkarounds(DataObject $address)
15121512
}
15131513
// attempt to fetch region_id from directory
15141514
if ($address->getCountryId() && $address->getRegion()) {
1515-
$regions = $this->_countryFactory->create()->loadByCode(
1516-
$address->getCountryId()
1517-
)->getRegionCollection()->addRegionCodeOrNameFilter(
1518-
$address->getRegion()
1519-
)->setPageSize(
1520-
1
1521-
);
1515+
$regions = $this->_countryFactory->create()
1516+
->loadByCode($address->getCountryId())
1517+
->getRegionCollection()
1518+
->addRegionCodeOrNameFilter($address->getRegion())
1519+
->setPageSize(1);
15221520

15231521
if ($regions->count()) {
15241522
$regionItems = $regions->getItems();
@@ -1627,7 +1625,7 @@ protected function _filterPeriodUnit($value)
16271625
case 'year':
16281626
return 'Year';
16291627
default:
1630-
break;
1628+
return '';
16311629
}
16321630
}
16331631

@@ -1656,7 +1654,7 @@ protected function _filterBillingAgreementStatus($value)
16561654
case 'active':
16571655
return 'Active';
16581656
default:
1659-
break;
1657+
return '';
16601658
}
16611659
}
16621660

@@ -1697,7 +1695,7 @@ protected function _filterPaymentStatusFromNvpToInfo($value)
16971695
case 'Voided':
16981696
return \Magento\Paypal\Model\Info::PAYMENTSTATUS_VOIDED;
16991697
default:
1700-
break;
1698+
return null;
17011699
}
17021700
}
17031701

@@ -1715,7 +1713,7 @@ protected function _filterPaymentReviewAction($value)
17151713
case \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_DENY:
17161714
return 'Deny';
17171715
default:
1718-
break;
1716+
return null;
17191717
}
17201718
}
17211719

dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Paypal\Model\Express;
77

88
use Magento\Checkout\Model\Type\Onepage;
9+
use Magento\Directory\Model\CountryFactory;
910
use Magento\Framework\ObjectManagerInterface;
1011
use Magento\Paypal\Model\Api\Nvp;
1112
use Magento\Paypal\Model\Api\Type\Factory;
@@ -17,8 +18,6 @@
1718
use Magento\TestFramework\Helper\Bootstrap;
1819

1920
/**
20-
* Class CheckoutTest
21-
*
2221
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2322
*/
2423
class CheckoutTest extends \PHPUnit\Framework\TestCase
@@ -634,10 +633,6 @@ public function testGuestReturnFromPaypal()
634633
->setMethods(['call', 'getExportedShippingAddress', 'getExportedBillingAddress'])
635634
->getMock();
636635

637-
$api->expects($this->any())
638-
->method('call')
639-
->will($this->returnValue([]));
640-
641636
$apiTypeFactory->expects($this->any())
642637
->method('create')
643638
->will($this->returnValue($api));
@@ -652,6 +647,14 @@ public function testGuestReturnFromPaypal()
652647
->method('getExportedShippingAddress')
653648
->will($this->returnValue($exportedShippingAddress));
654649

650+
$this->addCountryFactory($api);
651+
$data = [
652+
'COUNTRYCODE' => $quote->getShippingAddress()->getCountryId(),
653+
'STATE' => 'unknown'
654+
];
655+
$api->method('call')
656+
->willReturn($data);
657+
655658
$paypalInfo->expects($this->once())
656659
->method('importToPayment')
657660
->with($api, $quote->getPayment());
@@ -710,4 +713,19 @@ private function getFixtureQuote(): Quote
710713

711714
return $quoteCollection->getLastItem();
712715
}
716+
717+
/**
718+
* Adds countryFactory to a mock.
719+
*
720+
* @param \PHPUnit\Framework\MockObject\MockObject $api
721+
* @throws \ReflectionException
722+
* @return void
723+
*/
724+
private function addCountryFactory(\PHPUnit\Framework\MockObject\MockObject $api): void
725+
{
726+
$reflection = new \ReflectionClass($api);
727+
$property = $reflection->getProperty('_countryFactory');
728+
$property->setAccessible(true);
729+
$property->setValue($api, $this->objectManager->get(CountryFactory::class));
730+
}
713731
}

0 commit comments

Comments
 (0)