I'm a beginner in Spring Boot as well as in REST API. I'm trying to integrate a payment gateway for creating payment requests and I'm using the Instamojo payment gateway for that. I'm getting NULL in the response with 200 success code. What is the main difference between postForObject
, postForEntity
or some people use the exchange method? It appears that postForEntity
and the exchange method are used to get return for reponseEntity
, When should i go for postForObject
, postForEntity
or exchange method? Can anyone tell me what I'm doing wrong?
@PostMapping(value="/paymentcreate")
public void createOrderCashFree(@RequestBody CreateOrder createorder) {
CreateOrder corder = new CreateOrder();
corder.setAmount(createorder.getAmount());
corder.setBuyer_name(createorder.getBuyer_name());
corder.setEmail(createorder.getEmail());
corder.setPurpose(createorder.getPurpose());
corder.setPhone(createorder.getPhone());
corder.setRedirect_url("https://www.google.com/"); // just for test
corder.setWebhook("");
corder.setAllow_repeated_payments(false);
corder.setSend_email(false);
corder.setSend_sms(false);
corder.setExpire_at(new Date());
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
header.set("X-Api-Key", "test-api-key"); // actual key is provided
header.set("X-Auth-Token","test-auth-token"); // actual token is provided
HttpEntity<CreateOrder> entity = new HttpEntity<CreateOrder>(corder, header);
System.out.println(entity.getBody());
CreateOrder response =resttemplate.postForObject("https://test.instamojo.com/api/1.1/payment-requests/", entity, CreateOrder.class);
System.out.println(response); // this return null
}
The expected result is a response with some fields, but the actual result is a 200 success code but NULL in the body.