#Java Webhook Issue

7 messages · Page 1 of 1 (latest)

spice yew
#

Hello everyone,
I am facing a rather annoying issue on webhooks and couuld not find any answer despite hours of researching the web. Could anyone help me please ?
Here is my java method:

private static boolean handleWebhookEvent(String payload, String sigHeader) throws StripeException {
        try {
            System.out.println("Payload : " + payload);
            System.out.println("sigHeader : " + sigHeader);

            Event event = Webhook.constructEvent(payload, sigHeader, WEBHOOK_ENDPOINT_SECRET);
            
            System.out.println("Event" + event);

            if ("checkout.session.completed".equals(event.getType())) {
                Session session = (Session) event.getDataObjectDeserializer().getObject()
                        .orElseThrow(() -> new RuntimeException("Error deserializing session object"));
                System.out.println(session);
                String sessionId = session.getId();
                System.out.println("Payment succeeded for session: " + sessionId);

                StripeSessionInfo stripeSession = new StripeSessionInfo(sessionId);
                stripeSession.fetchSessionInfo(YOUR_STRIPE_CLE_PRIVE);

                System.out.println(stripeSession.getMetadata().get("paiementId"));

                // Perform additional actions based on successful payment
                // ...
                return true;
                
            } else {
                System.out.println("Received webhook event of type: " + event.getType());
                return false;
            }
        } catch (SignatureVerificationException e) {
            System.out.println("Webhook signature verification failed: " + e.getMessage());
            return false;
        }
    }

The issue is that the SignatureVerificationException is always raised
Webhook signature verification failed: No signatures found matching the expected signature for payload
I am using Stripe by the way

jolly juncoBOT
#

This post has been reserved for your question.

Hey @spice yew! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

spice yew
#

Oh and the arguments are defined this way:

String payload = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
        String sigHeader = request.getHeader("Stripe-Signature");      

#

If it may help, here is a screen of the STRIPE CLI I used to create a local endpoint:

calm escarp
#

printstacktrace and see what line is throwing the error

#

@spice yew