如何从带有Laravel Cashier 4的Stripe计划中删除优惠券 [英] How to remove coupon from Stripe plan w/ Laravel Cashier 4

查看:86
本文介绍了如何从带有Laravel Cashier 4的Stripe计划中删除优惠券的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试实现一种将人们调换为新计划的方法.我遇到的问题是旧计划中的优惠券会继续使用,并且用户不会被收取费用.每次我尝试删除旧优惠券时,似乎都不允许这样做.

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!';
}

对此表示赞赏.干杯.

推荐答案

以下是最终起作用的地方:

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!';
}

我在这里处理遗留代码,因此有很多细节尚不清楚.例如,deleteDiscount方法甚至不是Laravel Cashier的功能,或者至少不是我正在使用的版本.在我的项目中,该方法包含在其他代码集中,位于以下位置:vendor/stripe/stripe-php/lib/Stripe,而Laravel Cashier位于vendor/laravel/cashier/src/Laravel/Cashier中.

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.

总体而言,我再次发现Laravel文档缺少冗长和示例.它说它可以处理优惠券,并且显示了如何添加优惠券,但没有显示如何删除优惠券,因此让我认为它不能,这可能就是为什么必须包含其他库的原因.但这只是猜测.

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.

这篇关于如何从带有Laravel Cashier 4的Stripe计划中删除优惠券的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