条纹上的“测试网络钩子错误:超时”


'Test webhook error: Timed out' on Stripe

我的网络应用使用 Stripe 进行付款处理。我在 Stripe 中有一个网络钩子调用 mysite.com/callback。当我尝试测试 webhook 时,它会超时。订单通过我的/charge 路由成功处理并显示在 Stripe 中。

我的/回调路由有什么问题?它不会更新数据库中的数据。

下面是回调路由:

Route::post('/callback', function () {
http_response_code(200);
  $amount=array('1900'=>array('name'=>'small','period'=>"+1 month",'visits'=>1000),
                '7900'=>array('name'=>'medium','period'=>"+3 month",'visits'=>10000),
                '14900'=>array('name'=>'large','period'=>"+6 month",'visits'=>25000),
                '39900'=>array('name'=>'xlarge','period'=>"+12 month",'visits'=>100000),
                '79900'=>array('name'=>'enterprise','period'=>"+24 month",'visits'=>500000),
            );
$input =Input::all();
$email = $input["data"]["object"]["source"]["name"];
$stripe_plan=$amount[$input["data"]["object"]['amount']]['name'];
$user = DB::table('users')
                    ->where('email',$email)
                    ->select('remaining_visits','subscription_ends_at')->first();
$date=$user->subscription_ends_at;
$remaining_visits=$user->remaining_visits+$amount[$input["data"]["object"]['amount']]['visits'];
$affectedRows=User::where('email',$email)->update(['secret' => uniqid(),'stripe_active' => 1,'stripe_plan'=>$stripe_plan,'remaining_visits'=>$remaining_visits,'subscription_ends_at'=> date( 'Y-m-d H:i:s', strtotime($date.$amount[$input["data"]["object"]['amount']]['period']))]);
});

这看起来像 Laravel,看起来该函数没有返回任何内容,因此 Stripe 没有得到响应。 我怀疑你想在那里做这样的事情:

try {
    return response("", 200);
} finally {
    // All the other fun stuff you're doing after you respond
}

注意:部分从这个答案中窃取...