简体   繁体   中英

I am getting blank response from webhook url which I am using for Stripe events

I am getting blank response from the stripe webhook url.

I am using the below code:

$json = file_get_contents('php://input'); 
$action = json_decode($json, true);

But in $json array, I am getting blank response.

I'm assuming you mean that the $action array is empty. My guess would be - and I've never looked in there - that the body of the request coming from php://input isn't JSON.

The code I use is basically the same as the example on Stripe's site and it works just fine for me:

    $payload = @file_get_contents('php://input');
    $sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
    $event = null;
    try {
        $event = Webhook::constructEvent(
            $payload,
            $sig_header,
            $this->stripeApiKey
        );
    } catch (\UnexpectedValueException $e) {
        throw new BadRequestHttpException('Unexpected value error');
    } catch (SignatureVerification $e) {
        throw new BadRequestHttpException('Signature verification error');
    }

After this point you should have a valid event in $event and its core object can be fetched with $object = $event->data->object . What type this object will be will depend on what events you are getting webhook calls for. You can get the event type out with $event->type .

(Yes, I know using @ is bad practice, but I don't really mind failures there as everything is to do with whether Webhook::constructEvent() works or not.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM