Skip to content

Instantly share code, notes, and snippets.

@LarryUllman
Created July 23, 2014 14:49
Show Gist options
  • Save LarryUllman/fbe8db2f1ecc6c92e74a to your computer and use it in GitHub Desktop.
Save LarryUllman/fbe8db2f1ecc6c92e74a to your computer and use it in GitHub Desktop.
Stripe - Calculate Subscription Proration
proration cost = (period end - API request time) / (period end - period start) * quantity * plan price
@bocharsky-bw
Copy link

What is API request time and how to get it? Is it a time in seconds?

@wannymiarelli
Copy link

wannymiarelli commented Aug 13, 2018

@bocharsky-bw it is the actual time, like date() now() or wathever. As of Stirpe uses unix time you should be able to use it to.

@ggcespia
Copy link

I would use this for a yearly subscription: quantity * plan_price * 12 * (period end - Api request time) / (period end - period start)
You compute a ratio of the time left / total time, then multiply that by the annual cost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment