Jump to content

PayPal PHP Help.


Helljumper

Recommended Posts

Hello all.  I want to create a page in PHP that shows a basket of items currently selected by the user (a shopping cart) and then it allows the user to check out and send the payment to a PayPal address already set in the code.  After the payment is sent, I want an e-mail to automatically be sent to the user and also to the administrator, notifying that the order has been received (to the buyer) and that a new order has been placed (to the administrator).

Thanks,
  --  Mike
Link to comment
Share on other sites

I know you want it, but it has to do with creating it
Paypal instant notification system is what you are looking for, you can find out more at paypal's developer site.  You have to activate it, it's simple, just look at the documentation.  MAKE sure that the page that the payment notification system is going to IS NOT password protected, or carrying sessions, or it'll kill it midway, 6 hours of fighting with this has taught me that lesson, other than that it's pretty straight forward.
Link to comment
Share on other sites

I think I didn't even use it.
I logged into her paypal account, and went over and started making buttons,a fter some difficulties I tried another paypal system, that wasn't for me, so I used ipn, and I saw the manual on the website.  It was easy, just pass a few specific things into the form that you are sending through paypal, I wanted to use paypal's encrypted buttons, but it's such a low budget project, I don't give a shit.
Link to comment
Share on other sites

of course I can.  But I have to hurry I am working.

<p>$5.99(30 day plan)</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="ewkilgore@yahoo.com">
<input type="hidden" name="item_name" value="upgrade account 1 month(30 day) plan">
<input type="hidden" name="item_number" value="30">
<input type="hidden" name="amount" value="5.99">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="http://www.elostandfound.info/thankyou.php">
<input type="hidden" name="cancel_return" value="http://www.elostandfound.info/cancelpayment.php">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<p>$19.99(365 day plan)</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="ewkilgore@yahoo.com">
<input type="hidden" name="item_name" value="account upgrade 1 year(365 day) plan">
<input type="hidden" name="item_number" value="365">
<input type="hidden" name="amount" value="19.99">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="http://www.elostandfound.info/thankyou.php">
<input type="hidden" name="cancel_return" value="http://www.elostandfound.info/cancelpayment.php">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Ok these are my forms, you can just copy and paste these forms but you just have to change a few things.
Here is a cut down of the various fields and what you can change them with.
[code]<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
It has to go to that address, just set it there WITH the https  it also HAS to go through post method
<input type="hidden" name="cmd" value="_xclick">
This HAS to be _xclick
<input type="hidden" name="business" value="ewkilgore@yahoo.com">
Here you can simply change that email address to your paypal email address you are working with.
<input type="hidden" name="item_name" value="account upgrade 1 year(365 day) plan">
This is the item NAME, the actual name of the item
<input type="hidden" name="item_number" value="365">
This can be for an item number, OR some notes on the item, just to help you remember something
<input type="hidden" name="amount" value="19.99">
This is the price, whatever you want it to charge the person.
<input type="hidden" name="no_shipping" value="2">
leave this alone unless you are more advanced
<input type="hidden" name="no_note" value="1">
leave this alone
<input type="hidden" name="currency_code" value="USD">
leave this alone unless you are more advanced
<input type="hidden" name="bn" value="PP-BuyNowBF">
have no idea
<input type="hidden" name="return" value="http://www.elostandfound.info/thankyou.php">
this is the address that paypal will return the user to after they pay, just make it one of your pages, and leave a little thank you message or something should do.  this will be after they saw payment details so all you really have to have there is thank you, but you can turn that off if you want, it just brings them back to your site where you specify
<input type="hidden" name="cancel_return" value="http://www.elostandfound.info/cancelpayment.php">
this is where they go if they cancel during the middle of the payment, they go to your site where you specificy, if you don't want this you can just leave it off.
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">[/code]
add this one in there too somewhere
<input type="hidden" name="notify_return" value="http://www.elostandfound.info/recieve.php" / >
this is the most important line of code, the paypal system will send information to a script on this page, and take care of everything from there.  On your recieving script you have to have a minimum of standard, te hn you can do your database operations based on what you have.

[code]<?php
// 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'];
$connect = mysql_connect("localhost", "##33", "####");
$select = mysql_select_db("elostand_general");
if ($item_number == "30") {
$paydate = date("m/d/y");
$timeperiod = 30;
$paid = "yes";
$update = "UPDATE userinfo SET paid = '$paid', timeperiod = '$timeperiod', paypalid = '$payer_email', paydate = '$paydate' WHERE email = '$payer_email';";
mysql_query($update);
}
if ($item_number == "365") {
$paydate = date("m/d/y");
$timeperiod = 365;
$paid = "yes";
$update = "UPDATE userinfo SET paid = '$paid', timeperiod = '$timeperiod', paypalid = '$payer_email', paydate = '$paydate' WHERE email = '$payer_email';";
mysql_query($update);
}

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
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}

?>[/code]
Link to comment
Share on other sites

no return just returns them after they pay, You have to get it to send a token to your script if you want to play with the variables, just add
<input type="hidden" name="notify_synch" value="http://www.yourdomain.com/script.php" />
or something and it will send the information to your script there are things you HAVE to do, for it to work, so all of that script except my database calls are from paypal, that HAS to happen, you just put your db calls in there, how much php do you know??  The stuff get's pretty hairy in themiddle of it.
Link to comment
Share on other sites

I used to be amazing at PHP.  I haven't used it for months.  ~_~

After all of that is done, and it returns to my website, how are you saying that I will still have the variables?  Should I make the link to my site something like:

http://mydomain.ext/thankyou.php?get=<?= urlencode ('' . $buyerEmailVar . ',' . $itemTransID . '') ?>

So that when it goes to my site, a "Thank You" message is displayed, and in the code there would be:

<?php

$headers = "From: addr@domain.ext\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

$subject = 'Your order has been received.';

$get = $_GET['get'];
$get = urldecode ($get);
$stuff = explode (',', $get);
$buyerEmail = $stuff[0];
$transID = $stuff[1];

$body = '<b>Thank you for your order!</b><br /><br /><strong>Transaction ID:</strong> ' . $transID . '<br />To check the status of your order, go to the link below:<br /><a href="http://mydomain.ext/order.php?ID=' . md5 ($transID) . '">Order Status</a><br /><br /><small>MySite Staff</small>';

mail ($buyerEmail, $subject, $body, $headers);

?>
Link to comment
Share on other sites

no paypal automatically sends everything you need to do that, if you tell it to notify, the people never even go to that page, it just sends a token to the page, that activates the page, and handles things, I told you, you are getting into something pretty hairy, you might want to freshen up on php a bit before tackling this, it can get pretty rough, and I have to get back to concentrating on work soon.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.