Currency Conversion With foxrate.org's XML-RPC API

Foxrate.org provides XML-RPC API to convert the currency from one to another. I needed it for a project to convert from Euro to Pound and vice-versa. I had once read about such a work in roshanbh.com.np so I finally thought to follow the same API. After searching for some days, I came up with some code but had some problem for which I couldn't get any help. At last our friend from college, Sanjeev, added last two lines of code to make it run.
Thanks Sanjeev.

<?php
require_once('lib/xmlrpc.inc');//initialize client
$xmlrpc_client=new xmlrpc_client('/rpc','www.foxrate.org',80);
$xmlrpc_client->setDebug(3);//turn on debugging mode
//construct the request (xml-rpc message)
$xmlrpc_msg=new xmlrpcmsg('foxrate.currencyConvert', array(new xmlrpcval('USD','string'), new xmlrpcval('EUR','string'), new xmlrpcval(1,'double')));
//send the request
$xmlrpc_resp=$xmlrpc_client->send($xmlrpc_msg);
//working with the server's response
if (!$xmlrpc_resp)
{
print ("Could not connect to HTTP server.");
}
elseif ($xmlrpc_resp->faultCode())
{
print ("XML-RPC Fault #" . $xmlrpc_resp->faultCode() . \": \" .$xmlrpc_resp->faultString();
}
else
{
$result = $xmlrpc_resp->value();
$amount = $result->structmem('amount');
echo ("Amount Converted: ".$amount->scalarval());
}
?>

Comments

Popular posts from this blog

Simple Invoice Creation With Jasper Report

Dynamic Image in Jasper Report

Auto Increment Oracle Table Id Mapping With JPA Entity