#bennettcolecohen
1 messages ยท Page 1 of 1 (latest)
Hey there
Hey hey
Usually this means that you aren't passing the raw body of the request and there is something on your end that is manipulating the raw body
So for instance payload = await request.body() is likely JSONifying the body
When this needs to be the raw body
I think it's the raw body in FastAPI? Because they have a separate function to jsonify it
Also is there a faster workflow than deploying this everytime I want to make a change?
I'm not familiar with FastAPI so can't tell you in terms of deploying
Can you log out payload and tell me what you see?
Yep okay so see how that is JSON?
That should be a buffer type (looks like binary)
So something in your framework is manipulating the raw body prior to you actually passing it to construct_event
Yeah got it. Can I just encode the payload before passing to construct?
I wouldn't recommend doing that, no.
Hmm looking at the FastAPI docs though I do see what you are saying
The little ASGI library that shines.
The request body as bytes: await request.body()
That seems like it should be the raw body
Okay and you grabbed the secret from the endpoint in your Dashboard that you are testing with....
Hmm
I'd do a quick double check to make sure you have the correct secret (have definitely seen people mix this up on accident)
Then yeah trying stream() seems like a good option
Yeah
Yeah .stream() actually produces the same result as .body()
Hi ๐
I'm stepping in as @sonic laurel needs to go. Have you taken a look at our webhook endpoint builder?
https://stripe.com/docs/webhooks/quickstart
This code seems the most relevant:
payload = request.data
try:
event = json.loads(payload)
Yeah I just copied the flask version and changed it to fast api syntax
I think i got the .stream() to work somehow
Testing right now
When I'm in the event handler, can i grab the subscription id somehow?
Extract session, email
session = event['data']['object']
email = session['customer_details']['email']
What is the event you are listening to?
Currently it is "checkout.session.completed" because the only checkout that can be completed is subscribing to this saas thing
should i change to a diff event
And these Checkout Sessions are being used to create subscriptions?
Yeah
Then the subscription property should be included in the Checkout Session object provided by the Event: https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-subscription
Okay I'll look. in order to test this faster, what's the best flow? I don't want to deploy every time i make a change
can i run the api locally and use the cli?
Yes. i would recommend developing locally and using the CLI and stripe listen to forward webhook events to your local dev box
https://stripe.com/docs/cli/listen
Okay so I did that (stripe login/listen) but then when i trigger events - nothign happens
Are you triggering events in a different terminal window?
than my api terminal ? or the stripe listneer terminal
The stripe listener
No worries!
Okay so when I log out the session, the subscription is null
Do the no-code payment links not create subscriptions on checkout?
They should if they are created for recurring prices
Can you share an example Checkout Session ID?
Yup, thanks!
This Checkout Session was created with mode: "payment" so it won't create a Subscription
https://admin.corp.stripe.com/request-log/req_PEjDV37LqO5krA
The price is not a recurring price
This is the creation request for that price: https://dashboard.stripe.com/test/logs/req_AihxWOOtHAh7wH
It does not have any recurring parameters. Is it possible you just used a different price ID?
I'm seeing some weird stuff with ghost products being made
that link is attached to myproduct ... which ive never seen before
never made that
That is being created by the CLI
In order to trigger the checkout.session.succeeded event the CLI has to create a product and a price first
Can I pass an arg to trigger a specific product then?
I find it useful to look at the fixture that defines how the event works to know what parameters you can override.