I'm trying to create an order programmatically using "paypal_express" method in Magento 2.1.x. The entire checkout process is done via custom module and paypal payment via API. All the transactions and process has been done but unable to create order.
Getting the below Error:
1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): PayPal gateway has rejected request. Invalid token (#10410: Invalid token).
Exception #0 (Magento\Framework\Exception\LocalizedException): PayPal gateway has rejected request. Invalid token (#10410: Invalid token).
#0 /var/www/html/shop/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(89): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Magento\\Framewo...', Array)
The order can successfully created with 'checkmo' method.
Code Sample:
$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod('freeshipping_freeshipping'); //shipping method
$cart->getShippingAddress()->addShippingRate($this->shippingRate);
$cart->setPaymentMethod('paypal_express'); //checkmo
//@todo insert a variable to affect the invetory
$cart->setInventoryProcessed(false);
// Set sales order payment
$cart->getPayment()->importData(['method' => 'paypal_express']); //checkmo
Anyone please help me to resolve this issue.