[advanced search]
Results from the most recent live auction are here.
19 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 10-09-2005, 09:59 PM   · #1
iNod
Eating Pie
 
iNod's Avatar
 
Name: Steve
Location: Canada
Trader Rating: (66)
Join Date: Nov 2004
Posts: 2,282
NP$: 91.30 (Donate)
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
PayPal IPN -> MySql DB

Hello All,

Well this is a very basic PayPal IPN script which can be changed to make a very nice Automated Paypal Signup Script.

SQL.SQL (MySql SQL Dump)
Code:
/*------------------------------------*/ /* Sales - Order received via Paypal */ /*------------------------------------*/ CREATE TABLE sales ( invoice INT UNSIGNED AUTO_INCREMENT, receiver_email VARCHAR(60), item_name VARCHAR(100), item_number VARCHAR(10), quantity VARCHAR(6), payment_status VARCHAR(10), pending_reason VARCHAR(10), payment_date VARCHAR(20), mc_gross VARCHAR(20), mc_fee VARCHAR(20), tax VARCHAR(20), mc_currency VARCHAR(3), txn_id VARCHAR(20), txn_type VARCHAR(10), first_name VARCHAR(30), last_name VARCHAR(40), address_street VARCHAR(50), address_city VARCHAR(30), address_state VARCHAR(30), address_zip VARCHAR(20), address_country VARCHAR(30), address_status VARCHAR(10), payer_email VARCHAR(60), payer_status VARCHAR(10), payment_type VARCHAR(10), notify_version VARCHAR(10), verify_sign VARCHAR(10), referrer_id VARCHAR(10), PRIMARY KEY (invoice) );

PHP.PHP (PHP Code)
PHP Code:
<?php
//Lets do MySql connection stuff
$mysql_host='localhost'; //Leave at localhost
$mysql_user='blah'; //DB User
$mysql_pass='blah'; //DB Pass
$mysql_db='blah'; //DB Name

//------------------------------------------------------------------
// Open log file (in append mode) and write the current time into it.
// Open the DB Connection. Open the actual database.
//-------------------------------------------------------------------
$log = fopen("ipn.log", "a");
fwrite($log, "\n\nipn - " . gmstrftime ("%b %d %Y %H:%M:%S", time()) . "\n");
$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db,$db);
//------------------------------------------------
// Read post from PayPal system and create reply
// starting with: 'cmd=_notify-validate'...
// then repeating all values sent - VALIDATION.
//------------------------------------------------
$postvars = array();
while (list (
$key, $value) = each ($HTTP_POST_VARS)) {
$postvars[] = $key;
}
$req = 'cmd=_notify-validate';
for (
$var = 0; $var < count ($postvars); $var++) {
$postvar_key = $postvars[$var];
$postvar_value = $$postvars[$var];
$req .= "&" . $postvar_key . "=" . urlencode ($postvar_value);
}
//--------------------------------------------
// Create message to post back to PayPal...
// Open a socket to the PayPal server...
//--------------------------------------------
$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);

//---------------------------------------------
fwrite($log, "Vals: ". $invoice." ". $receiver_email." ". $item_name." ". $item_ number." ". $quantity." ". $payment_status." ". $pending_reason." ".$payment_dat e." ". $payment_gross." ". $payment_fee." ". $txn_id." ". $txn_type." ". $first_ name." ". $last_name." ". $address_street." ". $address_city." ". $address_state . " ".$address_zip." ". $address_country." ". $address_status." ". $payer_email. " ". $payer_status." ". $payment_type." ". $notify_version." ". $verify_sign. "\ n");

// 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'];

