问题
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.
回答1:
Here is what ended up working:
protected function swapToYearlyPlan(){
$company = Auth::user()->company;
$customer = $company->subscription()->getStripeCustomer();
if($customer->subscription->discount instanceof Stripe_Object){
$customer->subscription->deleteDiscount();
}
$company->subscription("Gold Annual Plan")->swapAndInvoice();
// Dealing with GST is a whole other issue
return 'Upgraded Gold Annual plan!';
}
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 in vendor/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.
来源:https://stackoverflow.com/questions/33990191/how-to-remove-coupon-from-stripe-plan-w-laravel-cashier-4