View Full Version : Paypal...
Mr. Orange
03-02-2010, 02:35 PM
right, as you guys know.. theawesomelist.co.uk Isn't really going to plan :(
So, I've decided to make it free, stick like 2 adverts on it(one will be NT of course :D), and have a donation button, which people can use.
The plan is:
Whoever donates more, is higher up in the list.
Now, for everything to be automated, I need a way to tell how much someone has donated. And then of course just use
$result = mysql_query(" SELECT * FROM theawesomelist ORDER BY `num` DESC");
to list the names ordered by the highest number. :D
ok, so i'm creating a paypal button. and I came across this for 'advanced variables'
notify_url
The URL to which PayPal posts information about the transaction, in the form of Instant Payment Notification messages.
This is what I need? if so, how would I set it up so it will be able to insert data in to the database?
get the variable sent from paypal about how much was given to u and then put this into the table.
Mr. Orange
03-02-2010, 02:45 PM
get the variable sent from paypal about how much was given to u and then put this into the table.
I know... that's what i'm asking how to do... automated.
Aaron78
03-02-2010, 03:03 PM
So what're the donations for?
Kinda reminds me of this http://www.milliondollarhomepage.com/
Wish I'd thought of that lol
Mr. Orange
03-02-2010, 03:12 PM
So what're the donations for?
Kinda reminds me of this http://www.milliondollarhomepage.com/
Wish I'd thought of that lol
World Challenge Expedition to Nepal in 2011, I have to raise £3,295. and because i'm in a group of 5 people, that means we have to raise altogether £16,475
Oscar99
03-02-2010, 05:02 PM
i'm still in school with no job :( but if i get the chance, i might donate £10 or something.
Mr. Orange
03-02-2010, 05:18 PM
i'm still in school with no job :( but if i get the chance, i might donate £10 or something.
<3<3<3<3<3<3<3
Oscar99
03-02-2010, 05:37 PM
just depends like, because i have Clan servers to pay for & advertising.
Mr Grapes
03-02-2010, 05:59 PM
also don't use
select * from...
it's very inefficient, even for small tables and doesn't cope well when you add columns later and don't handle them in code. specify the actual columns you're interested in, even if it's only one
Mr. Orange
03-02-2010, 06:26 PM
also don't use
select * from...
it's very inefficient, even for small tables and doesn't cope well when you add columns later and don't handle them in code. specify the actual columns you're interested in, even if it's only one
ok cheers.
:D
I saw this IPN(Instant Payment Notification) on PayPal, and they give you this php script to use. Is there a way I can use this to put the amount paid into the database ?
<?php
error_reporting(E_ALL ^ E_NOTICE);
$email = $_GET['ipn_email'];
$header = "";
$emailtext = "";
// Read the post from PayPal and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc'))
{ $get_magic_quotes_exits = true;}
foreach ($_POST as $key => $value)
// Handle escape characters, which depends on setting of magic quotes
{ if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1)
{ $value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
// Post back to PayPal 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);
// Process validation from PayPal
if (!$fp) { // HTTP ERROR
} else {
// NO HTTP ERROR
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// TODO:
// 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
// If 'VERIFIED', send an email of IPN variables and values to the
// specified email address
foreach ($_POST as $key => $value){
$emailtext .= $key . " = " .$value ."\n\n";
}
mail($email, "Live-VERIFIED IPN", $emailtext . "\n\n" . $req);
} else if (strcmp ($res, "INVALID") == 0) {
// If 'INVALID', send an email. TODO: Log for manual investigation.
foreach ($_POST as $key => $value){
$emailtext .= $key . " = " .$value ."\n\n";
}
mail($email, "Live-INVALID IPN", $emailtext . "\n\n" . $req);
}
}
fclose ($fp);
?>
Edit:
I guess we'll need the
<?php
$con = mysql_connect
in there... somewhere..
jonbanjo
04-02-2010, 08:18 AM
As no one else has answered...
At a very quick look, it seems it might be possible. That appears to be what Paypal call a listener and is a script that paypal posts to you on your website. Their guide gives this as a sample message.
mc_gross=19.95&protection_eligibility=Eligible&address_status=confirmed&pay
er_id=LPLWNMTBWMFAY&tax=0.00&address_street=1+Main+St&payment_date=20%3A12%
3A59+Jan+13%2C+2009+PST&payment_status=Completed&charset=windows-
1252&address_zip=95131&first_name=Test&mc_fee=0.88&address_country_code=US&
address_name=Test+User¬ify_version=2.6&custom=&payer_status=verified&add
ress_country=United+States&address_city=San+Jose&quantity=1&verify_sign=Atk
OfCXbDm2hu0ZELryHFjY-Vb7PAUvS6nMXgysbElEn9v-
1XcmSoGtf&payer_email=gpmac_1231902590_per%40paypal.com&txn_id=61E67681CH32
38416&payment_type=instant&last_name=User&address_state=CA&receiver_email=g
pmac_1231902686_biz%40paypal.com&payment_fee=0.88&receiver_id=S8XGHLYDW9T3S
&txn_type=express_checkout&item_name=&mc_currency=USD&item_number=&residenc
e_country=US&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_g
ross=19.95&shipping=0.00
I think that means there should be sufficient in your $_POST array to know what the payment is about.
I think you will need a thorough read through the pdf guide on this page https://www.paypal.com/ipn before thinking about your SQL.
Mr. Orange
10-02-2010, 10:46 PM
ok, sorry for the really really late reply. I really appreciate your help.
as I understand it.
IPN is where Paypal sends information to the server. So maybe not the right way?
I've been looking into great depth at these button's variables.
rm
Optional
Return method. The FORM METHOD used to send data to the URL specified by the return variable after payment completion. Allowable values:
0 – all shopping cart transactions use the GET method
1 – the payer’s browser is redirected to the return URL by the GET method, and no transaction variables are sent
2 – the payer’s browser is redirected to the return URL by the POST method, and all transaction variables are also posted
The default is 0.
NOTE: The rm variable takes effect only if the return variable is also set
I have a feeling, that this set at 2. is what I need... Is it?
Mr. Orange
10-02-2010, 11:15 PM
I DID IT!!!! (with the help of Rhys)
<?php
// PHP 4.1
// 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 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);
$payment_amount = $_POST['mc_gross'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
?>
<FORM ACTION="submit.php" METHOD="POST" NAME="TheAwesomeList">
<TABLE>
<TR>
<TD class="Text">Name</TD>
<TD> <input type=text name="name"></TD>
</TR>
<TR>
<TD><input type="submit" value="Submit" name="Submit"></TD>
</TR>
</TABLE>
<input type="hidden" value="<? echo $payment_amount;?>" name="amount">
</FORM>
<?
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
} ?>
I can probably neaten it up a lot. will do tomorrow maybe :D
theawesomelist.co.uk
It's free to get on, costs a bit to get to the top, I'll just neaten it up, should all be done by 00:30am
took a while lolol.
Kinda just had to find the right variables and all that jazz
jonbanjo
11-02-2010, 11:15 AM
It may sound empty but good for you. It sounds nothing but I believe you and Rhys as a clever pair.. Please, I hope, take as meant by me.
Mr. Orange
11-02-2010, 07:59 PM
It may sound empty but good for you. It sounds nothing but I believe you and Rhys as a clever pair.. Please, I hope, take as meant by me.
You've now confused Rhys and me.. :confused: :D
A Ginger Sheep
11-02-2010, 08:03 PM
what is the actual point of this website? not the aim but the whole point as in why would i give you money on it?
Mr. Orange
11-02-2010, 08:28 PM
what is the actual point of this website? not the aim but the whole point as in why would i give you money on it?
out of noble heart :D, read the World Challenge bit. and hopefully, eventually the site gets like popular, (It's 5th on google search for 'The Awesome List') so hopefully if people really want to be higher than other people, like their friends etc. in the list, they can be :)
Ian.H
11-02-2010, 10:05 PM
[ snip ]
I can probably neaten it up a lot. will do tomorrow maybe :D
Cool that you got it sorted.
If you want to tidy it up, try looking into curl and PHP's curl functions :)
Regards,
Ian
jonbanjo
12-02-2010, 08:09 AM
You've now confused Rhys and me.. :confused: :D
OK I must have worded it really badly but was only trying to give you some respect.
Re the problem btw, I must admit to still being confused. I'd maybe wronglr imagine sort of league table.
member
memberid
username
realname
transaction
transactionid
memberid
dated
amount
Awsomenes cacl as say/
SELECT username, sum(ammount) as awsomeness from member, transaction
Where member.memberid = transaction.memberid
GROUP BY username
ORDER BY donated desc
I'm not seeing how to tie it in with a member.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.