Laravel收银员6取消后续订

时间:2016-05-19 12:35:56

标签: laravel-5.2 stripe-payments subscription laravel-cashier

我刚刚将Laravel收银包从5个版本更新到最新的6个版本。它支持多个订阅,而且非常酷。但是在订阅取消后我续订了一个问题。

我从条带信息中心手动删除订阅,并且 customer.subscription.deleted 事件正在触发。

收银员方法正在抓住此事件:    \Laravel\Cashier\Http\Controllers\WebhookController@handleWebhook

$subscription->markAsCancelled();正在解雇。

从那时起,订阅无法续订。我尝试使用resume()功能,但订阅可以在宽限期内仅恢复(!)

在先前版本的收银台中,我使用swap()方法恢复订阅。现在它返回:

Stripe\Error\InvalidRequest: Customer cus_*** does not have a subscription with ID sub_***** in /**/vendor/stripe/stripe-php/lib/ApiRequestor.php:103 from API request 'req_****'

创建新客户和订阅的方式不是很有效。你对这个问题的想法是什么?

1 个答案:

答案 0 :(得分:1)

此刻我的解决方案:

public function resume()
{
    $user = Auth::user();
    $subscription = $user->subscription(ServicePackageRepository::SUBSCRIPTION_NAME);

    if ($subscription->cancelled() && $subscription->onGracePeriod()) { 
        //if it was cancelled by user in grace period
        $subscription->resume();

        return $this->respondWithSaved([]);
    } else { //if cancelled by payment failure or smth else...
        if($user->subscription(ServicePackageRepository::SUBSCRIPTION_NAME)) {
            $user->newSubscription(ServicePackageRepository::SUBSCRIPTION_NAME,
                    $user->subscription(ServicePackageRepository::SUBSCRIPTION_NAME)->stripe_plan)
                ->create();

            return $this->respondWithSaved([]);
        } else {
            return $this->respondWithError([]);
        }
    }
}