#sadeghiamir_webhooks

1 messages ยท Page 1 of 1 (latest)

drifting sonnetBOT
#

๐Ÿ‘‹ 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/1278300233872445545

๐Ÿ“ 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.

restive vapor
#

my java code is:
@PostMapping("/stripe/webhooks")
@ResponseStatus(HttpStatus.ACCEPTED)
public String handleStripeWebhook(@RequestBody String payload, @RequestHeader("Stripe-Signature") String sigHeader) throws Exception {
Event event = null;
try {
event = ApiResource.GSON.fromJson(payload, Event.class);
} catch (JsonSyntaxException e) {
// Invalid payload
ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
return "";
}
if (stripeEndpointSecret != null && sigHeader != null) {

        Subscription subscription = null;
        try {
            event = Webhook.constructEvent(
                    payload, sigHeader, stripeEndpointSecret
            );
        } catch (JsonSyntaxException e) 
            return "";
        } catch (SignatureVerificationException e) {
            return "";
        }
        // Deserialize the nested object inside the event
        EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
        if (dataObjectDeserializer.getObject().isPresent()) {
            subscription = (Subscription) dataObjectDeserializer.getObject().get();
        } else {
            // Deserialization failed, probably due to an API version mismatch.
            // Refer to the Javadoc documentation on `EventDataObjectDeserializer` for
            // instructions on how to handle this case, or return an error here.
            log.error("deserialize failed for {} ", dataObjectDeserializer.getRawJson());
        }

but this segment (if (dataObjectDeserializer.getObject().isPresent())) return false

agile haven
#

Hi, let me help you with this.

#

Do you know if no other errors are thrown? Can you print the event object?

restive vapor
#

I got event but "dataObjectDeserializer.getObject().isPresent()" return false value

agile haven
#

What do you use to print the object?

restive vapor
#

I run server in debugging mode and this event is value of debugging mode

drifting sonnetBOT
fallow glacier
restive vapor
#

<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>26.7.0</version>
</dependency>

fallow glacier
restive vapor
#

I have breakpoint at this line:if (dataObjectDeserializer.getObject().isPresent())
I get this event from debugger thread & variables

fallow glacier
#

Hmm this kind of issues normall signify a mismatch between the API version of the event/webhook and the SDK.

#

But that doesn't seem to be true here โ€“ 26.7.0 is fixed to 2024-06-20 version which the example event you've shared was generated with

restive vapor
#

can you suggest me java sdk version and api version for resolving this issue?

fallow glacier
#

I don't think that's the root cause here as the version of the SDK version you're using is locked to the same API version of the event (as noted above)

#

Checking with a colleague

#

Can you try and use the deserializeUnsafe method as outlined here?

GitHub

Java library for the Stripe API. . Contribute to stripe/stripe-java development by creating an account on GitHub.

#

As an example:

subscription = (Subscription) dataObjectDeserializer.deserializeUnsafe();
#

Also, can you make sure your in that your integration code is indeed using version 26.7.0 of the SDK? Recent requests from your account are using 25.x.x

#

That would result in the API version mismatch and the issues you're seeing. Maybe you need to re-sync Gradle?

restive vapor
#

dataObjectDeserializer.deserialize() hast this error:
eserialize()' has private access in 'com.stripe.model.EventDataObjectDeserializer'

fallow glacier
#

It's deserializeUnsafe()

restive vapor
fallow glacier
#

Well looking at API requests made today (like the above) I don't think it's actually upgraded the SDK version compiled in your code. You likely need to rebuild and/or resync the dependencies