Home Page - www.tele-pro.co.uk - Ecommerce Integration


E-Commerce Scripts > WorldPay Currency Rates

PHP WorldPay Currency Rates Script

The PHP WorldPay Currency Rates script simplifies the use of real-time currency rates on Worldpay-enabled web sites and shopping carts.

It provides several routines which can be used by PHP applications, or by client-side JavaScript code on any web site to display currency rates and perform currency conversion calculations.

 Go Technical Summary
 Go Download the PHP WorldPay Currency Rates Script
 Go Script Setup/Installation
 Go Usage Instructions
 Go PHP Function Reference
 Go JavaScript Function Reference
 Go Technical Details
 Go Demonstration
 Go Exchange Rates
Technical Summary

The WorldPay Currency Rates script interacts with the WorldPay information service using the methods documented on the WorldPay support knowledgebase, to retrieve the list of currency rates for a particular installation Id.

The script encapsulates the code necessary to query the WorldPay information service and interpret the response. It can be included in a PHP script as an include file, and can also be included in any HTML page as a external JavaScript source file.

The script provides the following resources for developers:-
 Go A function to convert any amount, using the currency rates available with your WorldPay installation
 Go A method to display the list of currency rates in various formats
 Go The list of currency rates is made available as an array, accessible in your PHP or JavaScript code.

Download the PHP WorldPay Currency Rates Script

The PHP WorldPay Currency Rates script can be downloaded in the following file formats:

Download compressed zip file

 Download Zip file worldpay_currency.zip 5Kb

Download as a plain text file:

 View Source code worldpay_currency.php.txt 16Kb

Script Setup/Installation

Download one of the files above. If you have downloaded the zip file, extract it to a folder on your computer. Place the PHP script worldpay_currency.php on your web site

Important: The web site must have PHP scripting enabled.

The script can be placed in any folder, and can be renamed if necessary.

If you are not sure if PHP is running on your web site, try uploading and browsing to the well-known debugging script, phpinfo.php, to see if PHP is installed and running.

Usage Instructions

Once the script is installed on your web site, you are ready to use the functions provided by the script in your code or web pages.

To use the PHP functions from within your PHP scripts, include the Currency rates script as follows:

include('worldpay_currency.php');

This directive should appear only once in any PHP script. Once the Currency rates script has been included in this way, the functions described in the reference section are available for you to use in your code.

To use the functions from within JavaScript code, include the Currency rates script as an external JavaScript source file. The reference to the external JavaScript source file must include a identifier in the query string as follows:

<script language="JavaScript" src="worldpay_currency.php?type=.js">
</script>

The identifying code, "?type=Js", indicates that the script is running in JavaScript mode, and causes the JavaScript functions to be output.

PHP Function Reference

The following functions are provided to PHP by including the Currency rates script, worldpay_currency.php, in your code as described in the Usage/Instructions section. .

// list currencies in various formats
// $format can be specified as 'list' or 'table'
list_currencies($format)

// convert a given amount into the currency code
convert_currency($amount, $code, $dp)

// returns the rate for a code, or '0' if it does not exist
currency_rate($code)

 

JavaScript Function Reference

A similar set of functions is provided to JavaScript code by including the Currency rates script, worldpay_currency.php, in a web page. This is described in the Usage/Instructions section.

// convert a given amount into the currency code
WorldpayConvert(amount, code, DP)

// returns the rate for a code, or '0' if it does not exist
WorldpayCurrencies[$code]

// variable contains a string list of the currencies
htmlCurrencyList

// variable contains the html for a table of currencies
htmlCurrencyTable
 

Technical Details

The WorldPay Currency Rates script contains a number of generic functions which offer enhanced features to the repertoire of built-in PHP functions. These can be used in your own PHP code, after including the PHP functions file.

// option_explicit is an error handler function to deliver the
// same functionality provided by the VB directive Option Explicit.
option_explicit($errno,$errstr,$errfile,$errline)

// get_http is a wrapper to fetch a page from the Web.
get_http($host)

// a series of functions are included to provide the built-in ASP
// feature of Application values which persist between user sessions.
// Application values are saved in a temporary file on the web site
get_php_app($key_name)
set_php_app($key_name, $str_value)

WorldPay Currency Exchange Rates Script Demonstration
A demonstration of the PHP WorldPay Currency Rates script is available and shows the steps that need to be taken to display WorldPay Currency Rates and calculate currency conversions in JavaScript code in an HTML web page.

 Go Demonstration - JavaScript

WorldPay Currency Exchange Rates

The exchange rates used by WorldPay are updated every 24 hours at midnight GMT. These rates are then guaranteed for the next 24 hours for all transactions through WorldPay.

 Go WorldPay support knowledgebase - Exchange Rates

 Go ECommerce Scripts
 Go Other Commercial Scripts
 Go Free Scripts Index
 

As a WorldPay Accredited Partner, we offer integration with the full range of WorldPay products, a complete ecommerce solution, and a discounted WorldPay set-up fee.

WorldPay Integration - WorldPay Accredited Partner

WorldPay's product and service offerings are unique in the e-commerce arena.

WorldPay Integration - WorldPay, trusted worldwide

Top | Home | ECommerce | Hosting | Site Map | Search | © 2003-6 | Contact