Solved

how to change a session variable using PHP

Posted on 2009-05-10
4
210 Views
Last Modified: 2012-05-06
Hi,

I have an order form that passes a price including shipping to Paypal. PayPal then confirms the user, determines the address, and returns the amount and address to a confirmation page form. From this page the user hits submit and the amount is passed and the transaction gets completed.

If the user has a California shipping address I have a function on the confirmation page that calculates the tax. The problem is I cannot get the newly tax calculated total passed in the final phase of the order process. So when he user hits submit from the order confirmation page the amount without the tax gets passed, not the amount with the tax that has been calculated.

This is the 4 steps of my order process.

Price page > Paypal > confirmation Page > Transaction complete page

The problem is, the Price generated at the Price page stays in the URL during the whole transaction. I need to change it at the Confirmation page and pass the new amount in the URL to the Transaction complete page.

Below is the code that I don't understand that I am hoping I can modify.


<!-- confirmation page -->
 
<!-- this is the tax calculation function, nothing wrong here, I just included it for explanation purposes -->
 
$caltax = (($_REQUEST['paymentAmount'] - $_REQUEST['SHIPPINGAMT']) * 0.0925);
 
if ($resArray['SHIPTOSTATE'] == 'CA')
{
$_REQUEST['paymentAmount'] = ($_REQUEST['paymentAmount'] + $caltax);               
}
 
<!-- this is the price variable who's value want to change but cannot figure out how to-->
 
$_SESSION['paymentAmount']=$_REQUEST['paymentAmount'];
 
<!-- Transaction complete page  -->
 
$paymentAmount =urlencode ($_SESSION['paymentAmount']);
 
<!-- This is the code that passes the final amount to complete the transaction  -->
 
$nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currCodeType.'&IPADDRESS='.$serverName ;

Open in new window

0
Comment
Question by:jackie777
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:NeoDiffusion
ID: 24349280

Hello jackie777,

So far I remember, $_REQUEST['paymentAmount'] and $paymentAmount are two different variables, even if initially containing the same values. Meaning that if $_REQUEST['paymentAmount'] is modified but $paymentAmount is sent back, the original value is sent back, not the modified one (assuming the register global variable are still ON).

So, either do (in the confirmation page):
$paymentAmount = ($_REQUEST['paymentAmount'] + $caltax);  


or change the URL string to contain the modified value.

Rgds,

Werner.
0
 

Author Comment

by:jackie777
ID: 24349579
Thanks,

I wasn't getting that they were two different variables, so that was very helpful.

How would I change the URL string to contain the modified value?
0
 
LVL 10

Accepted Solution

by:
NeoDiffusion earned 500 total points
ID: 24349676
Just do the change proposed above:
$paymentAmount = ($_REQUEST['paymentAmount'] + $caltax);  

replacing
$_REQUEST['paymentAmount'] = ($_REQUEST['paymentAmount'] + $caltax);              

Rgds,
Werner.
0
 

Author Closing Comment

by:jackie777
ID: 31579936
Thanks!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question