#Nil

1 messages ยท Page 1 of 1 (latest)

worthy salmonBOT
frank falcon
tight furnace
#

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? ๐Ÿ˜ฆ

frank falcon
#

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.

tight furnace
#

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

frank falcon
#

It seems like your route code on that route returns a 500

tight furnace
#

What i return is return new ResponseEntity<>("Success", HttpStatus.OK);

frank falcon
#

Can you try and remove the code thats there on that route and see if it can just respond with a 200?

tight furnace
#

is a 200

#

witout anything?

frank falcon
#

yes

tight furnace
#

give me a min

frank falcon
#

that'd confirm if the payload actually hits the route and the issue is somewhere in the code

tight furnace
#

okey

#

deploying

#

now it works

#

so the problem is not routing

#

but the code I write inside is the one of the tutorial ๐Ÿ˜ฆ

frank falcon
#

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

tight furnace
#

yes

#

hahahaha

#

will try one by onme

#

one

#

if i dont find it out will contact you another time

#

Thank you!

frank falcon
#

๐Ÿ‘

tight furnace
#

Hello hanzo

#

it crashes here

#

if (dataObjectDeserializer.getObject().isPresent()) {

#

in this check

#

EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();

#

can it be a api version problem?

frank falcon
#

Not sure.
Can you print out the event object and see if it can be deserialized?

tight furnace
#

sure

#

let me send you the json

#

The JSON file represents the dataObjectDeserializer object which is declared as: EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();

viral osprey
#

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?

tight furnace
#

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>

viral osprey
#

Interesting 21.0.0 should use 2022-08-01 so I don't think version is the problem

tight furnace
#

should i change to 21.0.0?

viral osprey
#

you are already on the right version

tight furnace
#

okey

#

it is weird because in localhost it works

viral osprey
#

Are you using a different secret key when you are testing without localhost?

#

Because that endpoint will have a different secret

tight furnace
#

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

viral osprey
#

Sorry secret key was the slightly wrong term. I mean are you using a different webhook secret

tight furnace
#

Yes i understand. You mean: event = Webhook.constructEvent(
payload, sigHeader, endpointSecret
);

viral osprey
tight furnace
#

But i amb not getting it trhought this construct method. i create the event object through: event = ApiResource.GSON.fromJson(payload, Event.class);

viral osprey
#

Gotcha, I'm just asking because if this works with localhost, it sounds like your code is right but the config not be right

tight furnace
#

and payload is the json string formatted body that i receive from stripe

tight furnace
#

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?

viral osprey
#

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

tight furnace
#

yes

#

but will check another time

#

are you trying to call me?

viral osprey
#

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

tight furnace
#

no, don't worry. might be another stripe question from another team member