#Nil
1 messages ยท Page 1 of 1 (latest)
๐ we have an example here that you can use
https://stripe.com/docs/webhooks/quickstart?lang=java
i have just created one
but i receive the following error {
"timestamp": "2022-09-14T13:30:34.899+00:00",
"status": 500,
"error": "Internal Server Error",
"message": "",
"path": "/stripe-webhook/invoice-paid"
}
My piece of code is the following:
Event event = null;
try {
event = ApiResource.GSON.fromJson(payload, Event.class);
} catch (JsonSyntaxException e) {
e.printStackTrace();
System.out.println("Failed JsonSyntaxException ");
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
}
EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
StripeObject stripeObject = null;
if (dataObjectDeserializer.getObject().isPresent()) {
stripeObject = 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.
System.out.println("Deserialization failed");
return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(null);
}
switch (event.getType()) {
case "invoice.payment_succeeded":
System.out.println("invoice.payment_succeeded.");
break;
default:
// Unexpected event type
break;
}
return new ResponseEntity<>("Success", HttpStatus.OK);
hanzo are you there? ๐ฆ
where exactly are you seeing this error? Is it on your server? Have you defined "path": "/stripe-webhook/invoice-paid" this path anywhere?
Are you seeing this on Stripe? Sorry, this is a ton of code with no real information.
i see this on stripe
but on localhost it works
Have you defined "path": "/stripe-webhook/invoice-paid" this path anywhere?
SURE! if you browse for it, it will return you 405 because it has been made for the POST request but this way you can check is online
It seems like your route code on that route returns a 500
What i return is return new ResponseEntity<>("Success", HttpStatus.OK);
Can you try and remove the code thats there on that route and see if it can just respond with a 200?
yes
give me a min
that'd confirm if the payload actually hits the route and the issue is somewhere in the code
okey
deploying
now it works
so the problem is not routing
but the code I write inside is the one of the tutorial ๐ฆ
yup its in your code somewhere
I'd recommend adding one function at a time and seeing what breaks this
You'd also find more information about the error in your server log
yes
hahahaha
will try one by onme
one
if i dont find it out will contact you another time
Thank you!
๐
Hello hanzo
it crashes here
if (dataObjectDeserializer.getObject().isPresent()) {
in this check
EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
can it be a api version problem?
Not sure.
Can you print out the event object and see if it can be deserialized?
sure
let me send you the json
The JSON file represents the dataObjectDeserializer object which is declared as: EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
Hello, hanzo had to step out but I can help. API version can definitely be an issue when trying to deserialize objects with our java libraries
Because Java is a statically typed language, we need to pin each version of the library to a specific API version. If your lib isn't using 2022-08-01, then you might want to delete your endpoint and create a new endpoint that is configured to use your java library's API version
What version of stripe-java are you using?
Thank you Pompey!
I feel like we are going to figure it out!
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>21.7.0</version>
</dependency>
Interesting 21.0.0 should use 2022-08-01 so I don't think version is the problem
should i change to 21.0.0?
you are already on the right version
Are you using a different secret key when you are testing without localhost?
Because that endpoint will have a different secret
i am not using any secret key for verification
to avoid problems
okey
sorry
in localhost the event invoice.payment_succeeded gives a Deserialization failed
because dataObjectDeserializer.getObject().isPresent() is false
Sorry secret key was the slightly wrong term. I mean are you using a different webhook secret
Yes i understand. You mean: event = Webhook.constructEvent(
payload, sigHeader, endpointSecret
);
Like if you go to https://dashboard.stripe.com/test/webhooks or https://dashboard.stripe.com/webhooks and click on your webhook, there will be a "reveal" link on the endpoint's page. If you click it, the page will reveal the enpoints secret
But i amb not getting it trhought this construct method. i create the event object through: event = ApiResource.GSON.fromJson(payload, Event.class);
Gotcha, I'm just asking because if this works with localhost, it sounds like your code is right but the config not be right
and payload is the json string formatted body that i receive from stripe
it does not work
it works for payment_intent.succeeded but not for invoice.payment_succeeded
and i want to make it work for invoice.payment_succeeded too
Because with payment_intent.succeeded the webhook will trigger always someone pays
And with invoice.payment_succeeded will trigger just when the invoice that is sent using Stripe Invoicing is paid
Am i wrong?
Interesting. It should work across event types
Are you decoding the event we sent you as UTF-8?
When some events work but not others, typically that comes from decoding as ACII
Nope, on your phone or did you get a Discord call?
I don't think I clicked anything call related, apologies if you got some ring from me on here
no, don't worry. might be another stripe question from another team member