#bennettcolecohen

1 messages ยท Page 1 of 1 (latest)

scarlet carbonBOT
sonic laurel
#

Hey there

frozen beacon
#

Hey hey

sonic laurel
#

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

frozen beacon
#

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?

sonic laurel
#

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?

frozen beacon
#

Yep one sec pushing and rerunning

sonic laurel
#

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

frozen beacon
#

Yeah got it. Can I just encode the payload before passing to construct?

sonic laurel
#

I wouldn't recommend doing that, no.

#

Hmm looking at the FastAPI docs though I do see what you are saying

#

The request body as bytes: await request.body()

#

That seems like it should be the raw body

frozen beacon
#

Yeah right so weird

#

I see maybe .stream() might work?

sonic laurel
#

How are you testing here?

#

Are you using the CLI?

frozen beacon
#

my UI... the CLI hasn't been working

#

edit: i can't get it to work lol

sonic laurel
#

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

frozen beacon
#

It's just the signing secret on the webhook right?

#

whsec....

sonic laurel
#

Yeah

scarlet carbonBOT
frozen beacon
#

Yeah .stream() actually produces the same result as .body()

loud storm
#

This code seems the most relevant:

payload = request.data

    try:
        event = json.loads(payload)
frozen beacon
#

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']

loud storm
#

What is the event you are listening to?

frozen beacon
#

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

loud storm
#

And these Checkout Sessions are being used to create subscriptions?

frozen beacon
#

Yeah

loud storm
frozen beacon
#

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?

loud storm
frozen beacon
#

Okay so I did that (stripe login/listen) but then when i trigger events - nothign happens

loud storm
#

Are you triggering events in a different terminal window?

frozen beacon
#

than my api terminal ? or the stripe listneer terminal

loud storm
#

The stripe listener

frozen beacon
#

OH

#

duh.

#

I'm stupid

#

Okay testing now

loud storm
#

No worries!

frozen beacon
#

Okay so when I log out the session, the subscription is null

#

Do the no-code payment links not create subscriptions on checkout?

loud storm
#

They should if they are created for recurring prices

#

Can you share an example Checkout Session ID?

frozen beacon
#

cs_test_a1akHy0yx3h17lnbxl32XSeGNDT9l2k5I1SvUSsl4dZrQVlzpZXzxZn5Rt

#

Is that one?

loud storm
#

Yup, thanks!

#

The price is not a recurring price

frozen beacon
#

weird?

#

I just checked my dash. It is recurring

loud storm
#

It does not have any recurring parameters. Is it possible you just used a different price ID?

frozen beacon
#

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

loud storm
#

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

frozen beacon
#

Can I pass an arg to trigger a specific product then?

loud storm
#

Yes you can override certain parameters

frozen beacon
#

Okay thanks. I think i should be able to take it from here

#

Thank you

loud storm
#

I find it useful to look at the fixture that defines how the event works to know what parameters you can override.