- Issue created by @dwahba
php://input always reads NULL
I have been struggling with this for weeks now. i am completely newbie and trying to configure a webhook to catch the Payment_intent.succeeded event from stripe and do some actions accordingly... the probelm is, i always get the below error :
TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in array_keys() (line 279 of /var/www/html/vendor/stripe/stripe-php/lib/StripeObject.php).
I narrowed down the issue to always getting null from 'php://input' stream, i tried almost every trick i found online in previous posts but none of them worked for me..
I appreciate any support here..
this is written in file called webhook.php in custom_module directory. and is called in custom_module.module using
require 'webhook.php'
<?php
require_once '../vendor/autoload.php';
require_once 'secrets.php';
\Stripe\Stripe::setApiKey($stripeSecretKey);
// Replace this endpoint secret with your endpoint's unique secret
// If you are testing with the CLI, find the secret by running 'stripe listen'
// If you are using an endpoint defined with the API or dashboard, look in your webhook settings
// at https://dashboard.stripe.com/webhooks
$endpoint_secret = 'whsec_....';
$payload = @file_get_contents('php://input');
$event = null;
var_dump($payload);
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
}
catch(\UnexpectedValueException $e) {
// Invalid payload
echo '⚠️ Webhook error while parsing basic request.';
http_response_code(400);
exit();
}
Active
3.0
Miscellaneous