Contractor UK Bulletin Board  PayStream

Go Back   Contractor UK Bulletin Board > Contractor UK Forums > Technical
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 10th November 2008, 14:22   #1
xoggoth
Super poster
 
xoggoth's Avatar
 
Join Date: Jul 2005
Location: xoggoth towers
Posts: 3,026
Default Shopping cart euro conversion

I want to show an approximate value of an order in Euros on my shopping cart. I could just manually update a rate at regular intervals but as there are so many useful little gadgets around I was wondering if there might be a freeware/cheap link thingy one can embed in a website that I can retrieve in jscript?

Cheers for any ideas.
__________________
bloggoth
xoggoth is offline   Reply With Quote
Old 10th November 2008, 15:15   #2
Moscow Mule
Super poster
 
Join Date: Mar 2007
Location: London
Posts: 4,062
Default

http://www.xe.com/ucc/customize.php

?
__________________
Level 20 Xeno Geek.
Moscow Mule is offline   Reply With Quote
Old 10th November 2008, 15:42   #3
xoggoth
Super poster
 
xoggoth's Avatar
 
Join Date: Jul 2005
Location: xoggoth towers
Posts: 3,026
Default

Ta mule, have found a few neat little converters like that to add to website but am ideally looking for something that needs no user input and will just supply me with a multiplier so I can work out a euro cost from pound cost and show on order page.
__________________
bloggoth
xoggoth is offline   Reply With Quote
Old 10th November 2008, 16:46   #4
Moscow Mule
Super poster
 
Join Date: Mar 2007
Location: London
Posts: 4,062
Default

Ok. I think you'll end up paying for that sort of thing. I've never seen anywhere that does it for free but then I haven't researched it that thoroughly .

Maybe you could use their (free) email service some how (maybe extracting the rate you need and plugging into your database?).

Looking at it though, you might be breaking some rules if you use the data commercially (http://www.xe.com/cus/)
__________________
Level 20 Xeno Geek.
Moscow Mule is offline   Reply With Quote
Old 10th November 2008, 16:49   #5
MPwannadecentincome
Should try harder
 
Join Date: Aug 2008
Posts: 141
Default

Quote:
Originally Posted by xoggoth View Post
I want to show an approximate value of an order in Euros on my shopping cart. I could just manually update a rate at regular intervals but as there are so many useful little gadgets around I was wondering if there might be a freeware/cheap link thingy one can embed in a website that I can retrieve in jscript?

Cheers for any ideas.
Well can you "call" Google - it seems to know the latest exchange rate, e.g. do a search for "100 GBP to EUR", you only have to parse the response.

Last edited by MPwannadecentincome : 10th November 2008 at 16:50. Reason: clarify parse
MPwannadecentincome is offline   Reply With Quote
Old 10th November 2008, 17:42   #6
DimPrawn
Godlike
 
DimPrawn's Avatar
 
Join Date: Jul 2005
Posts: 10,425
Default

I use Yahoo to get the exchange rate.

Here's some quick and dirty C# code:

Code:
using System;
using System.IO;
using System.Net;

namespace DimPrawn.ASP.NET.Support
{
	/// <summary>
	/// Summary description for LookupCurrency.
	/// </summary>
	public class LookupCurrency
	{
		public LookupCurrency()
		{
			
		}

		public decimal GetExchangeRate(string fromCurrencyCode, string toCurrencyCode)
		{
			decimal exchangeRate = 0.0m;

			string url = string.Format(URL, fromCurrencyCode, toCurrencyCode);

			Uri uri = new Uri(url);

			string content = FetchPage(uri);

			Numeric.IsNumber(content, out exchangeRate);

			return exchangeRate;

		}

		private string FetchPage(Uri uri)
		{
			string content = null;

			WebResponse response = null;

			try
			{

				// Create a request for this uri
				WebRequest request = WebRequest.Create(uri);

				// First we only want to ge the HEADER to determine the type of resource at this url
				request.Method = "HEAD";

				// Fetch the response
				response = request.GetResponse();

				if ( response is HttpWebResponse )
				{
					_statusCode        = ((HttpWebResponse)response).StatusCode.ToString();
					_statusDescription = ((HttpWebResponse)response).StatusDescription;

					if ( _statusCode.Equals( "OK" ) )
					{
						// read the headers
						WebHeaderCollection headers = response.Headers;

						// get the content type
						string contentType = headers["Content-type"];

						// If HTML, we will read the content
						if (contentType.StartsWith("application/octet-stream"))
						{

							// Fetch full content
							request = WebRequest.Create(uri);

							// Fetch the response
							response = request.GetResponse();

							if ( response is HttpWebResponse )
							{
								_statusCode        = ((HttpWebResponse)response).StatusCode.ToString();
								_statusDescription = ((HttpWebResponse)response).StatusDescription;

								if ( _statusCode.Equals( "OK" ) )
								{
									StreamReader sr = new StreamReader( response.GetResponseStream( ) );

            
									content = sr.ReadToEnd( );
								}
								else
								{
									_errorCount++;
								}
							}
							else
							{
								_errorCount++;
							}

						}

					}
				}


			}
			catch(Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.ToString());
				_errorCount++;
			}
			finally
			{
				if (response != null)
				{
					response.Close();
				}
			}

			return content;
					

		}

		private string _statusCode;
		private string _statusDescription;
		private int _errorCount;

		private const string URL = "http://finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=a&e=.txt";
	}
}
usage:

