|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package cokr.xit.ens.modules.nice.service;
|
|
|
|
|
|
|
|
|
|
import java.time.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.*;
|
|
|
|
@ -104,36 +105,24 @@ public class NiceCiAcceptService {
|
|
|
|
|
d.setInputDataXits(niceCiMapper.selectInputDataXits(niceCiParam));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String prefixBillUid = PostSeCd.intgrnNoti.getCode() + "-" + IdGenerator.getCurrentTimeSec();
|
|
|
|
|
final KkoPayUrlRespData kkoPayUrlRespData = KkoPayUrlRespData.builder()
|
|
|
|
|
.customUrl(CustomUrl.builder()
|
|
|
|
|
.noticeUrl(BILL_HOST + BILL_NOTICE_URL)
|
|
|
|
|
.prepayUrl(BILL_HOST + BILL_PREPAY_URL)
|
|
|
|
|
.payResultUrl(BILL_HOST + BILL_PAYREUSLT_URL)
|
|
|
|
|
.build())
|
|
|
|
|
.expireAt(DateUtil.getStringFromLocalDate(list.get(0).getExpiresDt(), "yyyyMMddHHmmss"))
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(NiceCiDTO.InputXit xit : list){
|
|
|
|
|
final KkoPayUrlRespData kkoPayUrlRespData = buildKkoPayUrlRespData(xit.getPayExpiresDt());
|
|
|
|
|
final OrgMng orgMng = niceCiMapper.selectKkoBpApiUrlFromEnsOrgMng(xit.getOrgCd())
|
|
|
|
|
.orElseThrow(() -> new EnsException(EnsErrCd.NO_DATA_FOUND, EnsErrCd.NO_DATA_FOUND.getCodeNm()));
|
|
|
|
|
|
|
|
|
|
NiceCiDTO.BillHistDTO billHistDTO = null;
|
|
|
|
|
try {
|
|
|
|
|
List<NiceCiDTO.InputDataXit> inputDataXits = xit.getInputDataXits();
|
|
|
|
|
for (NiceCiDTO.InputDataXit data : inputDataXits) {
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
// pay Url API call & Get Result START
|
|
|
|
|
// pay Url API call & Get Result
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
PayApiRespDTO<Map<String, Object>> respDTO = getPayUrl(data, billHistDTO, orgMng, kkoPayUrlRespData);
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
// pay Url API call & Get Result START
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
// API Call 후처리 START - response 반영 & 결제 이력 생성
|
|
|
|
|
// API Call 후처리 - response 반영 & 결제 이력 생성
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
// FIXME: API 호출 결과 SET - 연계 설정후 확인 필요
|
|
|
|
|
data.setPayUrl(String.valueOf(respDTO.getData()));
|
|
|
|
@ -146,31 +135,10 @@ public class NiceCiAcceptService {
|
|
|
|
|
billHistoryService.updateBillHistory(billHistDTO);
|
|
|
|
|
|
|
|
|
|
// FIXME: bill_se_cd, org_cd 설정 및 확인 필요???
|
|
|
|
|
niceCiMapper.insertBill(
|
|
|
|
|
NiceCiDTO.BillDTO.builder()
|
|
|
|
|
.billId(keySequenceService.getKeySequence("Bill_id"))
|
|
|
|
|
.billUid(billUid)
|
|
|
|
|
.billerUserKey(data.getDataId())
|
|
|
|
|
.billSeCd(BillSeCd.privt.getCode())
|
|
|
|
|
.orgCd(xit.getOrgCd())
|
|
|
|
|
.build()
|
|
|
|
|
);
|
|
|
|
|
// FIXME: biller_notice_key, custom_url, expire_at 설정 및 확인 필요???
|
|
|
|
|
niceCiMapper.mergeBillKko(
|
|
|
|
|
NiceCiDTO.BillKkoDTO.builder()
|
|
|
|
|
.billId(keySequenceService.getKeySequence("BillKko_id"))
|
|
|
|
|
.billerUserKey(data.getDataId())
|
|
|
|
|
.billerNoticeKey(billUid)
|
|
|
|
|
// FIXME: 저장형태 확인 필요
|
|
|
|
|
.customUrl(gson.toJson(kkoPayUrlRespData.getCustomUrl()))
|
|
|
|
|
.expireAt(kkoPayUrlRespData.getExpireAt()) //d.getExpiresDt()
|
|
|
|
|
.billUid(billUid)
|
|
|
|
|
.build()
|
|
|
|
|
);
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
// API Call 후처리 END - response 반영 & 결제 이력 생성
|
|
|
|
|
//----------------------------------------------------------
|
|
|
|
|
insertBillRecord(data, xit, billUid);
|
|
|
|
|
|
|
|
|
|
// FIXME: biller_notice_key, custom_url, expire_at 설정 및 확인 필요???
|
|
|
|
|
insertBillKkoRecord(data, kkoPayUrlRespData, billUid);
|
|
|
|
|
}
|
|
|
|
|
xit.setPrcsCd(IupPrcsCd.GRUC.getCode());
|
|
|
|
|
niceCiMapper.updatePrcsCdAndErrorOfInputXit(xit);
|
|
|
|
@ -190,19 +158,13 @@ public class NiceCiAcceptService {
|
|
|
|
|
niceCiMapper.updatePrcsCdAndErrorOfInputXit(xit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return EnsResponseVO.okBuilder()
|
|
|
|
|
//.resultInfo(niceCiMapper.selectAcceptTgts(null))
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {
|
|
|
|
|
* "res_code": "OK"
|
|
|
|
|
* "mseeage": "정상응답"
|
|
|
|
|
* "data": {"url":"https://billgates-web.kakao.com/r/platform/pages/paynow/search/1832/11/1a481760-b0da-4a77-9a7a-74951db5fa01"}
|
|
|
|
|
* }
|
|
|
|
|
* NICE CI payUrn Call
|
|
|
|
|
* @param dataXit NiceCiDTO.InputDataXit
|
|
|
|
|
* @param billHistDTO NiceCiDTO.BillHistDTO
|
|
|
|
|
* @param orgMng OrgMng
|
|
|
|
@ -211,40 +173,94 @@ public class NiceCiAcceptService {
|
|
|
|
|
*/
|
|
|
|
|
private PayApiRespDTO<Map<String, Object>> getPayUrl(final NiceCiDTO.InputDataXit dataXit, NiceCiDTO.BillHistDTO billHistDTO, final OrgMng orgMng, final KkoPayUrlRespData kkoPayUrlRespData){
|
|
|
|
|
// FIXME: 파라메터 확인 필요
|
|
|
|
|
Map<String, Object> requestParam = createRequestParam(dataXit, kkoPayUrlRespData);
|
|
|
|
|
|
|
|
|
|
// FIXME: API 호출 로그 저장
|
|
|
|
|
saveBillHistory(dataXit, billHistDTO, orgMng, requestParam);
|
|
|
|
|
|
|
|
|
|
ResponseEntity<String> resEntity = billKkoPayApi.url(orgMng.getKkoBpBillerCode(), orgMng.getKkoBpAuthorization(),
|
|
|
|
|
gson.toJson(requestParam));
|
|
|
|
|
|
|
|
|
|
// 마스터 상태 실패처리
|
|
|
|
|
String responseBody = resEntity.getBody();
|
|
|
|
|
if(resEntity.getStatusCode() != HttpStatus.OK){
|
|
|
|
|
handleApiError(billHistDTO, resEntity, responseBody);
|
|
|
|
|
}
|
|
|
|
|
return parseApiResponse(responseBody, billHistDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private KkoPayUrlRespData buildKkoPayUrlRespData(LocalDateTime expiresDt) {
|
|
|
|
|
return KkoPayUrlRespData.builder()
|
|
|
|
|
.customUrl(CustomUrl.builder()
|
|
|
|
|
.noticeUrl(BILL_HOST + BILL_NOTICE_URL)
|
|
|
|
|
.prepayUrl(BILL_HOST + BILL_PREPAY_URL)
|
|
|
|
|
.payResultUrl(BILL_HOST + BILL_PAYREUSLT_URL)
|
|
|
|
|
.build())
|
|
|
|
|
.expireAt(DateUtil.getStringFromLocalDate(expiresDt, "yyyyMMddHHmmss"))
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void insertBillRecord(NiceCiDTO.InputDataXit data, NiceCiDTO.InputXit xit, String billUid) {
|
|
|
|
|
niceCiMapper.insertBill(
|
|
|
|
|
NiceCiDTO.BillDTO.builder()
|
|
|
|
|
.billId(keySequenceService.getKeySequence("Bill_id"))
|
|
|
|
|
.billUid(billUid)
|
|
|
|
|
.billerUserKey(data.getDataId())
|
|
|
|
|
.billSeCd(BillSeCd.privt.getCode())
|
|
|
|
|
.orgCd(xit.getOrgCd())
|
|
|
|
|
.build()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void insertBillKkoRecord(NiceCiDTO.InputDataXit data, KkoPayUrlRespData kkoPayUrlRespData, String billUid) {
|
|
|
|
|
niceCiMapper.mergeBillKko(
|
|
|
|
|
NiceCiDTO.BillKkoDTO.builder()
|
|
|
|
|
.billId(keySequenceService.getKeySequence("BillKko_id"))
|
|
|
|
|
.billerUserKey(data.getDataId())
|
|
|
|
|
.billerNoticeKey(billUid)
|
|
|
|
|
.customUrl(gson.toJson(kkoPayUrlRespData.getCustomUrl()))
|
|
|
|
|
.expireAt(kkoPayUrlRespData.getExpireAt())
|
|
|
|
|
.billUid(billUid)
|
|
|
|
|
.build()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> createRequestParam(NiceCiDTO.InputDataXit dataXit, KkoPayUrlRespData kkoPayUrlRespData) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put("biller_user_key", dataXit.getDataId());
|
|
|
|
|
map.put("expire_at", kkoPayUrlRespData.getExpireAt());
|
|
|
|
|
map.put("custom_url", gson.toJsonTree(kkoPayUrlRespData.getCustomUrl()));
|
|
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
|
|
param.put("data", map);
|
|
|
|
|
return param;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FIXME: API 호출 로그 저장
|
|
|
|
|
private void saveBillHistory(final NiceCiDTO.InputDataXit dataXit, NiceCiDTO.BillHistDTO billHistDTO, final OrgMng orgMng, Map<String, Object> requestParam) {
|
|
|
|
|
billHistDTO = NiceCiDTO.BillHistDTO.builder()
|
|
|
|
|
.linkedUuid(dataXit.getDataId())
|
|
|
|
|
.orgCd(orgMng.getOrgCd())
|
|
|
|
|
.requestData(gson.toJson(param))
|
|
|
|
|
.requestData(gson.toJson(requestParam))
|
|
|
|
|
.build();
|
|
|
|
|
billHistoryService.insertBillHistory(billHistDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResponseEntity<String> resEntity = billKkoPayApi.url(orgMng.getKkoBpBillerCode(), orgMng.getKkoBpAuthorization(),
|
|
|
|
|
gson.toJson(param));
|
|
|
|
|
|
|
|
|
|
// 마스터 상태 실패처리
|
|
|
|
|
String rsltStr = resEntity.getBody();
|
|
|
|
|
if(resEntity.getStatusCode() != HttpStatus.OK){
|
|
|
|
|
billHistDTO.setErrorCode(EnsErrCd.API_COMM_ERROR.getCode());
|
|
|
|
|
billHistDTO.setErrorMessage("["+ BillLogSeCd.VD +"] " + EnsErrCd.API_COMM_ERROR.getCodeNm() + " " + resEntity.getStatusCode().toString());
|
|
|
|
|
billHistoryService.updateBillHistory(billHistDTO);
|
|
|
|
|
throw new EnsException(EnsErrCd.API_COMM_ERROR, "["+ BillLogSeCd.VD +"] " + EnsErrCd.API_COMM_ERROR.getCodeNm() + " " + resEntity.getStatusCode().toString(), rsltStr);
|
|
|
|
|
}
|
|
|
|
|
private void handleApiError(NiceCiDTO.BillHistDTO billHistDTO, ResponseEntity<String> resEntity, String responseBody) {
|
|
|
|
|
String errorMessage = "[" + BillLogSeCd.VD + "] " + EnsErrCd.API_COMM_ERROR.getCodeNm() + " " + resEntity.getStatusCode().toString();
|
|
|
|
|
billHistDTO.setErrorCode(EnsErrCd.API_COMM_ERROR.getCode());
|
|
|
|
|
billHistDTO.setErrorMessage(errorMessage);
|
|
|
|
|
billHistoryService.updateBillHistory(billHistDTO);
|
|
|
|
|
throw new EnsException(EnsErrCd.API_COMM_ERROR, errorMessage, responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PayApiRespDTO<Map<String, Object>> parseApiResponse(String responseBody, NiceCiDTO.BillHistDTO billHistDTO) {
|
|
|
|
|
try {
|
|
|
|
|
return gson.fromJson(rsltStr, new TypeToken<PayApiRespDTO<Map<String, Object>>>() {}.getType());
|
|
|
|
|
return gson.fromJson(responseBody, new TypeToken<PayApiRespDTO<Map<String, Object>>>() {}.getType());
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
String errorMessage = "[" + BillLogSeCd.VD + "] " + EnsErrCd.INVALID_RESPONSE.getCodeNm();
|
|
|
|
|
billHistDTO.setErrorCode(EnsErrCd.INVALID_RESPONSE.getCode());
|
|
|
|
|
billHistDTO.setErrorMessage("["+ BillLogSeCd.VD +"] " + EnsErrCd.INVALID_RESPONSE.getCodeNm());
|
|
|
|
|
billHistDTO.setErrorMessage(errorMessage);
|
|
|
|
|
billHistoryService.updateBillHistory(billHistDTO);
|
|
|
|
|
throw new EnsException(EnsErrCd.INVALID_RESPONSE, "["+ BillLogSeCd.VD +"] " + EnsErrCd.INVALID_RESPONSE.getCodeNm(), ex);
|
|
|
|
|
throw new EnsException(EnsErrCd.INVALID_RESPONSE, errorMessage, ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|