-1

Problem/Motivation php://input always returns 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 a 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();
}

I was expecting to recieve the value of the payload but it always shows null.

1

1 Answer 1

-2

As documentation says:

php://input is not available with enctype="multipart/form-data".

I think you are using it to read a form with enctype="multipart/form-data".

Consider using php://stdin instead.

Alternative

Although something unusual can happen.

The request body data has been read, but its contents were not stored anywhere. php://input cannot give us anything.

Sign up to request clarification or add additional context in comments.

4 Comments

tried that, still getting null..
Sir I think You're getting everything wrong! who is calling your custom_module.module file? I think this is a simple get and there is no json in body at all!
i think i kinda understand what you mean. is it because the whole thing is just a get not a post? how can i fix that. do you know of a link you can share of how i can structure it and validate during development?? Thanks
Just use $_GET variable. Data is in url not in body

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.