Here is some code I'd like to donate for anyone to use on their buy pages. It gets the customer's IP address, then uses cURL to get the product price for the stated quantity in the local currency from Plimus and builds a buy button with the displayed price data.
Hope someone finds it useful. Perhaps it can be improved upon.
<?php
function PlimusContractPriceForIP($contract, $quantity) {
if (getenv(HTTP_X_FORWARDED_FOR)) {
$ipaddress = getenv(HTTP_X_FORWARDED_FOR);
} else {
$ipaddress = getenv(REMOTE_ADDR);
}
$price = '';
$url = 'http://www.plimus.com/jsp/get_local_price.jsp';
$postfields = 'contractId=' . $contract .
'&quantity=' . $quantity .
'&ip=' . $ipaddress .
'&responseType=symbol_number';
$c = curl_init($url);
curl_setopt($c, CURLOPT_TIMEOUT, 3);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 3);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, $postfields);
$price = curl_exec($c);
curl_close($c);
$price = trim($price);
return $price;
}
function plimusbuynowbuttonandtext ($contractID, $quantity, $linktext) {
echo '<tr>';
$link = 'https://www.plimus.com/jsp/buynow.jsp?contractId=' . $contractID . '&quantity=' . $quantity;
$button = '<img src="buynow.png" alt="buy now" width="xx" height="yy" border="0">';
$price = PlimusContractPriceForIP($contractID, $quantity);
echo '<td valign="top" align="center">';
echo '<a href="' . $link . '" rel="nofollow">' . $button . '</a>';
echo '</td>';
echo '<td valign="top" align="left">' . $linktext . '</a>';
echo $price;
echo '</td></tr>';
}
?>
<table>
<?php
plimusbuynowbuttonandtext('xxxxxx', 1, 'Product1', ' ');
plimusbuynowbuttonandtext('yyyyyy', 1, 'Product2 (1 user)');
plimusbuynowbuttonandtext('yyyyyy', 5, 'Product2 (5 user)'');
?>
</table>
where 'xxxxxx' and 'yyyyyy' are the contract codes. The image 'buynow.png' and its height and width are, of course, to be determined by your own requirements.
I did indent this code but the indenting gets removed - sorry!