access tally from php curl - php

I am trying to insert data from php to tally using php curl,I have already succeeded in inserting data when i ran the code in tally in local machine by giving ip 127.0.0.1,but when i am trying it live curl is giving me error like connection timeout couldnot connect to host.
I had also tried port forwarding.
Below is my xml:
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Import Data</TALLYREQUEST>
</HEADER>
<BODY>
<IMPORTDATA>
<REQUESTDESC>
<REPORTNAME>Vouchers</REPORTNAME>
<STATICVARIABLES> </STATICVARIABLES>
</REQUESTDESC>
<REQUESTDATA>
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<VOUCHER VCHTYPE="Sales" Action="Create">
<ISOPTIONAL>No</ISOPTIONAL>
<VOUCHERTYPENAME>Sales</VOUCHERTYPENAME>
<DATE>20130413</DATE>
<EFFECTIVEDATE>20130413</EFFECTIVEDATE>
<ISCANCELLED>No</ISCANCELLED>
<USETRACKINGNUMBER>No</USETRACKINGNUMBER>
<ISPOSTDATED>No</ISPOSTDATED>
<DIFFACTUALQTY>No</DIFFACTUALQTY>
<VOUCHERNUMBER>11</VOUCHERNUMBER>
<REFERENCE>IS/11/13-14</REFERENCE>
<PARTYLEDGERNAME>INFOSOL</PARTYLEDGERNAME>
<NARRATION>Booked By: KUNAL SINGH | Used By: SANTOSH PARAB</NARRATION>
<ASPAYSLIP>No</ASPAYSLIP>
<ALTERID>11</ALTERID>
<ALLLEDGERENTRIES.LIST>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<LEDGERNAME>INFOSOL</LEDGERNAME>
<AMOUNT>-2200.00</AMOUNT>
<BILLALLOCATIONS.LIST>
<NAME>IS/11/13-14</NAME>
<BILLTYPE>New Ref</BILLTYPE>
<BILLCREDITPERIOD>20130413</BILLCREDITPERIOD>
<AMOUNT>-2200.00</AMOUNT>
</BILLALLOCATIONS.LIST>
</ALLLEDGERENTRIES.LIST>
<ALLLEDGERENTRIES.LIST>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<LEDGERNAME>Rental Income</LEDGERNAME>
<AMOUNT>1000.00</AMOUNT>
<CATEGORYALLOCATIONS.LIST>
<CATEGORY>Primary Cost Category</CATEGORY>
<COSTCENTREALLOCATIONS.LIST>
<NAME>Rental Income</NAME>
<AMOUNT>1000.00</AMOUNT>
</COSTCENTREALLOCATIONS.LIST>
</CATEGORYALLOCATIONS.LIST>
</ALLLEDGERENTRIES.LIST>
<ALLLEDGERENTRIES.LIST>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<LEDGERNAME>Parking N Toll</LEDGERNAME>
<AMOUNT>1200.00</AMOUNT>
</ALLLEDGERENTRIES.LIST>
</VOUCHER>
</TALLYMESSAGE>
</REQUESTDATA>
</IMPORTDATA>
</BODY>
</ENVELOPE>
And here is my php:
$server = "http://".$_SERVER['REMOTE_ADDR'].":9000";
$headers = array( "Content-type: text/xml" ,"Content-length: ".strlen($strXML) ,"Connection: close" );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $strXML);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec($ch);
if(curl_errno($ch)){
echo curl_error($ch);
echo " $server something went wrong..... try later ";
if($_GET[counter]==$_GET[total])
echo 'done###';
}else{
curl_close($ch);
}

Related

How can I render data from Tally to server application?

