php://input always reads NULL

Created on 11 March 2023, almost 2 years ago

Problem/Motivation

php://input always reads NULL

Steps to reproduce

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..

Here is my Code

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();
}

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

3.0

Component

Miscellaneous

Created by

🇦🇺Australia dwahba

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024