Open e4se opened 7 months ago
Hello. If I understand correctly what's happening.... You have a monthly subscription so that line calculates how many months you already had from the start of the subscription to now. It then adds a month to that (next line of code) to tell you when the next recurrence ends. I don't think that function tells you when the subscription ends, only when the next cycle ends.
What is the difference between recurrence ends and subscription ends?
Let's say your subscription is a monthly subscription that lasts 1 year. You started on January 6th 2024.
Recurrence ends will be on the 5th of each month until January 2025. Subscription end will be January 5th 2025.
Again... If I understand correctly, please somebody correct me if I misunderstood.
Let's consider an example: I have a monthly subscription that started_at is 01.01.2024 and expired_at is 31.01.2024. When I use the ->renew() method, I expect it to update the subscription to started_at is 01.01.2024 and expired_at is 29.02.2024. But now it depends on the date when I call this method. For instance, if I renew it on 01.11.2023, the subscription gets updated to started_at is 01.01.2024 and expired_at is 29.04.2024 instead.
I think you are confusing the system because you are renewing a subscription that hasn't even started yet. When you call renew() on 01.11.2023, the subscription is not overdue yet so getRenewedExpiration() calls calculateNextRecurrenceEnd($this->expired_at)
So in your example calculateNextRecurrenceEnd will calculate the time between 01.11.2023 and 31.01.2024 (original end date) which is 3 months rest of November, then December, then January). Then add 1 month to that to know the new duration of the subscription. It will add that duration to the original start date (01.01.2024) and you'll end up with a new expiration date 4 months after 01.01.2024 which is 29.04.2024 that to give you the new expiration date.
Now let's say you renew while the subscription is active so between 01.01.2024 and 31.01.2024. Let's say on 15.01.2024 Then the system calculate the difference in month between now (15.01.2024) and 31.01.2024 and finds 1. It adds 1 month to that so that's 2 months. he adds the 2 month to the start date 01.01.2024 which give you the correct end date of 29.02.2024
Finally let's say you renew the subscription when it's overdue so after 31.01.2024. Let's say on 15.02.2024. The calculation will be slightly different as instead of calculating the difference between now and the real expiry date, it will calculate the difference between now and now which is 0. Then add 1 month to that wich is 15.03.2024 which will be your new expiry date
However, the ->renew() method adds a month to the expired_at date or now() instead of adding it to the started_at date, contrary to what is described.
I didn't run it myself. I based my answer on the code and the information you provided. From what I can see the code is working properly when used as it is intended.
It does add it to the expired_at date or now() indeed. If the subscription is still ongoing, adding it to expired_at or started_at will give you the same result. If the subscription has already expired and is overdue, adding it to the started_at date wouldn't make sense.
Hi, could someone please explain the rationale behind adding this line? I'm encountering an issue with the subscription renewal method when attempting to renew a subscription that expires in two months. I'm on a monthly plan, but when I renew a subscription that has two months left until expiry, the new expires_at date incorrectly extends by three months instead of one. Here's the relevant code segment for reference:
https://github.com/lucasdotvin/laravel-soulbscription/blob/develop/src/Models/Concerns/HandlesRecurrence.php#L20