payolapayments / payola

Drop-in Rails engine for accepting payments with Stripe
http://www.payola.io
Other
818 stars 154 forks source link

Stripe::InvalidRequestError: And Payola::Subscriptions might be out of sync #314

Closed dylanjha closed 6 years ago

dylanjha commented 7 years ago

I'm seeing webhooks fail with this error.

Stripe::InvalidRequestError: Customer cus_xxx does not have a subscription with ID sub_xxx

When I log into the stripe dashboard I can see that this subscription is associated to the customer that it's trying to use. I think I see what's happening.

  1. User creates a subscription.
  2. Payments fail, using the default settings in stripe to retry 3 times then cancel subscription and after it is canceled the subscription is no longer "active", it's still associated with the customer on stripe but calling subscriptions.retrieve will fail because the subscription is now canceled:
stripe_sub = Stripe::Customer.retrieve(subscription.stripe_customer_id, secret_key).subscriptions.retrieve(invoice.subscription, secret_key)

I'm using the default retry failed payments strategy for Stripe subscriptions:

image 2017-07-13 at 2 35 45 pm

This might be causing the Payola::Subscriptions table to be out-of sync with the real stripe data. Is the following data I'm seeing correct?

A. Subscription is canceled by the user

B. Subscription has been canceled due to inability to collect payment

Are these the expected states for the above subscriptions^

In situation A it makes sense to let the user still have access to the application until the end of the billing cycle that they already paid for. In situation B, I want to block access to the application because they haven't paid for this billing cycle.