//----------------------------------------------------------------------
// Check HTTP connection made to PayPal OK, If not, print an error msg
//----------------------------------------------------------------------
if (!$fp) {
echo
"$errstr ($errno)";
fwrite($log, "Failed to open HTTP connection!");
$res = "FAILED";
}
//--------------------------------------------------------
// If connected OK, write the posted values back, then...
//--------------------------------------------------------
else {
fputs ($fp, $header . $req);
//-------------------------------------------
// ...read the results of the verification...
// If VERIFIED = continue to process the TX...
//-------------------------------------------
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (
strcmp ($res, "VERIFIED") == 0) {

//--------------------------------------
// Insert Transaction details into DB.
//--------------------------------------
$qry = "INSERT into psales (
invoice, receiver_email, item_name, item_number, quantity, payment_status, pendi ng_reason, payment_date, payment_gross, payment_fee, txn_id, txn_type, first_nam e, last_name, address_street, address_city, address_state, address_zip, address_ country, address_status, payer_email, payer_status, payment_type, notify_version , verify_sign )
VALUES
( \"$invoice\", \"$receiver_email\", \"$item_name\", \"$item_number\", \"$quanti ty\", \"$payment_status\", \"$pending_reason\", \"$payment_date\", \"$payment_gr oss\", \"$payment_fee\", \"$txn_id\", \"$txn_type\", \"$first_name\", \"$last_na me\", \"$address_street\", \"$address_city\", \"$address_state\", \"$address_zip \", \"$address_country\", \"$address_status\", \"$payer_email\", \"$payer_status \", \"$payment_type\", \"$notify_version\", \"$verify_sign\" ) "
;

$result = mysql_query($qry,$db);
}
}
}
//-------------------------------------------
// Close PayPal Connection, Log File and DB.
//-------------------------------------------
fclose ($fp);
fclose ($log);
mysql_close($db);
?>


I never tested this so it may be buggy. If it is post bug and I will fix it up.

Thanks,
iNod


Please register or log-in into NamePros to hide ads
__________________
RegisterDub.com - 200th Customer Milestone
ZuneParts.net - International Zune Parts and Accessories
FeaturedFont.com - One Top Free Font a Day!
iNod is offline   Reply With Quote
Old 10-10-2005, 11:56 AM   · #2
miseria
SQLdumpster.com
 
miseria's Avatar
 
Name: Unknown
Location: West Sussex, UK
Trader Rating: (7)
Join Date: Jun 2005
Posts: 543
NP$: 108.00 (Donate)
miseria will become famous soon enoughmiseria will become famous soon enough
Thanks, very useful. There are a few errors in the following, I believe but I may be wrong:

PHP Code:
$qry = "INSERT into psales (
invoice, receiver_email, item_name, item_number, quantity, payment_status, pendi ng_reason, payment_date, payment_gross, payment_fee, txn_id, txn_type, first_nam e, last_name, address_street, address_city, address_state, address_zip, address_ country, address_status, payer_email, payer_status, payment_type, notify_version , verify_sign )
VALUES
( \"$invoice\", \"$receiver_email\", \"$item_name\", \"$item_number\", \"$quanti ty\", \"$payment_status\", \"$pending_reason\", \"$payment_date\", \"$payment_gr oss\", \"$payment_fee\", \"$txn_id\", \"$txn_type\", \"$first_name\", \"$last_na me\", \"$address_street\", \"$address_city\", \"$address_state\", \"$address_zip \", \"$address_country\", \"$address_status\", \"$payer_email\", \"$payer_status \", \"$payment_type\", \"$notify_version\", \"$verify_sign\" ) "
;


"psales" - top line
"$quanti ty" "$last_na me" and "$payment_gr oss" on the other hand, they may be intentional, I haven't read it thoroughly yet
__________________
!!!!!!! see something you like? Accepting offers for great affiliate websites !!!!!!!
Free Databases for your Website | All Things Playstation 3
Website Design Books | Music While You Work? | Computer Gadgets
miseria is offline   Reply With Quote
Old 10-10-2005, 11:58 AM   · #3
axilant
Account Closed
 
axilant's Avatar
 
Name: Cody Selzer
Location: /etc/passwd
Trader Rating: (40)
Join Date: May 2004
Posts: 2,194
NP$: 0.00 (Donate)
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
Member of the Month
July 2005
Did you make this code... cause i could have sworn i saw something like this in an opensource project? On sourceforge :-/
axilant is offline   Reply With Quote
Old 10-10-2005, 02:48 PM   · #4
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (140)
Join Date: Mar 2005
Posts: 4,195
NP$: 1660.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
Fixed a bug or two, spaced things out so it's easier to read.. (If you don't mind)
PHP Code:
<?php

//Lets do MySql connection stuff
$mysql_host = 'localhost'; //Leave at localhost
$mysql_user = 'blah'; //DB User
$mysql_pass = 'blah'; //DB Pass
$mysql_db = 'blah'; //DB Name

//------------------------------------------------------------------
// Open log file (in append mode) and write the current time into it.
// Open the DB Connection. Open the actual database.
//-------------------------------------------------------------------
$log = fopen("ipn.log", "a");
fwrite($log, "\n\nipn - ".gmstrftime("%b %d %Y %H:%M:%S", time())."\n");
$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db, $db);

