I am trying to test my Spring Boot Java based rest controller to receive Chargebee webhook notifications.
Here is my code:
```
@RestController
@RequestMapping("/no-auth/manager/chargebee/webhook")
public class ChargeBeeWebhook {
@Autowired
private AppUserRepository AppUserRepository;
private UserManager userManager;
private Logger logger = LoggerFactory.getLogger(ChargeBeeWebhook.class);
@PostMapping
public ResponseEntity<Object> processEvent(@RequestBody Event event) {
String customerID = event.content().customer().id();
AppUser AppUser = AppUserRepository.findByChargeBeeCustomerID(customerID);
if (AppUser == null) {
logger.info("ChargeBee Event: {} received for Non-existent User: {}", event, AppUser);
return ResponseEntity.status(HttpStatus.OK).build();
}
logger.info("ChargeBee Event: {} received for User: {}", event, AppUser);
EventType eventType = event.eventType();
if (eventType.equals(EventType.PAYMENT_SOURCE_ADDED) || eventType.equals(EventType.PAYMENT_SOURCE_UPDATED)) {
AppUser.setHasPaymentSource(true);
userManager.managePaymentSourceUpdate(AppUser);
if (eventType.equals(EventType.PAYMENT_SOURCE_DELETED)) {
AppUser.setHasPaymentSource(false);
if (eventType.equals(EventType.PENDING_INVOICE_CREATED)) {
String invoiceID = event.content().invoice().id();
userManager.updateInvoiceMetadata(AppUser, invoiceID);
if (eventType.equals(EventType.PAYMENT_SUCCEEDED)) {
int amountInCents = event.content().transaction().amount();
userManager.applyInvoicePayment(AppUser, invoiceID, amountInCents);
When I test it form Chargee I always receive the HTTP 400 error for both v1 and v2.
What is going wrong?
Headers HTTP/1.1 400 Server: nginx/1.14.1 Date: Thu, 17 Jan 2019 07:09:57 GMT Content-Length: 0 Connection: keep-alive X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Body No body returned
ProxyCircuit
I am trying to test my Spring Boot Java based rest controller to receive Chargebee webhook notifications.
Here is my code:
```
@RestController
@RequestMapping("/no-auth/manager/chargebee/webhook")
public class ChargeBeeWebhook {
@Autowired
private AppUserRepository AppUserRepository;
@Autowired
private UserManager userManager;
private Logger logger = LoggerFactory.getLogger(ChargeBeeWebhook.class);
@PostMapping
public ResponseEntity<Object> processEvent(@RequestBody Event event) {
String customerID = event.content().customer().id();
AppUser AppUser = AppUserRepository.findByChargeBeeCustomerID(customerID);
if (AppUser == null) {
logger.info("ChargeBee Event: {} received for Non-existent User: {}", event, AppUser);
return ResponseEntity.status(HttpStatus.OK).build();
}
logger.info("ChargeBee Event: {} received for User: {}", event, AppUser);
EventType eventType = event.eventType();
if (eventType.equals(EventType.PAYMENT_SOURCE_ADDED) || eventType.equals(EventType.PAYMENT_SOURCE_UPDATED)) {
AppUser.setHasPaymentSource(true);
userManager.managePaymentSourceUpdate(AppUser);
}
if (eventType.equals(EventType.PAYMENT_SOURCE_DELETED)) {
AppUser.setHasPaymentSource(false);
userManager.managePaymentSourceUpdate(AppUser);
}
if (eventType.equals(EventType.PENDING_INVOICE_CREATED)) {
String invoiceID = event.content().invoice().id();
userManager.updateInvoiceMetadata(AppUser, invoiceID);
}
if (eventType.equals(EventType.PAYMENT_SUCCEEDED)) {
String invoiceID = event.content().invoice().id();
int amountInCents = event.content().transaction().amount();
userManager.applyInvoicePayment(AppUser, invoiceID, amountInCents);
}
return ResponseEntity.status(HttpStatus.OK).build();
}
}
```
When I test it form Chargee I always receive the HTTP 400 error for both v1 and v2.
What is going wrong?