如何从带有Laravel Cashier 4的条纹计划中删除优惠券

时间:2015-11-30 01:25:20

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

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

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

我们对此表示赞赏。欢呼声。

1 个答案:

答案 0 :(得分: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文档缺乏详细程度和例子。它说它可以处理优惠券,它显示了如何添加优惠券,但没有显示如何删除优惠券,这让我觉得它不能,这可能是为什么必须包括其他库。但这都是猜测。