0

I'm trying to catch WebHooks triggers from Stripe Platform within an HttpServlet . Here's the code :

@WebServlet("/StripeWebhook")
public class StripeWebhook extends HttpServlet {
    private static final long serialVersionUID = 1L;
    // MySessionScopedBeanSaveEvent persist to database all Stripe objects (cust,price,prod,subs,..) 
    @Inject 
    private MySessionScopedBeanSaveEvent MySessionScopedBeanSaveEvent
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String test ;
        String rawRequestBody = getRawRequestBody(request);

        // Configure the Stripe API with your secret key
        Stripe.apiKey = STRIPE_SECRET_KEY;

        String sigHeader = request.getHeader("Stripe-Signature");
        Event event;
        try {
            event = Webhook.constructEvent(rawRequestBody, sigHeader, WEBHOOK_SECRET);
            //event = ApiResource.GSON.fromJson(rawRequestBody, Event.class);
        } catch (JsonSyntaxException | SignatureVerificationException e) {
            // Invalid payload or signature
            response.setStatus(400);
            System.out.println("JsonSyntaxException | SignatureVerificationException e: " + e.getLocalizedMessage());
            return;
        }
        eventHandlingPool.execute(new Runnable() {
            @Override
            public void run() {
              persistStripeObjects(event,MySessionScopedBeanSaveEvent.Persist);
            }
        }
        response.setStatus(200);
    } 
...

private void persistStripeObjects(Event eventType, String persistType) {
                switch (eventType.getType()) {
                    case "payment_intent.succeeded": .... }

But i always get a null value for MySessionScopedBeanSaveEvent object (the user is logged). May anyone help me, have an answer ?

Thanks for answers.

MADARASSOU David
  • 149
  • 1
  • 1
  • 5

0 Answers0