Dynamic Trial Period - 90 days maximum

I’m using @raamdev awesome post to generate a dynamic trial period that sets a specific day for all members to start paying for their subscription.

My client wants their members to start payment for their yearly subscription on 31st July 2016. However this poses a problem because the dynamic trial period will start from 159 days if someone was to register today.

S2member does not allow the trial period in days to go beyond 90 days due to PayPal subscription restrictions e.g. 90 days, 52 weeks, 1 Year.

Do I just convert it to weeks by altering this piece of code: $trial_days = floor($difference/60/60/168);

Some insight would be great here.

That’s right. You can just convert it to weeks in order to stay within the limits imposed by PayPal. It’s worth noting that Stripe is easier to work with in this regard, as this limitation does not apply if you’re using Stripe. Just wanted to mention it :slight_smile:

Thanks for replying. Unfortunately converting into weeks means that the latest day the free trial would end for a member would be August the 6th (6 day margin of error) :sweat:. The snippet of code does not impose an absolute limit which is July 31st when converted to weeks.

$cycle_start_year = '2016';

$cycle_start_month = '7';

$cycle_start_day = '31';

$cdate = mktime(0, 0, 0, $cycle_start_month, $cycle_start_day, $cycle_start_year);

$today = time();

$difference = $cdate - $today;

if ($difference < 0) { $difference = 0; }

$trial_weeks = ceil($difference/60/60/168);  //rounded up instead of down