Using PayPal Express Checkout Payment on my website getting function getId() on null error

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

Code :

https://paste.ofcode.org/aYg5Tz4jEx5Kcuez3vPKij

ANy help thanks?

So, it’s telling you where it had a problem. Line 1524.
If Nvp.php is what you’ve pasted there, that makes this line:$address->setRegionId($region->getId());

(Which makes sense, because it’s calling the getId function.
Error message says that you’re calling getId() on null, which means it thinks $region is null.
$region = array_shift($regionItems);
so Region is the first item from $regionItems… if one exists…
$regionItems = $regions->getItems();
So this must have returned an empty array. It didnt fail though so $regions existed.
Figure out what the value of $regions was, and why $regions->getItems() returned an empty array.

1 Like

For Australia Paypal Payment method payment.log showing => ‘STATE’ => ‘Victoria’ compare than USA Paypal Payment method payment.log showing ‘STATE’ => ‘TX’ instead of ‘Texas’ . Is my Australia PayPal Payment method configuration is right? because i am getting Fatal during Australia PayPal payment, $address->setRegionId($region->getId()); clearly it’s not getting the region id. I am using Multi-Website, any developers who configure australia paypal payment method help me, thanks.

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 15

Note: Unique Paypal account for my both website store.

(I’m not going to bother to retype my original response to your previous post on this issue.)

Threads merged.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.