#maxitrol_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1319770682397163582
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hello, the stripe-php library has an Event::constructFrom method that can build objects for you afer decoding the json:
$event = null;
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
}```
We show example PHP webhook handler code in these docs
https://docs.stripe.com/webhooks#webhook-endpoint-def
https://docs.stripe.com/webhooks/quickstart?lang=php
Pompey are you human?
you know i am developing on localhost. how can i make stripe webhook call my xxx.localhost url? that is not possible? so i saved that file i got from php://input and tried to load then parse it but that function you pasted returns error
Yep, human. Can you send me the exact text of the error that you are getting? Is it about no signatures matching or something like that?
i tried with your code and i added this on top (that include i use to be able to use stripe functions and it works at checkout):
require_once('stripe-php-16.3.0/init.php');
TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in C:\GITHUB\lunch\stripe-php-16.3.0\lib\StripeObject.php:305 Stack trace: #0 C:\GITHUB\lunch\stripe-php-16.3.0\lib\StripeObject.php(305): array_keys(NULL) #1 C:\GITHUB\lunch\stripe-php-16.3.0\lib\StripeObject.php(276): Stripe\StripeObject->refreshFrom(NULL, NULL, false, 'v1') #2 C:\GITHUB\lunch\x.php(15): Stripe\StripeObject::constructFrom(NULL) #3 {main}
oh man this webhook is so hard... i manage to create buttons, i can see the charge in your dashboard but i am having problems intercepting webhook. i mean i can intercept it and i save it to FILE but now i am trying to use that txt file to write the code and it doesnt work. maybe php://input result is not same as when i save this to file.txt and load from there
let me show you screenshot
when i run this x.php (above) i get this error
TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in C:\GITHUB\lunch\stripe-php-16.3.0\lib\StripeObject.php:305 Stack trace: #0 C:\GITHUB\lunch\stripe-php-16.3.0\lib\StripeObject.php(305): array_keys(NULL) #1 C:\GITHUB\lunch\stripe-php-16.3.0\lib\StripeObject.php(276): Stripe\StripeObject->refreshFrom(NULL, NULL, false, 'v1') #2 C:\GITHUB\lunch\x.php(15): Stripe\StripeObject::constructFrom(NULL) #3 {main}
What is in stripe_webhook_debug.txt?
What line of code did this error message come from? From constructEvent?
x.php 15 - you see line 15 on white screenshot above
and i created webhook intercept php script on the server, which does only this: intercept php://input and saves it to file
$i = file_get_contents('php://input');
INT_save2File("stripe_webhook_string.txt", $i);
i just saved it as text... but somehow i must parse it and i dont know how
i mean i must parse what i get from php://input (i saved this to stripe_webhook_debug.txt) you see it above -- starts with s:3370:"{
maybe i dont know how to ask. so i will try to ask simple: 1) when i read php://input, how do i parse that in php to get variables i can access?
I am not that knowledgable on PHP specifically but it looks like you may be able to just use file_put_contents and file_get_contents https://stackoverflow.com/questions/17731493/how-can-i-use-php-to-take-raw-post-data-and-save-to-a-file
That being said, this may be easier if you just use our CLIs localhost endpoint and then trigger events with its trigger command. Those can give you an easy way to test it like an actual endpoint on command
https://docs.stripe.com/cli/listen
https://docs.stripe.com/cli/trigger
what is CLI
hmm
so i can listen to webhooks on my localhost somehow?
how can i run this command? in windows terminal or where? >> stripe listen
CLI is command line interface, basically we have a command line tool that helps with some dev stfuf
Install instructions at the top of this doc https://docs.stripe.com/stripe-cli
oh
so i install this CLI and then i can listen to API webhook or forward it to my php script?
if i understand well: i have to install CLI, then use that stripe listen command to forward webhook call to x.php (for example) and then in x.php i can read what you send with php://input?
Exactly
It is an easy way to test our webhook events on a local server without using something like ngrok