박세일
박세일2mo ago

결재관련

결재승인관련 추가 문의 드립니다. https://docs.tosspayments.com/reference#결제-승인 로 답변을 주셨는데 responseStream 에 들어온다는건가요? 테스트로 해서인지 URL url = new URL("https://api.tosspayments.com/v1/payments/confirm"); HttpURLConnection connection = (HttpURLConnection) url.openConnection() ; connection.setRequestProperty("Authorization", authorizations); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestMethod("POST"); connection.setDoOutput(true); OutputStream outputStream = connection.getOutputStream(); outputStream.write(obj.toString().getBytes("UTF-8")); int code = connection.getResponseCode(); boolean isSuccess = code == 200; logger.info("responseStream Test: "); InputStream responseStream = isSuccess ? connection.getInputStream() : connection.getErrorStream(); logger.info("responseStream : "+responseStream); responseStream : sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@4299b971이렇게만 들어와서요 responseStream 데이터를 파싱해서 쓰라는건가요? realKey로 하면 데이터가 들어오는건가요? 아래 답변내용에 답변이 없어 추가로 문의 드립니다.
코어 API | 토스페이먼츠 개발자센터
토스페이먼츠 API 엔드포인트(Endpoint)와 객체 정보, 파라미터, 요청 및 응답 예제를 살펴보세요.
3 Replies
토스페이먼츠 BOT
⏳ 잠시만 기다려주세요! 곧 답변드리겠습니다
오류 문의일 경우 아래 정보를 미리 전달해주시면, 빠른 답변에 도움이 됩니다.
- 주문번호(orderId) : - 문의 내용 :
(img를 함께 첨부해주시면 도움이됩니다)
* 계약관련 내용은 1544-7772로 문의주세요. * 주말/공휴일에는 답변이 늦을 수 있어요.
박의원
박의원2mo ago
아래 내용 참고 부탁드립니다. URL url = new URL("https://api.tosspayments.com/v1/payments/confirm");
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("Authorization", authorizations); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestMethod("POST"); connection.setDoOutput(true);
JSONObject obj = new JSONObject(); obj.put("paymentKey", paymentKey); obj.put("orderId", orderId); obj.put("amount", amount); OutputStream outputStream = connection.getOutputStream(); outputStream.write(obj.toString().getBytes("UTF-8")); int code = connection.getResponseCode(); boolean isSuccess = code == 200 ? true : false;
InputStream responseStream = isSuccess? connection.getInputStream(): connection.getErrorStream(); Reader reader = new InputStreamReader(responseStream, StandardCharsets.UTF_8); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(reader); responseStream.close(); <!DOCTYPE html> <html lang="ko"> <head> <title>결제 성공</title> <meta http-equiv="x-ua-compatible" content="ie=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> </head> <body> <section> <% if (isSuccess) { %> <h1>결제 성공</h1> <p>결과 데이터 : <%= jsonObject.toJSONString() %></p> <p>orderName : <%= jsonObject.get("orderName") %></p> <p>method : <%= jsonObject.get("method") %></p> <p> <% if(jsonObject.get("method").equals("카드")) { out.println(((JSONObject)jsonObject.get("card")).get("number"));} %> <% if(jsonObject.get("method").equals("가상계좌")) { out.println(((JSONObject)jsonObject.get("virtualAccount")).get("accountNumber"));} %> <% if(jsonObject.get("method").equals("계좌이체")) { out.println(((JSONObject)jsonObject.get("transfer")).get("bank"));} %> <% if(jsonObject.get("method").equals("휴대폰")) { out.println(((JSONObject)jsonObject.get("mobilePhone")).get("customerMobilePhone"));} %> </p> <%} else { %> <h1>결제 실패</h1> <p><%= jsonObject.get("message") %></p> <span>에러코드: <%= jsonObject.get("code") %></span> <% } %> </section> </body> </html>
토스페이먼츠 BOT
❤️ 기술문의 경험이 어떠셨나요?!
간단히 코멘트 남겨주세요! 제품 발전에 큰 힘이 됩니다.

Did you find this page helpful?