mshoaibdev
mshoaibdev

Reputation: 133

stripe webhook test mode response "none"

I am trying to update database.

I have set up the webhook in stripe in test mode and send a "invoice.payment_succeeded" test webhook to file.but it shows response "none" in stripe output.

What have i done wrong, here is the webhook file, please someone help me, i am very stuck at this. any help will be appreciate...

 <?php 

include '../admin/include/functions.php';

require_once('Stripe/lib/Stripe.php');
require_once 'stripe_secret.php';

// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);


$event_id = $event_json->id;

    if(isset($event_json->id)) {

        try {
                Stripe::setApiKey($stripe['secretkey']);

                $event = Stripe_Event::retrieve($event_id);

                var_dump($event);

                $invoice = $event->data->object;

                if($event->type == 'invoice.payment_succeeded') {

                    $customer = Stripe_Customer::retrieve($invoice->customer);

                    $email  = $customer->email;

                    $customerid = $customer->id;

                    /*$amount = $invoice->amount / 100;*/

                    $expiry = $invoice->period->end;
                    $expiredate = date('Y-d-m', $expiry);

                    $userup = $obj->run_query("UPDATE users SET Expiry_Date = '$expiredate' WHERE user_stripe_id = '$customerid' ");

                    if ($userup) {
                        echo "User Date extended";
                    }
                    // send a invoice notice email here
                }
                if($event->type == 'invoice.payment_failed') {

                    $obj->run_query("UPDATE users SET Status = '0' WHERE user_stripe_id = '$customerid' ");

                    echo "User membership expired";
                }

            } 


        catch(Stripe_CardError $e) {

        }
        catch (Stripe_InvalidRequestError $e) {
        // Invalid parameters were supplied to Stripe's API

        } catch (Stripe_AuthenticationError $e) {
        // Authentication with Stripe's API failed
        // (maybe you changed API keys recently)

        } catch (Stripe_ApiConnectionError $e) {
        // Network communication with Stripe failed
        } catch (Stripe_Error $e) {

        // Display a very generic error to the user, and maybe send
        // yourself an email
        } catch (Exception $e) {

        // Something else happened, completely unrelated to Stripe
        }

    }

http_response_code(200);


 ?>

Upvotes: 3

Views: 1376

Answers (1)

Matthew Arkin
Matthew Arkin

Reputation: 4648

The test webhooks from the test webhook button sends a webhook with the right format but all the values are null / zero / etc. Thus your line that does $obj->run_query("UPDATE users SET Expiry_Date = '$expiredate' WHERE user_stripe_id = '$customerid' "); will return a falsey result. This means you don't echo anything and just send back an empty 200 response.

Upvotes: 1

Related Questions