Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

Hi any one tell me about how to i connect my web application with xero ?

Started by Sumit Patel -   in Wrapper libraries

Hi I make a one web shopping cart system. i generate invoice in that application. now i need that invoice also generate in xero?
i download all code and implement that. but at last i don't know how to use that code. also i not decided that i need to use in public private or partner. ?

so can you please guide me how can i implement this...
The overview page lists each type of application and underneath, there is a link to a guide on choosing the correct application type.

If the shopping cart system is installed on each website (self hosted), then private would probably work best.
 

Ronan Quirke (Community Manager)  

Hi sir Thanks For your reply. i download code from following link :

http://blog.xero.com/developer/getting-started/code/php/

but i facing following error while running that code :

"oauth_problem=signature_method_rejected&oauth_problem_advice=Public%20applications%20must%20use%20the%20HMAC-SHA1%20signature%20method"

I use following code :

<?php

include_once "xero.php";

define('XERO_KEY','JHC0YH5FWJHHVDU74TTUGTZLN71J9F');
define('XERO_SECRET','SS1SEGRWC92ASQZJMCTC0AWIGV605L');

$xero = new Xero(XERO_KEY, XERO_SECRET, 'xero_keys/publickey.cer', 'xero_keys/privatekey.pem', 'xml');

$new_contact = array(
array(
"Name" => "rahul parmar",
"FirstName" => "Rahul",
"LastName" => "Contact",
"Addresses" => array(
"Address" => array(
array(
"AddressType" => "POSTAL",
"AddressLine1" => "PO Box 100",
"City" => "Someville",
"PostalCode" => "3890"
),
array(
"AddressType" => "STREET",
"AddressLine1" => "1 Some Street",
"City" => "Someville",
"PostalCode" => "3890"
)
)
)
)
);

$new_invoice = array(
array(
"Type"=>"ACCREC",
"Contact" => array(
"ContactID" => "102"
),
"Date" => "2013-03-05",
"DueDate" => "2013-03-05",
"Status" => "SUBMITTED",
"LineAmountTypes" => "Exclusive",
"LineItems"=> array(
"LineItem" => array(
array(
"Description" => "Just another test invoice",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
)
)
)
);

$new_payment = array(
array(
"Invoice" => array(
"InvoiceNumber" => "INV-0002"
),
"Account" => array(
"Code" => "100"
),
"Date" => "2013-03-05",
"Amount"=>"100.00",
)
);


$invoice_result = $xero->Invoices( $new_invoice );

$payment_result = $xero->Payments( $new_payment );


$result = $xero->Accounts(false, false, array("Name"=>"Test Account") );

$all_accounts = $xero->Accounts;

if ( is_object($result) ) {

echo htmlentities($result->asXML()) . "<hr />";
} else {

echo json_encode($result) . "<hr />";
}
?>
So can you pls help me?
 

Sumit Patel  

As the error message indicates, you are using a public API application but using it in code meant for a private API application. Reading the oauth error message generally helps diagnosing this sort of issue "Public%20applications%20must%20use%20the%20HMAC-SHA1%20signature%20method""

We have a page that explains common OAuth error messages here.
 

Ronan Quirke (Community Manager)  

Also, you have just shared your consumer key and secret publicly, as this is sensitive information, I suggest you regenerate them in the Developer Centre (within the application profile, there is an option to regenerate).
 

Ronan Quirke (Community Manager)  

Hi Ronan thanks for reply.

ok i generate new test application in private. after that i run code above. now i got following result :

<?xml version="1.0"?> <Response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Id>3209ae10-f72a-4f2e-a680-5c9fd9983696</Id> <Status>OK</Status> <ProviderName>wwmd</ProviderName> <DateTimeUTC>2013-03-06T04:20:35.5759547Z</DateTimeUTC> </Response>

Now there is no any error with this code as per result.

Bt when i am going to check that customer and invoice generate in xero or not. ???

I found that invoice and customer not generate in xero.??

So can you please help me to generate invoice and customer ???

Thanks in advanced....
 

Sumit Patel  

Hi Ronan,

I try to find out in google how can i generate customer and his invoice in xero through my web application but i didnt found.

I use following code for generate customer and inovice :

//the input format for creating a new contact see http://blog.xero.com/developer/api/contacts/ to understand more
$new_contact = array(
array(
"Name" => "rahul parmar",
"FirstName" => "Rahul",
"LastName" => "Contact",
"Addresses" => array(
"Address" => array(
array(
"AddressType" => "POSTAL",
"AddressLine1" => "PO Box 100",
"City" => "Someville",
"PostalCode" => "3890"
),
array(
"AddressType" => "STREET",
"AddressLine1" => "1 Some Street",
"City" => "Someville",
"PostalCode" => "3890"
)
)
)
)
);

//the input format for creating a new invoice (or credit note) see http://blog.xero.com/developer/api/invoices/
$new_invoice = array(
array(
"Type"=>"ACCREC",
"Contact" => array(
"ContactID" => "102"
),
"Date" => "2013-03-05",
"DueDate" => "2013-03-05",
"Status" => "SUBMITTED",
"LineAmountTypes" => "Exclusive",
"LineItems"=> array(
"LineItem" => array(
array(
"Description" => "Just another test invoice",
"Quantity" => "2.0000",
"UnitAmount" => "250.00",
"AccountCode" => "200"
)
)
)
)
);



//raise an invoice
$invoice_result = $xero->Invoices( $new_invoice );

But its not working so can you please help me to generate customer and invoices???
 

Sumit Patel  

Hi Ronan,

After doing hard work finally invoice generate in xero and also customer.

Thanks for help me. Now i have one question and error that how can we add state tax , coupon code and shipping charges in invoice through php code??

I try to add shipping tax but it display me following error :

error no => 10

Message=> A validation exception occurred

Error : The document total does not equal the sum of the lines.

please find the this link for more information about result and errors which i got :

http://wwmdusa.com/xero_example/test.php

I use following code for add invoice with state tax :

$new_invoice = array(
array(
"Type"=>"ACCREC",
"Contact" => array(
"Name" => "Rahul Parmar"
),
"InvoiceNumber" => "INV-0002",
"Date" => "2013-03-08",
"DueDate" => "2013-03-20",
"Status" => "DRAFT",
"LineAmountTypes" => "Inclusive",
"SubTotal" => "500.00",
"TotalTax" => "10.00",
"Total" => "510.00",
"LineItems"=> array(
"LineItem" => array(
array(
"Description" => "First line",
"Quantity" => "2.0000",
"UnitAmount" => "250.00"
)
)
)
)
);

So can you please help me in this example that how can i added grand total , sub total , shipping charges, state tax and discount ?

So please help to fix this. thanks in advanced.
 

Sumit Patel