파트너코드 조회
This commit is contained in:
@@ -1,36 +1,84 @@
|
||||
package com.eactive.ext.kjb.obp;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.eactive.ext.kjb.common.KjbObpException;
|
||||
import com.eactive.ext.kjb.common.KjbProperty;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public class KjbObpModule {
|
||||
private static final String FAKE_PARTNER_CODE = "999999-99";
|
||||
|
||||
private static KjbObpModule _instance;
|
||||
|
||||
private final KjbProperty property;
|
||||
private final ObpClient client;
|
||||
|
||||
public static synchronized KjbObpModule getInstance(KjbProperty kjbProperty) {
|
||||
if (_instance == null) {
|
||||
_instance = new KjbObpModule(kjbProperty);
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
private KjbObpModule(KjbProperty kjbProperty) {
|
||||
if (kjbProperty == null) {
|
||||
throw new IllegalArgumentException("KjbProperty cannot be null");
|
||||
}
|
||||
this.property = kjbProperty;
|
||||
this.client = ObpClient.getInstance(kjbProperty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim, 숫자이외 자동 치환
|
||||
* @param bizNo
|
||||
* @return
|
||||
* 사업자등록번호로 partnerCode 조회
|
||||
* @param bizNo 사업자등록번호 (숫자 외 문자 자동 제거)
|
||||
* @return partnerCode
|
||||
* @throws KjbObpException 조회 실패 시
|
||||
*/
|
||||
public static JsonObject queryOrganization(String bizNo) {
|
||||
public String queryPartnerCode(String bizNo) throws KjbObpException {
|
||||
bizNo = ObpUtil.onlyDigit(bizNo);
|
||||
|
||||
if (StringUtils.isEmpty(bizNo)) {
|
||||
throw new IllegalArgumentException("BizNo is not empty.");
|
||||
throw new IllegalArgumentException("BizNo is empty.");
|
||||
}
|
||||
|
||||
if (bizNo.length() != 10) {
|
||||
throw new IllegalArgumentException("BizNo is not valid.");
|
||||
throw new IllegalArgumentException("BizNo must be 10 digits. (input: " + bizNo + ")");
|
||||
}
|
||||
|
||||
return null;
|
||||
// 가상모드: URL 미설정 시 가상 파트너코드 반환
|
||||
if (!client.isRealMode()) {
|
||||
log.info("[OBP] 가상모드 - 가상 partnerCode 반환: {}", FAKE_PARTNER_CODE);
|
||||
return FAKE_PARTNER_CODE;
|
||||
}
|
||||
|
||||
String path = String.format(property.getObpUrlOrganizationFmt(), bizNo);
|
||||
log.debug("[OBP] queryPartnerCode - bizNo: {}, path: {}", bizNo, path);
|
||||
|
||||
ObpResponse response = client.get(path);
|
||||
|
||||
if (response.getStatus() != 200) {
|
||||
log.warn("[OBP] queryPartnerCode failed - status: {}, body: {}", response.getStatus(), response.getBody());
|
||||
throw new KjbObpException(response.getStatus(), "OBP 조회 실패: " + response.getBody());
|
||||
}
|
||||
|
||||
ObpOrganization org = ObpOrganization.fromResponse(response);
|
||||
|
||||
if (org == null) {
|
||||
throw new KjbObpException("OBP 응답 파싱 실패");
|
||||
}
|
||||
|
||||
if (!org.hasPartnerCode()) {
|
||||
throw new KjbObpException("partnerCode가 없습니다. bizNo: " + bizNo);
|
||||
}
|
||||
|
||||
return org.getPartnerCode();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
log.info("queryOrganization Test");
|
||||
queryOrganization("123asd123asd123");
|
||||
/**
|
||||
* ObpClient 반환 (직접 API 호출용)
|
||||
*/
|
||||
public ObpClient getClient() {
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user