/    Sign up×
Community /Pin to ProfileBookmark

passing a variable total to paypal.

hello everyone.. i hope someone is able to help me here.

my site sells tickets for train journeys in Ukraine. it collects all the user inputs and the final price variable is passed to the final payment screen.. these variavles are passed using PHP session variables.

I have a script which collects a total price and then offers the user the option of a return ticket. the PHP session variables are converted to javascript and the final total is calculated, before the total is passed to paypal for payment. the script works fine, but i am lost as to what i need to put in the (value =””) form that is submitted to paypal.

here is my script.

[CODE]
<?php

$single = $_SESSION[‘tickets’];
$rate = $single + $_SESSION[‘services’];

?>

<script language=”javascript” type=”text/javascript”>
var test = “<?php echo $single; ?>”;
var rate = “<?php echo $rate; ?>”;

var total = rate;
function priceUpdate(tog)
{
var tCheck = tog.checked;
if (tCheck)
{
total = parseInt(rate,10) + parseInt(test,10)
}
else
{
total = rate
}
tPrice = document.getElementById(‘totalprice’);

tPrice.innerHTML = total;
}
–>
</script>
<input type=”checkbox” id=”chk1″ onClick=”priceUpdate(this)”/><b>Return Ticket</b>
<br />

<h1><b>Your Total £<span id=”totalprice”><script>document.write(total);</script></span></h1><br/>

<form action=”https://www.paypal.com/cgi-bin/webscr” method=”post”>
<input type=”hidden” name=”cmd” value=”_xclick”>
<input type=”hidden” name=”business” value=”GSMCxxxXD5TMA”>
<input type=”hidden” name=”lc” value=”GB”>
<input type=”hidden” name=”item_name” value=”Your Tickets”>

<input type=”hidden” name=”amount” value=”totalprice”>

<input type=”hidden” name=”currency_code” value=”GBP”>
<input type=”hidden” name=”button_subtype” value=”services”>
<input type=”hidden” name=”no_note” value=”1″>
<input type=”hidden” name=”no_shipping” value=”2″>
<input type=”hidden” name=”rm” value=”1″>
<input type=”hidden” name=”return” value=”http://mysite/returnpage”>
<input type=”hidden” name=”bn” value=”PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest”>
<input type=”image” src=”https://www.paypal.com/en_US/GB/i/btn/btn_buynowCC_LG.gif” border=”0″ name=”submit” alt=”PayPal – The safer, easier way to pay online.”>
<img alt=”” border=”0″ src=”https://www.paypal.com/en_GB/i/scr/pixel.gif” width=”1″ height=”1″>

</script>
</form>
[/CODE]

this line is what will not work

[CODE]<input type=”hidden” name=”amount” value=”totalprice”>[/CODE]

does anyone have any ideas ??

thanks for looking

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@eastsideskiJun 03.2010 — first, assign the hidden field an id so you can manipulate it.

You can't have a javascript variable as the value of something, it will just be a string. You need to do document.getElementById("whatever").value=yourvalue

I would also caution against this style of using paypal. Anyone can use a program like firebug to change the price of something. The paypal stored buttons are much more secure
Copy linkTweet thisAlerts:
@j1979authorJun 03.2010 — WOW... thank you !! it worked 1st time ?

i added this at the end of the script
[CODE]document.getElementById("finalpaypal").value = total;[/CODE]

and this in the paypal form
[CODE]<input type="hidden" name="amount" id="finalpaypal">[/CODE]


the security issues are not a major issue as all payments are manually checked and in the terms and conditions, people manipulating the price will incur a charge.

THANK YOU
Copy linkTweet thisAlerts:
@tirnaJun 03.2010 — Paypal's customer integration guide will show you how to set up your forms to send PayPal information for online payments.
×

Success!

Help @j1979 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...