#geimsdin-Webhook

1 messages ยท Page 1 of 1 (latest)

fleet spear
#

Hi there, what kind of doc are you looking for?

trim pulsar
#

Hi Jack, I just need to implement the php logic that will handle the webhook data to update the order on my ecommerce

#

I need to know which data is passed so I can parse it

fleet spear
#

The data type corresponds to the event type. For instance, if you are listening to payment_intent.succeeded, the the data that you receive in this event is a payment_intent

trim pulsar
#

Ok, thanks

#

It was not clear to me before

fleet spear
trim pulsar
#

I cannot retrieve it, is it passed as POST data?

fleet spear
#

What can't you retrieve?

trim pulsar
#

I'm triggering an event with the Stripe CLI and dumping in a log file all the POST and GET data but the log is empty like there's no data to catch.

fleet spear
#

Show me the code

trim pulsar
#

public function init()
{
$post = $_POST;
$get = $_GET;

    if (is_array($post)) {
        foreach ($post as $postdatum) {
            $error = new WP_Error('POSTWH', $postdatum);
        }
    }

    if (is_array($get)) {
        foreach ($get as $getdatum) {
            $error = new WP_Error('GETWH', $getdatum);
        }
    }

    if ( isset($_GET['wcnp-response']) &&
        $_GET['wcnp-response'] == 'wcnp-stripe-api' &&
        isset($_GET['wcnp-type'])
    ) {
        if (method_exists($this, $_GET['wcnp-type'])) {
            $this->$_GET['wcnp-type'];
            $post = $_POST;
            $get = $_GET;

            if (is_array($post) || is_object($post)) {
                foreach ($post as $postdatum) {
                    $error = new WP_Error('POSTWH', $postdatum);
                }
            }

            if (is_array($get) || is_object($get)) {
                foreach ($get as $getdatum) {
                    $error = new WP_Error('GETWH', $getdatum);
                }
            }

            wp_die('', '', ['response' => 200]);
        }
    }

}
#

is removing the "||" logical OR in the if

fleet spear
#

Is this code executed when a webhook event request arrives?

trim pulsar
#

Yes

fleet spear
trim pulsar
#

Thanks Jack, going to have a look

#

The triggered event calls my listener but no data is passed

#

file_get_contents('php://input') doesn't retrieve anything

fleet spear
#

I don't see file_get_contents in your code.

trim pulsar
#

I added after you shared the docs ๐Ÿ™‚

fleet spear
#

Can you do a echo @file_get_contents('php://input'); and see what does it print out?

trim pulsar
#

$payload = print_r(file_get_contents('php://input'));

    $logger = new udLogger();

    $logger->addError($payload);

    unset($logger);
#

I did this, a simple logger I created for debug purposes and the result is 1

#

"1"

fleet spear
#

Why are you setting $payload = print_r(file_get_contents('php://input')); instead of $payload = file_get_contents('php://input'); ?

trim pulsar
#

To test, if it is an object I cannot write it to file as it is and I need to format it

#

I cannot simply echo as I cannot get the answer in console

#

So I need to log in a file

fleet spear
#

That's why your are getting 1.

trim pulsar
#

/**

  • Prints human-readable information about a variable
#

It means the data is empty

#

If there is data will return the data in a human readable format, if no data will return true = 1

#

Am I wrong

#

?

fleet spear
#

I think you need to find a way to log/see the content of the request, so that you can know if you are getting the webhook data or not.