Im trying to create an order in Magento 2 programmatically and able to do with "checkmo" method. But I need to update the payment method with paypal and its transaction details. I have the trans details which processed the payment via Paypal API.

If anyone can help me, it would be great. Thankyou.

$shippingAddress = $cart->getShippingAddress(); 
//@todo set in order data
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod('freeshipping_freeshipping'); //shipping method
$cart->getShippingAddress()->setPaymentMethod('paypal_express');  //checkmo
$cart->getPayment()->importData(array('method' => 'paypal_express', 'additional_information'=>$payment_trans_array));
//$cart->getPayment()->importData(['method' => 'checkmo']);
//@todo insert a variable to affect the invetory
  • can you please add some details like in which file you are trying to add/change this code. Jan 7 '19 at 11:30
  • This code has to include in the controller where place order function which you are looking to process the order Apr 11 '19 at 11:20
  • @sreejith , what is inside $payment_trans_array, please provide details
    – amit_game
    Jan 7 '20 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.