Jump to content
Larry Ullman's Book Forums

Ipn Help With Different Subscription Parameters


Recommended Posts

Hi Larry,

Your book has enabled a veterinarian to learn php! Talk about teaching an old dog new tricks...

 

My question is how would I modify the ipn "check values" code if I wanted to offer a two week free trial subscription before charging monthly? I know how to set up the subscribe button in paypal but not this part in your code.

Thanks in advance. I am not sure how this should be handled because initially the 'mc_gross' would be zero but eventually would equal the monthly subscription amount...

 

// Check for the right values:
		if ( isset($_POST['payment_status'])
		 && ($_POST['payment_status'] == 'Completed')
		 && ($_POST['receiver_email'] == 'dream_1299424800_biz@mpvets.com')
		 && ($_POST['mc_gross'] == 10.00)
		 && ($_POST['mc_currency']  == 'USD') 
		 && (!empty($_POST['txn_id']))
		) {

Thanks,

Sam

Link to comment
Share on other sites

Hello Sam,

 

Thanks for the nice words. Me teaching you PHP is probably a lot easier than you teaching me to be a vet!

 

Okay, and I'm just free thinking here, you could add a two_week column to the table. A user registers and the expiration is set to yesterday and the two_week is 0. The user goes through PayPal. The first time the IPN sends back a 0 amount, if two_week is still 0, meaning they haven't done a two-week subscription yet, you set the expiration to 2 weeks from now and update the two_week to 1. When future IPNs come in, with appropriate amounts, you add a month to the expiration. If another 0 amount comes through for that same user, they don't get credited another two weeks because they already had that. Does that sound like what you want to do?

Link to comment
Share on other sites

Yes, that sounds like it will work.

 

 if ( isset($_POST['payment_status'])
                        && ($_POST['payment_status'] == 'Completed')
                        && ($_POST['receiver_email'] == 'dream_1299424800_biz@mpvets.com')
                        && ($_POST['mc_gross'] == 0.00)
                        && ($_POST['mc_currency']  == 'USD') 
                        && (!empty($_POST['txn_id']))
                        && ($2week == '0')
                       ) {
                      //"add 2 weeks subscription" to expiration date
                       .........
if ( isset($_POST['payment_status'])
                        && ($_POST['payment_status'] == 'Completed')
                        && ($_POST['receiver_email'] == 'dream_1299424800_biz@mpvets.com')
                        && ($_POST['mc_gross'] == 10.00)
                        && ($_POST['mc_currency']  == 'USD') 
                        && (!empty($_POST['txn_id']))
                        && ($2week == '1')
                       ) { //"add 1 month" to expiration date



 

Is that what you mean?

Thanks,

Sam

Link to comment
Share on other sites

Yes, exactly. Although...you can't have a variable named $2week and that would come from the database and it'd be a number, so you shouldn't use quotes around it. You can simplify this code in a couple of ways, too. I'd be inclined to have one conditional that confirms payment status, receiver email, mc currency, and txn ID. Then another conditional determines the expiration increase based upon the value of mc gross and the two week subscription. But that's all minor stuff. It looks like you've got the premise down.

Link to comment
Share on other sites

 Share

×
×
  • Create New...