[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 06-24-2006, 12:50 PM   #1 (permalink)
NamePros Member
 
Join Date: Oct 2005
Posts: 38
9.80 NP$ (Donate)

Scott2503 is an unknown quantity at this point


PHP PayPal IPN

I am trying to make a basic PHP PayPal IPN and when I say basic I mean really basic. I have tried everything and can't get anything to work... I am just trying to check if it is verified and it can't even do that. I am using the example with something I added:

PHP Code:
// 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.eliteweaver.co.uk', 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'];

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

// it worked
mail("email@domain.com", "It worked", "The IPN worked");
}
else if (
strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
I am using http://www.eliteweaver.co.uk because it tests IPN scripts without actually buying something on PayPal so that is why you see www.eliteweaver.co.uk instead of www.paypal.com

Any reasons why this doesn't work?
Scott2503 is offline  
Old 06-24-2006, 01:55 PM   #2 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
alot of those ipn testin g sites are very selective on when they work. your best bet would just do a test transction on paypal and the just refund the payment.
Peter is offline  
Old 06-24-2006, 02:04 PM   #3 (permalink)
NamePros Member
 
Join Date: Oct 2005
Posts: 38
9.80 NP$ (Donate)

Scott2503 is an unknown quantity at this point


Hmm... I was wondering if it might be the actual site I was using to test it. Thanks I'll try an actual purchse.
Scott2503 is offline  
Old 06-24-2006, 03:03 PM   #4 (permalink)
NamePros Regular
 
Join Date: Mar 2005
Posts: 412
162.25 NP$ (Donate)

paaaaaaaaaa is a jewel in the roughpaaaaaaaaaa is a jewel in the roughpaaaaaaaaaa is a jewel in the rough


test it using paypal sanbox https://www.sandbox.paypal.com/

It is a copy of paypal but used for testing non real transactions you can set up as many accounts as possible and transfer any amount of cash between them.

This is what i used to test my IPN code. I remember when I was working on it the paypal IPN system wasn't working on their side for quite a while. I also found eliteweaver to fail testing.
__________________
Please add to my rep points if i was helpful. Thanks.

Ripe Website Manager - Steve Parish
paaaaaaaaaa is offline  
Old 06-24-2006, 03:15 PM   #5 (permalink)
Senior Member
 
RickM's Avatar
 
Join Date: Sep 2005
Location: Herts, UK
Posts: 3,769
62.06 NP$ (Donate)

RickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant futureRickM has a brilliant future

Cancer Survivorship Save The Children Save The Children Cancer Animal Cruelty Child Abuse Cancer Survivorship 9/11/01 :: Never Forget Animal Cruelty Child Abuse Animal Rescue Animal Cruelty Protect Our Planet Protect Our Planet Protect Our Planet Animal Cruelty Save a Life
Yes, sandbox is the best option...it gives you a virtual credit card number just for the sandbox, you can then run tests.

It may also be an idea to checkout paypaldev.com
__________________
I am no longer a NP moderator -- please do not PM me with moderation requests!

~ VPSSpeed.com - Unmanaged VPS Hosting from $9.95
Get a FREE Mach-1 VPS PLAN with any order - Use the coupon FREEWHIZ
RickM is offline  
Old 06-24-2006, 03:23 PM   #6 (permalink)
NamePros Member
 
Join Date: Oct 2005
Posts: 38
9.80 NP$ (Donate)

Scott2503 is an unknown quantity at this point


Ok I set up the sandbox but how do I add the imaginary funds?
Scott2503 is offline  
Old 06-24-2006, 04:22 PM   #7 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
the problem with the sandbox is that if I remember correctly the server that is doing the testing also needs to be logged onto the sandbox.
Peter is offline  
Old 06-24-2006, 08:22 PM   #8 (permalink)
I'll do it

Technical Services

 
-Nick-'s Avatar
 
Join Date: Dec 2005
Location: India
Posts: 6,434
5,169.80 NP$ (Donate)

-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute

Adoption
Hey guys. Here is the code that I use normally for the setup.

checkout.php
PHP Code:
<?php
include("Includes/functions.php");
$dbc = dbconnect();
$pageid = $QUERY_STRING;
if (
$QUERY_STRING == "")
{
$pageid = 1;
}
$arr = explode("x", $pageid);
$hid = $arr[0];
$catid = $arr[1];
$site_url = "http://www.hehehahahaha.com";
$order_total = 10;
$order_total = number_format($order_total, 2, ".", ",");
$order_id = "$hid" . "x" . "$catid";

$r = mysql_query("Select * from tblhost WHERE HID = '$hid'");
while (
$row = mysql_fetch_array ( $r ) )
{
$my_sFirstName = $row['User'];
$my_sLastName = $row['User'];
$hemail = $row['Email'];
$hname = $row['Host'];
}
$my_clientEmail = $hemail;
$business_paypal = "xxxxx@xxxxx.com";
$currency_id = "USD";
$sdate = time();
$r = mysql_query("INSERT INTO tblsponser (HID, CID, Sdate) VALUES ('$hid', '$catid', '$sdate')");


//redirect to paypal
header("location:https://www.paypal.com/xclick?business=$business_paypal&item_name=$hname$order_id&first_name=$my_sFirstName&last_name=$my_sLastName&email=$my_clientEmail&item_number=1&custom=$hid&amount=$order_total&currency_code=$currency_id&notify_url=$site_url/notify.php&return=$site_url/thankyou.php");
?>

Now for the IPN script:
notify.php
PHP Code:
<?php

    
// Assign posted variables to local variables
    
$receiver_email = $_POST['receiver_email'];
    
$payer_email = $_POST['payer_email'];
    
$payer_status = $_POST['payer_status'];
    
$payment_gross = $_POST['payment_gross'];
    
$payment_fee = $_POST['payment_fee'];
    
$payment_date = $_POST['payment_date'];
    
$payment_type = $_POST['payment_type'];
    
$payment_status = $_POST['payment_status'];
    
$pending_reason = $_POST['pending_reason'];
    
$txn_id = $_POST['txn_id'];
    
$txn_type = $_POST['txn_type'];
    
    
$custom = $_POST['custom'];

    if (
$_REQUEST['payment_status'] == "Completed" || $_REQUEST['payment_status'] == "Pending") {

//Query for the payment recieved

include("Includes/functions.php");

$dbc = dbconnect();

$hid = $custom;



$r = mysql_query("Update tblsponser SET Payment = 'Y' WHERE HID = '$hid'");

////////////////////////////////////////


}
?>
I hope this helps.
-Nick- is offline  
Old 06-25-2006, 05:28 PM   #9 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
For the sandbox on Paypal, is the money being sent to a fake account on the sandbox from another fake account on the sandbox?

Also, how long should it take for the verification email to come for the sandbox account..

edit: Why do they send the emails to that email buttons? I got lucky I found it. -_-

edit2: Never mind all of that. ^

But I still can't get it to work.

index.php
Code:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="rocky@sanchez.com">
<input type="hidden" name="item_name" value="something">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="10.00">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="return" value="http://css.la/ipn/return.php">
<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="image" src="https://www.sandbox.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
return.php
PHP 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.sandbox.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'];

if (!
$fp) {
    echo
'HTTP ERROR';
} else {
    
fputs ($fp, $header . $req);
    while (!
feof($fp)) {
        
$res = fgets ($fp, 1024);
        if (
strcmp ($res, "VERIFIED") == 0) {
            echo
'it worked';
        } else if (
strcmp ($res, "INVALID") == 0) {
            echo
'log for manual investigation';
        }
    }
    
fclose ($fp);
}

?>

Last edited by Dan Friedman; 06-25-2006 at 07:38 PM.
Dan is offline  
Old 06-25-2006, 08:33 PM   #10 (permalink)
I'll do it

Technical Services

 
-Nick-'s Avatar
 
Join Date: Dec 2005
Location: India
Posts: 6,434
5,169.80 NP$ (Donate)

-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute

Adoption
Hey Dan use my notify.php code instead. And it will work.
-Nick- is offline  
Old 06-26-2006, 04:01 AM   #11 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
What does $pageid have in it? Somehow the different people can be determined by it.
Dan is offline  
Old 06-26-2006, 05:19 AM   #12 (permalink)
I'll do it

Technical Services

 
-Nick-'s Avatar
 
Join Date: Dec 2005
Location: India
Posts: 6,434
5,169.80 NP$ (Donate)

-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute

Adoption
Page ID is hte variable passed to the page.
-Nick- is offline  
Old 06-26-2006, 12:26 PM   #13 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
Obviously..

But show me an example of what could be in it.

Code:
$pageid = $QUERY_STRING;
if ($QUERY_STRING == "")
{
$pageid = 1;
}
$arr = explode("x", $pageid);
$hid = $arr[0];
$catid = $arr[1];
I can't use the script if I don't have $QUERY_STRING and I don't know what it is, so how can I use it?
Dan is offline  
Old 06-26-2006, 01:17 PM   #14 (permalink)
NamePros Member
 
Join Date: Oct 2005
Posts: 38
9.80 NP$ (Donate)

Scott2503 is an unknown quantity at this point


Alright I ended up modify the script to work and I just tested it on an actual payment (of 31 cents ). Anyways is there some sort of way to get PayPal to pass a custom variable to the IPN?

For example when someone is on my site and they have $_SESSION variable set and they go to the site... can you some how pass the information of that $_SESSION variable to the PayPal payment thing so it then will pass that variable to my IPN?

EDIT: I am using a buy now button so could I just add:
<input type="hidden" name="custom" value="SESSION VARIABLE">

even if the rest of the button is encrypted?

Last edited by Scott2503; 06-26-2006 at 01:26 PM.
Scott2503 is offline  
Old 06-26-2006, 02:12 PM   #15 (permalink)
Senior Member
 
ahtum's Avatar
 
Join Date: May 2006
Posts: 1,266
1,620.58 NP$ (Donate)

ahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud ofahtum has much to be proud of

Ethan Allen Fund Find Marrow Donors!
oups wrong place ... sorry :P
ahtum is offline  
Old 06-26-2006, 09:15 PM   #16 (permalink)
I'll do it

Technical Services

 
-Nick-'s Avatar
 
Join Date: Dec 2005
Location: India
Posts: 6,434
5,169.80 NP$ (Donate)

-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute-Nick- has a reputation beyond repute

Adoption
Quote:
Originally Posted by Dan Friedman
Obviously..

But show me an example of what could be in it.

Code:
$pageid = $QUERY_STRING;
if ($QUERY_STRING == "")
{
$pageid = 1;
}
$arr = explode("x", $pageid);
$hid = $arr[0];
$catid = $arr[1];
I can't use the script if I don't have $QUERY_STRING and I don't know what it is, so how can I use it?
The script right now passes two variables. One is the category ID of which the listing is a member of and other one is the listing ID itself. Both variables are seperated by a "-" seperator.

Then I explode it when I recieve the whole query string and process it accordingly.

The live thing can be seen here. http://www.firescripts.com Which I recently launched and it has the automatic sponsoring system.
-Nick- is offline  
Old 06-26-2006, 11:33 PM   #17 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Quote:
Originally Posted by Scott2503

EDIT: I am using a buy now button so could I just add:
<input type="hidden" name="custom" value="SESSION VARIABLE">

even if the rest of the button is encrypted?
I am sure you can only do that if it is not encrypted.
Peter is offline  
Old 06-30-2006, 06:16 PM   #18 (permalink)
NamePros Member
 
eddy0's Avatar
 
Join Date: Jun 2006
Posts: 32
32.00 NP$ (Donate)

eddy0 is an unknown quantity at this point


I am not sure, but paypal is usually on a secure connection. Port 80 is http and I think Port 443 is https. I hope this helps!
eddy0 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 08:02 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85