7 Replies - 1119 Views - Last Post: 28 January 2010 - 09:51 PM Rate Topic: -----

#1 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Working with the PayPal API : Post Removed by Poster

Posted 27 January 2010 - 06:23 PM

Post Removed

This post has been edited by brosskgm: 27 January 2010 - 10:38 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Working with the PayPal API : Post Removed by Poster

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Working with the PayPal API : Post Removed by Poster

Posted 27 January 2010 - 10:49 PM

View Postbrosskgm, on 27 Jan, 2010 - 07:23 PM, said:

Does anyone have the step by Step setup for paypal subscription using php mysql?

What documentation are you using for this project?

PayPal's website has all kinds of wonderfully detailed information about their API from functionality to variable usage.

Quote

I've created the sandbox account to test, I have downloaded all the php and mysql tables, but have been running in to a mental block how to get it to work.

I didn't do any of this. Not that I'm saying you shouldn't, but it certainly doesn't guarantee it to work. The mysql tables would be for your own usage. The data that you pass to PayPal will transfer the money & create a subscription for the account paying you. Using mysql (or any data storage) on your side is only for your own records.

Quote

I have a sign-up page, but all the info in the paypal pages has a lot more than mine

Without seeing your code, it's impossible to know if you have the code correct.

Quote

Do I have to have our login use their tables or do I still use our own.

Login for PayPal or for your membership site that they are signing up for?

PayPal does not govern your site.

Quote

They don't really give much in the way of help or man pages.

Untrue.

Quote

Their site needs a return url. But doesn't say what they are looking for in the return.

Again, this isn't true. The usage of their API is available in full detail.


The main documentation for using the PayPal API (IPN) is available here, complete with detailed explanation of the transaction, & a sample IPN message and response scenario.


Also, make sure that your account is setup to even accept payments from the PayPal API. Refer to page 36 of this documentation.

View Postbrosskgm, on 27 Jan, 2010 - 07:23 PM, said:

Post Removed

Dude, that's just not cool.

I spent all that time trying to help you out...
Was This Post Helpful? 1
  • +
  • -

#3 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: Working with the PayPal API : Post Removed by Poster

Posted 28 January 2010 - 01:10 PM

Sorry,

I removed the post when no one responded. your post was not even listed after a day 1/2 so I figured I shouldn't have asked the question and didn't want to clutter up the list with unwanted questions and an awfull amount of code..

I have an html page with username, password fields and the paypal subscribe button. It goes to their sandbox site to test.

When I get to the site I log in with the test user that was created, but once I log in it tells me

"The link you have used to enter the PayPal system is invalid. Please review the link and try again."

I want the user to pay and have the account ready to go with no intervention to having to add them.


# Table structure for table `paypal_cart_info` #

CREATE TABLE `paypal_cart_info` (
 `txnid` varchar(30) NOT NULL default '',
 `itemname` varchar(255) NOT NULL default '',
 `itemnumber` varchar(50) default NULL,
 `os0` varchar(20) default NULL,
 `on0` varchar(50) default NULL,
 `os1` varchar(20) default NULL,
 `on1` varchar(50) default NULL,
 `quantity` char(3) NOT NULL default '',
 `invoice` varchar(255) NOT NULL default '',
 `custom` varchar(255) NOT NULL default ''
) TYPE=MyISAM;

# Table structure for table `paypal_subscription_info` #

CREATE TABLE `paypal_subscription_info` (
`subscr_id` varchar(255) NOT NULL default '',
 `sub_event` varchar(50) NOT NULL default '',
 `subscr_date` varchar(255) NOT NULL default '',
 `subscr_effective` varchar(255) NOT NULL default '',
 `period1` varchar(255) NOT NULL default '',
 `period2` varchar(255) NOT NULL default '',
 `period3` varchar(255) NOT NULL default '',
 `amount1` varchar(255) NOT NULL default '',
 `amount2` varchar(255) NOT NULL default '',
 `amount3` varchar(255) NOT NULL default '',
 `mc_amount1` varchar(255) NOT NULL default '',
 `mc_amount2` varchar(255) NOT NULL default '',
 `mc_amount3` varchar(255) NOT NULL default '',
 `recurring` varchar(255) NOT NULL default '',
 `reattempt` varchar(255) NOT NULL default '',
 `retry_at` varchar(255) NOT NULL default '',
 `recur_times` varchar(255) NOT NULL default '',
 `username` varchar(255) NOT NULL default '',
 `password` varchar(255) default NULL,
 `payment_txn_id` varchar(50) NOT NULL default '',
 `subscriber_emailaddress` varchar(255) NOT NULL default '',
 `datecreation` date NOT NULL default '0000-00-00' 
) TYPE=MyISAM; 


