Reference values from a text box
Posted: Thu Jun 17, 2010 3:29 am
Hi guys,
I'm in the process of building a PHP payment page which works somewhat like a donation page. The user inputs the amount they wish to pay, hit send and are taken to the HSBC CPI. I HAVE MANAGED TO GET THIS WORKING! although only with an amount stated in the PHP, not with it referencing values from a text box.
Here's my PHP code to make it clearer:
The above code works perfectly however it doesn't allow the total to be input by a user instead it's stated as
I need to make this $total reference the text input box...
Any help would be greatly appreciated
I'm in the process of building a PHP payment page which works somewhat like a donation page. The user inputs the amount they wish to pay, hit send and are taken to the HSBC CPI. I HAVE MANAGED TO GET THIS WORKING! although only with an amount stated in the PHP, not with it referencing values from a text box.
Here's my PHP code to make it clearer:
Code: Select all
<?php
session_start();
if (!extension_loaded("libCcCpiTools")){
echo "CPI Tool Loaded Successfully!";
}
else{
echo "not loaded";
}
define("MODULE_PAYMENT_HSBC_ID","myid");
define("MODULE_PAYMENT_HSBC_HASH","my hash key");
define("MODULE_PAYMENT_HSBC_TESTMODE","Test");
function process_button(){
global $order, $currency;
$country_codes=array
(
'GB'=>'826',
);
//Currency code setup
$currency_code = $currency;
if (!in_array($currency_code, array('EUR', 'GBP', 'HKD', 'JPY', 'USD'))) {
$currency_code = 'USD';
}
$curr=array('EUR'=>978,'HKD'=>344,'JPY'=>392,'GBP'=>826,'USD'=>840);
$currency_code= "826";
//Total setup without .
$total= "55";
// $total=round($total,2);
// $total=number_format($total, 2, '.', '');
//Generation of the order_id
srand ((float) microtime() * 10000000);
$r1 = rand(100,999);
$t1 = date("yz-his");
$sequence = $t1.$r1;
$sequence = "Order $t1";
//POST time
/*
$time=time();
//Change the 0 if your server is located at a different GMT time
// $time=($time+(0*3600));
// $time=$time*1000;
$time = $time."000";
*/
$time=time();
$time*=1000;
$post_1=array(
'CpiDirectResultUrl'=>'https://www.winstonsolicitors.co.uk/Complete.php',
'CpiReturnUrl'=>'https://www.winstonsolicitors.co.uk/Complete.php',
'OrderDesc'=>'Our order',
'OrderId'=>'Orderid8368',
'PurchaseAmount'=>$total, //
'PurchaseCurrency'=>$currency_code,
'StorefrontId'=>'UK54587401GBP',
'TimeStamp'=>$time,
'TransactionType'=>'Auth',
'MerchantData'=>session_id(),
'BillingAddress1'=>'12 Downsway',
'BillingCity'=>'Southwak',
//'BillingCountry'=>$order->billing['country']['title'],
'BillingCountry'=>'826',
'BillingCounty'=>'Surrey',
'BillingFirstName'=>'Dan',
'BillingLastName'=>'Heaver',
'BillingPostal'=>'BN41 4WC',
'ShopperEmail'=>'rusagar@hotmail.com',
'ShippingAddress1'=>'24 Downsway',
'ShippingCity'=>'Southwark',
//'ShippingCountry'=>$order->delivery['country']['title'],
'ShippingCountry'=>'826',
'ShippingCounty'=>'Surrey',
'ShippingFirstName'=>'Dan',
'ShippingLastName'=>'Heaver',
'ShippingPostal'=>'BN41 4WC'
);
//Test Order
if (MODULE_PAYMENT_HSBC_TESTMODE == 'Test') $post_1['Mode']='T';
else $post_1['Mode']='P';
reset($post_1);
//Sets hidden fields on the form
$cmd="";
$process_button_string='';
while(list($k,$v)=each($post_1)){
//echo $k. " - ".$v."<br>";
//$process_button_string.=tep_draw_hidden_field($k,$v);
$process_button_string.='<input type="hidden" name="'.$k.'" value="'.$v.'">';
}
//Gets the hash
$hash = getHash($post_1);
//echo "My Hash -- ".$hash;
$process_button_string.='<input type="hidden" name="OrderHash" value="'.$hash.'">';
//$process_button_string.='<input type="hidden" name="OrderHash" value="IDJjY5lpaYO15sO6Mb8DgW/4T9g=">';
return $process_button_string;
}
//Function to generate a hash to perform the POST or to check received parameters
function getHash($fields){
$cmd="";
reset($fields);
while(list($k,$v)=each($fields)){
$cmd.=" \"$v\" ";
}
//Path where the TestHash.e executable is located
//$path='D:/wamp/www/hsbc_payment/cgi-bin/hsbc';
//$path='/home/wakie/public_html/catalog/cgi-bin/hsbc';
$path ='/home/sites/winstonsolicitors.co.uk/cgi-bin';
$path ='/home/sites/winstonsolicitors.co.uk/cgi-bin';
putenv("LD_LIBRARY_PATH=$path");
//Executes the TestHash to get the hash
$cmd="$path/TestHash.e \"".MODULE_PAYMENT_HSBC_HASH."\" $cmd 2>&1";
//$cmd="$path/TestHash.e \""."2DsIdINvHawcRZdLrugRDq/9pXq5MaXq"."\" $cmd 2>&1";
//$cmd="$path/TestHash.e \2DsIdINvHawcRZdLrugRDq/9pXq5MaXq\" $cmd 2>&1";
//echo $cmd;
//$ret=exec($cmd, $output);
$ret=exec($cmd);
//echo "Genreated Hash: ".$ret;
$ret=split(':',$ret);
//Returns the hash
$hash=trim($ret[1]);
echo "Hash Key (If successfull!) >> ".$hash;
return($hash);}
?>
<form name="cpi_results" method="POST" action="https://www.cpi.hsbc.com/servlet">
<p><label for="total">Total:</label><input name="total" id="total" type="text"></p>
<?=process_button();?>
<input type="submit" name="Submit" value="Submit">
</form>
Code: Select all
$total= "55";Any help would be greatly appreciated