결제 - 키움결제 적용 1차
This commit is contained in:
@@ -1023,6 +1023,15 @@ public interface BOOrdrMapper {
|
||||
* @param refundVO
|
||||
*/
|
||||
public Integer selectSubsvcRefundAmt(BOOrdrRefundVO refundVO);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 키움결제 GC_ORDER_PG_API_LOG 결과 조회
|
||||
* @param payVO
|
||||
* @return List<DataMap>
|
||||
*/
|
||||
public DataMap selectKiwoomPgApiLog(BOPayVO payVO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -191,7 +191,11 @@ public class BOOrdrLogService {
|
||||
pgResult = false;
|
||||
} else {
|
||||
|
||||
if ("kcp".equals(payVO.getPgCmpnyNm())) {
|
||||
if("kiwoom".equals(payVO.getPgCmpnyNm())) {
|
||||
resCd = "0000";
|
||||
message = "결제 승인 성공";
|
||||
//결제실패에 대한 응답은 없음
|
||||
} else if ("kcp".equals(payVO.getPgCmpnyNm())) {
|
||||
resCd = StringUtil.isNullToString(resultMap.get("res_cd"));
|
||||
message = StringUtil.isNullToString(resultMap.get("res_msg"));
|
||||
|
||||
@@ -227,7 +231,7 @@ public class BOOrdrLogService {
|
||||
String logDtlCn = "";
|
||||
String operNm = "";
|
||||
String dvCd = payVO.getDvCd();
|
||||
String setleTyCd = payVO.getSetleTyCd();
|
||||
//String setleTyCd = payVO.getSetleTyCd();
|
||||
if ("02".equals(dvCd)) { // 관리자 주문
|
||||
String mbrNm = "";
|
||||
if (payVO.getMbrNm() != null) {
|
||||
@@ -311,7 +315,7 @@ public class BOOrdrLogService {
|
||||
|
||||
/**
|
||||
* 주문 로그 단순 등록
|
||||
* @param pgApiLogVO
|
||||
* @param logVO
|
||||
*/
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void insertBOOrderLogRegist(BOOrderLogVO logVO, boolean result, String message) {
|
||||
@@ -336,7 +340,7 @@ public class BOOrdrLogService {
|
||||
|
||||
/**
|
||||
* 주문 종기능 로그 등록
|
||||
* @param pgApiLogVO
|
||||
* @param bellVO
|
||||
*/
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void insertBOOrderBellLogRegist(BOOrderLogVO bellVO) {
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.wb.domainserver.domain.sopmal.ordr.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.wb.domainserver.common.msg.GconeMessageSource;
|
||||
import com.wb.domainserver.domain.gcone.ordr.ordr.service.BOOrdrLogService;
|
||||
import com.wb.domainserver.domain.gcone.ordr.pay.vo.BOPayVO;
|
||||
import com.wb.domainserver.domain.sopmal.ordr.vo.OrdrVO;
|
||||
import com.wb.domainserver.exception.WnbtRestException;
|
||||
import com.wb.domainserver.response.WnbtWebClientResponseHandler;
|
||||
@@ -9,17 +11,23 @@ import com.wb.domainserver.security.authorization.annotation.AuthPolicy;
|
||||
import com.wb.domainserver.security.authorization.annotation.Policy;
|
||||
import com.wb.domainserver.util.communicate.RESRC;
|
||||
import com.wb.domainserver.util.communicate.SendToResrc;
|
||||
import com.wb.domainserver.util.dataaccess.DataMap;
|
||||
import com.wb.domainserver.util.string.StringUtil;
|
||||
import com.wb.domainserver.util.util.Util;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.BufferedReader;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
@Controller
|
||||
@@ -34,6 +42,9 @@ public class OrdrApiController {
|
||||
@Autowired
|
||||
private GconeMessageSource messageSource;
|
||||
|
||||
@Autowired
|
||||
private BOOrdrLogService ordrLogService;
|
||||
|
||||
private Util utilClass;
|
||||
|
||||
/* ####################################
|
||||
@@ -95,4 +106,135 @@ public class OrdrApiController {
|
||||
return Integer.parseInt(cleanedCode.toString(), 16);
|
||||
}
|
||||
|
||||
|
||||
/* ##################################################
|
||||
사용자 > 결제(키움) > 결제 성공 후 결제값 응답받음
|
||||
################################################## */
|
||||
/**
|
||||
* 키움 결제 연계처리 - 결과통보페이지
|
||||
* @author 이경숙
|
||||
*/
|
||||
@Policy(AuthPolicy.RESTRICTED)
|
||||
@RequestMapping(value="/kiwoomPayWebhook")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> selectPaymentkiwoomWebhook(HttpServletRequest request) throws Exception {
|
||||
|
||||
// 0. 키움에서 온 값 로그 출력 (결제실패에 대한 응답은 없음)
|
||||
printKiwoomRequest(request);
|
||||
|
||||
// 1. 주문 로그 남김 (GC_ORDER_LOG)
|
||||
BOPayVO payVO = new BOPayVO();
|
||||
DataMap pgApiLogReqVO = new DataMap();
|
||||
String orderNo = StringUtil.isNullToString(request.getParameter("ORDERNO"));
|
||||
String orderNm = StringUtil.isNullToString(request.getParameter("USERNAME"));
|
||||
String resParam = queryStringToJson(request.getQueryString());
|
||||
|
||||
payVO.setPgCmpnyNm("kiwoom"); //pg사명
|
||||
payVO.setDvCd("01"); //사용자
|
||||
payVO.setOrderId(orderNo); //주문번호
|
||||
payVO.setSetlerNm(orderNm); //주문자명
|
||||
pgApiLogReqVO.put("resParam",resParam); //응답전문
|
||||
|
||||
ordrLogService.insertSetleOrderPgLog(payVO, pgApiLogReqVO);
|
||||
|
||||
// 2. PG API 로그 남김 (GC_ORDER_PG_API_LOG)
|
||||
pgApiLogReqVO.put("reqParam", ""); //요청전문
|
||||
pgApiLogReqVO.put("ordrInnb", orderNo); //주문번호
|
||||
pgApiLogReqVO.put("sopmalCd", "SK"); //쇼핑몰코드
|
||||
pgApiLogReqVO.put("pgCmpnyNm", "kiwoom"); //pg사명
|
||||
pgApiLogReqVO.put("mbrInnb", ""); //회원번호
|
||||
pgApiLogReqVO.put("resParam", resParam); //응답전문
|
||||
|
||||
ordrLogService.insertBOPgApiLogReqRegist(pgApiLogReqVO);
|
||||
|
||||
String response = "<html><body><RESULT>SUCCESS</RESULT></body></html>";
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.TEXT_HTML)
|
||||
.body(response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void printKiwoomRequest(HttpServletRequest request) {
|
||||
try {
|
||||
System.out.println("========== [KIWOOM REQUEST START] ==========");
|
||||
|
||||
// 1. 기본 정보
|
||||
System.out.println("URL : " + request.getRequestURL());
|
||||
System.out.println("METHOD : " + request.getMethod());
|
||||
System.out.println("QUERY : " + request.getQueryString());
|
||||
System.out.println("REMOTE IP : " + request.getRemoteAddr());
|
||||
|
||||
// 2. 파라미터 (가장 중요)
|
||||
System.out.println("---------- PARAM ----------");
|
||||
request.setCharacterEncoding("EUC-KR");
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
System.out.println(key + " = " + Arrays.toString(values));
|
||||
});
|
||||
|
||||
// 3. 헤더
|
||||
System.out.println("---------- HEADER ----------");
|
||||
Collections.list(request.getHeaderNames()).forEach(header -> {
|
||||
System.out.println(header + " = " + request.getHeader(header));
|
||||
});
|
||||
|
||||
// 4. Body (JSON 대응)
|
||||
System.out.println("---------- BODY ----------");
|
||||
|
||||
StringBuilder body = new StringBuilder();
|
||||
BufferedReader reader = request.getReader();
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
body.append(line);
|
||||
}
|
||||
|
||||
System.out.println(body.toString());
|
||||
|
||||
System.out.println("========== [KIWOOM REQUEST END] ==========");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("❌ REQUEST LOG ERROR");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String queryStringToJson(String queryString) throws Exception {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
if (queryString != null && !queryString.isEmpty()) {
|
||||
String[] pairs = queryString.split("&");
|
||||
|
||||
for (String pair : pairs) {
|
||||
String[] keyValue = pair.split("=", 2);
|
||||
|
||||
String key = URLDecoder.decode(keyValue[0], "UTF-8");
|
||||
String value = keyValue.length > 1 ? URLDecoder.decode(keyValue[1], "UTF-8") : "";
|
||||
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.writeValueAsString(map);
|
||||
}
|
||||
|
||||
public Map<String, String> queryStringToMap(String queryString) throws Exception {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
if (queryString != null) {
|
||||
for (String param : queryString.split("&")) {
|
||||
String[] pair = param.split("=", 2);
|
||||
|
||||
String key = URLDecoder.decode(pair[0], "EUC-KR");
|
||||
String value = pair.length > 1 ? URLDecoder.decode(pair[1], "EUC-KR") : "";
|
||||
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -703,98 +703,6 @@ public class PayController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 키움 결제 연계처리 - 결과통보페이지
|
||||
* @return PayKiwoomSucsC.jsp
|
||||
* @author 이경숙
|
||||
*/
|
||||
@Policy(AuthPolicy.RESTRICTED)
|
||||
@RequestMapping(value="/kiwoomPayWebhook")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> selectPaymentkiwoomWebhook(HttpServletRequest request) throws Exception {
|
||||
|
||||
String resultCode = request.getParameter("RESULTCODE");
|
||||
String orderNo = request.getParameter("ORDERNO");
|
||||
String amount = request.getParameter("AMOUNT");
|
||||
|
||||
printKiwoomRequest(request);
|
||||
|
||||
/* 실제 처리해야 되는 부분
|
||||
// 1. 주문 조회
|
||||
Order order = orderService.find(orderNo);
|
||||
|
||||
// 2. 중복 방지
|
||||
if ("PAID".equals(order.getStatus())) return "OK";
|
||||
|
||||
// 3. 금액 검증
|
||||
if (!order.getAmount().equals(Integer.parseInt(amount))) {
|
||||
order.setStatus("FAIL");
|
||||
return "OK";
|
||||
}
|
||||
|
||||
// 4. 성공 처리
|
||||
if ("0000".equals(resultCode)) {
|
||||
order.setStatus("PAID");
|
||||
} else {
|
||||
order.setStatus("FAIL");
|
||||
}
|
||||
|
||||
orderService.save(order);
|
||||
*/
|
||||
String response = "<html><body><RESULT>SUCCESS</RESULT></body></html>";
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.TEXT_HTML)
|
||||
.body(response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void printKiwoomRequest(HttpServletRequest request) {
|
||||
try {
|
||||
System.out.println("========== [KIWOOM REQUEST START] ==========");
|
||||
|
||||
// 1. 기본 정보
|
||||
System.out.println("URL : " + request.getRequestURL());
|
||||
System.out.println("METHOD : " + request.getMethod());
|
||||
System.out.println("QUERY : " + request.getQueryString());
|
||||
System.out.println("REMOTE IP : " + request.getRemoteAddr());
|
||||
|
||||
// 2. 파라미터 (가장 중요)
|
||||
System.out.println("---------- PARAM ----------");
|
||||
request.getParameterMap().forEach((key, values) -> {
|
||||
System.out.println(key + " = " + Arrays.toString(values));
|
||||
});
|
||||
|
||||
// 3. 헤더
|
||||
System.out.println("---------- HEADER ----------");
|
||||
Collections.list(request.getHeaderNames()).forEach(header -> {
|
||||
System.out.println(header + " = " + request.getHeader(header));
|
||||
});
|
||||
|
||||
// 4. Body (JSON 대응)
|
||||
System.out.println("---------- BODY ----------");
|
||||
|
||||
StringBuilder body = new StringBuilder();
|
||||
BufferedReader reader = request.getReader();
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
body.append(line);
|
||||
}
|
||||
|
||||
System.out.println(body.toString());
|
||||
|
||||
System.out.println("========== [KIWOOM REQUEST END] ==========");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("❌ REQUEST LOG ERROR");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 키움 결제 연계처리 - 성공결과페이지
|
||||
* @return PayKiwoomSucsC.jsp
|
||||
|
||||
Reference in New Issue
Block a user