#DeReb

1 messages · Page 1 of 1 (latest)

modern juncoBOT
granite latch
#

hi! can you share the exact code you're using for the endpoint?

coral ermine
#

hello, this is the response

granite latch
#

can you share the exact code you're using for the endpoint?

coral ermine
#

@Override
public ResponseEntity<String> handleStripeEvent(String payload, String sigHeader) {

    Stripe.apiKey = "";
    
    logger.info("sigheader log: {}", sigHeader);
    logger.info("payload log: {}", payload);
            
    String endpointSecret = "";

        if(sigHeader == null) {
            return new ResponseEntity<> (HttpStatus.NOT_ACCEPTABLE);
        }

        Event event = ApiResource.GSON.fromJson(payload, Event.class);

        // Only verify the event if you have an endpoint secret defined.
        // Otherwise use the basic event deserialized with GSON.
        try {
            event = Webhook.constructEvent(
                    payload, sigHeader, endpointSecret
                    );
        } catch (JsonSyntaxException e) {
            // Invalid payload
            logger.error("⚠️  Webhook error while validating signature for payload.", e);
            return new ResponseEntity<> (HttpStatus.BAD_REQUEST);
        } catch (SignatureVerificationException e) {
            // Invalid signature
            logger.error("⚠️  Webhook error while validating signature.", e);
            return new ResponseEntity<> (HttpStatus.BAD_REQUEST);
        }
#

// Deserialize the nested object inside the event
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.
}

        // Handle the event
        switch (event.getType()) {
        case "payment_intent.succeeded":
            PaymentIntent paymentIntent = (PaymentIntent) stripeObject;
            logger.info("Payment for id={}, {} succeeded.",paymentIntent.getId() ,paymentIntent.getAmount());
            // Then define and call a method to handle the successful payment intent.
            // handlePaymentIntentSucceeded(paymentIntent);
            break;
        default:
            logger.warn("Unhandled event type: {}" ,event.getType());
            break;
        }
        return new ResponseEntity<> (HttpStatus.OK);
    }
granite latch
#

I do this in my Spring app and it works fine

@RequestMapping(method=RequestMethod.POST)
    public @ResponseBody String getEvent(@RequestBody String request, @RequestHeader(value="Stripe-Signature") String signature){
        Event event = Webhook.constructEvent(request, signature, secret)
coral ermine
#

I hid the api keys and split the message in two for size