#maxitrol_api

1 messages ยท Page 1 of 1 (latest)

ruby solarBOT
#

๐Ÿ‘‹ 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.

spice jungle
#

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
nimble pendant
#

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

spice jungle
#

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?

nimble pendant
#

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}

spice jungle
#

What is in stripe_webhook_debug.txt?

nimble pendant
spice jungle
nimble pendant
#

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?

spice jungle
nimble pendant
#

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

spice jungle
#

CLI is command line interface, basically we have a command line tool that helps with some dev stfuf

nimble pendant
#

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?

spice jungle
#

Exactly

#

It is an easy way to test our webhook events on a local server without using something like ngrok

nimble pendant
#

oh interesting!

#

i didnt know about this... and ngrok i dont even know ๐Ÿ™‚

#

thank you for this! i will try with CLI tomorrow

#

oh wait

#

but how do i parse that php://input to get values in varibles? what is that output type? json?

#

this one i mean