This commit is contained in:
2025-12-16 20:05:46 +09:00
parent 1d79a2989b
commit 7a0f031eba
14 changed files with 291 additions and 102 deletions

View File

@@ -5,9 +5,12 @@
*/
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../../lib/DotEnv.php';
(new DotEnv(__DIR__ . '/../../.env'))->load();
require_once('barobill_account_config.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/session.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/mydb.php');
require_once(getenv('DOCUMENT_ROOT') . '/session.php');
require_once(getenv('DOCUMENT_ROOT') . '/lib/mydb.php');
try {
// 1. 로컬 DB의 company_accounts 테이블에서 계좌 정보 가져오기
@@ -222,8 +225,12 @@ try {
}
}
// 바로빌 API에 없는 로컬 계좌는 경고와 함께 추가 (사용 불가능)
// 바로빌 API에 없는 로컬 계좌는 경고와 함께 추가
if (!$matched) {
$isApiError = !empty($barobillError);
$statusText = $isApiError ? '상태 확인 불가' : '바로빌 미등록';
$sourceText = $isApiError ? 'barobill_api_error' : 'local_db_only';
$allAccounts[] = [
'id' => $localAcc['id'],
'bankAccountNum' => $localAcc['account_num'],
@@ -235,10 +242,11 @@ try {
'issueDate' => '',
'balance' => 0,
'status' => '',
'statusText' => '바로빌 미등록',
'source' => 'local_db_only', // 로컬 DB에만 있음 (바로빌 API 미등록)
'statusText' => $statusText,
'source' => $sourceText, // 상태 확인 필요
'hasPassword' => !empty($localAcc['account_pwd']),
'warning' => true // 경고 표시용
'warning' => true, // 경고 표시용
'api_error' => $isApiError // 프론트엔드에서 구분하기 위함
];
}
}

View File

