#michael-1219_webhooks
1 messages · Page 1 of 1 (latest)
👋 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/1301491926230634630
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- michael-1219_webhooks, 5 days ago, 19 messages
Hi
Have you tried to check what element is missing in the event payload ?
not sure acttually
You need to debug your integration and check
what you can is to use stripe cli
and forward the event to your localhot and debug the event ingestions
In the stripe_events method of the PayController class, an exception (java.util.NoSuchElementException: No value present) is thrown when processing a Stripe webhook callback. Specifically, the error occurs at the line event.getDataObjectDeserializer().getObject().get(), indicating that an attempt was made to retrieve the value of an empty Optional object, which resulted in the exception.
Possible Causes
1. Deserialization Failure: The Stripe event data may not be deserialized as expected, leading to event.getDataObjectDeserializer().getObject() returning an empty Optional. This could happen if some required fields are missing in the event data or if the data format does not match the expected structure.
2. Missing Event Data: It’s possible that certain types of webhook events do not include a data.object field, while the code assumes that all events contain it. If Stripe sends an event without data.object, then getDataObjectDeserializer().getObject() would return an empty value.
3. Incorrect Webhook Verification: If the webhook signature verification fails, it could lead to data parsing issues. Therefore, it’s important to ensure that the webhookSecret is correctly configured and that the webhook verification is successful.
4. Data Structure Differences in Testing Environment: In a test environment, Stripe may return data with a different structure, causing the code to encounter an empty Optional when accessing certain fields.
Which version of the SDK are you using?
2024-06-20
i am not very sure about what cause this error, since I am not very familier with webhook
No, that's the API version. Which SDK version: https://github.com/stripe/stripe-java/blob/master/CHANGELOG.md
Looks like 26.0.0 according to logs which aligns with that API version
yeah i though the api version might not be the causes of this error
My guess would be that signature verification is failing via constructEvent, generally happens for one of two reasons:
- Event payload is malformed –
constructEventrequires the raw event payload - Your signing secret is wrong
It can be though for strongly typed SDKs like Java if your SDK version mismatches the API version the event(s) are generated in. That's why I checked
i actually not sure how to check stripe-jave version, but java-SDK in this project is 1.8
got you point
hot to check them
you only get this error of getDataObjectDeserializer().getObject being empty if there's an API version mismatch. What version of stripe-java is your project using?
emmm, how to check the stripe-java version
check your pom.xml perhaps
search for "stripe-java" in your project and find the file where you declare the dependency. etc
the version is 24
can you share the exact version?
ok. Well that version https://github.com/stripe/stripe-java/blob/master/CHANGELOG.md#2400---2023-10-16
uses API version 2023-10-16 , which means it can not handle a webhook event that is sent using the API version 2024-06-20, which is exactly why you're getting this error.
the 'easiest' fix would be to update your code to use the latest version of the library (28.0.0) and also create a new webhook endpoint that uses the latest API version, and use that instead.
alternative solutions include
- create a webhook endpoint pinned to
2023-10-16and use that(you have to do that in the API (https://docs.stripe.com/api/webhook_endpoints/create#create_webhook_endpoint-api_version), the Dashboard doesn't support it) - find which version of stripe-java supports
2024-06-20and use that in the project(though I don't recommend upgrading to "old" versions of the library like that).
appreciate your help, i will try it
another alternative is there is an "unsafe" function you can call to try and access the data anyway even if the API versions don't match dataObjectDeserializer.deserializeUnsafe()
but the api version i intergrated is 2024-6-20
well the API version you use in API requests is determined by the version of stripe-java you're using.
the API version in webhooks is generally the default version on your account(which depends on when you created your Stripe account) , or you can create a new endpoint and set it to the latest API version, or use https://docs.stripe.com/api/webhook_endpoints/create#create_webhook_endpoint-api_version as mentioned
in your case the best solution here is probably to create a webhook endpoint pinned to 2023-10-16 using that API call. Alternatively, upgrade your code + libraries + webhook to the lateset API version.
quoting:
you have to do that in the API (https://docs.stripe.com/api/webhook_endpoints/create#create_webhook_endpoint-api_version), **the Dashboard doesn't support it **