Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Holding Data while away from the site

Status
Not open for further replies.

Seecke

IS-IT--Management
Aug 23, 2003
68
US
I have form data that I need to hold on to while the user is sent to the paypal site to process a payment then when the payment is excepted the user is returned to a "thank you" page that dumps the data into a database. IF the payment is declined or canceled by the user, then he/she user is sent to another page that that clears the data and reports that the payment was declined or the process was canceled buy the user.

New to this PHP stuff...

Thanks in advance!
 
The question is: What is the best way to do this?
 
use sessions. make sure that you provide paypal the relevant id to return the user to the right session.
 
do I have to declare each variable as its own session and also what are you meaning by the relevant ID to paypal?
 
you declare session variables like this

Code:
session_start();
$_SESSION['myvar'] = 'some data';

i have not looked at the paypal specification for some time but I believe that you can provide a url to which paypal sends the customer after the transaction is finished. that url needs to be able to tell your server which customer the request relates to. you can do this via the session_id or whatever other unique information you want. which is best depends on your business choices. typically I would use a unique id that is associated with the basket payment transaction.

and although I said about that you can/should use session storage to save data between visits, sometimes it is better to store them discretely from the session store so that the garbage collection routines don't screw with them.
 
OK... let me get this straight... I have a form with several user entry points... each point now MUST be a session variable so... IF I have 12 items in the form and I need those items when I get back from paypal (Yes I can tell paypal where to send the user after processing),

i.e.

session_start();
$_SESSION['myvar1'] = 'form data1';
$_SESSION['myvar2'] = 'form data2';
$_SESSION['myvar3'] = 'form data3';
$_SESSION['myvar4'] = 'form data4';
$_SESSION['myvar5'] = 'form data5';
$_SESSION['myvar6'] = 'form data6';
$_SESSION['myvar7'] = 'form data7';

etc... etc... until ALL of the input fields are accounted for.

Then when I get back to the site AFTER paypal, I then call those session variables individually so that I can place that data into the database?

 
Ideally you should be using Pay Pal's "Instant Payment Notification (IPN)". Basically you create a script which Pay Pal will call once the user has finished paying. The script will be able to check whether or not the user has paid etc, and perform any other functions you require.

However, this would mean you can't use sessions to store data, as Pay Pal can't access the users session data. Instead you would save the data to a database, and the IPN can process it after the transaction.

If you do want to go the sessions route, i'm unsure if Pay Pal is reliable at redirecting the user back to your website. There is probably an auto-redirect option but I have only ever seen a link which the user must click to return at the end of the transaction, in which case you would have to rely on the user to click this link. Even if there is an auto-redirect option, the user may close the webpage before your script has time to process.

I strongly suggest looking into Pay Pal's IPN.

Chris

 
Sorry,

You could still use a session to store data if you pass the driver/id to Pay Pal etc.

I'm just suggesting that Pay Pal's IPN is the modern standard way to perform your task.

Chris
 
OK, I got the paypal IPN thing to work in the 'sandbox'... sorta... or at least it passes the test in sandbox.

I was hoping that the code
Code:
$email = $_GET['ipn_email'];
would actually send me an email when I passed the email address to the handler via the get statement...

(i.e. http"//someURL/paypalpage.php?me@somesite.whatever)

but no go... I never received an email. Once I am sure that works then I will try and finish this off by taking the data obtained prior to the paypal process and dump it to the dB. (Only if the payment is made though)

ACCCKKKKKKKKKK Would love some in depth help if anyone would care to share.

Thanks again!
Steve
 
get in touch with me via my tektips handle at apple's mobile me domain. i can help offline and then we can post back the highspots in the forum for others to learn from.

the reason for not doing it in-forum is that it is likely that the code snips will grow very long.
 
Great! Thanks! The email was sent from the Google domain preceded by half of my handle, punctuation and 620. Maybe we could do all the stuff in a shared doc for easier posting when ready.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top