@singh The subscription will be updated via a webhook Stripe sends to your server.
Laravel 8 Stripe Syncing up with the Subscription Table in Real Time
I am aware that Laravel has the following function for to sync the subscriptions table with Cashier/Stipe.
protected static function booted() { static::updated(queueable(function ($customer) { $customer->syncStripeCustomerDetails(); })); }
However, this method is dependent on queues. However, in certain cases - such as Plan Cancellation or Upgrade a user may want to see the updates right away and that requires syncing in the real time. Can this be done in the controller? For example lets say I switch a user to a different plan. that is effective immediately by using the following code; How do I make a sync immediately after the successful upgrade so that the user can see their new plan in the user dashboard of my app once they are redirected to it. $user->subscription('default')->swapAndInvoice('price_yearly');
After doing additional search - it updates the stripe_price field in the db but not the name . That throws off what my customers will see.
Temporary Hack:
$user->subscription($oldname)->swapAndInvoice($newpriceid);
DB::table('subscriptions')
->where('user_id', $user->id)->where('stripe_status', 'active')->where('name', $oldname)
->update([
'name' => $newname,
]);
II have requested the Laravel team to see if they can treat this as a bug. Cashier should be able to update the Subscription table upon an upgrade. Otherwise this requires querying for the stripe_price to determine what plan user has been subscribed to.
Please or to participate in this conversation.