My web app uses Stripe for payment processing. I have a webhook in Stripe calling mysite.com/callback. When I try to test the webhook, it times out. Orders process successfully through my /charge route and show up in Stripe.
What is wrong with my /callback route? It doesn't update the data in the DB.
Here is the callback route:
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']))]);
});
That looks like Laravel, and it looks like that function doesn't return anything, so Stripe is not getting a response. I suspect you want to do something like this in there:
try {
return response("", 200);
} finally {
// All the other fun stuff you're doing after you respond
}