# Table structure for table `paypal_payment_info` # 

CREATE TABLE `paypal_payment_info` (
`firstname` varchar(100) NOT NULL default '',
 `lastname` varchar(100) NOT NULL default '',
 `buyer_email` varchar(100) NOT NULL default '',
 `street` varchar(100) NOT NULL default '',
 `city` varchar(50) NOT NULL default '',
 `state` char(3) NOT NULL default '',
 `zipcode` varchar(11) NOT NULL default '',
 `memo` varchar(255) default NULL,
 `itemname` varchar(255) default NULL,
 `itemnumber` varchar(50) default NULL,
 `os0` varchar(20) default NULL,
 `on0` varchar(50) default NULL,
 `os1` varchar(20) default NULL,
 `on1` varchar(50) default NULL,
 `quantity` char(3) default NULL,
 `paymentdate` varchar(50) NOT NULL default '',
 `paymenttype` varchar(10) NOT NULL default '',
 `txnid` varchar(30) NOT NULL default '',
 `mc_gross` varchar(6) NOT NULL default '',
 `mc_fee` varchar(5) NOT NULL default '',
 `paymentstatus` varchar(15) NOT NULL default '',
 `pendingreason` varchar(10) default NULL,
 `txntype` varchar(10) NOT NULL default '',
 `tax` varchar(10) default NULL,
 `mc_currency` varchar(5) NOT NULL default '',
 `reasoncode` varchar(20) NOT NULL default '',
 `custom` varchar(255) NOT NULL default '',
 `country` varchar(20) NOT NULL default '',
 `datecreation` date NOT NULL default '0000-00-00' 
) TYPE=MyISAM; 



<?php

/////////////////////////////////////////////////
/////////////Begin Script below./////////////////
/////////////////////////////////////////////////

// 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";

// If testing on Sandbox use:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 
30);

// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);


