@@ -242,24 +242,23 @@ This SDK provides utility method for verifying the HMAC signature of the incomin
242
242
class WebhookController {
243
243
244
244
@PostMapping (" /api/webhook" )
245
- @ResponseBody
246
- public ResponseEntity<String > webhookHandler (@RequestBody String webhook , @RequestHeader HttpHeaders headers ) {
245
+ public ResponseEntity<String > webhookHandler (@RequestBody byte [] webhook , @RequestHeader HttpHeaders headers ) {
247
246
final String secret = System . getenv(" WEBHOOK_SIGNATURE_SECRET" );
248
247
if (secret == null || secret. isEmpty()) {
249
- return new ResponseEntity< String > ( " Secret key is not configured" , HttpStatus . INTERNAL_SERVER_ERROR );
248
+ return ResponseEntity . status( HttpStatus . INTERNAL_SERVER_ERROR ) . body( " Secret key is not configured" );
250
249
}
251
250
252
251
final String signature = headers. getFirst(" fpjs-event-signature" );
253
252
if (signature == null || signature. isEmpty()) {
254
- return new ResponseEntity< String > ( " Missing fpjs-event-signature header" , HttpStatus . BAD_REQUEST );
253
+ return ResponseEntity . status( HttpStatus . BAD_REQUEST ) . body( " Missing fpjs-event-signature header" );
255
254
}
256
255
257
- final boolean isValidSignature = Webhook . isValidWebhookSignature(signature, webhook. getBytes( StandardCharsets . UTF_8 ) , secret);
256
+ final boolean isValidSignature = Webhook . isValidWebhookSignature(signature, webhook, secret);
258
257
if (! isValidSignature) {
259
- return new ResponseEntity< String > ( " Webhook signature is not valid" , HttpStatus . BAD_REQUEST );
258
+ return ResponseEntity . status( HttpStatus . BAD_REQUEST ) . body( " Webhook signature is not valid" );
260
259
}
261
260
262
- return new ResponseEntity< String > (" Webhook received" , HttpStatus . OK );
261
+ return ResponseEntity . ok (" Webhook received" );
263
262
}
264
263
}
265
264
```
0 commit comments