윤정빈
윤정빈
ec2 배포시 결제 콜백 에러
No description
28 replies
400 Bad Request: INVALID_REQUEST, 필수 파라미터 누락
https://docs.tosspayments.com/reference/test/v1/payments/confirm/POST 위 API를 Spring Boot에서 사용하려 합니다. 요청을 하면 400 Bad Request: "{"code":"INVALID_REQUEST","message":"필수 파라미터가 누락되었습니다."}" 라는 에러가 나옵니다. 필수 파라미터를 모두 보낸 것 같은데 왜 저 에러가 나오는지 궁금합니다. 아래는 Spring Boot 코드와 요청을 보낼때의 JSON 데이터입니다.
RestTemplate rest = new RestTemplate();

HttpHeaders headers = new HttpHeaders();

String testSecretApiKey = tossPaymentConfig.getTestSecretKey() + ":";
String encodedAuth = new String(Base64.getEncoder().encode(testSecretApiKey.getBytes(StandardCharsets.UTF_8)));

headers.setBasicAuth(encodedAuth);
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

JSONObject param = new JSONObject();
param.put("orderId", orderId);
param.put("amount", amount);
param.put("paymentKey", paymentKey);

//System.out.println(new HttpEntity<>(param, headers));
return rest.postForEntity(
PAYMENT_URL + paymentKey,
new HttpEntity<>(param, headers),
TossPaymentSuccessDto.class
).getBody();
RestTemplate rest = new RestTemplate();

HttpHeaders headers = new HttpHeaders();

String testSecretApiKey = tossPaymentConfig.getTestSecretKey() + ":";
String encodedAuth = new String(Base64.getEncoder().encode(testSecretApiKey.getBytes(StandardCharsets.UTF_8)));

headers.setBasicAuth(encodedAuth);
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

JSONObject param = new JSONObject();
param.put("orderId", orderId);
param.put("amount", amount);
param.put("paymentKey", paymentKey);

//System.out.println(new HttpEntity<>(param, headers));
return rest.postForEntity(
PAYMENT_URL + paymentKey,
new HttpEntity<>(param, headers),
TossPaymentSuccessDto.class
).getBody();
<{"amount":3243,"orderId":"qec1d544-2a34-4f44-ada0-c5213d8fd8da","paymentKey":"e75jWNka9lpP2YxJ4K879ml2Knk5ovVRGZwXLObgyB0vMDm1"},[Authorization:"Basic dGVzdF9za19CYTVQelIwQXJubjlkN3dHRDZ2eHJ2bVluTmVEOg==", Content-Type:"application/json", Accept:"application/json"]>
33 replies