Code:
LookupCurrency currencyRate = new LookupCurrency();

			Decimal exchangeRate = currencyRate.GetExchangeRate("GBP", "EUR");
__________________
Last week I cashed a cheque and the bank bounced.
DimPrawn is offline   Reply With Quote
Old 10th November 2008, 19:45   #7
PAH
Super poster
 
PAH's Avatar
 
Join Date: Oct 2006
Location: iamapratville - I love the valleys
Posts: 2,597
Default

Isn't a general conversion rate asking for trouble, if it doesn't match what your payment processor conversion rate (+ commission, handling fees etc, etc) is?

Last thing you want is to advertise an example calculation, then the punters get charged a totally different amount. Bound to end in tears.
__________________
A bird's for christmas not for life.
PAH is offline   Reply With Quote
Old 10th November 2008, 19:59   #8
TheFaQQer
Lord of the FAQ
 
TheFaQQer's Avatar
 
Join Date: Oct 2006
Location: North West
Posts: 6,817
Default

Quote:
Originally Posted by PAH View Post
Isn't a general conversion rate asking for trouble, if it doesn't match what your payment processor conversion rate (+ commission, handling fees etc, etc) is?

Last thing you want is to advertise an example calculation, then the punters get charged a totally different amount. Bound to end in tears.
You just need to caveat it when you display the price in Euros, that this is an indicative cost and may vary from the amount charged by the payment processor. Same as eBay does for their converted currencies.
__________________
Quote:
Originally Posted by Cyberman View Post
Only Labour politicians deliberately lie.
Test please delete - The greatest thread in CUK history (TM)

Visit TPDVille - the online TPD City
TheFaQQer is offline   Reply With Quote
Old 10th November 2008, 20:02   #9
NickFitz
Super poster
 
NickFitz's Avatar
 
Join Date: Jun 2007
Location: Your local branch
Posts: 2,776
Default

Quote:
Originally Posted by PAH View Post
Isn't a general conversion rate asking for trouble, if it doesn't match what your payment processor conversion rate (+ commission, handling fees etc, etc) is?

Last thing you want is to advertise an example calculation, then the punters get charged a totally different amount. Bound to end in tears.
That's an excellent point - the exchange rate on the foreign currency markets would have only marginal relevance to the actual rate used in processing payment. I know you originally specified an approximate conversion, but people don't read the words next to the figures, and whinge when the final figure varies.

Does the company that provides payment processing offer some kind of web service that would allow you to get a more accurate approximation? Better still would be if users could select their currency of choice and see all prices presented in that. Though then that price would become binding, I would imagine.
NickFitz is online now   Reply With Quote
Old 10th November 2008, 20:56   #10
xoggoth
Super poster
 
xoggoth's Avatar
 
Join Date: Jul 2005
Location: xoggoth towers
Posts: 3,026
Default

Ta for all replies. Code looks good Dim, will try that.

I assumed it wouldn't exactly match value they will be charged when they get into Worldpay where they are presented with a choice of currency and it then shows the appropriate sum, although I had assumed the charges fell on us rather than them so difference would be small. Still, easy enough to check that out.

Couldn't find any facility on Worldpay except processing an email after the order.
__________________
bloggoth

Last edited by xoggoth : 10th November 2008 at 20:58.
xoggoth is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT. The time now is 03:21.


Advertisers
PayStream

CUK Navigation

Contractor Alliance
Formed a new Ltd Co?

20% off business insurance
£10 off Bauer & Cottrell contract reviews
Find co-workers & client introductions

Increase your value to clients here

Fast Company Formation
Same day online company formation £75 + VAT

Form your Ltd Co Here

Contractor Services


 
Content Relevant URLs by vBSEO 2.4.0 © 2005, Crawlability, Inc.