Magento – How to create order with payment method “paypal_express” in Magento through Custom Api

magento-1.9paypal-expresssoap-api-v2

I have a situation where I did complete the payment process using paypal express mobile sdk, in return I get transaction id, that according to my understanding have to save with the previously created order.

That is exactly what I did, when completed the payment process using paypal standard. I am explaining what i did in paypal standard.

1) Place order and created incrementid.

2) Initiate paypal standard sdk and provide item information to it along with credentials.

3) Successfully complete the payment process, in paypal standard mobile sdk.

4) In return I get transaction id.

5) Save this transaction-id in the previously created order, by editing the order.

Now if talking about paypal express, In Paypal Express payment process got complete before order is been created. So let me explain what I did here.

1) After Customer choose payment method as Paypal Express, and proceed to next step, I use paypal Express sdk for the payment process.

2) Completed the payment process.

3) Saved Payment method in customer quote.

4) and at last created order with following code.

$quote->collectTotals();
$service = Mage::getModel("sales/service_quote", $quote);
$service->submitAll();
if($isNewCustomer)
    $customerResource->involveNewCustomer($quote);
$order = $service->getOrder();
if($order) {
    Mage::dispatchEvent("checkout_type_onepage_save_order_after", array("order" => $order, "quote" => $quote));
    try {
        $order->sendNewOrderEmail();
    }
    catch(Exception $e) {
        Mage::logException($e);
    }
}
Mage::dispatchEvent("checkout_submit_all_after", array("order" => $order, "quote" => $quote));

But this results in following error.

exception 'Mage_Core_Exception' with message 'PayPal NVP gateway errors: Invalid token (#10410: Invalid token). Correlation ID: 61dee43edff3a. Version: 72.0.' in /usr/share/nginx/www/app/code/core/Mage/Paypal/Model/Api/Nvp.php:1062

Any help is much appreciated 🙂

Thanks

Best Answer

Paypal Express payment method doesn't support online capturing. There is no way to get a full order creation flow like on Checkout via Magento API interface. It is impossible to change the order state and process payments. As a workaround try the following:

  1. Create a custom payment method
  2. Enable for REST API only(Not on website checkout page)
  3. While making payment using rest api use this method (after successful payment using you android/ios SDK)
  4. After placing the order make send transaction id(PAY-xxxxx) return by paypal sdk payment to save trasaction.(tell your server side tio implement this call).

I am writting a complete atrticle regarding this step by step. I will let you know when it is done.