// assign posted variables to local variables
$item_name = $_POST['item_name'];
$business = $_POST['business'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$mc_gross = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$receiver_id = $_POST['receiver_id'];
$quantity = $_POST['quantity'];
$num_cart_items = $_POST['num_cart_items'];
$payment_date = $_POST['payment_date'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payment_type = $_POST['payment_type'];
$payment_status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$payment_fee = $_POST['payment_fee'];
$settle_amount = $_POST['settle_amount'];
$memo = $_POST['memo'];
$payer_email = $_POST['payer_email'];
$txn_type = $_POST['txn_type'];
$payer_status = $_POST['payer_status'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$item_number = $_POST['item_number'];
$tax = $_POST['tax'];
$option_name1 = $_POST['option_name1'];
$option_selection1 = $_POST['option_selection1'];
$option_name2 = $_POST['option_name2'];
$option_selection2 = $_POST['option_selection2'];
$for_auction = $_POST['for_auction'];
$invoice = $_POST['invoice'];
$custom = $_POST['custom'];
$notify_version = $_POST['notify_version'];
$verify_sign = $_POST['verify_sign'];
$payer_business_name = $_POST['payer_business_name'];
$payer_id =$_POST['payer_id'];
$mc_currency = $_POST['mc_currency'];
$mc_fee = $_POST['mc_fee'];
$exchange_rate = $_POST['exchange_rate'];
$settle_currency  = $_POST['settle_currency'];
$parent_txn_id  = $_POST['parent_txn_id'];
$pending_reason = $_POST['pending_reason'];
$reason_code = $_POST['reason_code'];


// subscription specific vars

$subscr_id = $_POST['subscr_id'];
$subscr_date = $_POST['subscr_date'];
$subscr_effective  = $_POST['subscr_effective'];
$period1 = $_POST['period1'];
$period2 = $_POST['period2'];
$period3 = $_POST['period3'];
$amount1 = $_POST['amount1'];
$amount2 = $_POST['amount2'];
$amount3 = $_POST['amount3'];
$mc_amount1 = $_POST['mc_amount1'];
$mc_amount2 = $_POST['mc_amount2'];
$mc_amount3 = $_POST['mcamount3'];
$recurring = $_POST['recurring'];
$reattempt = $_POST['reattempt'];
$retry_at = $_POST['retry_at'];
$recur_times = $_POST['recur_times'];
$username = $_POST['username'];
$password = $_POST['password'];

//auction specific vars

$for_auction = $_POST['for_auction'];
$auction_closing_date  = $_POST['auction_closing_date'];
$auction_multi_item  = $_POST['auction_multi_item'];
$auction_buyer_id  = $_POST['auction_buyer_id'];



//DB connect creds and email
$notify_email =  "bross@kingmanaz.net";         //email address to which 
debug emails are sent to
$DB_Server = "kingmanaz.net"; //your MySQL Server
$DB_Username = "bobross"; //your MySQL User Name
$DB_Password = "90-01145"; //your MySQL Password
$DB_DBName = "alldatabase"; //your MySQL Database Name


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



//create MySQL connection
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . 
mysql_errno());


//select database
$Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database:<br>" . mysql_error(). "<br>" . 
mysql_errno());


$fecha = date("m")."/".date("d")."/".date("Y");
$fecha = date("Y").date("m").date("d");

//check if transaction ID has been processed before
$checkquery = "select txnid from paypal_payment_info where 
txnid='".$txn_id."'";
$sihay = mysql_query($checkquery) or die("Duplicate txn id check query 
failed:<br>" . mysql_error() . "<br>" . mysql_errno());
$nm = mysql_num_rows($sihay);
if ($nm == 0){

//execute query



    if ($txn_type == "cart"){
    $strQuery = "insert into 
paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
values 
('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";

     $result = mysql_query($strQuery) or die("Cart - paypal_payment_info, 
Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
     for ($i = 1; $i <= $num_cart_items; $i++) {
         $itemname = "item_name".$i;
         $itemnumber = "item_number".$i;
         $on0 = "option_name1_".$i;
         $os0 = "option_selection1_".$i;
         $on1 = "option_name2_".$i;
         $os1 = "option_selection2_".$i;
         $quantity = "quantity".$i;

         $struery = "insert into 
paypal_cart_info(txnid,itemnumber,itemname,os0,on0,os1,on1,quantity,invoice,custom) 
values 
('".$txn_id."','".$_POST[$itemnumber]."','".$_POST[$itemname]."','".$_POST[$on0]."','".$_POST[$os0]."','".$_POST[$on1]."','".$_POST[$os1]."','".$_POST[$quantity]."','".$invoice."','".$custom."')";
         $result = mysql_query($struery) or die("Cart - paypal_cart_info, 
Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());

     }
    }



    else{
     $strQuery = "insert into 
paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,itemnumber,itemname,os0,on0,os1,on1,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
values 
('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$item_number."','".$item_name."','".$option_name1."','".$option_selection1."','".$option_name2."','".$option_selection2."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";
     $result = mysql_query("insert into 
paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,itemnumber,itemname,os0,on0,os1,on1,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
values 
('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$item_number."','".$item_name."','".$option_name1."','".$option_selection1."','".$option_name2."','".$option_selection2."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')") 
or die("Default - paypal_payment_info, Query failed:<br>" . mysql_error() . 
"<br>" . mysql_errno());
    }


    // send an email in any case
 echo "Verified";
     mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n 
$struery\n  $strQuery2");
}
else {
// send an email
mail($notify_email, "VERIFIED DUPLICATED TRANSACTION", "$res\n $req \n 
$strQuery\n $struery\n  $strQuery2");
}

    //subscription handling branch
    if ( $txn_type == "subscr_signup"  ||  $txn_type == "subscr_payment"  ) 
{

      // insert subscriber payment info into paypal_payment_info table
      $strQuery = "insert into 
paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
values 
('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";
      $result = mysql_query($strQuery) or die("Subscription - 
paypal_payment_info, Query failed:<br>" . mysql_error() . "<br>" . 
mysql_errno());


         // insert subscriber info into paypal_subscription_info table
        $strQuery2 = "insert into paypal_subscription_info(subscr_id , 
sub_event, subscr_date ,subscr_effective,period1,period2, period3, amount1 
,amount2 ,amount3,  mc_amount1,  mc_amount2,  mc_amount3, recurring, 
reattempt,retry_at, recur_times, username ,password, payment_txn_id, 
subscriber_emailaddress, datecreation) values ('".$subscr_id."', 
'".$txn_type."','".$subscr_date."','".$subscr_effective."','".$period1."','".$period2."','".$period3."','".$amount1."','".$amount2."','".$amount3."','".$mc_amount1."','".$mc_amount2."','".$mc_amount3."','".$recurring."','".$reattempt."','".$retry_at."','".$recur_times."','".$username."','".$password."', 
'".$txn_id."','".$payer_email."','".$fecha."')";
        $result = mysql_query($strQuery2) or die("Subscription - 
paypal_subscription_info, Query failed:<br>" . mysql_error() . "<br>" . 
mysql_errno());


             mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n 
$struery\n  $strQuery2");

    }
}

// if the IPN POST was 'INVALID'...do this


else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

mail($notify_email, "INVALID IPN", "$res\n $req");
}
}
fclose ($fp);
}
?>



View Postno2pencil, on 27 Jan, 2010 - 09:49 PM, said:

View Postbrosskgm, on 27 Jan, 2010 - 07:23 PM, said:

Does anyone have the step by Step setup for paypal subscription using php mysql?

What documentation are you using for this project?

PayPal's website has all kinds of wonderfully detailed information about their API from functionality to variable usage.

Quote

I've created the sandbox account to test, I have downloaded all the php and mysql tables, but have been running in to a mental block how to get it to work.

I didn't do any of this. Not that I'm saying you shouldn't, but it certainly doesn't guarantee it to work. The mysql tables would be for your own usage. The data that you pass to PayPal will transfer the money & create a subscription for the account paying you. Using mysql (or any data storage) on your side is only for your own records.

Quote

I have a sign-up page, but all the info in the paypal pages has a lot more than mine

Without seeing your code, it's impossible to know if you have the code correct.

Quote

Do I have to have our login use their tables or do I still use our own.

Login for PayPal or for your membership site that they are signing up for?

PayPal does not govern your site.

Quote

They don't really give much in the way of help or man pages.

Untrue.

Quote

Their site needs a return url. But doesn't say what they are looking for in the return.

Again, this isn't true. The usage of their API is available in full detail.


The main documentation for using the PayPal API (IPN) is available here, complete with detailed explanation of the transaction, & a sample IPN message and response scenario.


Also, make sure that your account is setup to even accept payments from the PayPal API. Refer to page 36 of this documentation.

View Postbrosskgm, on 27 Jan, 2010 - 07:23 PM, said:

Post Removed

Dude, that's just not cool.

I spent all that time trying to help you out...


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 28 January 2010 - 02:35 PM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: Working with the PayPal API : Post Removed by Poster

Posted 28 January 2010 - 02:36 PM

Dude, please...use CODE TAGS when you're posting code.

:code:
Was This Post Helpful? 0
  • +
  • -

#5 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: Working with the PayPal API : Post Removed by Poster

Posted 28 January 2010 - 05:54 PM

Ooops, Sorry, I missed this one.

View PostJackOfAllTrades, on 28 Jan, 2010 - 01:36 PM, said:

Dude, please...use CODE TAGS when you're posting code.

:code:

Was This Post Helpful? 0
  • +
  • -

#6 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: Working with the PayPal API : Post Removed by Poster

Posted 28 January 2010 - 06:10 PM

The link you gave telling how everything needs to be set up tells me nothing.

I'm told this is easy, and it's not. I don't understand this. This is why I keep asking for a book, or site or something that tells you how to do it.

It tells you

A Sample IPN Message and Response

An IPN message consists of variables that describe the transaction. These variables contain information about you, your customer, and the details of the transaction itself.

PayPal sends a message, similar to the following one, for a $19.95 purchase made by Express Checkout:

But doesn't tell you how to handle it, or how to get it.

This is not for someone trying to learn all this.

No wonder people are charging to do this and no one in their support forum they send you to has helped anyone since last June.

Yes the business account is set up and so is the sandbox account, and test client accounts. I even get told that the return link is valid when you run the test from their site, but not when you run it.

Again, it tells you this, but not to do with it.

mportant:

After you receive the VERIFIED message, there are several important checks you must perform before you can assume that the message is legitimate and not already processed:

Confirm that the payment status is Completed.

Use the transaction ID to verify that the transaction has not already been processed, which prevents duplicate transactions from being processed.

Validate that the receiver’s email address is registered to you.

Verify that the price, item description, and so on, match the transaction on your website.
Non-IPN Notification Mechanisms

You can use IPN with other notification mechanisms. For example, you can use PDT or the API to determine real-time information about a transaction and let IPN notify you of any changes after the transaction occurs.

If you are using Website Payments Standard, you can use PDT to obtain information about the transaction. If you are using Express Checkout or Direct Payment, the PayPal API notifies you of the status and details of the transaction immediately and automatically. In either case, you can immediately display to your customer the information being returned from PayPal. You should not use IPN for this purpose.

View Postbrosskgm, on 28 Jan, 2010 - 12:10 PM, said:

Sorry,

I removed the post when no one responded. your post was not even listed after a day 1/2 so I figured I shouldn't have asked the question and didn't want to clutter up the list with unwanted questions and an awfull amount of code..

I have an html page with username, password fields and the paypal subscribe button. It goes to their sandbox site to test.

When I get to the site I log in with the test user that was created, but once I log in it tells me

"The link you have used to enter the PayPal system is invalid. Please review the link and try again."

I want the user to pay and have the account ready to go with no intervention to having to add them.


# Table structure for table `paypal_cart_info` #

CREATE TABLE `paypal_cart_info` (
 `txnid` varchar(30) NOT NULL default '',
 `itemname` varchar(255) NOT NULL default '',
 `itemnumber` varchar(50) default NULL,
 `os0` varchar(20) default NULL,
 `on0` varchar(50) default NULL,
 `os1` varchar(20) default NULL,
 `on1` varchar(50) default NULL,
 `quantity` char(3) NOT NULL default '',
 `invoice` varchar(255) NOT NULL default '',
 `custom` varchar(255) NOT NULL default ''
) TYPE=MyISAM;

# Table structure for table `paypal_subscription_info` #

CREATE TABLE `paypal_subscription_info` (
`subscr_id` varchar(255) NOT NULL default '',
 `sub_event` varchar(50) NOT NULL default '',
 `subscr_date` varchar(255) NOT NULL default '',
 `subscr_effective` varchar(255) NOT NULL default '',
 `period1` varchar(255) NOT NULL default '',
 `period2` varchar(255) NOT NULL default '',
 `period3` varchar(255) NOT NULL default '',
 `amount1` varchar(255) NOT NULL default '',
 `amount2` varchar(255) NOT NULL default '',
 `amount3` varchar(255) NOT NULL default '',
 `mc_amount1` varchar(255) NOT NULL default '',
 `mc_amount2` varchar(255) NOT NULL default '',
 `mc_amount3` varchar(255) NOT NULL default '',
 `recurring` varchar(255) NOT NULL default '',
 `reattempt` varchar(255) NOT NULL default '',
 `retry_at` varchar(255) NOT NULL default '',
 `recur_times` varchar(255) NOT NULL default '',
 `username` varchar(255) NOT NULL default '',
 `password` varchar(255) default NULL,
 `payment_txn_id` varchar(50) NOT NULL default '',
 `subscriber_emailaddress` varchar(255) NOT NULL default '',
 `datecreation` date NOT NULL default '0000-00-00' 
) TYPE=MyISAM; 


# Table structure for table `paypal_payment_info` # 

CREATE TABLE `paypal_payment_info` (
`firstname` varchar(100) NOT NULL default '',
 `lastname` varchar(100) NOT NULL default '',
 `buyer_email` varchar(100) NOT NULL default '',
 `street` varchar(100) NOT NULL default '',
 `city` varchar(50) NOT NULL default '',
 `state` char(3) NOT NULL default '',
 `zipcode` varchar(11) NOT NULL default '',
 `memo` varchar(255) default NULL,
 `itemname` varchar(255) default NULL,
 `itemnumber` varchar(50) default NULL,
 `os0` varchar(20) default NULL,
 `on0` varchar(50) default NULL,
 `os1` varchar(20) default NULL,
 `on1` varchar(50) default NULL,
 `quantity` char(3) default NULL,
 `paymentdate` varchar(50) NOT NULL default '',
 `paymenttype` varchar(10) NOT NULL default '',
 `txnid` varchar(30) NOT NULL default '',
 `mc_gross` varchar(6) NOT NULL default '',
 `mc_fee` varchar(5) NOT NULL default '',
 `paymentstatus` varchar(15) NOT NULL default '',
 `pendingreason` varchar(10) default NULL,
 `txntype` varchar(10) NOT NULL default '',
 `tax` varchar(10) default NULL,
 `mc_currency` varchar(5) NOT NULL default '',
 `reasoncode` varchar(20) NOT NULL default '',
 `custom` varchar(255) NOT NULL default '',
 `country` varchar(20) NOT NULL default '',
 `datecreation` date NOT NULL default '0000-00-00' 
) TYPE=MyISAM; 



<?php

/////////////////////////////////////////////////
/////////////Begin Script below./////////////////
/////////////////////////////////////////////////

// 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";

// If testing on Sandbox use:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 
30);

// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);


// assign posted variables to local variables
$item_name = $_POST['item_name'];
$business = $_POST['business'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$mc_gross = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$receiver_id = $_POST['receiver_id'];
$quantity = $_POST['quantity'];
$num_cart_items = $_POST['num_cart_items'];
$payment_date = $_POST['payment_date'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payment_type = $_POST['payment_type'];
$payment_status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$payment_fee = $_POST['payment_fee'];
$settle_amount = $_POST['settle_amount'];
$memo = $_POST['memo'];
$payer_email = $_POST['payer_email'];
$txn_type = $_POST['txn_type'];
$payer_status = $_POST['payer_status'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$item_number = $_POST['item_number'];
$tax = $_POST['tax'];
$option_name1 = $_POST['option_name1'];
$option_selection1 = $_POST['option_selection1'];
$option_name2 = $_POST['option_name2'];
$option_selection2 = $_POST['option_selection2'];
$for_auction = $_POST['for_auction'];
$invoice = $_POST['invoice'];
$custom = $_POST['custom'];
$notify_version = $_POST['notify_version'];
$verify_sign = $_POST['verify_sign'];
$payer_business_name = $_POST['payer_business_name'];
$payer_id =$_POST['payer_id'];
$mc_currency = $_POST['mc_currency'];
$mc_fee = $_POST['mc_fee'];
$exchange_rate = $_POST['exchange_rate'];
$settle_currency  = $_POST['settle_currency'];
$parent_txn_id  = $_POST['parent_txn_id'];
$pending_reason = $_POST['pending_reason'];
$reason_code = $_POST['reason_code'];


// subscription specific vars

$subscr_id = $_POST['subscr_id'];
$subscr_date = $_POST['subscr_date'];
$subscr_effective  = $_POST['subscr_effective'];
$period1 = $_POST['period1'];
$period2 = $_POST['period2'];
$period3 = $_POST['period3'];
$amount1 = $_POST['amount1'];
$amount2 = $_POST['amount2'];
$amount3 = $_POST['amount3'];
$mc_amount1 = $_POST['mc_amount1'];
$mc_amount2 = $_POST['mc_amount2'];
$mc_amount3 = $_POST['mcamount3'];
$recurring = $_POST['recurring'];
$reattempt = $_POST['reattempt'];
$retry_at = $_POST['retry_at'];
$recur_times = $_POST['recur_times'];
$username = $_POST['username'];
$password = $_POST['password'];

//auction specific vars

$for_auction = $_POST['for_auction'];
$auction_closing_date  = $_POST['auction_closing_date'];
$auction_multi_item  = $_POST['auction_multi_item'];
$auction_buyer_id  = $_POST['auction_buyer_id'];



//DB connect creds and email
$notify_email =  "bross@kingmanaz.net";         //email address to which 
debug emails are sent to
$DB_Server = "kingmanaz.net"; //your MySQL Server
$DB_Username = "bobross"; //your MySQL User Name
$DB_Password = "90-01145"; //your MySQL Password
$DB_DBName = "alldatabase"; //your MySQL Database Name


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



//create MySQL connection
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . 
mysql_errno());


//select database
$Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database:<br>" . mysql_error(). "<br>" . 
mysql_errno());


$fecha = date("m")."/".date("d")."/".date("Y");
$fecha = date("Y").date("m").date("d");

//check if transaction ID has been processed before
$checkquery = "select txnid from paypal_payment_info where 
txnid='".$txn_id."'";
$sihay = mysql_query($checkquery) or die("Duplicate txn id check query 
failed:<br>" . mysql_error() . "<br>" . mysql_errno());
$nm = mysql_num_rows($sihay);
if ($nm == 0){

//execute query



    if ($txn_type == "cart"){
    $strQuery = "insert into 
paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
values 
('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";

     $result = mysql_query($strQuery) or die("Cart - paypal_payment_info, 
Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
     for ($i = 1; $i <= $num_cart_items; $i++) {
         $itemname = "item_name".$i;
         $itemnumber = "item_number".$i;
         $on0 = "option_name1_".$i;
         $os0 = "option_selection1_".$i;
         $on1 = "option_name2_".$i;
         $os1 = "option_selection2_".$i;
         $quantity = "quantity".$i;

         $struery = "insert into 
paypal_cart_info(txnid,itemnumber,itemname,os0,on0,os1,on1,quantity,invoice,custom) 
values 
('".$txn_id."','".$_POST[$itemnumber]."','".$_POST[$itemname]."','".$_POST[$on0]."','".$_POST[$os0]."','".$_POST[$on1]."','".$_POST[$os1]."','".$_POST[$quantity]."','".$invoice."','".$custom."')";
         $result = mysql_query($struery) or die("Cart - paypal_cart_info, 
Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());

     }
    }



    else{
     $strQuery = "insert into 
paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,itemnumber,itemname,os0,on0,os1,on1,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
values 
('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$item_number."','".$item_name."','".$option_name1."','".$option_selection1."','".$option_name2."','".$option_selection2."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";
     $result = mysql_query("insert into 
paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,itemnumber,itemname,os0,on0,os1,on1,quantity,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
values 
('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$item_number."','".$item_name."','".$option_name1."','".$option_selection1."','".$option_name2."','".$option_selection2."','".$quantity."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')") 
or die("Default - paypal_payment_info, Query failed:<br>" . mysql_error() . 
"<br>" . mysql_errno());
    }


    // send an email in any case
 echo "Verified";
     mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n 
$struery\n  $strQuery2");
}
else {
// send an email
mail($notify_email, "VERIFIED DUPLICATED TRANSACTION", "$res\n $req \n 
$strQuery\n $struery\n  $strQuery2");
}

    //subscription handling branch
    if ( $txn_type == "subscr_signup"  ||  $txn_type == "subscr_payment"  ) 
{

      // insert subscriber payment info into paypal_payment_info table
      $strQuery = "insert into 
paypal_payment_info(paymentstatus,buyer_email,firstname,lastname,street,city,state,zipcode,country,mc_gross,mc_fee,memo,paymenttype,paymentdate,txnid,pendingreason,reasoncode,tax,datecreation) 
values 
('".$payment_status."','".$payer_email."','".$first_name."','".$last_name."','".$address_street."','".$address_city."','".$address_state."','".$address_zip."','".$address_country."','".$mc_gross."','".$mc_fee."','".$memo."','".$payment_type."','".$payment_date."','".$txn_id."','".$pending_reason."','".$reason_code."','".$tax."','".$fecha."')";
      $result = mysql_query($strQuery) or die("Subscription - 
paypal_payment_info, Query failed:<br>" . mysql_error() . "<br>" . 
mysql_errno());


         // insert subscriber info into paypal_subscription_info table
        $strQuery2 = "insert into paypal_subscription_info(subscr_id , 
sub_event, subscr_date ,subscr_effective,period1,period2, period3, amount1 
,amount2 ,amount3,  mc_amount1,  mc_amount2,  mc_amount3, recurring, 
reattempt,retry_at, recur_times, username ,password, payment_txn_id, 
subscriber_emailaddress, datecreation) values ('".$subscr_id."', 
'".$txn_type."','".$subscr_date."','".$subscr_effective."','".$period1."','".$period2."','".$period3."','".$amount1."','".$amount2."','".$amount3."','".$mc_amount1."','".$mc_amount2."','".$mc_amount3."','".$recurring."','".$reattempt."','".$retry_at."','".$recur_times."','".$username."','".$password."', 
'".$txn_id."','".$payer_email."','".$fecha."')";
        $result = mysql_query($strQuery2) or die("Subscription - 
paypal_subscription_info, Query failed:<br>" . mysql_error() . "<br>" . 
mysql_errno());


             mail($notify_email, "VERIFIED IPN", "$res\n $req\n $strQuery\n 
$struery\n  $strQuery2");

    }
}

// if the IPN POST was 'INVALID'...do this


else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation

mail($notify_email, "INVALID IPN", "$res\n $req");
}
}
fclose ($fp);
}
?>



View Postno2pencil, on 27 Jan, 2010 - 09:49 PM, said:

View Postbrosskgm, on 27 Jan, 2010 - 07:23 PM, said:

Does anyone have the step by Step setup for paypal subscription using php mysql?

What documentation are you using for this project?

PayPal's website has all kinds of wonderfully detailed information about their API from functionality to variable usage.

Quote

I've created the sandbox account to test, I have downloaded all the php and mysql tables, but have been running in to a mental block how to get it to work.

I didn't do any of this. Not that I'm saying you shouldn't, but it certainly doesn't guarantee it to work. The mysql tables would be for your own usage. The data that you pass to PayPal will transfer the money & create a subscription for the account paying you. Using mysql (or any data storage) on your side is only for your own records.

Quote

I have a sign-up page, but all the info in the paypal pages has a lot more than mine

Without seeing your code, it's impossible to know if you have the code correct.

Quote

Do I have to have our login use their tables or do I still use our own.

Login for PayPal or for your membership site that they are signing up for?

PayPal does not govern your site.

Quote

They don't really give much in the way of help or man pages.

Untrue.

Quote

Their site needs a return url. But doesn't say what they are looking for in the return.

Again, this isn't true. The usage of their API is available in full detail.


The main documentation for using the PayPal API (IPN) is available here, complete with detailed explanation of the transaction, & a sample IPN message and response scenario.


Also, make sure that your account is setup to even accept payments from the PayPal API. Refer to page 36 of this documentation.

View Postbrosskgm, on 27 Jan, 2010 - 07:23 PM, said:

Post Removed

Dude, that's just not cool.

I spent all that time trying to help you out...


*** MOD EDIT: Added code tags. Please :code: ***

Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Working with the PayPal API : Post Removed by Poster

Posted 28 January 2010 - 07:03 PM

View Postbrosskgm, on 28 Jan, 2010 - 07:10 PM, said:

This is not for someone trying to learn all this.

This API reference link is printed off & in a binder in my office. It's my PayPal IPN bible, as well as what I learned from.

I will continue to look over your code, so don't think I'm shrugging you off. I'll post again later.

Also... you have mixed content in your post. Some of it is referenced from a site, & some of it is your own post. Please use quote tags appropriately. It's hard to read what you are saying compared to what you are referencing. & there is no need to include a quote from the entire previous post.
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5382
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Working with the PayPal API : Post Removed by Poster

Posted 28 January 2010 - 09:51 PM

View Postbrosskgm, on 28 Jan, 2010 - 02:10 PM, said:

<?php

/////////////////////////////////////////////////
/////////////Begin Script below./////////////////
/////////////////////////////////////////////////

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';


Your cmd needs to be set to '_xclick-subscriptions' for reoccurring payments. You can't validate it until after it's been submitted.

After you send your initial request to PayPal, you'll get a return back (you set your return URL in the variables as per the API document) & switch case on $_GET['action'] for 'process', 'success', 'cancel', or 'ipn'.

I think part of the confusion here is that you have everything in the same php file. Anytime that I've setup a PayPal IPN project, I use Micah Carrick's PayPal class (available here) in it's own file, build the request & parse the result in a 2nd file. I would put the entire database part off until you have an understanding for the IPN process.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1