#fobor10362-checkout

1 messages · Page 1 of 1 (latest)

sweet geode
hot iron
#

I need something like if event.type == 'checkout.session.completed' and price_id = settings.MONTHLY_PRICE_ID or if event.type == 'checkout.session.completed' and price_id = settings.YEARLY_PRICE_ID

#

For cancels I was able to do something like this: event.type == 'customer.subscription.deleted' and event.data.object['items'].data[0].price.product == settings.STRIPE_MEMBERSHIP_PRODUCT_ID

sweet geode
hot iron
#

hmm ok let me see if I can figure it out

#

Would this be the session id? "id": "cs_test_a16UAFHb1t6eeuXfZuhgB1P2kZxLnhlrlLvnETKPQWsxbob1wra60HcieJ"

sweet geode
#

yes

hot iron
#

with expand=['customer'], inside of it too?

sweet geode
#

yep!

#

well, expand=["line_items", "customer"] I would say, since you want the line items since that's where the Price ID is.

hot iron
#

ok let me try

#

ok now I see it that worked

#

So now to get the price ID from that would be event.data.object['items'].data[0].price.id ?

sweet geode
#

I think so

#

or maybe just event.data.object['items'].data[0].price, not sure if the Price is expanded or not, but it's easy enough for you to test

hot iron
#

I will show you the output

#

checkout_session.line_items.data[0].price.id

#

I think this is it

#

checkout_session is the retrieve line from above

sweet geode
#

cool!

hot iron
#

I have another question

#

I want to have 2 webhooks in 1 python file

#

I suppose I need to have 2 separate endpoint_secret variables

#

They should probably be named differently?

#

like endpoint_secret_1 and endpoint_secret_2

sweet geode
#

you should not do it that way, use different URLs and different scripts for each.

hot iron
#

Then in the event have event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret_1
)

#

Yes each function is its own URL

#

I have def stripe_cancel_webhook(request) as 1 webhook function and def stripe_membership_payment_webhook(request) as another webhook function. Both functions have their own URLs

sweet geode
#

cool, then you configure it.

Like you set it up as
-on Stripe : example.com/webhook-1
-and in your code, you configure that the code running at webhook-1 uses webhook secret X
-on Stripe : example.com/webhook-2
-and in your code, you configure that the code running at webhook-2 uses webhook secret Y

hot iron
#

Right exactly that is what I was thinking

sweet geode
#

makes sense then

hot iron
#

Ok cool

#

thank you i think those are all my questions for now

#

Oh wait 1 more question. Why is it that when I navigate to my webhook URL I always get an error regarding request.META['HTTP_STRIPE_SIGNATURE']

#

But when I complete the checkout session there are no errors

void zenith
#

Hi 👋 Jumping in as @sweet geode needs to step away.

hot iron
#

ok

void zenith
#

If you're referring to the actual endpoint that you're hosting, then we won't know as that is all your code. However, it sounds like that route is expecting to find the Stripe header, but isn't because that's not added when you just browse to the location.

hot iron
#

Yea it only seems to be added when the webhook completes or the checkout session gets created

void zenith
#

It's a header that is included by Stripe when we send events to your endpoint.

hot iron
#

Should I set the header to None to prevent the error or put it in a try except block ?

void zenith
#

If you want to still be able to view that page, and the framework you're using allows it, then you can host a GET and POST route at the same location to have separate flows based on the type of request.

hot iron
#

ok

#

I am wondering how you could tell based on the type of request it is

#

Would the payload body tell us that?

#

I am basically using this code here

void zenith
#

We can help you understand what the Stripe requests will look like, but we won't have any insight into what the rest of your site traffic looks like as that depends on how you structure your site.

hot iron
#

The site is not live and I am using ngrok locally

#

someone would have to type in the webhook URL which they probably would not know

#

in order to expose this error

void zenith
#

It's up to you how you'd like to handle the returned response if people hit that page directly. For example, you could look for the Stripe header and return a 404 if it isn't present so it looks like the page doesn't exist, but I'm not sure if that would be a flow that you desire.

hot iron
#

ok i will try doing something like that the thanks

void zenith
#

Any time!