longshotlabs / meteor-plans-stripe

Stripe service add-on for aldeed:plans package
https://atmospherejs.com/aldeed/plans-stripe
MIT License
18 stars 11 forks source link

After deleting billing information (delete stripe customer) user should remain on plan until end of billing cycle #9

Open sferoze opened 7 years ago

sferoze commented 7 years ago

I was working on implementing this today and ran into one issue.

If a customer wants to delete their billing information, the only way to do it with Stripe is to delete the customer from Stripe.

So the user will no longer has a stripe customer #.

Thus it always sets the user back to the free plan when it syncs since the customer is no longer in Stripe.

But if a customer deletes their billing information (thus deleting stripe customer), and the customer still has time left on the current billing cycle....syncing will make the customer forfeit the remaining time they paid for.

Syncing would be fine as long as the next time the customer subscribes to pro (thus creating a new stripe customer) the system should determine if they have time left on the current billing cycle. If so the system should set a trial_start_date at the date the current billing cycle end.

The hack below avoids syncing with Stripe until the current billing cycle end date has arrived. But there is a problem with it.

Accounts.onLogin (info) ->
  userId = info.user._id

  syncAndSet = ->
    AppPlans.sync userId: userId
    plan = AppPlans.get(userId: userId)
    if !plan
      AppPlans.set 'lite', userId: userId

  if !!AppPlans.endDate('pro', userId: userId)
    if moment().isAfter(AppPlans.endDate('pro', userId: userId))
      syncAndSet()
  else
    syncAndSet()

This issue arises when the customer tries to resubscribe to the plan and they also have time left on the current billing cycle ... since they are no longer a stripe customer (since they deleted their billing info) ... it charges them immediately instead of charging them on the next billing cycle.

So what needs to happen is when they subscribe again, and if they are no longer a stripe customer, the package should set the first billing date to be when AppPlans.endDate is

sferoze commented 7 years ago

@aldeed I have updated the post above to clarify the issue.

aldeed commented 7 years ago

@sferoze OK, so you have to delete the customer, which also cancels all subscriptions, and by default no proration refund is given.

One solution would be to issue a refund for the rest of the month as soon as you delete the customer. Then going back to the paid plan would start over with a different billing period, but they wouldn't be overcharged.

Otherwise, yeah I think it would make sense to use the endDate as the first billing date if we are creating a new customer.