cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.3 - PayPal Express Checkout Payment Error - function getId() on null

Highlighted

Magento 2.3 - PayPal Express Checkout Payment Error - function getId() on null

If a customer try to pay via card getting the following error,

 

Fatal error: Uncaught Error: Call to a member function getId() on null in /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.php:1524 Stack trace: 
#0 /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.php(1493): Magento\Paypal\Model\Api\Nvp->_applyStreetAndRegionWorkarounds(Object(Magento\Framework\DataObject)) 
#1 /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.php(849): Magento\Paypal\Model\Api\Nvp->_exportAddresses(Array) 
#2 /var/www/html/test/app/code/Magento/Paypal/Model/Express/Checkout.php(621): Magento\Paypal\Model\Api\Nvp->callGetExpressCheckoutDetails() 
#3/var/www/html/test/app/code/Magento/Paypal/Controller/Express/AbstractExpress/ReturnAction.php(32): Magento\Paypal\Model\Express\Checkout->returnFromPaypal('*********') 
#4/var/www/html/test/generated/code/Magento/Paypal/Controller/Express/ReturnAction/Interceptor.php(24): Magento\Paypal\Controller\Express\AbstractExpress\ReturnAction->execute() 
#5 /var/www/html/test/lib/internal/Magento/Framework/App/Action/Ac in /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.php on line 1524

How to solve this error?

4 REPLIES 4
Highlighted

Re: Magento 2.3 - PayPal Express Checkout Payment Error - function getId() on null

Hello @Aveeva 

 

Paypal is a core module which Magento provides, why it's in your app/code folder, have you extended it ? if yes, then it's because of that, or just upgrade the paypal version as it can be a lower version issue.

 

Hope it helps !

Problem Solved ? Click on 'Kudos' & Accept as Solution to encourage to write more answers !
Highlighted

Re: Magento 2.3 - PayPal Express Checkout Payment Error - function getId() on null

@gaurav_harsh1  I am using muli website, website 1( for USA) PayPal working, website 2 ( for Australia) here i am getting error. I did nothing, after migration PayPal available in app/code folder. Any help thanks.

Highlighted

Re: Magento 2.3 - PayPal Express Checkout Payment Error - function getId() on null

Code:

 

    protected function _applyStreetAndRegionWorkarounds(DataObject $address)
    {
        // merge street addresses into 1
        if ($address->getData('street2') !== null) {
            $address->setStreet(implode("\n", [$address->getData('street'), $address->getData('street2')]));
            $address->unsetData('street2');
        }
        // attempt to fetch region_id from directory
        if ($address->getCountryId() && $address->getRegion()) {
            $regions = $this->_countryFactory->create()->loadByCode(
                $address->getCountryId()
            )->getRegionCollection()->addRegionCodeOrNameFilter(
                $address->getRegion()
            )->setPageSize(
                1
            );
            $regionItems = $regions->getItems();
            $region = array_shift($regionItems);
            $address->setRegionId($region->getId());
            $address->setExportedKeys(array_merge($address->getExportedKeys(), ['region_id']));
        }
    }

complete code : https://paste.ofcode.org/aYg5Tz4jEx5Kcuez3vPKij

Highlighted

Re: Magento 2.3 - PayPal Express Checkout Payment Error - function getId() on null

@Aveeva 

 

Seems like it's not getting the items from the specific country_id and region, you have to debug which country_id and region it's fetching and why it's not getting items.

 

Or pull a new magento demo version and compare code from core.

Problem Solved ? Click on 'Kudos' & Accept as Solution to encourage to write more answers !