Skip to content

Commit

Permalink
Deserialize webhook json
Browse files Browse the repository at this point in the history
  • Loading branch information
gcatanese committed Sep 19, 2023
1 parent 5739db1 commit 03fe478
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.security.SignatureException;

/**
Expand All @@ -40,7 +41,11 @@ public GivingWebhookResource(ApplicationProperty applicationProperty, HMACValida


@PostMapping("/webhooks/giving")
public ResponseEntity<String> webhooks(@RequestBody NotificationRequest notificationRequest) {
public ResponseEntity<String> webhooks(@RequestBody String json) throws IOException {


// from JSON string to object
var notificationRequest = NotificationRequest.fromJson(json);

// fetch first (and only) NotificationRequestItem
var notificationRequestItem = notificationRequest.getNotificationItems().stream().findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.security.SignatureException;

/**
Expand All @@ -40,11 +41,14 @@ public WebhookResource(ApplicationProperty applicationProperty) {
* Process incoming Webhook notification: get NotificationRequestItem, validate HMAC signature,
* consume the event asynchronously, send response ["accepted"]
*
* @param notificationRequest
* @param json Payload of the webhook event
* @return
*/
@PostMapping("/webhooks/notifications")
public ResponseEntity<String> webhooks(@RequestBody NotificationRequest notificationRequest) {
public ResponseEntity<String> webhooks(@RequestBody String json) throws IOException {

// from JSON string to object
var notificationRequest = NotificationRequest.fromJson(json);

// fetch first (and only) NotificationRequestItem
var notificationRequestItem = notificationRequest.getNotificationItems().stream().findFirst();
Expand Down

0 comments on commit 03fe478

Please sign in to comment.