Fix PHP 5.2 compatibility issues
This commit is contained in:
+51
-10
@@ -32,20 +32,61 @@ function write_toss_log($reason, $orderId = '', $status = '')
|
||||
}
|
||||
}
|
||||
|
||||
function g5_toss_http_response_code($code)
|
||||
{
|
||||
if (function_exists('http_response_code')) {
|
||||
http_response_code($code);
|
||||
return;
|
||||
}
|
||||
|
||||
$messages = array(
|
||||
200 => 'OK',
|
||||
400 => 'Bad Request',
|
||||
);
|
||||
$message = isset($messages[$code]) ? $messages[$code] : 'Status';
|
||||
header('HTTP/1.1 ' . $code . ' ' . $message);
|
||||
}
|
||||
|
||||
function g5_toss_json_last_error_msg()
|
||||
{
|
||||
if (function_exists('json_last_error_msg')) {
|
||||
return json_last_error_msg();
|
||||
}
|
||||
|
||||
if (!function_exists('json_last_error')) {
|
||||
return 'JSON error';
|
||||
}
|
||||
|
||||
switch (json_last_error()) {
|
||||
case JSON_ERROR_NONE:
|
||||
return 'No error';
|
||||
case JSON_ERROR_DEPTH:
|
||||
return 'Maximum stack depth exceeded';
|
||||
case JSON_ERROR_STATE_MISMATCH:
|
||||
return 'State mismatch';
|
||||
case JSON_ERROR_CTRL_CHAR:
|
||||
return 'Control character error';
|
||||
case JSON_ERROR_SYNTAX:
|
||||
return 'Syntax error';
|
||||
}
|
||||
|
||||
return 'Unknown error';
|
||||
}
|
||||
|
||||
// 입금통보 결과 데이터 읽기
|
||||
$raw = file_get_contents('php://input');
|
||||
if ($raw == false) {
|
||||
write_toss_log("입력 데이터 읽기 실패");
|
||||
http_response_code(400);
|
||||
g5_toss_http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
// json 파싱 체크
|
||||
$data = json_decode($raw, true);
|
||||
if (!is_array($data)) {
|
||||
$json_error = json_last_error_msg();
|
||||
$json_error = g5_toss_json_last_error_msg();
|
||||
write_toss_log("데이터 파싱 실패: " . $json_error);
|
||||
http_response_code(400);
|
||||
g5_toss_http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -59,7 +100,7 @@ $TOSS_TRANSACTIONKEY = sql_real_escape_string(isset($data["transactionKey"]) ? $
|
||||
// orderId 형식 검증 (영문, 숫자, 하이픈, 언더스코어만 허용)
|
||||
if ($TOSS_ORDERID && !preg_match('/^[a-zA-Z0-9_-]+$/', $TOSS_ORDERID)) {
|
||||
write_toss_log("잘못된 orderId 형식", $TOSS_ORDERID, $TOSS_STATUS);
|
||||
http_response_code(400);
|
||||
g5_toss_http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -78,7 +119,7 @@ if (!$orderResult || $order_info['secret'] !== $TOSS_SECRET) {
|
||||
$error_msg = isset($order_info['message']) ? $order_info['message'] : '주문 정보 조회 실패';
|
||||
$error_code = isset($order_info['code']) ? $order_info['code'] : 'UNKNOWN_ERROR';
|
||||
write_toss_log("주문 정보 조회 실패 - {$error_code} : {$error_msg}", $TOSS_ORDERID, $TOSS_STATUS);
|
||||
http_response_code(400);
|
||||
g5_toss_http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -150,7 +191,7 @@ if($TOSS_STATUS == "DONE"){
|
||||
$row = sql_fetch($sql);
|
||||
if(!$row['od_id']) {
|
||||
write_toss_log("주문내역 조회 실패", $TOSS_ORDERID, $TOSS_STATUS);
|
||||
http_response_code(400);
|
||||
g5_toss_http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -244,7 +285,7 @@ elseif($TOSS_STATUS == "WAITING_FOR_DEPOSIT")
|
||||
$row = sql_fetch($sql);
|
||||
if(empty($row['od_id'])) {
|
||||
write_toss_log("주문 데이터가 존재하지 않음", $TOSS_ORDERID, $TOSS_STATUS);
|
||||
http_response_code(400);
|
||||
g5_toss_http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -415,15 +456,15 @@ if($payLog) {
|
||||
|
||||
if ($result)
|
||||
{
|
||||
http_response_code(200); // 절대로 지우지마세요
|
||||
g5_toss_http_response_code(200); // 절대로 지우지마세요
|
||||
echo "OK";
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
http_response_code(400);
|
||||
g5_toss_http_response_code(400);
|
||||
echo "FAIL";
|
||||
exit;
|
||||
}
|
||||
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
|
||||
@@ -61,17 +61,17 @@ $amount = $order_price;
|
||||
$type = ($_POST['tr_code'] == '0') ? '소득공제' : '지출증빙';
|
||||
$customerIdentityNumber = $_POST['id_info'];
|
||||
$orderName = $od_name;
|
||||
$customerEmail = $_POST['buyeremail'] ?: $od_email;
|
||||
$customerMobilePhone = $_POST['buyertel'] ?: $od_tel;
|
||||
$customerEmail = !empty($_POST['buyeremail']) ? $_POST['buyeremail'] : $od_email;
|
||||
$customerMobilePhone = !empty($_POST['buyertel']) ? $_POST['buyertel'] : $od_tel;
|
||||
|
||||
// 토스페이먼츠 현금영수증 발급 API 호출
|
||||
$toss->setCashReceiptsData([
|
||||
$toss->setCashReceiptsData(array(
|
||||
'orderId' => $orderId,
|
||||
'amount' => $amount,
|
||||
'type' => $type,
|
||||
'customerIdentityNumber' => $customerIdentityNumber,
|
||||
'orderName' => $goods_name,
|
||||
]);
|
||||
));
|
||||
$toss_result = $toss->issueCashReceipt();
|
||||
|
||||
/*
|
||||
@@ -199,4 +199,4 @@ function showreceipt() // 현금 영수증 출력
|
||||
</div>
|
||||
|
||||
<?php
|
||||
include_once(G5_PATH.'/tail.sub.php');
|
||||
include_once(G5_PATH.'/tail.sub.php');
|
||||
|
||||
@@ -14,11 +14,11 @@ $orderId = isset($_REQUEST['orderId']) ? $_REQUEST['orderId'] : '';
|
||||
$amount = isset($_REQUEST['amount']) ? $_REQUEST['amount'] : '';
|
||||
$paymentKey = isset($_REQUEST['paymentKey']) ? $_REQUEST['paymentKey'] : '';
|
||||
|
||||
$toss->setPaymentData([
|
||||
$toss->setPaymentData(array(
|
||||
'orderId' => $orderId,
|
||||
'amount' => $amount,
|
||||
'paymentKey' => $paymentKey,
|
||||
]);
|
||||
));
|
||||
|
||||
// 장바구니 ID 설정 (바로구매 여부 확인)
|
||||
$ss_cart_id = get_session('ss_direct') ? get_session('ss_cart_direct') : get_session('ss_cart_id');
|
||||
@@ -48,7 +48,7 @@ $sql = "
|
||||
LIMIT 1
|
||||
";
|
||||
$res = sql_fetch($sql);
|
||||
$dt_data = [];
|
||||
$dt_data = array();
|
||||
if (isset($res['dt_data'])) {
|
||||
$dt_data = unserialize(base64_decode($res['dt_data']));
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ $toss = new TossPayments(
|
||||
);
|
||||
|
||||
// 결제데이터 셋팅
|
||||
$toss->setPaymentData([
|
||||
$toss->setPaymentData(array(
|
||||
'amount' => $amount,
|
||||
'orderId' => $orderId,
|
||||
'paymentKey' => $paymentKey
|
||||
]);
|
||||
));
|
||||
$toss->setPaymentHeader();
|
||||
|
||||
// 결제승인 요청
|
||||
@@ -105,4 +105,4 @@ if ($result) {
|
||||
}
|
||||
} else {
|
||||
alert($toss->responseData['message'].' 코드 : '.$toss->responseData['code'], G5_SHOP_URL);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user