Clan Adverts

Custom PHPNuke Scripts

 

www.clan-themes.co.uk :: View topic - Paypal IPN

 Welcome To Clan Themes 

As the board grows please remember the Search Option and we hope you find our community useful.

We also monitor Private Messages to stop members from abusing our sites system.
If you are asking for assistance please provide your site link and nuke version, Thanks.

Paypal IPN

3 Replies / 242 Views


Post new topic   Reply to topic  

   www.clan-themes.co.uk Forum Index » Modules

View previous topic :: View next topic


Untergang
Reputation: 598.5
votes: 4
Local time: 9:06 AM
Location: Lommel
belgium.gif

Status: Offline
0.50 posts per day
Medals: 0

Joined: May 08, 2007
Last Visit: 10 Oct 2008
Posts: 261
Points: 6563 

Post Paypal IPN Posted: Thu Jul 03, 2008 9:53 pm   

Hi,

I'm working on a digital goods shop, first I used nuketreasury for the ipn.
But it only works with 1 emailadress. So I started making the IPN myself.
The problem is, I can't get it to work, it doesn't add anthing to the database.
Here's my form:
Code:
<form method='post' action='https://www.paypal.com/cgi-bin/webscr' target='paypal'>
<input type='hidden' name='cmd' value='_xclick'>
<input type='hidden' name='business' value='$account'>
<input type='hidden' name='item_name' value='$itemname'>
<input type='hidden' name='item_number' value='$lid'>
<input type='hidden' name='amount' value='$price'>
<input type='hidden' name='notify_url' value='$nukeurl/modules/$module_name/ipn.php'>
<input type='hidden' name='return' value='$nukeurl/modules/$module_name/ipn.php'>
<input type='hidden' name='rm' value='2'>
<input type='hidden' name='cancel_return' value='$nukeurl'>
<input type='hidden' name='on0' value='Username'>
<input type='hidden' name='os0' value='$usernamea'>
<input type='hidden' name='currency_code' value='$currency'>
<input type='hidden' name='quantity' value='1'>
<input type='image' name='add' src='modules/$module_name/images/buy.gif' class='paypal'>
</form>

And the ipn.php:
Code:
<?php
include("../../mainfile.php");
global $db, $prefix;

// 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'];
$buyer = $_POST['option_selection1'];

if (!$fp) {
// HTTP ERROR
echo"ERROR: fp";
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

   // check that txn_id has not been previously processed
   $matchtxn = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_dlshop_paypal WHERE txn_id='$txn_id'"));
   // check that receiver_email is your Primary PayPal email
   $matchmail = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_dlshop_items WHERE account='$receiver_email' AND itemname='$item_name'"));
   // check that payment_amount/payment_currency are correct
   $matchprice = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_dlshop_items WHERE itemname='$item_name' AND currency='$payment_currency' AND price='$payment_amount'"));
//   if($matchtxn == 0 && $matchmail > 0 && $matchprice > 0){
   
   // process payment
   $db->sql_query("INSERT INTO ".$prefix."_dlshop_paypal VALUES (NULL, '$txn_id', '$item_name', '$item_number', '$buyer', '$payment_amount', '$payment_currency', '$receiver_email', '$payer_email')");
//   }

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
echo"ERROR";
}
}
fclose ($fp);
}
?>


Is there someone who can tell me why this doesn't work?

Thanks
 

 
View user's profileSend private messageSend e-mailVisit poster's websiteMSN Messenger Reply with quote

floppy
Reputation: 1784.6
votes: 10
Local time: 3:06 AM
Location: Jackson Mississippi
usa.gif

Status: Offline
2.86 posts per day
Medals: 1 (View more...)
Dedicated User (Amount: 1)
Clan Themes Scripts/Coder
Clan Themes Scripts/Coder
Joined: Nov 14, 2006
Last Visit: 10 Oct 2008
Posts: 1993
Points: 29819 

Post Paypal IPN Posted: Fri Jul 04, 2008 6:49 am   

Shop Purchases:
Clan Roster 2.0

I don't see the problem right away, but this might help.

Code:
   // process payment
   $db->sql_query("INSERT INTO ".$prefix."_dlshop_paypal VALUES (NULL, '$txn_id', '$item_name', '$item_number', '$buyer', '$payment_amount', '$payment_currency', '$receiver_email', '$payer_email')")
echo mysql_error();
die();


It is hard to tell where it might be fubar'ing but that is my first guess.
 

Free Clan Links - Submit Yours today  
View user's profileSend private messageVisit poster's website Reply with quote

Untergang
Reputation: 598.5
votes: 4
Local time: 9:06 AM
Location: Lommel
belgium.gif

Status: Offline
0.50 posts per day
Medals: 0

Joined: May 08, 2007
Last Visit: 10 Oct 2008
Posts: 261
Points: 6563 

Post Re: Paypal IPN Posted: Fri Jul 04, 2008 7:25 am   

I think I've found something. On paypal, you can edit your Instant Payment Notification Preference.
I still have the link of the nuketreasury module there so, if I edit that, I think it might work.
 

 
View user's profileSend private messageSend e-mailVisit poster's websiteMSN Messenger Reply with quote




Untergang
Reputation: 598.5
votes: 4
Local time: 9:06 AM
Location: Lommel
belgium.gif

Status: Offline
0.50 posts per day
Medals: 0

Joined: May 08, 2007
Last Visit: 10 Oct 2008
Posts: 261
Points: 6563 

View user's profileSend private messageSend e-mailVisit poster's websiteMSN Messenger Reply with quote
Post new topic   Reply to topic  
   www.clan-themes.co.uk Forum Index » Modules


 
3 Replies / 242 Views
Page 1 of 1
All times are GMT
Display posts from previous:   
 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum