View Full Version : Communicating with PayPal to update database
JasonDFR
09-25-2008, 02:51 PM
I need paypal to verify that a transaction has successfully completed, then communicate with a mysql database in order to update an inventory.
Has anyone had experience doing something like this or know of online resources with information?
I am using PHP and MySQL. A PHP script will send a user to Paypal in order to complete a transaction. I don't want to update my database until I am sure that the transaction has completed.
I need to receive a conformation from Paypal and then update the database.
I CAN NOT do this manually. It needs to be automatic.
Thanks in advance! These forums are the best!
gpigate
09-29-2008, 11:03 PM
I do that same thing using Paypal IPN. You have to turn on paypal ipn in your paypal preferences. Once paypal has the money it sends you a transaction back to your server. In the script that accepts the transaction you can have it update your tables.
if you need more info let me know. First thing I would do would be to look into the paypal ipn interface
JasonDFR
09-30-2008, 06:57 AM
Thanks a lot for your reply!
JasonDFR
10-08-2008, 06:30 PM
PayPal IPN is the way to go. It works well once you get it set up right. Through trial and error I got mine working well. If anyone needs a hand with this issue, feel free to contact me and I'll help out.
Also, a big thank you to Greg for replying to my post and exchanging emails with me while I worked through this; Thanks Greg!
Jason
gpigate
10-08-2008, 08:09 PM
Glad you got it working.
wangjiahua
10-16-2008, 02:23 AM
Cindy, is this the thing you were looking for?
www.liangdianup.com/computeraccessories_1.htm
It's on the list of computer accessories and parts. They have the DVI video thing to convert that jap monitor to work with your other computer. Just about any other kind of wire adaptor, usb connectors, monitor extension wires, ps2 extention wires, and all kinds of female and male swap connectors and things that I think would help your shop. If that above link don't work then goto www.lducompany.com and click on computer accessories. Let me know if that is what you need and give me your email address again.
I
:D
shotta
11-12-2008, 02:23 AM
I'm trying to get this to work for a long time and have been having trouble. Im new to this and programming your help will be surely be appreciated. After leaving paypal page want to go back to the website and update the database.
sambennet
01-02-2009, 12:36 PM
Hello,
I want to create a small e-business interface on my webpage and would like to use Paypal for the payment. I use PHP/MySQL (but I am no specialist at all) and I have already created my "Buy Now" button which transfers the information to paypal. But it remains to integrate the Paypal payment confirmation which is supposed to be sent back and that will automatically update my database.
I think this is exactly what you were looking for when you wrote this posting...
And since I am newbie with all that I would be very interested to learn more about the way you proceeded. I have found the piece of PHP code given as example on the IPN page of Paypal, but I don't know where I should put that file, and how to verify the different variables.
Also I would like to test the process but I haven't used the paypal sandbox so far. Did you use it ?
And I wonder how you avoid that 2 people start "buying" the same item, until the sale has not been confirmed (i.e. until the database has not been updated)...
Would you be so kind to help me setting this up ?
Thanks a lot for your help, and Happy New Year!
Sincerely yours,
Chris
P.S: By the way I saw you were located in France ? If you are French, on peut discuter aussi en Francais aussi si vous preferez :-)
JasonDFR
01-03-2009, 09:34 AM
Bonjour,
Je suis Americain, mais j'habite en France. Je parle un peu la francais.
I modified the PayPal PHP Instant Payment Notification script and got it to do what I needed.
I will edit it a bit and put a bunch of comments in and then post it for you. I'll try to get it up by tonight.
It took a little time to get it working, but I think it was because I was a PHP novice. Once you understand the basic idea of what the script is doing, it isn't that hard to make it work.
The sandbox is a bit tricky to get working too. But it does work and you should try to use it.
To use the sandbox, you need to change this line in the IPN script:
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
to:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
The following two uri are on the paypal site in the instructions for the IPN script to use in place of the two I posted above (https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_html_instantpaymentnotif), but I never used them:
https://www.paypal.com/cgi-bin/webscr
https://www.sandbox.paypal.com/cgi-bin/webscr
JasonDFR
01-03-2009, 06:17 PM
Check out the attached files. You'll definitely need some basic knowledge of PHP and MySQL and a basic understanding of how PayPal IPN works.
The attached zip contains two files. paypal_ipn.php and paypal_ipn.sql .
paypal_ipn.php is the instant notification script you'll need to put into a web accessible directory and inform PayPal of it's location.
paypal_ipn.sql contains the sql statements that can be used to create the standard database tables to be used with the paypal_ipn.php script . These came directly from the PayPal website.
Read all the comments I made on paypal_ipn.php .
If you have any questions after reading through the script and the documentation on PayPal's site, let me know.
I am fairly certain that the script works, but it does need modification to meet your needs. Notably you'll enter your database connection information and email address(es). I have tried to comment the script heavily. You should be able to tell where edits need to occur.
If anyone finds any problems with the script, please let me know, or correct them and repost. If you have any ideas of how to make it better or easier to understand, please share them!
Bonne chance !
Jason
Ireland
03-31-2009, 05:03 PM
The attached zip contains two files. paypal_ipn.php and paypal_ipn.sql .
Hi JasonDFR,
I have a website that sells some products and I want to change a field in the database from "Sale" to "Sold" when payment has been made through paypal.
Do you think that the files above will suit me as to what I require. i have an okay knowledge php so hopefully I can get this to work.
Thanks,
John.
borris83
04-08-2009, 11:59 AM
Hi... Glad to find someone who knows well about paypal IPN...
Initially I was using a script for processing paypal ipn which did not work, and I modified a little bit but don't know how to test it..
I signed up for paypal sandbox to test my script but i didn't know what to URL i need to post the variables back...
I am in a hurry to go and just saw this thread in the last minute.. Will post much details later today or tomorrow...Jason, pls help
JasonDFR
04-08-2009, 12:07 PM
I wouldn't say I know it well, but I was able to get it to work. The sandbox works as well, though I remember it being a little complicated to get set up. I haven't used this stuff for about 6 months, so I couldn't tell you off the top of my head how to work it out, but if you get stuck somewhere I'm happy to try to help out.
If I remember correctly,setting the sandbox correctly and changing the url in the pay_pal ipn script to reflect the sandbox's url, and correctly identiying the location of your paypal_ipn script when setting it up for your account, are the biggest things.
You should also set up the default paypal mysql tables in your database,They posted the SQL to get it set up on thieir site somewhere, and use that at least while your testing.
borris83
04-08-2009, 01:56 PM
Hi I have two files, config.php and protect.php... config.php simply has variable assignments.
protect.php has the actual code to receive the POST variables from paypal, send it back with the required appended text and check if the reply is INVALID or VERIFIED. If it is verified it will send an email to the customer with the download link for the product....
Also, I have set the page protect.php as the page the customer's will be redirected to after a successful check out. If the customer gets to the page this way, then the page will simply inform the payment is successful and download link has been emailed..
I have also enabled IPN in my paypal profile and entered the path for protect.php.... I now want to check it will work or not:
This is the contents of my config.php where I have replaced the actual details with www.example.com:
<?php
$website = "http://www.example.com";
$msg = "Thanks for your purchase at www.example.com";
$email = "contact@example.com";
$yourname = "Example.com Sales";
$product = "Example product";
$paypal = "paypal@example.com";
$amount = 14.99;
$download = "http://www.example.com/files/example.pdf";
global $website, $msg, $email, $yourname, $product, $paypal, $amount, $download;
?>
Here is the code inside protect.php:
<?
require("config.php");
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
//These are all of the variables that paypal sends us:
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$invoice = $_POST['invoice'];
$first_name = $_POST['first_name'];
<html>
<head>
<title><?=$msg?></title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
if (!$fp) {
echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> $errstr ($errno)<br><br>You may want to refresh your browser in a couple of minutes.</font></p>";
$email_msg = "There has been an error on your Paypal Download Protection script: $errstr ($errno)";
mail("$email", "Invalid Purchase", $email_msg, "From: $email");
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($payment_status != "Completed") {
echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> The status of the payment is not yet completed.</font></p>";
} elseif ($receiver_email != $paypal) {
echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> You did not purchase this item from the correct seller.</font></p>";
} elseif ($payment_gross == $amount) {
echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> You have no paid the full amount.</font></p>";
} else {
$headers = "From: $yourname <$email>\n";
$headers .= "X-Sender: <$email>\n";
$headers .= "X-Mailer: PHP\n";
$headers .= "X-Priority: 1\n";
$headers .= "Return-Path: <$email>\n";
$email_send_msg = "
Thank you for your purchase, $first_name
To download your $product, please go to: $download
Please feel free to email us at: $email
$yourname
$website
$email
";
mail($payer_email, $msg, $email_send_msg, $headers);
?>
<p align=center>The web site address containing the download link has been sent to <?=$payer_email?>
<br><br>If you do not receive an email from us within 24 hours, please email <?=$email?>
<br><br>Thank you, <?=$first_name?></p>
<?
// And.. that's it!
}
} else if (strcmp ($res, "INVALID") == 0) {
echo "<p align='center'><font face='Verdana' size=2 color='#FF0000'><b>Error:</b> You did not purchase this item from the correct seller.</font></p>";
$email_msg = "There has been an invalid request from your Paypal Download Protection script. You may want to investiage this manually from your paypal account.";
mail("$email", "Invalid Purchase", $email_msg, "From: $email");
$success = true;
}
}
fclose ($fp);
}
?>
<p><br>
</center>
</BODY>
</HTML>
Earlier I tried to use this with real time payments but it didn't work but I noticed then that in protect.php $HTTP_POST_VARS was used instead of $_POST.. So I changed it.. But haven't tested with this edited code.
borris83
04-09-2009, 01:18 PM
can anyone please reply?
JasonDFR
04-09-2009, 02:55 PM
What isn't working exactly? Where do you think your error is at? Did you start out with the files I had attached in the .zip ?
sniperman
05-11-2010, 04:27 PM
This seems like the forum to ask my PayPal integration question.
Currently I have a registration form with a couple of fields. The initial intention once a user pressed the submit button was to
1) validate the form
2) make the form action open a PHP file to send me an email with the form details
I have now integrated the PayPal HTML code into the registration and replaced my submit button with theirs.
The problem is that the form action has now changed to take me directly to PayPal, which defeats the purpose of collected information on the customer.
I am thinking, is it possible that I can do this once a user clicks the submit button?
1) validate the form
2) make the form action open a PHP file
3) Have PHP file send me an email with the form details
4) Then have PHP file redirect me to PayPal for payments
I am sure the PayPal form code fields can be embedded in PHP and used as a secondary action once the email action has been completed.
I just need some validation from senior coders.
Thanks in advance.
gpigate
05-11-2010, 05:14 PM
the only way I think that could be done is to separate the process out. so you would have to have form validated on page1.php that page1.php does your php file and email etc, then redirects to page2.php which has your paypal button on it.
the other option would be to use paypal ipn (instant payment notification) which will call a url on your server, passing it all of the information regarding the transaction. In that code, do what you need with the file etc and email. You may find that that ipn trans has the info in it you are looking for.
I tried a long time ago to update an order status when the paypal button was clicked and never was successful. Once you put that button on a page, its action is going to paypal
sniperman
05-11-2010, 11:43 PM
i've already taken the code from PayPal's form and wrapped the form around my input tags.
With the form action I've used whatever action PayPal gave. And it sends you to their servers you're right.
But I'm sure PHP could serve me better if I redirected the action to a PHP file (like ASP) and had it perform some functions (and keep the PayPal variables) and then send those in a URL query for example, via PHP, to PayPal servers.
Lots of sites I've come across have a similar form integration feature. I was just curious on the method so I could get a heads up before I made any attempts today.
Will keep you all posted.
aneesahmad
02-13-2011, 12:01 PM
PayPal IPN is the way to go. It works well once you get it set up right. Through trial and error I got mine working well. If anyone needs a hand with this issue, feel free to contact me and I'll help out.
Also, a big thank you to Greg for replying to my post and exchanging emails with me while I worked through this; Thanks Greg!
Jason
Hi, I am trying out to setup paypal ipn, but facing issue, my database is not updating, got script from paypal.com/ipn website.. help please
aneesahmad
02-13-2011, 12:04 PM
I am also trying to setup paypal ipn... but its not updating the database, got ipn script form paypal.com/ipn php script.. can you help me.
anees_psh@hotmail.com
djr33
02-13-2011, 06:03 PM
This forum is meant for public discussions. If you want help, post the information here so that others can help you.
kurian_86
04-25-2011, 01:26 PM
Hi Jason,
I have some questions , hope you will figured out for me, I shall be humbly thankful to you.
1.How can I turned on PAY PAL IPN ?
2.How can I inform pay pal of paypal_ipn.php location?
3.Can I use return and notify_url both at the same time?
4.What should I written in both of these url links?
Thanks and Regards
bftrs2
06-29-2011, 03:34 PM
Thanks for posting this code. I'm working on a project to set up online registration with paypal payment so IPN is a must. I'm totally new at this and have found the paypal documentation a bit confusing.
I've run in to a glitch though. When I set everything up in the sandbox and run a test IPN from the paypal sandbox IPN simulator it works perfectly. However, when the IPN is run off the submit button of my form it retries several times before failing. In the sandbox seller account I can't seem to find any more information as to why it failed. Do you have any suggestions on how I might troubleshoot this?
This has been frustrating me for several days. Thanks for any suggestions!
jscheuer1
08-11-2011, 08:07 AM
I just did a search of this thread for ssl and https - what you need to do this sort of communication.
I don't know if this would solve anyone's issues here but without a Secure Socket Layer that confers an https connection, PayPal will send little if anything back to the domain initiating the payment.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.