latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Prorated Upgrade

Home Forums Community Forum Prorated Upgrade

This topic contains 16 replies, has 3 voices. Last updated by  Eduan 4 years, 3 months ago.

Topic Author Topic
Posted: Monday Oct 8th, 2012 at 11:25 am #27802
Hamid
Username: zawiyaprojects

Hello Raam,

I have a programming question but please keep in mind I’m no programmer. I read up in the old forum (some time ago) something about using variables to prorate an upgrade.

I have 3 membership: Free, Plus (non-recurring) and Premier (recurring). Paid memberships are for one year.

I want to set up my options page so that Plus members can upgrade to Premier at a prorated amount based on days left in their annual membership. And Free members can simple upgrade to Plus or Premier as normal.

Here is my code so far. Syntax is NOT correct but I am hoping it will convey what I’m trying to do. My question is how would I get this to work and if not to much trouble point out the mistakes in the code.

Click link to upgrade to Premier at a prorated discount:

<?php if (current_user_is("s2member_level1")){ ?>


<?php } if (expiration_days("is greater than 1 but less than 30")){ ?>
    
http://www.domain.com/membership-options-page/?amount=77.50

<?php } else if (expiration_days("is greater than 31 but less than 60")){ ?>
    
http://www.domain.com/membership-options-page/?amount=72.95

<?php } else if (expiration_days("is greater than 61 but less than 90")){ ?>
    
http://www.domain.com/membership-options-page/?amount=68.40

<?php } else if (expiration_days("is greater than 91 but less than 120")){ ?>
    
http://www.domain.com/membership-options-page/?amount=63.85
<?php } else if (expiration_days("is greater than 121 but less than 150")){ ?>
    
http://www.domain.com/membership-options-page/?amount=59.30

<?php } else if (expiration_days("is greater than 151 but less than 180")){ ?>
    
http://www.domain.com/membership-options-page/?amount=54.75

<?php } else if (expiration_days("is greater than 181 but less than 210")){ ?>
    
http://www.domain.com/membership-options-page/?amount=50.20    
<?php } else if (expiration_days("is greater than 210 but less than 240")){ ?>
    
http://www.domain.com/membership-options-page/?amount=45.65

<?php } else if (expiration_days("is greater than 241 but less than 270")){ ?>
    
http://www.domain.com/membership-options-page/?amount=41.10

<?php } else if (expiration_days("is greater than 271 but less than 300")){ ?>
    
http://www.domain.com/membership-options-page/?amount=36.55    
<?php } else if (expiration_days("is greater than 301 but less than 330")){ ?>
    
http://www.domain.com/membership-options-page/?amount=32.00

<?php } else if (expiration_days("is greater than 331 but less than 365")){ ?>
    
http://www.domain.com/membership-options-page/?amount=27.45  

<?php } else { ?>
    
Something else

<?php } ?>

Then in the member option page I would put this (according to an old post by Jason)

[s2Member-PayPal-Button ... ra="<?php echo esc_attr($_REQUEST["amount"]); ?>"

Is this moving in the right direction? You feedback is much appreciated. Thanks

List Of Topic Replies

Viewing 16 replies - 1 through 16 (of 16 total)
Author Replies
Author Replies
Posted: Monday Oct 8th, 2012 at 1:09 pm #27808
Eduan
Username: Eduan
Moderator

Hello Hamid,

I believe you are working towards the right direction. :)

Just some quick tips, use elseif instead of else if, it is more correct, in terms of logic, and also faster. Also I suggest you use $_GET instead of $_REQUEST.

Also, in order to achieve this you will be interested in using s2Members content dripping, which you can find under Dashboard -› s2Member® -› API / Scripting -› Content Dripping, you can find a simply article about it here: Knowledge Base » Introduction to Content Dripping in s2Member®

Hope this helps. :)

Posted: Monday Oct 8th, 2012 at 1:35 pm #27810
Hamid
Username: zawiyaprojects

Thanks Eduan for the tips…

I’m getting ready to read up on the content dripping link you provided. My understanding of content dripping was offering content on a timed basis. I didn’t know you could offer upgrades with it though. Thanks again.

Posted: Monday Oct 8th, 2012 at 2:09 pm #27815
Hamid
Username: zawiyaprojects

