feat: Add pay in advance logic into date service #385
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
We want to add the ability to choose to bill users at subscription date anniversary and not only on a calendar basis.
Description
Following the previous introduction of a date service (see #360) to extract logic to compute fees boundaries, few changes are required in order to use this service in the
Fees::ChargeService
andFees::SubscriptionService
:from_date
andto_date
should return the boundaries of the coming subscription period when plan is payed in advance. It will kill the need for boundaries rewriting inFees::SubscriptionService
(see https://github.com/getlago/lago-api/blob/main/app/services/fees/subscription_service.rb#L152 for example)to_date
is also used for charge, acharges_to_date
is required as charges are always billed on the passed billing period no matter if the plan is payed in advance or in arrearsingle_day_price
method is required to compute the cost of a single subscription day based on the plan cost and the period durationcurrent_usage
flag is required to return forecast dates for charges boundaries