I am currently trying to implement a method that swaps people over to a new plan. The problem I am having is that the coupon from the old plan carries over and the user is not charged. Every time I try to remove the old coupon, it doesn't seem to allow it.
protected function swapToYearlyPlan(){
$user = Auth::user();
// Tried this, doesn't work
// $user->subscription()->retrieve($user->stripe_subscription)->deleteDiscount();
// This works fine
$user->subscription('Gold Annual Plan')->swap();
// Tried this, doesn't work
//$user->subscription()->applyCoupon(NULL);
return 'Upgraded plan!';
}
Thoughts are appreciated. Cheers.
Here is what ended up working:
I'm dealing with legacy code here, so there's a lot of details which aren't clear. For example, the
deleteDiscount
method isn't even a feature of Laravel Cashier, or at least the version I'm working with. That method is found included with my project in a whole other set of code located here:vendor/stripe/stripe-php/lib/Stripe
, whereas Laravel Cashier is located invendor/laravel/cashier/src/Laravel/Cashier
.Overall, I have found the Laravel documentation, once again, to be lacking verbosity and examples. It said it could deal with coupons, and it showed how to add one, but not how to remove one, so that makes me think that it can't, which might be why other libraries had to be included. But that's all speculation.