Eduan, I see what you mean now with the content dripping part. Thanks.

Would this be proper syntax then?

<?php if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 1){ ?>
	<?php if(S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 330){ ?>
		http://www.domain.com/membership-options-page/?amount=77.50
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 300){ ?>
		http://www.domain.com/membership-options-page/?amount=72.95
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 270){ ?>
		http://www.domain.com/membership-options-page/?amount=68.40
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 240){ ?>
		http://www.domain.com/membership-options-page/?amount=63.85
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 210){ ?>
		http://www.domain.com/membership-options-page/?amount=59.30
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 180){ ?>
		http://www.domain.com/membership-options-page/?amount=54.75
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 150){ ?>
		http://www.domain.com/membership-options-page/?amount=50.20
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 120){ ?>
		http://www.domain.com/membership-options-page/?amount=45.65
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 90){ ?>
		http://www.domain.com/membership-options-page/?amount=41.10
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 60){ ?>
		http://www.domain.com/membership-options-page/?amount=36.55
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 30){ ?>
		http://www.domain.com/membership-options-page/?amount=32.00        
	<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 1){ ?>
		http://www.domain.com/membership-options-page/?amount=27.45
	<?php } ?>
<?php } else if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 0){ ?>
    	Upgrade to Plus or Premier membership.
<?php } ?>
Posted: Monday Oct 8th, 2012 at 2:17 pm #27816
Eduan
Username: Eduan
Moderator

That should work, just take in mind in all of them you’re checking for greater than or equal to certain days (>=), and for the last else if, you can just use an else, so that it’s the default action.

– Eduan

Posted: Monday Oct 8th, 2012 at 2:42 pm #27820
Hamid
Username: zawiyaprojects

Nope, didn’t work :(

If I created a user via the dashboard and assigned them level 1, does it automatically assign them expiration date? And based on the code above, I will need to wait at least one day, correct?

Posted: Monday Oct 8th, 2012 at 2:49 pm #27821
Hamid
Username: zawiyaprojects

OK, it worked after setting the EOT date and changing the >=1 to >=0

What did you mean about changing the elseif to else?

Posted: Monday Oct 8th, 2012 at 3:06 pm #27825
Eduan
Username: Eduan
Moderator

The last elses:

<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 1){ ?>
	http://www.domain.com/membership-options-page/?amount=27.45
<?php } ?>
<?php } else if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 0){ ?>
   	Upgrade to Plus or Premier membership.
<?php } ?>

This doesn’t work, this would be more correct:

<?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 1){ ?>
	http://www.domain.com/membership-options-page/?amount=27.45
<?php } ?>
<?php } elseif (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 0){ ?>
   	Upgrade to Plus or Premier membership.
<?php } ?>

– Eduan

Posted: Monday Oct 8th, 2012 at 11:45 pm #27842
Hamid
Username: zawiyaprojects

It all seems to work up until I click on the Paypal button. When redirected to Paypal, I get the following error:

We were unable to decrypt the certificate id.
Posted: Tuesday Oct 9th, 2012 at 6:18 am #27871
Raam Dev
Username: Raam
Staff Member

That would indicate that something you’re doing is corrupting your PayPal button code. How are you generating the PayPal button? Are you copying/pasting the s2Member-generated shortcode or are you using HTML?

Could you please copy/paste one of the button codes here for us to see?

Posted: Tuesday Oct 9th, 2012 at 6:56 am #27878
Hamid
Username: zawiyaprojects

Hey Raam, here is the actual code in the member profile page contain the elseif statements

... <?php } elseif (S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 0){ ?>
<a href="http://www.domain.com/member-options/?amount=27.45">Upgrade to Premier for only $27.45</a>...
	

And here is the Paypal button short code in the member options page

[s2Member-PayPal-Button level="2" ccaps="" desc="Prorated Upgrade to Premier Member" 
ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="www.domain.com" ta="0" tp="0" tt="D" 
ra="<?php echo esc_attr($_GET["amount"]); ?>" rp="1" rt="Y" rr="BN" rrt="" rra="1" 
image="default" output="button" /]
  • This reply was modified 4 years, 3 months ago by  Hamid.
Posted: Tuesday Oct 9th, 2012 at 7:13 am #27885
Hamid
Username: zawiyaprojects

OK it works now. I had to turn off “Enable Button Encryption?” under the Paypal Options >> Paypal Account Details

Posted: Tuesday Oct 9th, 2012 at 9:03 am #27890
Hamid
Username: zawiyaprojects

Update:

Everything seems to work well using the above example and I was able to upgrade via Paypal. Thanks for the help :)

