Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new date service to compute bounds for subscription and charge fees #360

Merged
merged 18 commits into from
Aug 4, 2022

Conversation

vincent-pochet
Copy link
Collaborator

@vincent-pochet vincent-pochet commented Aug 2, 2022

Context

We want to add the ability to choose to bill users at subscription date anniversary and not only on a calendar basis.

Changes

The objective of this pull request is to introduce a new Subscriptions::DatesService.
This service is responsible for computing all bounds for invoice and related subscription and charge fees.

It exposes few methods:

  • from_date: compute the lower bound of an invoicing period based on a provided timestamp and subscription
  • to_date: compute the upper bound of an invoicing period based on a provided timestamp and subscription
  • charges_from_date: compute the lower bound of an invoicing period for charges based on a provided timestamp and subscription. It allows to handle the bill_charge_monthly case for yearly plans
  • next_end_of_period: compute the next end of period for a given subscription and date

Note: The service is not yet used in invoicing services. This will come with a latter change

Related resources

This PR follows the previous one #352 to update the subscription data model.

@vincent-pochet vincent-pochet added Subscription Relation to the Subscriptions Invoice Related to Invoices labels Aug 2, 2022
@vincent-pochet vincent-pochet self-assigned this Aug 2, 2022
app/services/subscriptions/dates_service.rb Outdated Show resolved Hide resolved
app/services/subscriptions/dates_service.rb Outdated Show resolved Hide resolved
app/services/subscriptions/dates_service.rb Outdated Show resolved Hide resolved
app/services/subscriptions/dates_service.rb Outdated Show resolved Hide resolved
app/services/subscriptions/dates_service.rb Outdated Show resolved Hide resolved
@rsempe
Copy link
Collaborator

rsempe commented Aug 3, 2022

Just a general thought: Do you think extracting that logic into 3 smaller classes (weekly, monthly and yearly) can be interesting?

@vincent-pochet
Copy link
Collaborator Author

Just a general thought: Do you think extracting that logic into 3 smaller classes (weekly, monthly and yearly) can be interesting?

Yeah, good suggestion, it could make it a bit easier to read. Let's try it!

Copy link
Contributor

@jdenquin jdenquin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a small typo
🚀

spec/services/subscriptions/dates/monthly_service_spec.rb Outdated Show resolved Hide resolved
@vincent-pochet vincent-pochet force-pushed the feature/subscription-date-service branch from 39ecc41 to 850285e Compare August 4, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invoice Related to Invoices Subscription Relation to the Subscriptions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants