Jump to content


Photo

PayPal PHP Help.


  • Please log in to reply
11 replies to this topic

#1 Helljumper

Helljumper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 August 2006 - 03:11 PM

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

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 04 August 2006 - 03:14 PM

Is that all you want?..lol. I would recomend a thrid party script like OS commerce or Cube Cart. At least until you are more familiar with php.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 04 August 2006 - 03:14 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Helljumper

Helljumper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 August 2006 - 03:16 PM

Thank you for your help (except for the first poster who's a troll :-D).

What is the PayPal developer site?  dev.paypal.com or something?

#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 04 August 2006 - 03:18 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 Helljumper

Helljumper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 August 2006 - 03:20 PM

Sorry, I really suck with all this IPN stuff.  >_>

Can you direct me to a link to the guide on the IPN stuff?  Or can you post a code example that you use maybe?

#7 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 04 August 2006 - 03:29 PM

This is the one that I use, it's easy and you don't have to change much to test it.

http://www.belahost.com/pp/

click download paypal.php and you are all set

-Chris

#8 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 04 August 2006 - 03:31 PM

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

<p>$5.99(30 day plan)</p>
<form action="https://www.paypal.c...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.elostandf.../thankyou.php">
<input type="hidden" name="cancel_return" value="http://www.elostandf...elpayment.php">
<input type="image" src="https://www.paypal.c...lick-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.c.../scr/pixel.gif" width="1" height="1">
</form>
<p>$19.99(365 day plan)</p>
<form action="https://www.paypal.c...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.elostandf.../thankyou.php">
<input type="hidden" name="cancel_return" value="http://www.elostandf...elpayment.php">
<input type="image" src="https://www.paypal.c...lick-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.c.../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.
<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">
add this one in there too somewhere
<input type="hidden" name="notify_return" value="http://www.elostandf...fo/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.

<?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);
}

?>

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#9 Helljumper

Helljumper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 August 2006 - 03:41 PM

Alright.  So I would have a list of items and next to each an image with that form.  Alright.

And the PHP code posted would go on the page defined in <input type="hidden" name="return" value="xxx" />?

#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 04 August 2006 - 03:43 PM

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.yourdomai...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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#11 Helljumper

Helljumper
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 August 2006 - 03:58 PM

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/...you.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);

?>

#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 04 August 2006 - 04:11 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users