I want to create an order using API in magento.

I have already create an api as following:

So quote is generated in magento when customer called API from android while product add to cart. Now next thing is to create an order of this quote.

Description More about query : we place an order in magento by following way :

  1. Add product to cart
  2. Select shipping method (but here not because I am using downlodable product)
  3. Select payment method
  4. Place order

Now see how I maintain above steps between android app and magento

  1. Customer add product to cart in application (service is called to magento this time and I am adding products to cart with method “cart.create”)
  2. Customer select payment method Paypal. This time any service is not called but as we have paypal sdk,customer redirect to paypal from app to gateway.there he pay amount and come back to application.
  3. Now when he come back to application,service is called. And on this call I have to create an order.

May be this is more easy to understand my query.

Here I am confused, how to create an order in Magento after success/canceled transaction response, sent from App to Magento.


2 Answers 2


Not sure if I understood correctly, but you should always create the order before before redirecting to paypal. Then when paypal notifies you that the payment was made the order should change status accordingly.

This is how I would create an order:

$quote = $this->getQuote();

try {
    $quotePayment = $quote->getPayment();


    $onePageCheckOut = \Mage::getSingleton('checkout/type_onepage');

    $this->redirectUrl = $onePageCheckOut->getCheckout()->getRedirectUrl();
} catch (\Exception $e) {
    throw new \Exception(
        'some error code'

$order = \Mage::getModel('sales/order')->load($onePageCheckOut->getLastOrderId(), 'increment_id');

Then you need to wait for the payment notification and update the order:

//check how to get the params in your case
$paymentId = $this->param('payment_id');
$transactionId = $this->param('transaction_id');

if($order->getStatus() === \Mage_Sales_Model_Order::STATE_CANCELED) {
    //do something if order is cancelled

$payment = $order->getPayment();

$amountOrdered = $payment->getAmountOrdered();

/** Save a comment regarding the transaction */
        "Transaction status: %s / Paypal id: %s",
  • have look on my edited query Jul 15, 2015 at 9:19
  • Still I think is not a good idea to redirect the customer to paypal without creating the order. If you still want to do it like this, then just combine the two code samples I provided above
    – lloiacono
    Jul 15, 2015 at 11:29

I have solved this issue by follwoing code :

$proxy = new Zend_XmlRpc_Client('http://www.test.com/api/xmlrpc/');
$session = $proxy->call('login', array(apiuser, 'apipassword'));
$shoppingCartId = $proxy->call('call', array($session,'cart.create',array(1)));

$arrProducts = array(
    "product_id" => 187,
    "quantity" => 1

$customer = array(
    'entity_id' => 26,
    'mode' => 'customer'

$resultCustomerSet = $proxy->call('call',array($session, 'cart_customer.set', array( $shoppingCartId, $customer, 1)) );

    $customer = Mage::getModel('customer/customer')->load(26); 
    $billingaddress = Mage::getModel('customer/address')->load($customer->getDefaultBilling());

       $arrAddresses = array(
                "mode" => "billing",
                "firstname" => $billingaddress->getFirstname(),
                "lastname" => $billingaddress->getLastname(),
                "street" => $billingaddress->getStreet(),
                "city" => $billingaddress->getCity(),
                "region" => $billingaddress->getRegionId(),
                "postcode" => $billingaddress->getPostcode(),
                "country_id" => $billingaddress->getCountryId(),
                "telephone" => $billingaddress->getTelephone(),
                "is_default_shipping" => 0,
                "is_default_billing" => 0

        $resultCustomerAddresses = $proxy->call('call',array($session, "cart_customer.addresses", array($shoppingCartId, $arrAddresses)));          
$resultCartProductAdd = $proxy->call('call',array($session,'cart_product.add',array($shoppingCartId,$arrProducts)));    

                $paymentMethod = array(
             "method" => "checkmo"


        $shoppingCartTotals = $proxy->call('call',array($session, "cart.totals", array($shoppingCartId)));

        $resultPaymentMethod = $proxy->call('call',array($session, "cart_payment.method", array($shoppingCartId, $paymentMethod)));

        $resultOrderCreation = $proxy->call('call',array($session, "cart.order", array($shoppingCartId, null)));


Here I have created an order using payment method check money order.

Now issue is when I want to create an order using paypal_express, I am passing an method code "paypal_express" but that time I am getting an error like : Payment method is not allowed. Please help me on this.

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.