//------------------------------------------------
// Read post from PayPal system and create reply
// starting with: 'cmd=_notify-validate'...
// then repeating all values sent - VALIDATION.
//------------------------------------------------
$postvars = array();

while(list(
$key, $value) = each($_POST))
{
  
$postvars[] = $key;
}
$req = 'cmd=_notify-validate';

for(
$var = 0; $var < count($postvars); $var++)
{
  
$postvar_key = $postvars[$var];
  
$postvar_value = $$postvars[$var];
  
$req .= "&".$postvar_key."=".urlencode($postvar_value);
}

//--------------------------------------------
// Create message to post back to PayPal...
// Open a socket to the PayPal server...
//--------------------------------------------
$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);

//---------------------------------------------
fwrite($log, "Vals: ".$invoice." ".$receiver_email." ".$item_name." ".$item_ number." ".$quantity." ".$payment_status." ".$pending_reason." ".$payment_date." ".$payment_gross." ".$payment_fee." ".$txn_id." ".$txn_type." ".$first_name." ".$last_name." ".$address_street." ".$address_city." ".$address_state." ".$address_zip." ".$address_country." ".$address_status." ".$payer_email." ".$payer_status." ".$payment_type." ".$notify_version." ".$verify_sign."\n");

// 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'];

//----------------------------------------------------------------------
// Check HTTP connection made to PayPal OK, If not, print an error msg
//----------------------------------------------------------------------
if(!$fp)
{
  echo
$errstr."(".$errno.")";
  
fwrite($log, "Failed to open HTTP connection!");
  
$res = "FAILED";
}
//--------------------------------------------------------
// If connected OK, write the posted values back, then...
//--------------------------------------------------------
else
{
  
fputs($fp, $header . $req);
  
//-------------------------------------------
  // ...read the results of the verification...
  // If VERIFIED = continue to process the TX...
  //-------------------------------------------
  
while(!feof($fp))
  {
    
$res = fgets($fp, 1024);
    if(
strcmp($res, "VERIFIED") == 0)
    {
      
//--------------------------------------
      // Insert Transaction details into DB.
      //--------------------------------------
      
$qry = "INSERT INTO sales (invoice, receiver_email, item_name, item_number, quantity, payment_status, pendi ng_reason, payment_date, payment_gross, payment_fee, txn_id, txn_type, first_nam e, last_name, address_street, address_city, address_state, address_zip, address_ country, address_status, payer_email, payer_status, payment_type, notify_version, verify_sign) VALUES('$invoice', '$receiver_email', '$item_name', '$item_number', '$quantity', '$payment_status', '$pending_reason', '$payment_date', '$payment_gross', '$payment_fee', '$txn_id', '$txn_type', '$first_name', '$last_name', '$address_street', '$address_city', '$address_state', '$address_zip ', '$address_country', '$address_status', '$payer_email', '$payer_status ', '$payment_type', '$notify_version', '$verify_sign')";
      
$result = mysql_query($qry);
    }
  }
}
//-------------------------------------------
// Close PayPal Connection, Log File and DB.
//-------------------------------------------
fclose($fp);
fclose($log);
mysql_close($db);

?>
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator
CodingPlanet.com - Coming soon...

Last edited by SecondVersion : 12-24-2005 at 10:16 AM.
SecondVersion is offline   Reply With Quote
Old 10-10-2005, 02:58 PM   · #5
ninedogger
DNOA Member
 
ninedogger's Avatar
 
Location: Iowa
Trader Rating: (38)
Join Date: Jun 2004
Posts: 656
NP$: 13.10 (Donate)
ninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of light
Save The Children
Im not meaning anything by this, but its amazing what a google search does and finds many similiarties to this code...
__________________
Want to prove yourself?

CHECK OUT MY DOMAINS!
ninedogger is offline  
  Reply With Quote
Old 10-12-2005, 07:43 PM   · #6
gamex
NamePros Regular
 
gamex's Avatar
 
Name: Joe
Location: Student @ UConn
Trader Rating: (9)
Join Date: Feb 2004
Posts: 408
NP$: 66.45 (Donate)
gamex has a spectacular aura aboutgamex has a spectacular aura about
Yea, like here: http://paypaldev.org/post.asp?metho...380&FORUM_ID=17, but I dont remember iNod saying that he wrote it, for all we know he could just be posting some code that others may find useful.
__________________
Joe
CarrotCash.com
gamex is offline   Reply With Quote
Old 10-12-2005, 08:16 PM   · #7
axilant
Account Closed
 
