[Bug: Wave] Canceled subscriptions in Stripe are not reflected in the database
When a user cancels their subscription in Stripe checkout, it's not updated in the database. Users can continue using a subscription after cancellation! I thought I had noticed this bug before and thought maybe my server had crashed or something. Well I just had another user cancel yesterday and you wouldn't know it anywhere. When I impersonate them they can still log into their account and use it like normal, even though my middleware checks for subscription. The DB still shows an active account. Do I need to lock the Stripe API to a specific version or something, or does the code need to be updated? Very critical problem!
Also, not sure if this is related or not, perhaps it has something to do with caching. But, when a new user registers, their subscription page does not immediately update. It will still show they are registered and ask them to choose a plan. Logging out/in/new window does not help. A few minutes pass and all is good. Not sure what that's about.
ALSO, if you set your product to cancel immediately upon cancellation (as opposed to the end of the billing period) an exception occurs when redirecting back from Stripe to the app URL. I noticed there's attempt at caching for subscriptions in the user mode. I think that's the culprit. I think caching subscriptions is a mistake, OR the clearUserCache() function looks like it's supposed to take care of that but it's never referenced anywhere.
public function plan()
{
$latest_subscription = $this->latestSubscription();
return Plan::find($latest_subscription->plan_id);
}
Cannot get plan_id on null
Did some digging in StripeWebhook.php and the docs. I followed the docs from the beginning and it says on https://devdojo.com/wave/docs/features/billing#add-stripe-webhook-secret:
"5. From this screen you will need to check all of the Checkout Events and all of the Billing Portal Events, then click continue."
These events only include:
- billing_portal.configuration.created
- billing_portal.configuration.updated
- billing_portal.session.created
- checkout.session.async_payment_failed
- checkout.session.async_payment_succeeded
- checkout.session.completed
- checkout.session.expired
The StripeWebhook.php looks for events such as customer.subscription.updated and customer.subscription.deleted but they are never sent from Stripe because they were not included in the events to send. I tried enabling them and I will see if that works.