How to use a variable dollar amount in php_payment sample?

Hi again,

My payment form works fine with the hardcoded dollar value in the example:

$money->setAmount(100);

However, I want to use a variable amount there, which is determined in my app depending on what the user is buying. I put that dollar value into a session variable called ‘square_total’ and want to use it in process-payment.php as follows:

$money->setAmount($_SESSION[‘square_total’]);

But I keep getting this error on the form:

“amount_money supplied was malformed”

Is there a simple way I am missing to be able to replace that hard-coded $1 in the sample code, with a variable amount determined by my local app?

Thanks!

For example, my code sets the following when someone goes to purchase a $135 item:

$_SESSION[‘square_total’] = “13500”;

Then I try to use that in process-payment.php as follows:

$money->setAmount($_SESSION[‘square_total’]);

OK I figured it out… Turns out I just had to add an include at the top of process-payment.php, to call in my session code that is already included on all my other pages.

Without that include, process-payment.php did not have access to session variables of course. Duh.

All good now, you can ignore this post :slight_smile:

Glad to hear you figured it out. :slightly_smiling_face: