Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 08, 2012, 10:07:28 AM

Pages: [1]   Go Down
  Print  
Author Topic: help me with paypal's subscriptions and IPN  (Read 2408 times)
bharkan
Spacescooter Operator
*****
Offline Offline

Posts: 44


WWW
« on: July 24, 2004, 11:20:00 AM »

Hi,
I have a client who wants to restrict access to particular pages on his website. He wants to give his customers a free trial period to view his online tutorials, but after sometime he wants to charge them. Also he has to have a shopping cart in his website. I am thinking of going with paypal as paypal doest charge anything per month for merchant account and it is easy to set up and manage. They also have subscriptions but I am not sure how to use them to restrict access to particular pages. I have been told about IPN and writing scripts. Can someone help me? I dont know where to start.

Thank you
Logged

Bharathy Ramamurthy
ann arbor web design
solution space specializes in web design, web development, logo design, graphic design and shopping cart services
jojooboo
Jabba the Hutt
*****
Offline Offline

Posts: 717



WWW
« Reply #1 on: July 24, 2004, 11:55:26 AM »

I use IPN for my subscriptions on fflschedules.com.  Basically when PayPal processes a subscription for me, it sends a request to the URL I specify and then I have certain things set up in a MySQL database.  For example, I use the email address PayPal provides as a username and the subscription ID as the initial password.  Then when the subscription is up, PayPal sends another request to the same URL telling me that and the logins are removed from the database.

Then I just use PHP and sessions to manage the logging in/out of the site.  If they are in the database they can login, if not they can't.  The collection part of things is all handled by PayPal and that works smoothly.

Good luck!
Logged

bharkan
Spacescooter Operator
*****
Offline Offline

Posts: 44


WWW
« Reply #2 on: July 25, 2004, 09:14:56 AM »

Quote from: jojooboo
I use IPN for my subscriptions on fflschedules.com.  Basically when PayPal processes a subscription for me, it sends a request to the URL I specify and then I have certain things set up in a MySQL database.  For example, I use the email address PayPal provides as a username and the subscription ID as the initial password.  Then when the subscription is up, PayPal sends another request to the same URL telling me that and the logins are removed from the database.

Then I just use PHP and sessions to manage the logging in/out of the site.  If they are in the database they can login, if not they can't.  The collection part of things is all handled by PayPal and that works smoothly.

Good luck!


The URL that you specify when you send the request , is the restricted URL right?

Do we process the subscriptions in the normal way? I dont see any code that would help me understand the whole process. Can you please send me the code , so that I can take a look at. I am new to php, probably after seeing it I can understand and try to implement it in jsp.
Thank you for your help.

btw, I am not able to sign up in your account!!!
Logged

Bharathy Ramamurthy
ann arbor web design
solution space specializes in web design, web development, logo design, graphic design and shopping cart services
jojooboo
Jabba the Hutt
*****
Offline Offline

Posts: 717



WWW
« Reply #3 on: July 25, 2004, 12:23:27 PM »

Not sure what you mean when you say "restricted URL."  It is the IPN URL that I was describing.  It's basically just a way to get the information into the database.  PayPal offers sample codes and they even have a way for you to post received inforamtion back to them to verify the authenticity of IPN transactions (I skip this step because it's not an issue for me).

Here is the code I use:
Code:

<?
require_once("userfunctions.php");

// Change the three variables below to reflect your own database connection information.

$database = "dbname";
$user = "user";
$pass = "pass";

$db = mysql_connect("localhost", $user, $pass);
mysql_select_db($database,$db);

$result = mysql_query("INSERT INTO paypal_transactions (receiver_email, item_name, item_number, quantity, invoice, custom, 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, response, subscr_date, period1, period2, period3, amount1, amount2, amount3, recurring, reattempt, retry_at, recur_times, username, password, subscr_id) VALUES ('$receiver_email', '$item_name', '$item_number', '$quantity', '$invoice', '$custom', '$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', 'NONE', '$subscr_date', '$period1', '$period2', '$period3', '$amount1', '$amount2', '$amount3', '$recurring', '$reattempt', '$retry_at', '$recur_times', '$username', '$password', '$subscr_id')",$db);


if ($txn_type == "subscr_signup")
{
$result = mysql_query("INSERT INTO users (username, password, first_name, last_name, payer_email, subscr_id) VALUES ('$payer_email', password('$subscr_id'), '$first_name', '$last_name', '$payer_email', '$subscr_id')",$db);

      $email = $payer_email;
      $from = "From: support@fflschedules.com\r\n"
."Bcc: bschaaf@bschaaf.com";
      $mesg = "Thank you for subscribing to fflschedules.com.  This message is being sent to inform you of your login credentials for the site.\r\n\r\nPlease use the following values to access your subscription for the first time:\r\n\r\n"
              ."Username: ".$payer_email."\r\n"
              ."Password: ".$subscr_id."\r\n\r\n"
              ."You may change either (or both) of these values after you login for the first time to something that is easier to remember.  For directions on how to use the site and answers to the most common questions, please visit the fflschedules.com help page.  Also, check out http://www.fflforums.com if you need a (FREE!) place to host a league messageboard and http://www.ffllinks.com for hundreds of fantasy football links.\r\n\r\nBest of luck with your league this season and thank you for using fflschedules.com!\r\n"
              ."\r\n"
              ."Brenden Schaaf\r\n"
              ."fflschedules.com \r\n";
      mail($email, "fflschedules.com login information", $mesg, $from);
}

if ($txn_type == "subscr_payment")
{
$result = mysql_query("INSERT INTO subscriptionmoney (payment_date, payment_gross, payment_fee, txn_type, first_name, last_name, payer_email, subscr_id) VALUES ('$payment_date', '$payment_gross', '$payment_fee', '$txn_type', '$first_name', '$last_name', '$payer_email', '$subscr_id')",$db);
}

if ($txn_type == "subscr_eot")
{

  // get a random dictionary word between 4 and 7 characters long (includes 2 characters for trailing \n)
  $couponcode = get_random_word(6,9);
 
  // add a number  between 0 and 999 to it
  srand ((double) microtime() * 1000000);
  $rand_number = rand(0, 999);
  $couponcode .= $rand_number;

$timeadjust = (24 * 6 * 60 * 60);
$expirydate = date("Y-m-d",time() + $timeadjust);

$result=mysql_query("INSERT INTO subscriptionplans
(sortorder, name, displayname, initialcost, termlengthqty, termlengthdesc, renews, renewalcost, renewlengthqty, renewlengthdesc, arrowname, display, descriptivetext, percentchoosing, couponcode, active, expires)
VALUES
('999', '$couponcode', 'Repeat Customer', '7.49', '1', 'Year', 'N', '0.00', '0', '', '', 'N', 'This personalized coupon code is valid for only 5 days from the time your subscription expired.  This plan is exactly the same as our \"One Year\" renewing plan, except it is significantly discounted.  You can view the regular prices and plan details at <A HREF=\"http://www.fflschedules.com/subscriptionrates.php\">http://www.fflschedules.com/subscriptionrates.php</A>, but make sure you sign up from this page to get the discounted rates!', '0', '$couponcode', 'Y',  '$expirydate')
");

$result = mysql_query("DELETE FROM users WHERE subscr_id = '$subscr_id'",$db);
$result = mysql_query("DELETE FROM leaguenames WHERE subscr_id = '$subscr_id'",$db);
//$result = mysql_query("DELETE FROM teamnames WHERE subscr_id = '$subscr_id'",$db);
$result = mysql_query("DELETE FROM divisionnames WHERE subscr_id = '$subscr_id'",$db);
$result = mysql_query("DELETE FROM conferencenames WHERE subscr_id = '$subscr_id'",$db);
      $email = $payer_email;
//      $email = 'webmaster@fflschedules.com';
      $from = "From: support@fflschedules.com\r\n"
."Bcc: bschaaf@bschaaf.com";
      $mesg = "$first_name $last_name\r\n$payer_email\r\n\r\nThis message is just to let you know that your fflschedules.com subscription term has ended.  "
     ."Thanks again for choosing fflschedules.com for your scheduling needs.  If you would like to sign up for a new subscription, we offer you the following coupon code, which is valid for the next 5 days.  It entitles you to 25% off the normal one year subscription price.\r\n\r\nCOUPON CODE: $couponcode\r\n\r\nDIRECT LINK: http://www.fflschedules.com/subscriptiondetails.php?couponcode=$couponcode\r\n\r\n"
     ."You may visit the link above or enter the coupon code in the designated spot on the fflSchedules.com main page and follow the instructions to activate your new subscription.  You will need to reenter your league information as this subscription will be considered entirley separate from your former plan.\r\n\r\n"
     ."Even if you choose not to use the special coupon code shown above, we look forward to having the opportunity to serve you again in the future.  "
              ."Best of luck with your league this season and thank you for using fflschedules.com!\r\n"
              ."\r\n"
              ."Brenden Schaaf\r\n"
              ."fflSchedules.com \r\n";
      mail($email, "your fflschedules.com term has ended", $mesg, $from);
}


?>
Logged

bharkan
Spacescooter Operator
*****
Offline Offline

Posts: 44


WWW
« Reply #4 on: July 25, 2004, 04:01:13 PM »

Oh Thank you so much for being so helpful.

Now, what I mean by restricted URL is that, restricted member access area. I want them to subscribe and once they login, I shoudl give them access to the members only URL. Now after the free trial ends, I need to send them an email and ask them if they want to continue and then if they say yes, then I give them access to continue to see. Otherwise i have to delete their names and password from my database and restrict them from going to the member only URL.
Now of these which is done by paypal and which should be done by me?
That is what is very unclear.

When you mean  by URL that you specify with IPN, I dont understand what it has. Is this the url where we get the information from customer when they login (like username and password?) But I thought that they created account with paypal to subscribe..(hope I am not confusing you)

I see that paypal offers some code in the form of scripts but how are they useful to me in this case?
Logged

Bharathy Ramamurthy
ann arbor web design
solution space specializes in web design, web development, logo design, graphic design and shopping cart services
jojooboo
Jabba the Hutt
*****
Offline Offline

Posts: 717



WWW
« Reply #5 on: July 25, 2004, 05:37:17 PM »

How you decide to restrict member access is entirely up to you.  The PayPal piece can help you manage usernames/password in a database, but it's up to you to design the site to utilize the database to restrict access.  I use PHP and the built in session-control but there are any number of ways to do this.


As far as the free trial period.  You can set that up in your PayPal code so that they have a free period for a certain amount of time and then get charged so much for another period of time.  If they don't want to pay, they would need to cancel with PayPal prior to being charged.

The PayPal code is what you will use at your PayPal IPN page (or use something similar to what I posted above).
Logged

bharkan
Spacescooter Operator
*****
Offline Offline

Posts: 44


WWW
« Reply #6 on: July 25, 2004, 06:03:28 PM »

So if I understood you correct, these are the steps
1. I have a subscribe button
2. When user clicks on that, it takes them to paypal's subscribe page.
3. Paypal sends this information to me once they complete their transaction. (I use the code similar to what you have posted for this?)
4. Now with the information, I store that in my database and return it back to paypal for authentication.

Now with that information that I have, I have to give them access to the URL that I decide to...
Is that what it is?
What exactly does a notify_url contain? CaN I see that in your website?

Quote from: jojooboo
How you decide to restrict member access is entirely up to you.  The PayPal piece can help you manage usernames/password in a database, but it's up to you to design the site to utilize the database to restrict access.  I use PHP and the built in session-control but there are any number of ways to do this.


As far as the free trial period.  You can set that up in your PayPal code so that they have a free period for a certain amount of time and then get charged so much for another period of time.  If they don't want to pay, they would need to cancel with PayPal prior to being charged.

The PayPal code is what you will use at your PayPal IPN page (or use something similar to what I posted above).
Logged

Bharathy Ramamurthy
ann arbor web design
solution space specializes in web design, web development, logo design, graphic design and shopping cart services
jojooboo
Jabba the Hutt
*****
Offline Offline

Posts: 717



WWW
« Reply #7 on: July 25, 2004, 07:31:01 PM »

1. Yes
2. Yes
3. Yes, they send the information to the URL you specify in your PayPal account for IPN transactions.
4. Yes, store it in your database and return it to them if you wish.  I don't do that last part, but it is best to do it for security purposes.  My transactions are for relatively small dollar amounts and I always receive an email from PayPal as well, so that's my verification.

Not sure what you mean by notify_url.  If you mean the URL that PayPal posts to, then it contains what I posted above or similar.

Also, your password protection is totally separate from all of this.  You should determine how you are going to do that and get it working first before you set up the PayPal piece.
Logged

bharkan
Spacescooter Operator
*****
Offline Offline

Posts: 44


WWW
« Reply #8 on: July 25, 2004, 07:55:47 PM »

Quote from: jojooboo
1. Yes
2. Yes
3. Yes, they send the information to the URL you specify in your PayPal account for IPN transactions.
4. Yes, store it in your database and return it to them if you wish.  I don't do that last part, but it is best to do it for security purposes.  My transactions are for relatively small dollar amounts and I always receive an email from PayPal as well, so that's my verification.

Not sure what you mean by notify_url.  If you mean the URL that PayPal posts to, then it contains what I posted above or similar.

Also, your password protection is totally separate from all of this.  You should determine how you are going to do that and get it working first before you set up the PayPal piece.


Thank you so much ...it was really helpful.  One final question.. What do they mean by password management ? It says that I dont have to use paypal's subscribe if I check password management. does it mean that the customers dont have to create a paypal account?
Logged

Bharathy Ramamurthy
ann arbor web design
solution space specializes in web design, web development, logo design, graphic design and shopping cart services
jojooboo
Jabba the Hutt
*****
Offline Offline

Posts: 717



WWW
« Reply #9 on: July 26, 2004, 04:41:25 AM »

No, it means that PayPal can generate usernames and passwords for you.  I used that for a while, but find it easier to use other elements of the transaction (or just randomly generate these myself) than have PP do it for me.
Logged

bharkan
Spacescooter Operator
*****
Offline Offline

Posts: 44


WWW
« Reply #10 on: July 26, 2004, 08:57:45 AM »

Quote from: jojooboo
No, it means that PayPal can generate usernames and passwords for you.  I used that for a while, but find it easier to use other elements of the transaction (or just randomly generate these myself) than have PP do it for me.


It is much clearer now. Thank you so much. I shall get back to you if I am stuck somewhere.
Logged

Bharathy Ramamurthy
ann arbor web design
solution space specializes in web design, web development, logo design, graphic design and shopping cart services
bboy121
Newbie
*
Offline Offline

Posts: 5


« Reply #11 on: February 07, 2010, 03:58:57 AM »

Quick question to the poster above. What is userfunctions.php? Is that just the name of your file? Thanks.
Logged
scanman20
Über Jedi
*****
Offline Offline

Posts: 1520



WWW
« Reply #12 on: February 07, 2010, 08:03:04 AM »

Dude, this post is nearly six years old.
Logged

Even a broken clock is right twice a day.
NotOneBit.com
MCSE - MCSA - MCP
bboy121
Newbie
*
Offline Offline

Posts: 5


« Reply #13 on: February 07, 2010, 09:00:18 AM »

Dude, this post is nearly six years old.

Haha, yes I realized that after posting. I actually found his email address through Google searching him and emailed him directly.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: