0

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.

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
bkvishal
  • 73
  • 1
  • 7
  • Please have a look. Hope it helps. https://stackoverflow.com/questions/52364187/resttemplate-exchange-vs-postforentity-vs-execute – Himanshu Apr 11 '19 at 16:54
  • thanks @Himanshu i tried postForEntity and exchange both but still got null.. may be problem is something else.. – bkvishal Apr 12 '19 at 13:16

0 Answers0