#Thorkell
1 messages ยท Page 1 of 1 (latest)
Hi there, 50x means server error, a certificate error should be 4xx.
Ahhhh ok cool. Should I wait for Render to get back with me then? I assume 500 means it's specific to their hosting correct?
Also I love your pfp
What is Render in this context?
Render is where our API is hosted, and we have a stripe_controller.rb for context that is setting up webhooks at https://api.getdistilled.io/stripe-webhooks
I'm trying to figure out why 85% of my webhooks have been failing ๐ฆ
Events:
https://dashboard.stripe.com/events/evt_1MZmi3FCaczULzzDSr4Cxo1c
https://dashboard.stripe.com/events/evt_1MZmi7FCaczULzzDWzRL3yDG
Stripe Controller (part):
when 'checkout.session.completed'
workspace = Workspace.find_by(id: event.data.object.client_reference_id)
if workspace
StripeCustomer.find_or_create_by!(
stripe_customer_id: event.data.object.customer, workspace: workspace
)
Rails.logger.info "Stripe checkout session completed - Workspace with id: #{workspace.id} was found and associated with stripe customer id: #{event.data.object.customer}"
else
Rails.logger.error "Stripe checkout session completed - Workspace with id: #{event.data.object.client_reference_id} was NOT found"
end
when 'customer.subscription.created'
workspace = StripeCustomer.find_by(stripe_customer_id: event.data.object.customer).workspace
if workspace
workspace.update!(stripe_product: event.data.object.plan.product)
Workspaces::OnboardingSteps.new(workspace).pass_onboarding_step('subscription')
Rails.logger.info "Stripe customer subscription created - Workspace with id: #{workspace.id} was found and updated with product: #{event.data.object.plan.product}"
else
Rails.logger.error "Stripe customer subscription created - Stripe customer with id: #{event.data.object.customer} was NOT found"
end
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Hmm, it looks like the same webhook endpoint was registered in both live and test mode
Is it intentional to use the same endpoint for both live and test mode events?
And your server is sometimes returning 500 or 422 errors
I'm not quite sure. A lot of this is my co-founders work ๐ . I'm not sure what 422 is tbh.
Since Stripe can still receive response from your server, I don't think the issue is related to certificate problem.
So it is receiving a response? This is wild to me because afaik what I have set up should work
https://dashboard.stripe.com/events/evt_1MZm1uFCaczULzzD5nPrQQG9 For example your server returns
<hash>
<status type="integer">500</status>
<error>Internal Server Error</error>
</hash>
Any suggestions on how to best troubleshoot?
I'd suggest you to check your server log and see why it returns 500 instead of 200.
Lol probably a good start ๐
I noticed this:
Do you think that running sentry might have made me run into rate limits?
Are you sending lots of requests to Stripe?
I didn't think we were? But if this is from our server wouldn't it be Render's rate limiting quota?
Is this 429 returned from Stripe or other server?
It's returned on the Render server
Do you know the request ID of this 429 error? Here's how you can find it: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
Alright, so let me rewind a bit. My main issue is that this part of the stripe_controller.rb isn't creating a customer:
Alright, just looking at the API, I think I've narrowed it down to being an issue with the stripe_controller.rb,
when 'checkout.session.completed'
workspace = Workspace.find_by(id: event.data.object.client_reference_id)
if workspace
StripeCustomer.find_or_create_by!(
stripe_customer_id: event.data.object.customer, workspace: workspace
)
Rails.logger.info "Stripe checkout session completed - Workspace with id: #{workspace.id} was found and associated with stripe customer id: #{event.data.object.customer}"
else
Rails.logger.error "Stripe checkout session completed - Workspace with id: #{event.data.object.client_reference_id} was NOT found"
end
when 'customer.subscription.created'
workspace = StripeCustomer.find_by(stripe_customer_id: event.data.object.customer).workspace
if workspace
workspace.update!(stripe_product: event.data.object.plan.product)
Workspaces::OnboardingSteps.new(workspace).pass_onboarding_step('subscription')
Rails.logger.info "Stripe customer subscription created - Workspace with id: #{workspace.id} was found and updated with product: #{event.data.object.plan.product}"
else
Rails.logger.error "Stripe customer subscription created - Stripe customer with id: #{event.data.object.customer} was NOT found"
end
And I gotta ask, could stripe throw that 500 and 422 errors if the request is messed up?
Stripe will respond 4xx error if the request is failed, or 500 if there's a server error at Stripe (rarely but it happens)
Huh, so is there any clear indication of what's going on here?
Do you have request ID of the failed customer creation request?
https://dashboard.stripe.com/logs you can check Stripe logs here
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Is this what you mean?
I don't see any problem in this event.
You mentioned part of the stripe_controller.rb isn't creating a customer:. Did you create the customer by yourself? or you let Checkout Session to create one for you?
That's the thing, they always fail on the first time but only succeed on the retry. And I let Checkout session create one
they always fail on the first time -> what failed? can you be more specific?
The webhook:
It failed because your server responded 500
I think I'm starting to put together pieces. But why did it succeed on the retry?
Your server returned 200
Lmao obviously
As I mentioned earlier, your webhook endpoint is listening events generated in both live and test mode.
So there's a possibility that the endpoint is using incorrect secret key when making request for resources created in a different mode.
I was wondering that. Need to look into that.
For example, you receive an event generated in live mode, but the endpoint is using test mode secret key to create requests
do I just need to switch the button? And check the key?
What button?
The test mode/live mode
That's just a switch in Dashboard. I'm talking about the secret key that you use in webhook endpoint to create requests.
Yeah, but I when I switch into test mode I see a totally different secret key
Yes, that's exactly what I mean. The test mode key and live mode key are different.
Are they not supposed to be?
Here's my suggestions
- Don't use the same URL to listen to events generated from live and test mode, you should use one URL for live events and the other for test evetns
- Make sure you are using the correct secret key when making requests in your webhook endpoint.
I mean I've checked my .env and the live secret key is the only one in prod so ๐คทโโ๏ธ
I made a few test requests from the CLI today, but that's about it
a few test requests from the CLI today, -> can you share with me the request ID?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Here you go
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
This another one
Oh that old tho
OK. So Both requested are created in test mode, which means the checkout sessions are created in test mode, not live mode.
However since your webhook endpoint is using prod mode secret key in making requests (it's trying to retrieve the customer created in this checkout session), it will fail because the resources are not available in live mode.
This explains why your server returned 500 errors
Wait I'm having trouble understanding what you're saying. Why are those requests that I made with the CLI relevant to the convo if they are in test mode? Sorry I'm trying to wrap my head around the implications because I'm just trying to get my webhooks working on live lol
Wait. I thinkkkkk I'm putting it together
Ok
I feel like an idiot
I'm saying the requests that you made with CLI were created in test mode (learn the difference between live and test mode here https://stripe.com/docs/keys#test-live-modes).
So when your code execute
stripe_customer_id: event.data.object.customer, workspace: workspace
)
Since you are using live mode secret key, you are asking stripe to retrieve the customer created in live mode, which will raise an error because the checkout session (and associated customer) is created in test mode.
Should I delete the webhook endpoint from test mode?
I will if I were you, and I'll set up a different endpoint for test events.
Cool. Let us know if you need more help.
Will do, thank you all for helping me out ๐ช