Last active
June 16, 2017 08:13
-
-
Save snez/b10090b752ee5d113ccf9f0b2fe82124 to your computer and use it in GitHub Desktop.
Modify getTrialDays() to make all subscriptions start on the 10th of each month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
protected function getTrialDays($details) | |
{ | |
switch ($details['trial_period_unit']) { | |
case null: | |
$days = 0; | |
break; | |
case 'day': | |
$days = $details['trial_period_frequency']; | |
break; | |
case 'week': | |
$days = $details['trial_period_frequency'] * 7; | |
break; | |
case 'semi_month': | |
$days = $details['trial_period_frequency'] * 14; | |
break; | |
case 'month': | |
$days = $details['trial_period_frequency'] * 30; | |
break; | |
case 'year': | |
$days = $details['trial_period_frequency'] * 356; | |
break; | |
} | |
// If set to month, bill on the 10th | |
if ($details['period_unit'] == 'month') | |
{ | |
$day = date("j"); | |
if ($day < 10) | |
{ | |
$days = 10 - $day; | |
} | |
else if ($day > 10) | |
{ | |
$target = strtotime("first day of next month"); | |
$target = strtotime(date("c", $target) . " + 9 days"); | |
$datediff = $target - time(); | |
$days = floor($datediff/(60*60*24)); | |
} | |
} | |
return round($days); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment