Reputation: 19
I am having a similar problem with Stripe webhooks. Spent all weekend trying to diagnose without success. Getting a general 500 error when running test through stripe dashboard. If I just load the page directly, it generates a blank page or if I echo something like echo http_response_code(200);
, I get 200 back. My code is pretty straightforward.
require('/stripe/init.php');
\Stripe\Stripe::setApiKey("[intentionally deleted for post]");
$payload = file_get_contents("php://input");
$event_json = json_decode($payload);
http_response_code(200);
PHP runs fine on the site in all other contexts. There are no issues with implementing charges, both one time and subscriptions. Posts and Get work fine on all other pages. It's sharing hosting so have pretty limited access to error logs, etc...
I have already looked through the one or two stackoverflow responses to stripe webhook errors with through a 500 error but unfortunately these did not help. Thanks in advance.
Upvotes: 1
Views: 485
Reputation: 649
I would try this kind of event creation:
$event = \Stripe\Webhook::constructEvent(
$request->getContent(),
$request->server->get('HTTP_STRIPE_SIGNATURE'),
$this->getParameter('stripe_webhook_secret')
);
This is Symfony code so $request
is provided by Symfony but you can replace those with your native PHP variables. After this assignment, $event
is populated with the data that you see in the Stripe docs examples.
Upvotes: 1