sois;10897556 wrote:Hello All,
I am working on a (hopefully) simple PayPal integration project. I would like to build a form on my site for team registration. I would like the user to pay the registration fee through PayPal.
I guess what it needs to do is allow payment to PayPal and then verify on my site (I guess using some POST data?) that the user paid the fee.
Then from there I guess they can choose to renew or create a new team. I figure this last step is easy. Does anyone has a good PayPal tutorial for this? This won't be very complex. No shopping cart or varying amounts. Just an option to pay the fee and if the fee is paid, allow team renewal/creation.
Thanks PHPB!
EDIT: I found a somewhat good solution in the PaPal "Buy Now" buttons, I am just wondering now to verify the data on my own site.
Here's what I would suggest if you can build a small database
Build the database with the team info - you really just need a username, email, password, invoice number (any unique number), and a Paypal field (PIAD or NOTPAID).
Create a form for users to input their info into the database. At this point make your PayPal field as NOTPAID.
For instance you have John, john@email.com, password, 12345(invoice number), NOTPAID just 5 fields in your database.
Second step is create a Paypal form and pass it the invoice number
Example form
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_ext-enter" />
<input type="hidden" name="redirect_cmd" value="_xclick" />
<input type="hidden" name="business" value="your_email_adress" />
<input type="hidden" name="item_name" value="any_name" />
<?php echo "<input type=\"hidden\" name=\"invoice\"value=\"$invoice\"><br>\n"; ?>
<input type="hidden" name="amount" value="10.00" />
<input type="hidden" name="notify_url" value="http://URL to your paypal notification_page/ppnotify.php" />
<input type="hidden" name="no_shipping" value="1" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="return" value="http://www.your_thank_you_page.php" />
<input type="hidden" name="currency_code" value="USD" />
<input name="submit" type="image" width="268" height="37" src="images/make_payment.gif" alt="Make payments with PayPal" border="0" />
<input type="hidden" name="add" value="1" />
</form>
Third step, read about PayPal's Instant Payment Notification. Basically here's what happens. A person makes a Paypal transaction, the transaction includes your invoice number, after the transaction PayPal sends a message to your "PayPal notification page" - we used the page ppnotify.php in the example above. When you get the notification from PayPal of a successful transaction you update your database using the invoice number. In our case we simply update the PayPal field in our database to say PAID .
Here is an example ppnotify.php page
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$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);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$invoicepp = $_POST['invoice']; // This is really all we care about
$quantity = $_POST['quantity'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
// Here we write code to update the PayPal field in the database of the person with this invoice number
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}