I was testing trial memberships to make sure they were behaving as expected, and I had my example one set to be for one year, with a trial membership of one hour. Once the hour expired and cron ran, the user's card was charged. I checked the database and the next_payment date was set to an hour after cron ran. It looked like it was updating next_payment based off of the trial membership setting (one hour) instead of the real setting (one year). After an hour when cron ran again, the card was incorrectly charged again, but the next_payment date was a year in the future, which is correct.
I tracked down this issue, and it seems to be with this line in the function ms_core_increment_recurring_schedule:
- if ($recurring_schedule->trial_amount AND $recurring_schedule->trial_length AND !$recurring_schedule->current_payments) {
- $next_payment = strtotime(ms_core_get_string_time($recurring_schedule->trial_length, $recurring_schedule->trial_unit), $time);
- }
- else {
- $next_payment = strtotime(ms_core_get_string_time($recurring_schedule->main_length, $recurring_schedule->main_unit), $time);
- }
I believe that the only time next_payment should be calculated using the trial unit and length is when the recurring schedule record is being created, not when it's being updated. The first time cron is run, it goes into the if condition and is incremented only an hour. The second time it runs, since $recurring_schedule->current_payments is now 1, then it goes into the else condition. I changed the code to remove the whole section above and used just the else condition:
- $next_payment = strtotime(ms_core_get_string_time($recurring_schedule->main_length, $recurring_schedule->main_unit), $time);
This then resulted into the customer being charged as expected.








Thanks for letting me know. This was something left over from before the create_recurring_schedule function was made. I've removed the code now.
-Leighton