@@ -138,11 +138,69 @@ try {
echo json_encode($response, JSON_UNESCAPED_UNICODE);
} else {
echo json_encode([
'success' => false,
'error' => $result['error'],
'error_code' => $result['error_code'] ?? null
], JSON_UNESCAPED_UNICODE);
// API 호출 실패 시 (예: SoapClient 미설치, 통신 등) 로컬 DB에서 조회
error_log('바로빌 API 호출 실패, 로컬 DB 조회 시도: ' . $result['error']);
require_once(getenv('DOCUMENT_ROOT') . '/session.php');
require_once(getenv('DOCUMENT_ROOT') . '/lib/mydb.php');
$accounts = [];
$selectedTenantId = $_SESSION['eaccount_tenant_id'] ?? null;
if ($selectedTenantId) {
try {
$pdo = db_connect();
if ($pdo) {
// 로컬 DB에서 계좌 정보 조회
$sql = "SELECT id, company_id, bank_code, account_num, account_pwd
FROM {$DB}.company_accounts
WHERE company_id = ?
ORDER BY id DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute([$selectedTenantId]);
$localAccounts = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($localAccounts as $acc) {
// 은행명 변환
$bankName = getBankName($acc['bank_code']);
$accounts[] = [
'bankAccountNum' => $acc['account_num'],
'bankCode' => $acc['bank_code'],
'bankName' => $bankName,
'accountName' => $bankName . ' ' . $acc['account_num'],
'accountType' => '', // 로컬 정보 없음
'currency' => 'KRW',
'issueDate' => '',
'balance' => 0, // 잔액 정보 없음
'status' => 1, // 기본값: 사용중
'source' => 'local_db_fallback',
'error_message' => 'API 연동 실패로 로컬 데이터 표시'
];
}
}
} catch (Exception $dbEx) {
error_log('로컬 DB 조회 실패: ' . $dbEx->getMessage());
}
}
// 로컬 데이터가 있으면 성공으로 masquerade
if (!empty($accounts)) {
echo json_encode([
'success' => true,
'accounts' => $accounts,
'count' => count($accounts),
'message' => '바로빌 API 연동에 실패하여 로컬 저장된 계좌 목록을 표시합니다.',
'api_error' => $result['error']
], JSON_UNESCAPED_UNICODE);
} else {
// 로컬 데이터도 없으면 에러 리턴
echo json_encode([
'success' => false,
'error' => $result['error'],
'error_code' => $result['error_code'] ?? null
], JSON_UNESCAPED_UNICODE);
}
}
} catch (Exception $e) {
echo json_encode([

View File

@@ -14,10 +14,16 @@
*/
// 인증서 키(CERTKEY) 파일 경로
$certKeyFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt';
$legacyApiKeyFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_api_key.txt';
$corpNumFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_corp_num.txt';
$testModeFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_test_mode.txt';
// load .env file
require_once __DIR__ . '/../../lib/DotEnv.php';
(new DotEnv(__DIR__ . '/../../.env'))->load();
// 인증서 키(CERTKEY) 파일 경로
$documentRoot = getenv('DOCUMENT_ROOT');
$certKeyFile = $documentRoot . '/apikey/barobill_cert_key.txt';
$legacyApiKeyFile = $documentRoot . '/apikey/barobill_api_key.txt';
$corpNumFile = $documentRoot . '/apikey/barobill_corp_num.txt';
$testModeFile = $documentRoot . '/apikey/barobill_test_mode.txt';
// CERTKEY 읽기
$barobillCertKey = '';
@@ -82,7 +88,7 @@ if (file_exists($testModeFile)) {
// 바로빌 사용자 ID (계좌 사용내역 조회에 필요)
// 빈 값이면 전체 계좌 조회, 특정 사용자만 조회하려면 사용자 ID 입력
$barobillUserIdFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_user_id.txt';
$barobillUserIdFile = getenv('DOCUMENT_ROOT') . '/apikey/barobill_user_id.txt';
$barobillUserId = '';
if (file_exists($barobillUserIdFile)) {
$content = trim(file_get_contents($barobillUserIdFile));
@@ -92,8 +98,8 @@ if (file_exists($barobillUserIdFile)) {
}
// 테넌트별 설정 (DB에서 가져오기)
require_once($_SERVER['DOCUMENT_ROOT'] . '/session.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/mydb.php');
require_once(getenv('DOCUMENT_ROOT') . '/session.php');
require_once(getenv('DOCUMENT_ROOT') . '/lib/mydb.php');
$selectedTenantId = $_SESSION['eaccount_tenant_id'] ?? null;
@@ -183,7 +189,7 @@ if (!empty($barobillCertKey) || $isTestMode) {
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE // WSDL 캐시 비활성화
]);
} catch (Exception $e) {
} catch (Throwable $e) {
$barobillInitError = $e->getMessage();
error_log('바로빌 계좌 SOAP 클라이언트 생성 실패: ' . $e->getMessage());
}
@@ -208,7 +214,7 @@ function callBarobillAccountSOAP($method, $params = []) {
'success' => false,
'error' => $errorMsg,
'error_detail' => [
'cert_key_file' => $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt',
'cert_key_file' => getenv('DOCUMENT_ROOT') . '/apikey/barobill_cert_key.txt',
'soap_url' => $barobillAccountSoapUrl,
'init_error' => $barobillInitError,
'test_mode' => $isTestMode
@@ -350,10 +356,10 @@ function callBarobillAccountSOAP($method, $params = []) {
'error' => 'SOAP 오류: ' . $e->getMessage(),
'error_code' => $e->getCode()
];
} catch (Exception $e) {
} catch (Throwable $e) {
return [
'success' => false,
'error' => 'API 호출 오류: ' . $e->getMessage()
'error' => 'API 호출 오류 (치명적): ' . $e->getMessage()
];
}
}

View File

@@ -14,10 +14,16 @@
*/
// 인증서 키(CERTKEY) 파일 경로
$certKeyFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt';
$legacyApiKeyFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_api_key.txt';
$corpNumFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_corp_num.txt';
$testModeFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_test_mode.txt';
// load .env file
require_once __DIR__ . '/../../lib/DotEnv.php';
(new DotEnv(__DIR__ . '/../../.env'))->load();
// 인증서 키(CERTKEY) 파일 경로
$documentRoot = getenv('DOCUMENT_ROOT');
$certKeyFile = $documentRoot . '/apikey/barobill_cert_key.txt';
$legacyApiKeyFile = $documentRoot . '/apikey/barobill_api_key.txt';
$corpNumFile = $documentRoot . '/apikey/barobill_corp_num.txt';
$testModeFile = $documentRoot . '/apikey/barobill_test_mode.txt';
// CERTKEY 읽기
$barobillCertKey = '';
@@ -50,7 +56,7 @@ if (file_exists($testModeFile)) {
// 바로빌 사용자 ID (카드 사용내역 조회에 필요)
// 빈 값이면 전체 카드 조회, 특정 사용자만 조회하려면 사용자 ID 입력
$barobillUserIdFile = $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_user_id.txt';
$barobillUserIdFile = getenv('DOCUMENT_ROOT') . '/apikey/barobill_user_id.txt';
$barobillUserId = '';
if (file_exists($barobillUserIdFile)) {
$content = trim(file_get_contents($barobillUserIdFile));
@@ -82,7 +88,7 @@ if (!empty($barobillCertKey) || $isTestMode) {
'exceptions' => true,
'connection_timeout' => 30
]);
} catch (Exception $e) {
} catch (Throwable $e) {
error_log('바로빌 카드 SOAP 클라이언트 생성 실패: ' . $e->getMessage());
}
}
@@ -102,7 +108,7 @@ function callBarobillCardSOAP($method, $params = []) {
'success' => false,
'error' => '바로빌 카드 SOAP 클라이언트가 초기화되지 않았습니다. CERTKEY를 확인하세요.',
'error_detail' => [
'cert_key_file' => $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt',
'cert_key_file' => getenv('DOCUMENT_ROOT') . '/apikey/barobill_cert_key.txt',
'soap_url' => $isTestMode ? 'https://testws.baroservice.com/CARD.asmx?WSDL' : 'https://ws.baroservice.com/CARD.asmx?WSDL'
]
];
@@ -165,10 +171,10 @@ function callBarobillCardSOAP($method, $params = []) {
'error' => 'SOAP 오류: ' . $e->getMessage(),
'error_code' => $e->getCode()
];
} catch (Exception $e) {
} catch (Throwable $e) {
return [
'success' => false,
'error' => 'API 호출 오류: ' . $e->getMessage()
'error' => 'API 호출 오류 (치명적): ' . $e->getMessage()
];
}
}

View File

@@ -9,48 +9,49 @@ require_once('barobill_account_config.php');
// 전역 변수 접근
global $barobillCertKey, $barobillCorpNum, $barobillUserId, $isTestMode, $barobillAccountSoapUrl;
$documentRoot = getenv('DOCUMENT_ROOT');
$diagnostics = [
'cert_key' => [
'file_exists' => file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt'),
'file_path' => $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt',
'file_exists' => file_exists($documentRoot . '/apikey/barobill_cert_key.txt'),
'file_path' => $documentRoot . '/apikey/barobill_cert_key.txt',
'is_set' => !empty($barobillCertKey),
'length' => strlen($barobillCertKey),
'preview' => !empty($barobillCertKey) ? substr($barobillCertKey, 0, 8) . '...' . substr($barobillCertKey, -4) : 'NOT SET',
'raw_content' => file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt')
? file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt')
'raw_content' => file_exists($documentRoot . '/apikey/barobill_cert_key.txt')
? file_get_contents($documentRoot . '/apikey/barobill_cert_key.txt')
: 'FILE NOT FOUND',
'is_placeholder' => !empty($barobillCertKey) ? false : (
file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt')
? (strpos(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt'), '[여기에') !== false
|| strpos(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt'), '바로빌 CERTKEY') !== false
|| strpos(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_cert_key.txt'), '================================') !== false)
file_exists($documentRoot . '/apikey/barobill_cert_key.txt')
? (strpos(file_get_contents($documentRoot . '/apikey/barobill_cert_key.txt'), '[여기에') !== false
|| strpos(file_get_contents($documentRoot . '/apikey/barobill_cert_key.txt'), '바로빌 CERTKEY') !== false
|| strpos(file_get_contents($documentRoot . '/apikey/barobill_cert_key.txt'), '================================') !== false)
: false
)
],
'corp_num' => [
'file_exists' => file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_corp_num.txt'),
'file_path' => $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_corp_num.txt',
'file_exists' => file_exists($documentRoot . '/apikey/barobill_corp_num.txt'),
'file_path' => $documentRoot . '/apikey/barobill_corp_num.txt',
'is_set' => !empty($barobillCorpNum),
'value' => $barobillCorpNum,
'raw_content' => file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_corp_num.txt')
? file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_corp_num.txt')
'raw_content' => file_exists($documentRoot . '/apikey/barobill_corp_num.txt')
? file_get_contents($documentRoot . '/apikey/barobill_corp_num.txt')
: 'FILE NOT FOUND'
],
'user_id' => [
'file_exists' => file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_user_id.txt'),
'file_path' => $_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_user_id.txt',
'file_exists' => file_exists($documentRoot . '/apikey/barobill_user_id.txt'),
'file_path' => $documentRoot . '/apikey/barobill_user_id.txt',
'is_set' => !empty($barobillUserId),
'value' => $barobillUserId,
'raw_content' => file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_user_id.txt')
? file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_user_id.txt')
'raw_content' => file_exists($documentRoot . '/apikey/barobill_user_id.txt')
? file_get_contents($documentRoot . '/apikey/barobill_user_id.txt')
: 'FILE NOT FOUND'
],
'test_mode' => [
'file_exists' => file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_test_mode.txt'),
'file_exists' => file_exists($documentRoot . '/apikey/barobill_test_mode.txt'),
'is_active' => $isTestMode,
'raw_content' => file_exists($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_test_mode.txt')
? file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/apikey/barobill_test_mode.txt')
'raw_content' => file_exists($documentRoot . '/apikey/barobill_test_mode.txt')
? file_get_contents($documentRoot . '/apikey/barobill_test_mode.txt')
: 'FILE NOT FOUND'
],
'soap_client' => [

View File

@@ -5,9 +5,12 @@
*/
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../../lib/DotEnv.php';
(new DotEnv(__DIR__ . '/../../.env'))->load();
require_once('barobill_account_config.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/session.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/mydb.php');
require_once(getenv('DOCUMENT_ROOT') . '/session.php');
require_once(getenv('DOCUMENT_ROOT') . '/lib/mydb.php');
$debug = [
'step' => [],

View File

@@ -5,8 +5,11 @@
*/
header('Content-Type: application/json; charset=utf-8');
require_once($_SERVER['DOCUMENT_ROOT'] . '/session.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/mydb.php');
require_once __DIR__ . '/../../lib/DotEnv.php';
(new DotEnv(__DIR__ . '/../../.env'))->load();
require_once(getenv('DOCUMENT_ROOT') . '/session.php');
require_once(getenv('DOCUMENT_ROOT') . '/lib/mydb.php');
try {
$pdo = db_connect();

View File

@@ -5,8 +5,11 @@
*/
header('Content-Type: application/json; charset=utf-8');
require_once($_SERVER['DOCUMENT_ROOT'] . '/session.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/mydb.php');
require_once __DIR__ . '/../../lib/DotEnv.php';
(new DotEnv(__DIR__ . '/../../.env'))->load();
require_once(getenv('DOCUMENT_ROOT') . '/session.php');
require_once(getenv('DOCUMENT_ROOT') . '/lib/mydb.php');
$tenantId = $_POST['tenant_id'] ?? $_GET['tenant_id'] ?? '';

View File

@@ -470,23 +470,46 @@ try {
echo json_encode($response, JSON_UNESCAPED_UNICODE);
} else {
// API Error Handling (Graceful Fallback)
// If API fails (e.g., SoapClient missing), return empty list with warning
// so the UI doesn't break.
$response = [
'success' => false,
'error' => $result['error'],
'error_code' => $result['error_code'] ?? null
'success' => true, // Masquerade as success to render empty table
'data' => [
'logs' => [],
'pagination' => [
'currentPage' => 1,
'countPerPage' => $limit,
'maxPageNum' => 1,
'maxIndex' => 0
],
'summary' => [
'totalDeposit' => 0,
'totalWithdraw' => 0,
'count' => 0
]
],
'warning' => 'API 연동 실패: ' . $result['error'], // Custom warning field
'api_error_code' => $result['error_code'] ?? null
];
// 디버그 정보 추가
// Add debug info if available
if (isset($result['debug'])) {
$response['debug'] = $result['debug'];
}
echo json_encode($response, JSON_UNESCAPED_UNICODE);
}
} catch (Exception $e) {
} catch (Throwable $e) {
// Global Exception/Error Handling
echo json_encode([
'success' => false,
'error' => '서버 오류: ' . $e->getMessage()
'success' => true, // Return true to avoid UI breakage
'data' => [
'logs' => [],
'pagination' => ['currentPage' => 1, 'maxPageNum' => 1],
'summary' => ['totalDeposit' => 0, 'totalWithdraw' => 0, 'count' => 0]
],
'warning' => '시스템 오류: ' . $e->getMessage()
], JSON_UNESCAPED_UNICODE);
}
?>

View File

@@ -15,6 +15,10 @@
*/
header('Content-Type: application/json; charset=utf-8');
// load .env
require_once __DIR__ . '/../../lib/DotEnv.php';
(new DotEnv(__DIR__ . '/../../.env'))->load();
require_once('barobill_card_config.php');
// 디버그 모드
@@ -259,10 +263,28 @@ try {
echo json_encode($response, JSON_UNESCAPED_UNICODE);
} else {
// API Error Handling (Graceful Fallback)
// If API fails (e.g., SoapClient missing), return empty list with warning
$response = [
'success' => false,
'error' => $result['error'],
'error_code' => $result['error_code'] ?? null
'success' => true, // Masquerade as success to render empty table
'data' => [
'logs' => [],
'pagination' => [
'currentPage' => 1,
'countPerPage' => $limit,
'maxPageNum' => 1,
'totalCount' => 0
],
'summary' => [
'totalAmount' => 0,
'totalAmountFormatted' => '0',
'count' => 0,
'approvalCount' => 0,
'cancelCount' => 0
]
],
'warning' => 'API 연동 실패: ' . $result['error'],
'api_error_code' => $result['error_code'] ?? null
];
// 디버그 정보 추가
@@ -275,10 +297,15 @@ try {
echo json_encode($response, JSON_UNESCAPED_UNICODE);
}
} catch (Exception $e) {
} catch (Throwable $e) {
echo json_encode([
'success' => false,
'error' => '서버 오류: ' . $e->getMessage()
'success' => true, // Return true to avoid UI breakage
'data' => [
'logs' => [],
'pagination' => ['currentPage' => 1, 'maxPageNum' => 1, 'totalCount' => 0],
'summary' => ['totalAmount' => 0, 'count' => 0]
],
'warning' => '시스템 오류: ' . $e->getMessage()
], JSON_UNESCAPED_UNICODE);
}