I have a separate question:

How do I actually display the number of S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS. What code would I use to display the actual number of days in a subscription?

Posted: Tuesday Oct 9th, 2012 at 11:54 am #27902
Hamid
Username: zawiyaprojects

Please disregard last question, I got it.

Posted: Tuesday Oct 9th, 2012 at 12:46 pm #27907
Eduan
Username: Eduan
Moderator

Glad you solved the problem Hamid. :)

Remember that you need to have a PHP Execution plugin installed, so the PHP can be executed. ;)

-Eduan

Posted: Wednesday Oct 10th, 2012 at 5:37 am #27967
Hamid
Username: zawiyaprojects

Hello Support and other s2member users,

After reading up on other coding examples and the s2member documentation, I ended up using an alternate solution which I think is much better, less coding and the user won’t have to go through two step process to get to Paypal’s payment page. It also resolves a formatting issue I was having with the Paypal button, but that may be related to my theme.

PREREQUISITE: If you offer an annual Level 1 membership and you want to automatically calculate the amount a user would have to pay to upgrade to an annual Level 2 membership.

WHAT IT DOES: Calculates a Level 1 user’s PAID REGISTRATION DAYS which is then subtracted from 365 and then multiplied with the daily rate of that subscription. This figure is the user’s credit amount toward Level 2 subscription. The prorated rate (for upgrading to Level 2) is calculated by subtracting this credit amount from the Level 2 subscription fee. It shows the prorated fee to only Level 1 members. For free subscribers it shows a link for each of the paid subscriptions.

WHERE IT GOES: You can place the code below in your members options page or a separate page that you members can call up.

<?php
$PlusFee = 49.95; // Enter subscription fee for Level 1 membership 
$PremFee = 79.95; // Enter subscription fee for Level 2 membership
$PlusDailyRate = .13685; // Enter daily rate based on level 1 subscription fee divided by 365
$PlusCredit = ((365 - S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS) * $PlusDailyRate);
$PremCharges = $PremFee - $PlusCredit; 
$PremCharges = round($PremCharges,2); //round off number to 2 decimal points
?>

<?php
if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 1){ ?>
	<?php if(S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 0){ ?>
<a href="[s2Member-PayPal-Button level="2" ccaps="" desc="Prorated Upgrade from Plus to Premier membership for one year for $<?php echo esc_attr($PremCharges); ?>" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="your.domain.com" ta="0" tp="0" tt="D" ra="<?php echo esc_attr($PremCharges); ?>" rp="1" rt="Y" rr="0" rrt="" rra="1" image="default" output="url" /]">Upgrade to Premier for only $<?php echo esc_attr($PremCharges); ?>!</a>
	<?php } ?>
	
<?php } elseif (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 0){ ?>
<a href="[s2Member-PayPal-Button level="1" ccaps="" desc="Plus membership for one year access, non-recurring (one time charge)" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="your.domain.com" ta="0" tp="0" tt="D" ra="49.95" rp="1" rt="Y" rr="0" rrt="" rra="1" image="default" output="url" /]">Upgrade to Plus member today!</a>
or
<a href="[s2Member-PayPal-Button level="2" ccaps="" desc="Premier membership for one year with automatic yearly recurring charges for ongoing access." ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="your.domain.com" ta="0" tp="0" tt="D" ra="79.95" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="url" /]">Upgrade to Premier status for immediate access to over 4000 audio files!</a>
<?php } ?>

NOTE: output=”url” if you want to use text instead of the Paypal image.

I’m now working on including my own “Buy Now!” image instead of the text. Just thought to share just in case someone else was looking to do the same :)

Posted: Wednesday Oct 10th, 2012 at 9:51 am #27989
Eduan
Username: Eduan
Moderator

That’s awesome Hamid! Thanks. :)

Viewing 16 replies - 1 through 16 (of 16 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.