Reputation: 3467
I am creating a website, where I will sell computer and calculator programs. When the "buy" button is pressed. I would like the user to be directed to Paypal (whether they stay on the website or not). After they pay, the user would be brought back to my website, and the program would automatically download.
How can i do this to ensure:
Thank you very much in advance!
Upvotes: 3
Views: 3677
Reputation: 2425
Paypal PDT (redirecting after payment) and IPN (behind the scenes) is exactly what you are after.
Check this: https://www.paypal.com/cgi-bin/webscr?cmd=p/xcl/rec/pdt-intro-outside
Here is sample code for the script to get you started instantly:
https://www.paypal.com/us/cgi-bin/?cmd=p/xcl/rec/pdt-code-outside
Some additional Tips for security: Verify amount, currency and product-id with your database's data to make the download available. Open a paypal sandbox account.
To don't reveal the download location: Use the order-id verified by pdt as a unique download-identifier. You have to use a script like this: redirect the user in the pdt-script here or include it in pdt if payment verrified:
<?
$orderid = $_GET['orderid'];
$productid = $_GET['productid'];
$time = $_GET['time_from_paypal']; // when the purchase was made
$fn = "files/".$productid.".mp3";
($time =here your conditional)?$do==true:$do==false;
if ($do==true){
header('Content-Disposition: attachment; filename=' . basename($fn));
readfile($fn);
} else {.....
?>
the part "here your conditional" can be anything. you could restrict them to download within the following x seconds after the payment was made. usually the processing from paypal takes a maximum of 20 seconds. so if you want the download to be made only once check if the payment_time and the actual time divergent less than 30 seconds. because of the redirect the user gets the download instantly after payment is veriffied. wrote but not tested
Upvotes: 4