Outpost Bali Spirit Pool

Outpost PayPal Payment Page

In the last week working from the Outpost co-working space in Ubud, Bali, I put together a little payment page to accept and handle PayPal payments using IPN.

Outpost PayPal Payment Gateway

Similar to YogaFit Ibiza, the page remembers the selections and entries as you go, it verifies and stores the data before redirecting to the PayPal payment gateway.

As soon as the payment is made with PayPal, they ping the website, mark the entry as paid and when the user views the thank you page, they can retrieve useful membership data.

I’ve also added a little code that connects with the Yahoo! financial market database to retrieve the latest currency rates between USD and IDR. Check out the YQL potential for yourself if you need similar data for your projects.

function get_currency($from,$to,$amount=1)
{
	$timeout = 0;
	$i = 0;
	$res = array();
	
	if (is_string($to))
	{
		$to = array($to);
	}
	
	$url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(';
	
	foreach ($to as $t)
	{
		$url .= '%22'.urlencode(strtoupper($from.$t)).'%22'.(($i < count($to)-1) ? '%2C' : '');
		$i++;
	}
	
	$url .= ')&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=';
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	$rawdata = curl_exec($ch);
	curl_close($ch);
	$data = json_decode($rawdata);
	
	if (!isset($data->query->results->rate) || !is_array($data->query->results->rate))
	{
		return $res;
	}
	
	if (is_object($data->query->results->rate))
	{
		$res = $data->query->results->rate->Rate*$amount;
	}
	
	if (is_array($data->query->results->rate))
	{
		foreach ($data->query->results->rate as $a)
		{
			$currency = substr($a->id,3,3);
			$res[$currency] = $a->Rate*$amount;
		}
	}
	
	return $res;
}

$usd_idr = get_currency('USD', 'IDR'); // 13230.12
$currency_rates = get_currency('USD', array('GBP', 'EUR')); // array('gbp' => 0.8123, 'eur' => 0.9123)

The Outpost in Ubud is an amazing new co-working space and it is worth making it your destination if you want to be productive in a tropical scene. They even have a pool to use whenever you like at the Bali Spirit Hotel next door.

Leave a Reply

Your email address will not be published. Required fields are marked *