If upgrading (say from a $10/month to a $20/month plan 3 days into the subscription):
- Calculate the fraction of the period used to this point under the previous plan,
3 days /30 days = 0.1 = x
Note: This is approximate, since months can have different numbers of days, there are leap years, etc.
xby the previous plan's billing amount,
amount_prevto get how much to credit the customer back,