【问题标题】:How to remove coupon from Stripe plan w/ Laravel Cashier 4如何使用 Laravel Cashier 4 从 Stripe 计划中删除优惠券
【发布时间】:2016-03-03 14:13:02
【问题描述】:

我目前正在尝试实施一种将人们换成新计划的方法。我遇到的问题是旧计划中的优惠券结转并且不向用户收费。每次我尝试删除旧优惠券时,它似乎都不允许。

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

感谢您的想法。干杯。

【问题讨论】:

    标签: laravel-4 stripe-payments laravel-cashier


    【解决方案1】:

    这是最终的工作:

    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

    总的来说,我再次发现 Laravel 文档缺乏冗长和示例。它说它可以处理优惠券,它展示了如何添加一张,但没有展示如何删除一张,所以这让我认为它不能,这可能就是为什么必须包含其他库的原因。但这都是猜测。

    【讨论】:

      猜你喜欢
      • 2018-07-09
      • 2015-07-24
      • 2016-03-10
      • 1970-01-01
      • 2020-10-10
      • 2020-02-26
      • 2021-04-02
      • 2015-06-14
      • 2021-12-27
      相关资源
      最近更新 更多