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