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?
Related
I'm new here so please be patient, This is my request code, I want to write another piece of code in another server that will be accepting it and returning an xml 7101 success code using php and curl. How do I write code in a receiving server. This is actually API that I will be using to exchange data between my system and another remote system stored in clouds I have managed to send request successfully but I have stuck at receiving their requests, I have spent an entire week on it please help me out on receiving the requests when they send them to me.
success code is
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gepgBillSubReqAck>
<TrxStsCode>7101</TrxStsCode>
</gepgBillSubReqAck>
the request code is this,
<?php
//Bill Request
$content ="<gepgBillSubReq>
<BillHdr>
<SpCode>SP103</SpCode>
<RtrRespFlg>true</RtrRespFlg>
</BillHdr>
<BillTrxInf>
<BillId>1812022009968</BillId>
<SubSpCode>1001</SubSpCode>
<SpSysId>TANESCO001</SpSysId>
<BillAmt>1180</BillAmt>
<MiscAmt>0</MiscAmt>
<BillExprDt>2017-12-31T23:59:59</BillExprDt>
<PyrId>5144AA5914</PyrId>
<PyrName>test</PyrName>
<BillDesc>Bill Number 5913</BillDesc>
<BillGenDt>2017-12-21T09:39:00</BillGenDt>
<BillGenBy>Bhstenkubo</BillGenBy>
<BillApprBy>Bhstenkubo</BillApprBy>
<PyrCellNum/>
<PyrEmail/>
<Ccy>TZS</Ccy>
<BillEqvAmt>1180</BillEqvAmt>
<RemFlag>false</RemFlag>
<BillPayOpt>1</BillPayOpt>
<BillItems>
<BillItem>
<BillItemRef>5144AA5914</BillItemRef>
<UseItemRefOnPay>N</UseItemRefOnPay>
<BillItemAmt>1180</BillItemAmt>
<BillItemEqvAmt>1180</BillItemEqvAmt>
<BillItemMiscAmt>0</BillItemMiscAmt>
<GfsCode>140316</GfsCode>
</BillItem>
</BillItems>
</BillTrxInf>
</gepgBillSubReq>";
$resultCurlPost = "";
$serverIp = "XXXXXXXXXXXXXXXX";
$uri = "/XXX/XXX/qrequest"; //this is for qrequest
echo "Message ready to GePG:"."\n".$content."\n";
$ch = curl_init($serverIp.$uri);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/xml',
'Gepg-Com:default.sp.in',
'Gepg-Code:SP103',
'Content-Length:'.strlen($content))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
//Capture returned content from GePG
$resultCurlPost = curl_exec($ch);
curl_close($ch);
//$resultCurlPost=$data;
if(!empty($resultCurlPost)){
echo "\n\n";
echo "Received Response\n";
echo $resultCurlPost;
echo "\n";
}
else
{
echo "No result Returned"."\n";
}
?>
Thanks, you guys for contributing I found a solution, I used file_get_contents("php://input"); on the receiving server and so far it is working fine.
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
I've fired a curl request. My code is
$URL = "http://demo.com";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xmlLeadCloud");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
Below I am getting the XML in $output variable.
<?xml version="1.0" encoding="utf-16"?>
<LeadCloud>
<InsuranceSvcRs>
<PersHealthPolicyQuoteInqRs>
<MsgStatus>
<MsgStatusCd>Success</MsgStatusCd>
<Payout>17.40</Payout>
<BuyerLeadId>4ded4da790c6fasasasas322</BuyerLeadId>
<BuyerId>34</BuyerId>
</MsgStatus>
</PersHealthPolicyQuoteInqRs>
</InsuranceSvcRs>
</LeadCloud>
How could I get MsgStatusCd element's value from it. So far I've tried.
$s = new SimpleXMLElement($output);
echo $s->InsuranceSvcRs->PersHealthPolicyQuoteInqRs->MsgStatus->MsgStatusCd; die; //not working
Cast the output to a string to get its value:
echo (string) $xml->InsuranceSvcRs->PersHealthPolicyQuoteInqRs->MsgStatus->MsgStatusCd;
You can see from this demo where it prints:
Success
You can use XPath to access this data (see PHP manual entry).
The reason why your accessor does not work is that the XML you are receiving is a data array, hence,
<?xml version="1.0" encoding="utf-16"?>
<LeadCloud> <!-- ROOT -->
<InsuranceSvcRs> <!-- Zero or more -->
<PersHealthPolicyQuoteInqRs> <!-- Zero or more -->
<MsgStatus> <!-- Zero or more -->
<MsgStatusCd>Success</MsgStatusCd> <!-- Zero or one -->
<Payout>17.40</Payout> <!-- Zero or one -->
<BuyerLeadId>4ded4da790c6fasasasas322</BuyerLeadId> <!-- Zero or one -->
<BuyerId>34</BuyerId> <!-- Zero or one -->
</MsgStatus>
</PersHealthPolicyQuoteInqRs>
</InsuranceSvcRs>
</LeadCloud>
and should be accessed as such.
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);
}
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'