Our company has started selling to larger customers, so we are creating subscription tiers with different feature sets to cater to our customers’ unique needs. We previously charged every customer a flat fee per month, but now we plan on charging for the number of users active on the customer's subscription plan. As a result, we're changing our billing system.
You’ve picked up the work item to implement the logic to compute the monthly charge:
Prorating Subscriptions (#8675309)
We'd like you to implement a monthlyCharge function to calculate the total monthly bill for a customer.
Customers are billed based on their subscription tier. We charge them a prorated amount for the portion of the month each user’s subscription was active. For example, if a user was activated or deactivated part way through the month, then we charge them only for the days their subscription was active.
We want to bill customers for all days users were active in the month (including any activation and deactivation dates, since the user had some access on those days).
- We do need to support historical calculations (previous dates)
- We only charge whole cents
Here’s an idea of how we might go about this:
- Calculate a daily rate for the subscription tier.
- For each day of the month, identify which users had an active subscription on that day.
- Multiply the number of active users for the day by the daily rate to calculate the total for the day.
- Return the running total for the month at the end.
- Your goal is production-quality code.
- The provided unit tests only cover a few cases that one of your colleagues shared.
- Performance is not a top concern since this code is mostly used in a batch process
- Function names and signatures are a constraint and should not change.
- Reminder: Please use the Online IDE so that your problem-solving approach is visible.