Skip to content

Commit 17a9587

Browse files
committed
Merge remote-tracking branch 'origin/MC-31196' into 2.4-develop-pr16
2 parents b6b38d5 + 8a73e53 commit 17a9587

File tree

2 files changed

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

2 files changed

+40
-21
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,17 +1512,18 @@ 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-
);
1522-
$regionItems = $regions->getItems();
1523-
$region = array_shift($regionItems);
1524-
$address->setRegionId($region->getId());
1525-
$address->setExportedKeys(array_merge($address->getExportedKeys(), ['region_id']));
1515+
$regions = $this->_countryFactory->create()
1516+
->loadByCode($address->getCountryId())
1517+
->getRegionCollection()
1518+
->addRegionCodeOrNameFilter($address->getRegion())
1519+
->setPageSize(1);
1520+
1521+
if ($regions->count()) {
1522+
$regionItems = $regions->getItems();
1523+
$region = array_shift($regionItems);
1524+
$address->setRegionId($region->getId());
1525+
$address->setExportedKeys(array_merge($address->getExportedKeys(), ['region_id']));
1526+
}
15261527
}
15271528
}
15281529

@@ -1624,7 +1625,7 @@ protected function _filterPeriodUnit($value)
16241625
case 'year':
16251626
return 'Year';
16261627
default:
1627-
break;
1628+
return '';
16281629
}
16291630
}
16301631

@@ -1653,7 +1654,7 @@ protected function _filterBillingAgreementStatus($value)
16531654
case 'active':
16541655
return 'Active';
16551656
default:
1656-
break;
1657+
return '';
16571658
}
16581659
}
16591660

@@ -1694,7 +1695,7 @@ protected function _filterPaymentStatusFromNvpToInfo($value)
16941695
case 'Voided':
16951696
return \Magento\Paypal\Model\Info::PAYMENTSTATUS_VOIDED;
16961697
default:
1697-
break;
1698+
return null;
16981699
}
16991700
}
17001701

@@ -1712,7 +1713,7 @@ protected function _filterPaymentReviewAction($value)
17121713
case \Magento\Paypal\Model\Pro::PAYMENT_REVIEW_DENY:
17131714
return 'Deny';
17141715
default:
1715-
break;
1716+
return null;
17161717
}
17171718
}
17181719

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)