3

I am trying to create sales order Invoice using Magento API in android application using XMLRPC.I am using the method "sales_order_invoice.create" for creating invoice.This method is giving me Invoice Id in the response for given quantity as mention in magento wiki.But the problem is that the Invoice qty isn't updated on magento store.Other thing is Order status is changing to Processing which is correct and the entry of created invoice is also present in invoice list of store but It is displaying the paid amount as $0.0 which is not correct.

I don't know if I need to call another method before calling sales_order_invoice.create or is there any problem in the method??
Below is some part of my code for calling method:

import java.util.HashMap;
import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MagentoStore extends Activity {

private XMLRPCClient client;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);
            String sessionId = "";


client = new XMLRPCClient("http://www.mystore.com/index.php/api/xmlrpc");
        try {

            sessionId = (String)client.call("login", "tester", "tester");
            Log.d("MY_XMLRPC_SUCCESS_SESSION_ID", sessionId);
            }
         catch (XMLRPCException e) {

            Log.d("MY_XMLRPCException_MSG", e.getMessage());
        }

        Object salesorderInfo = null;
        Object[] methodParams = new Object[]{"100000028"};
        Object[] callParams = new Object[]{sessionId,"sales_order.info", methodParams};
        String salesorderinvoice= null;
        try {
             salesorderInfo = (Object)client.callEx("call",callParams);
             HashMap map = (HashMap)salesorderInfo;
             Object[]items=(Object[])map.get("items");
             for(Object item :items)
             {
                 HashMap itemlist=(HashMap)item;
                 String item_id=(String)itemlist.get("item_id");
                 int itemids=Integer.parseInt(item_id);
                 String base_price=(String)itemlist.get("base_price");
                 if(base_price.equals("0.0000"))
                 {
                  continue;  
                 }   
                 String name=(String)itemlist.get("name");
                 Double qty=1.0;
                 String qty_ordered =(String)itemlist.get("qty_ordered");
                 String qty_invoiced=(String)itemlist.get("qty_invoiced");
                 Object[] methodParams1 = new Object[]{"100000028",itemids,qty};
                 Object[] callParams1 = new Object[]{sessionId,"sales_order_invoice.create", methodParams1};
                 salesorderinvoice= (String)client.callEx("call",callParams1);

             } 
            } catch (Exception e) {
            Log.d("APP_INFO", "Exception: " + e.getMessage());
            }               
    }
}

Anyone have any Idea?? Thanks in advance

krushnakant
  • 431
  • 9
  • 21
  • Are you not getting this Error:: 07-17 06:23:58.895: WARN/System.err(25812): java.net.UnknownHostException: Host is unresolved: cws16:80 07-17 06:23:58.916: WARN/System.err(25812): at java.net.Socket.connect(Socket.java:1037) 07-17 06:23:58.926: WARN/System.err(25812): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117) 07-17 06:23:58.926: WARN/System.err(25812): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:129) 07-17 06:23:58.926: WARN/System.err(25812): at org.apache. – Haresh Chaudhary Jul 18 '12 at 10:34
  • I am using same code as you but getting this Error...Please Krushnakant Help Me...Regargs. – Haresh Chaudhary Jul 18 '12 at 10:35
  • I am using my local server for this..and i know that i have problem with the url only...i am using the url as "http://cws24/magento/index.php/api/xmlrpc"...and it gives me unknownhost exception – Haresh Chaudhary Jul 18 '12 at 10:55
  • @Androider: No,I am not getting any error.I am getting the correct response but at magento store invoice is not created.And I think u r right may be there is some problem with ur Url.Are u using this code for Java app or Android app?? – krushnakant Jul 19 '12 at 06:40
  • I am creating a Android App on Magento WebSite – Haresh Chaudhary Jul 19 '12 at 06:45
  • Oppss...Sorry K...actually my this problem was solved yesterday...actually this problem still persist while i am using SOAP – Haresh Chaudhary Jul 19 '12 at 06:47
  • ok,Are u using SOAP or XMLRPC now?? – krushnakant Jul 19 '12 at 06:52
  • Are u getting the correct response and updatation at magento site when u r using create invoice method?? – krushnakant Jul 19 '12 at 06:55
  • Actually iam at the verge to develop this App...I have cleared login method through XMLRPC, I am using XMLRPC..Soap gives me lots of error. And I would like to get help from you man.. I have gone through your previous questions and got the Idea to Use XMLRPC. – Haresh Chaudhary Jul 19 '12 at 07:01
  • ok,Can you able to create Invoice at magento site??? – krushnakant Jul 19 '12 at 07:07
  • On the magento Site..if on Magento Site then yes,let me know if I understood you Right?? – Haresh Chaudhary Jul 19 '12 at 07:09
  • means using api and method "sales_order_invoice.create".I want to create invoice at magento site – krushnakant Jul 19 '12 at 07:13
  • No.Actually you are far ahead of me.You will have to help me to move further. he he.. – Haresh Chaudhary Jul 19 '12 at 07:17
  • Can you come on the Chat of SO – Haresh Chaudhary Jul 19 '12 at 07:30
  • Why you have used "100000028" as parameter..Object[] methodParams = new Object[]{"100000028"}; – Haresh Chaudhary Jul 19 '12 at 12:22
  • 100000028 is a orderIncrementId which u have to pass with this method to get detail information of particular order.For more info see the link. http://www.magentocommerce.com/api/soap/sales/salesOrder/sales_order.info.html – krushnakant Jul 20 '12 at 05:01
  • Krushnakant...that's Ok...but how to get the details of all the Orders..we have to pass the orderIncrementId of order to get it's details..but how we will get that orderIncrementId ??for that we have to get the details of all the Orders na first?? – Haresh Chaudhary Jul 20 '12 at 05:08
  • Hey check this link...very useful..http://www.magentocommerce.com/boards/viewthread/12899/P30/ – Haresh Chaudhary Jul 20 '12 at 06:05

1 Answers1

0

FYI

when you call the API sales_order_invoice.create, you must assign the array pointer name.

String qty_ordered =(String)itemlist.get("qty_ordered");
                 String qty_invoiced=(String)itemlist.get("qty_invoiced");
                 Object[] methodParams1 = new Object[]{"100000028",itemids,qty};

try to var_dump the methodParams1 with

methodParams1.toString();

it must be same with

array(
      'orderIncrementId' => '200000008', 
      array(
            'order_item_id' => '11', 
            'qty' => '1'
      )
);

because this is the way to put the parameter to sales_order_invoice.create

$result = $client->call(
    $session,
    'sales_order_invoice.create',
    array('orderIncrementId' => '200000008', array('order_item_id' => '11', 'qty' => '1'))
);
Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
  • it gives you invalid argument error because your parameter isn't correct. – Josua Marcel C Aug 20 '12 at 16:16
  • 1
    ok,But If I don't use methodParams1.toString() as suggested by u and only use methodParams1 then it is giving me Invoice Increment Id in response and not giving any error as I have mentioned earlier. – krushnakant Aug 21 '12 at 04:47
  • 1
    @krushnakant are you there..i am having problem in creating shipment of a order..please help me – Haresh Chaudhary Dec 19 '12 at 08:02