#geimsdin-Webhook
1 messages ยท Page 1 of 1 (latest)
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
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
https://stripe.com/docs/api/events/types this is the list of events and associated data types
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I cannot retrieve it, is it passed as POST data?
What can't you retrieve?
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.
Show me the code
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
Is this code executed when a webhook event request arrives?
Yes
https://stripe.com/docs/webhooks/quickstart?lang=php btw here's some example code for setting up a webhook endpoint in PHP.
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
I don't see file_get_contents in your code.
I added after you shared the docs ๐
Can you do a echo @file_get_contents('php://input'); and see what does it print out?
$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"
Why are you setting $payload = print_r(file_get_contents('php://input')); instead of $payload = file_get_contents('php://input'); ?
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
https://www.php.net/manual/en/function.print-r.php the return value of print_r is true
That's why your are getting 1.
/**
- 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
?
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.