I want to render data from tally to my application and vise versa using tally API. When I am using it locally, it is working fine, but I want a solution that when my application is on server connects to tally.
This is the code that I am using with tally API
<?php
$requestXML ='<ENVELOPE>
<HEADER>
<VERSION>1</VERSION>
<TALLYREQUEST> EXPORT</TALLYREQUEST>
<TYPE>COLLECTION</TYPE>
<ID> RTSAllVouchers_FilterForVchNoAndVchType</ID>
</HEADER>
<BODY>
<DESC>
<STATICVARIABLES>
<SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
<!-- TODO : Specify the VoucherNo -->
<RTS_KEY>VCH-INV-1</RTS_KEY>
<!-- TODO : Specify the VoucherType here -->
<RTS_VOUCHERTYPENAME>Sales</RTS_VOUCHERTYPENAME>
</STATICVARIABLES>
<TDL>
<TDLMESSAGE>
<!-- Retrieve all Vouchers for specified VoucherNo and VoucherType -->
<COLLECTION NAME="RTSAllVouchers_FilterForVchNoAndVchType" ISINITIALIZE="Yes">
<TYPE>Voucher</TYPE>
<FETCH>ALLLEDGERENTRIES.*</FETCH>
<FETCH>ALLINVENTORYENTRIES.*</FETCH>
<FILTER>RTS_FilterForVchNoAndVchType</FILTER>
</COLLECTION>
<VARIABLE NAME="RTS_KEY">
<TYPE> String</TYPE>
</VARIABLE>
<VARIABLE NAME="RTS_VOUCHERTYPENAME">
<TYPE>String</TYPE>
</VARIABLE>
<SYSTEM TYPE="FORMULAE" NAME="RTS_FilterForVchNoAndVchType">
$VoucherNumber = $$String:##RTS_KEY and $VoucherTypeName = $$String:##RTS_VOUCHERTYPENAME
</SYSTEM>
</TDLMESSAGE>
</TDL>
</DESC> </BODY></ENVELOPE>';
$server = 'http://localhost:9000/';
$headers = array( "Content-type: text/xml","Content-length:".strlen($requestXML) ,"Connection: close");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestXML);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);if(curl_errno($ch)){
print curl_error($ch);
echo " something went wrong..... try later";
}else{
echo " request accepted";
curl_close($ch);
$object = simplexml_load_string($data);print_r($object);
}
?>
$server = 'http://localhost:9000/';
This is the port of the tally its working fine in local.
I heard of the "Tally on cloud" that tally provides, can I render my data from my application to tally using that If yes, then how?

realex showing Mandatory Fields missing: [/request/sha1hash]. error message

This is full source code i am using with DCC where I replace merchantid and account with actual values
$merchantid = "merchantid"; $secret = "secret"; $account = 'account';
This is how i am creating hash
$tmp = "$timestamp.$merchantid.$orderid.$amountinCents.$currency.$cardnumber";
$md5hash = md5($tmp);
$tmp = "$md5hash.$secret";
$md5hash = md5($tmp);
below is the xml sending code
$xml = "<request type='auth' timestamp='$timestamp'>
<merchantid>$merchantid</merchantid>
<account>$account</account>
<orderid>$orderid</orderid>
<amount currency='$currency'>$amountinCents</amount>
<DCC_ENABLE>1</DCC_ENABLE>
<card>
<number>$cardnumber</number>
<expdate>$expdate</expdate>
<type>$cardtype</type>
<chname>$cardname</chname>
<cvn>
<number>$cvvno</number>
<presind>1</presind>
</cvn>
</card>
<dccinfo>
<ccp>euroconex</ccp>
<type>1</type>
<ratetype>S</ratetype>
<amount currency='$currency'>$amountinCents</amount>
</dccinfo>
<autosettle flag='1'/>
<md5hash>$md5hash</md5hash>
<tssinfo>
<address type=\"billing\">
<country>ie</country>
</address>
</tssinfo>
</request>";
// Send the request array to Realex Payments
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.realexpayments.com/epage-remote.cgi");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "payandshop.com php version 0.9");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //This should always be set to 'TRUE' when in production to ensure the SSL is enabled.
$response = curl_exec ($ch);
curl_close ($ch);
$parseXML = simplexml_load_string($response);
echo "<pre>";print_r($parseXML);die();
it return me "320 An internal error has occured." message
i am not sure what i am doing wrong I want to add DCC facility.
Thanks for your question. Firstly, I would highly recommend you use the SHA1 algorithm to hash the transaction details instead of MD5.
Secondly, you didn't post your request XML but it must adhere to the following format:
<?xml version='1.0' encoding='UTF-8'?>
<request type='auth' timestamp='20171025141809'>
<merchantid>Merchant ID</merchantid>
<account>internet</account>
<channel>ECOM</channel>
<orderid>N6qsk4kYRZihmPrTXWYS6g</orderid>
<amount currency='EUR'>1001</amount>
<card>
<number>4263970000005262</number>
<expdate>0519</expdate>
<chname>James Mason</chname>
<type>VISA</type>
<cvn>
<number>123</number>
<presind>1</presind>
</cvn>
</card>
<autosettle flag='1'/>
<comments>
<comment id='1'>Mobile Channel</comment>
<comment id='2'>Down Payment</comment>
</comments>
<sha1hash>87707637a34ba651b6185718c863abc64b673f20</sha1hash>
</request>
Can you please ensure that you have the sha1hash element in the request XML and that it is being populated with the appropriate value.
Best,
Seán
Realex Payments

eBay Trading API AddItem call returns 'Invalid job context type' error

Im trying to list an item on ebay with the Ebay Tradding API using php and CURL.
XML Request and CURL syntax seems fine to me, but API returns Invalid job context type error.
I suppose I'm missing something in the Header.
My request code is following:
$xml_string = '<?xml version="1.0" encoding="utf-8"?>
<AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>*Token*</eBayAuthToken>
</RequesterCredentials>
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<Item>
<Title>'.$postdata['item_name'].'</Title>
<Description>'.$postdata['external_comments'].'</Description>
<PrimaryCategory>
<CategoryID>377</CategoryID>
</PrimaryCategory>
<StartPrice>'.$postdata['ebay_price'].'</StartPrice>
<CategoryMappingAllowed>true</CategoryMappingAllowed>
<Country>US</Country>
<Currency>USD</Currency>
<ConditionID>1000</ConditionID>
<DispatchTimeMax>3</DispatchTimeMax>
<ListingDuration>Days_7</ListingDuration>
<ListingType>Chinese</ListingType>
<PaymentMethods>PayPal</PaymentMethods>
<!--Enter your Paypal email address-->
<PayPalEmailAddress>jash389#gmail.com</PayPalEmailAddress>
<PictureDetails>
<PictureURL>http://pics.ebay.com/aw/pics/dot_clear.gif</PictureURL>
</PictureDetails>
<PostalCode>95125</PostalCode>
<Quantity>1</Quantity>
<ReturnPolicy>
<ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<RefundOption>MoneyBack</RefundOption>
<ReturnsWithinOption>Days_30</ReturnsWithinOption>
<Description>If you are not satisfied, return the book for refund.</Description>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
</ReturnPolicy>
<ShippingDetails>
<ShippingType>Flat</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>
<ShippingService>USPSMedia</ShippingService>
<ShippingServiceCost>2.50</ShippingServiceCost>
</ShippingServiceOptions>
</ShippingDetails>
<Site>US</Site>
</Item>
</AddItemRequest>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.ebay.com/ws/api.dll");
$headers = array(
'Content-Type: text/xml',
'X-EBAY-API-COMPATIBILITY-LEVEL: 967',
'X-EBAY-API-DEV-NAME: ',
'X-EBAY-API-APP-NAME: ',
'X-EBAY-API-CERT-NAME: ',
'X-EBAY-API-SITEID: 2',
'X-EBAY-API-CALL-NAME: AddItems'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, "xmlRequest=" . $xml_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
And the response is:
<?xml version="1.0" encoding="UTF-8"?>
<AddItemsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2017-07-28T18:48:59.487Z</Timestamp>
<Ack>Failure</Ack>
<Errors>
<ShortMessage>Invalid job context type</ShortMessage>
<LongMessage>The job context object is not supported by Action Service Framework.</LongMessage>
<ErrorCode>21843</ErrorCode>
<SeverityCode>Error</SeverityCode>
<ErrorParameters ParamID="0"><Value>AddItems</Value></ErrorParameters>
<ErrorParameters ParamID="1"><Value>AddItemRequestType</Value></ErrorParameters>
<ErrorClassification>RequestError</ErrorClassification>
</Errors><Version>1021</Version><Build>E1021_UNI_API5_18478667_R1</Build></AddItemsResponse>
When I tried the same XML with API explorer. The request went through.
Some issue with the CURL I suppose.
Your specify X-EBAY-API-CALL-NAME as AddItems
Your XML is an AddItemRequest
These must match. AddItem & AddItems are 2 different calls.

Azure won't cURL a google site search xml

I'm running the XML to PHP install of paid Google site search.
https://code.google.com/p/google-csbe-example/downloads/detail?name=gss.php&can=2&q=
My initial implementation runs perfectly on a LAMP server, however I now have to run a PHP environment on the Windows Azure Platform.
It appears as though the $url variable is not being passed through cURL, as the $result varaible returns as NULL.
$url = 'https://www.google.com/cse?cx=' . $your_cx_number . '&client=google-csbe&output=xml_no_dtd&q=' . $q;
if(isset($start)){
$url .= '&start=' . $start;
}
If i modify the value of $url to a different remote xml file, with a little adjustment to the output structure, I get the expected results.
I have tried several different troubleshooting steps including:
cURL: alternate xml feed renders
simplexml: alternate rss feed renders
permissions: site permissions aren't required google cse dashboard
alternate azure site: tested and failed
alternate LAMP hosted site: tested and success
alternate search setup: this had no effect
is the domain blocked to google: don't think so
url queries blocked: not sure if this is causing any issues
I'm stumped.
Any help would be greatly appreciated.
Thanks!
Here's the full code (minus the cx number):
<?php
//ini_set('display_startup_errors',1);
//ini_set('display_errors',1);
//error_reporting(-1);
$q = $_GET['q'];
$q = urlencode($q);
//WRAPPED IN A IF STATEMENT SO PROMOTED RESULTS SHOW UP ON THE FIRST PAGE
if(isset($_GET['start'])){
$start = $_GET['start'];
}
$your_cx_number = 'enter_your_paid_google_site_search_cx_number';
$url = 'https://www.google.com/cse?cx=' . $your_cx_number . '&client=google-csbe&output=xml_no_dtd&q=' . $q;
if(isset($start)){
$url .= '&start=' . $start;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s
curl_setopt($ch, CURLOPT_HTTPGET, true); // set POST method
//curl_setopt($ch, CURLOPT_POSTFIELDS, "postparam1=postvalue"); // add POST fields
//submit the xml request and get the response
$result = curl_exec($ch);
curl_close($ch);
//now parse the xml with
$xml = simplexml_load_string($result);
$START = $xml->RES['SN'];
$END = $xml->RES['EN'];
$RESULTS = $xml->RES->M;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search results</title>
</head>
<body>
<form action="search-test.php" id="searchform" >
<input type="text" name="q" placeholder="Search..." <?php if(isset($_GET['q'])) { echo 'value="' . $_GET['q'] . '"' ; }?> id="search-text" size="25" autocomplete="off" />
<input type="submit" id="search-button" title="Search" value="" />
</form>
<p>The url of the XML output</p>
<?php
//extract the title, link and snippet for each result
if ($xml->RES->R) {
foreach ($xml->RES->R as $item) {
$title = $item->T;
$link = $item->U;
$snippet = $item->S;
echo '<h3>' . $title . '</h3>
<p>' . $title . '</p>
<p>' . $snippet . '</p>
<hr />';
}
}
?>
</body>
</html>
cURL error reporting returned an error code : 60
Curl error: 60 - SSL certificate problem: unable to get local issuer certificate
A search for a similar error provided the solution
HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK
Add in the line:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
The full cURL function is now:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 30s
curl_setopt($ch, CURLOPT_HTTPGET, true); // set POST method
$result = curl_exec($ch);
if(curl_errno($ch)){
echo 'Curl error: ' . curl_errno($ch) . ' - ' .curl_error($ch);
$info = curl_getinfo($ch);
if (empty($info['http_code'])) {
die("No HTTP code was returned");
} else {
echo $info['http_code'];
}
}
curl_close($ch);

gmail unread email count using curl

I created a script that can get the unread email list as a feed from the gmail here is my code
<?php
//function to get unread emails taking username and password as parameters
function check_email($username, $password)
{
//url to connect to
$url = "https://mail.google.com/mail/feed/atom";
// sendRequest
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
curl_close($curl);
//returning retrieved feed
return $curlData;
}
//making page to behave like xml document to show feeds
header('Content-Type:text/xml; charset=UTF-8');
//calling function
$feed = check_email("username", "password");
echo $feed;
?>
the output getting like this
<?xml version="1.0" encoding="UTF-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#">
<title>Gmail - Inbox for suneth2#gmail.com</title>
<tagline>New messages in your Gmail Inbox</tagline>
<fullcount>1282</fullcount>
<link rel="alternate" href="http://mail.google.com/mail" type="text/html" />
<modified>2012-08-01T12:33:48Z</modified>
<entry>
<title>eBCS Pro 1 August 2012</title>
<summary>bcs logo eBCS Pro 1 August 2012 Video interview Olympic IT The Met Police's director of IT, Steve</summary>
<link rel="alternate" href="http://mail.google.com/mail?account_id=test#gmail.com&message_id=138e21a3404cc7b2&view=conv&extsrc=atom" type="text/html" />
<modified>2012-08-01T12:12:44Z</modified>
<issued>2012-08-01T12:12:44Z</issued>
<id>tag:gmail.google.com,2004:1409100718455703474</id>
<author>
<name>eBCS Newsletter</name>
<email>e-bulletin#lists.bcs.org.uk</email>
</author>
</entry>
<entry>
so want to read the
<fullcount>1282</fullcount>
tag
when you pass the username and password to this function it can show the email list,
I need to get only the message count, is there any way to catch or count the items
this is the answer, i read the xml tag using php
$xmlobjc = new SimpleXMLElement($feed);
echo $xmlobjc->fullcount[0];
and replace the header with
header('Content-Type:text/html; charset=UTF-8');
This works too:
curl -u $(cat username):$(cat password) --silent 'https://mail.google.com/mail/feed/atom' | sed -n 's:.*<fullcount>\(.*\)</fullcount>.*:\1:p'

Categories