axilant's Avatar
 
Name: Cody Selzer
Location: /etc/passwd
Trader Rating: (40)
Join Date: May 2004
Posts: 2,194
NP$: 0.00 (Donate)
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
Member of the Month
July 2005
Originally Posted by gamex
Yea, like here: http://paypaldev.org/post.asp?metho...380&FORUM_ID=17, but I dont remember iNod saying that he wrote it, for all we know he could just be posting some code that others may find useful.




He didnt claim it.

But.

Its obvious he tried to change some of the code, and made a few mistakes, so thats where i got the assumtion that he was claiming it
axilant is offline   Reply With Quote
Old 10-13-2005, 04:10 PM   · #8
iNod
Eating Pie
 
iNod's Avatar
 
Name: Steve
Location: Canada
Trader Rating: (66)
Join Date: Nov 2004
Posts: 2,282
NP$: 91.30 (Donate)
iNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud ofiNod has much to be proud of
Special Olympics AIDS/HIV Cystic Fibrosis Save The Children Baby Health Cystic Fibrosis
Originally Posted by ps2gamer
Im not meaning anything by this, but its amazing what a google search does and finds many similiarties to this code...




Amazing too how I can say I never coded it and you guys claim that because I post it for others to use and see you bash me.

Hrm.. Intresting.
__________________
RegisterDub.com - 200th Customer Milestone
ZuneParts.net - International Zune Parts and Accessories
FeaturedFont.com - One Top Free Font a Day!
iNod is offline   Reply With Quote
Old 10-13-2005, 04:48 PM   · #9
cbr600
NamePros Member
 
Trader Rating: (5)
Join Date: Jul 2005
Posts: 177
NP$: 26.00 (Donate)
cbr600 is on a distinguished road
Thanks, its exactly what i was looking for. I understand the php/sql but the paypal stuff confuses me a little ya know. Its hard to test out your code w/o spending $$ buying your product through paypal ya know?
__________________
Developer for hire (PM for portfolio)
PHP | .NET | Javascript | AJAX | Flash/Flex | Perl | C++ | Java
cbr600 is offline   Reply With Quote
Old 10-13-2005, 05:08 PM   · #10
ninedogger
DNOA Member
 
ninedogger's Avatar
 
Location: Iowa
Trader Rating: (38)
Join Date: Jun 2004
Posts: 656
NP$: 13.10 (Donate)
ninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of lightninedogger is a glorious beacon of light
Save The Children
Originally Posted by iNod
Amazing too how I can say I never coded it and you guys claim that because I post it for others to use and see you bash me.

Hrm.. Intresting.





Nobody is bashing, but when someone just posts code and not showing the source...people are going to assume that the person wrote

and also, in most cases, you can't just grab or copy and paste someone elses code/script and post it elsewhere
__________________
Want to prove yourself?

CHECK OUT MY DOMAINS!
ninedogger is offline  
  Reply With Quote
Old 12-24-2005, 07:50 AM   · #11
hanzo
NamePros Member
 
Trader Rating: (1)
Join Date: Oct 2005
Posts: 97
NP$: 107.93 (Donate)
hanzo is an unknown quantity at this point
This is also a nice one if you're doing automated Paypal Payments: http://paypaltech.com/Patrick/content/phptoolkit/
hanzo is offline   Reply With Quote
Old 12-25-2005, 08:40 AM   · #12
bbalegere
Senior Member
 
Name: Bharat Balegere
Location: Bangalore
Trader Rating: (15)
Join Date: Jul 2005
Posts: 1,178
NP$: 9.25 (Donate)
bbalegere is just really nicebbalegere is just really nicebbalegere is just really nicebbalegere is just really nice
Excellent
bbalegere is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help testing my PayPal IPN script (50 NP$ award) Michau Programming 3 04-19-2005 05:22 AM
PAYPAL Litigation johnn Domain Name Discussion 6 07-31-2004 09:51 PM
Paypal Settlement Lord The Break Room 2 07-30-2004 09:30 PM
AuzzieGirls.com --> $99 US via Paypal LifeIsBeautiful Domains For Sale - Fixed Price 1 05-07-2004 02:58 PM
WARNING: PayPal Fraud Emails NamePopper Warnings & Alerts 18 06-27-2003 07:01 PM

Site Sponsors
Domain Tasting Find out how! http://www.mobisitetrader.com/
Advertise your business at NamePros
All times are GMT -7. The time now is 10:17 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0