Commit abcdb482 authored by Antonio.Suerte's avatar Antonio.Suerte

Payment API Callback Sender Issue Fix [Multiple CB Prevention]

parent fc1c2eb3
......@@ -126,12 +126,68 @@ class LogicSettlement extends SettlementModelClass {
}
}
/*-------------------------------------------------------------------------
* @function_name: データは商人へ送信する処理
* @parameter : なし
* @return : なし
-------------------------------------------------------------------------*/
private function sendCallbackToIntegrator($callBack, $data){
//log directory
$apiPath = dirname(SYSTEM_PATH).DIRECTORY_SEPARATOR.'api';
$responseUrl = $apiPath.DIRECTORY_SEPARATOR.'Logs'.DIRECTORY_SEPARATOR.'settlement'.DIRECTORY_SEPARATOR.'settlement_response_data';
if(!file_exists($responseUrl)){
mkdir($responseUrl, 0777, true);
}
// callback sender to merchant and response logger
$context = curl_init();
curl_setopt_array($context, [
CURLOPT_URL => $callBack,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true,
CURLOPT_ENCODING => "utf8",
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded",
"Content-length: ".strlen($data)
]
]);
if($err = curl_error($context)){
$cboutput = $err;
}else {
$cboutput = curl_exec($context);
$headerSize = curl_getinfo($context, CURLINFO_HEADER_SIZE);
$responseHeaders = substr($cboutput, 0, $headerSize);
$responseBody = substr($cboutput, $headerSize);
$cboutput = "[Headers]\n\n{$responseHeaders}[Body]\n\n{$responseBody}";
}
//logging response data
$logFileName = $responseUrl.DIRECTORY_SEPARATOR.'Log_H'.date("Y-m-d").'.log';
error_log("\r\n[".date("Y-m-d H:i:s")."][{$this -> getProgramCode()}]\r\n\nReturn URL:\r\n\n{$callBack}\r\n\nContext: {$data}\r\n\nResponse:\r\n\n{$cboutput}\r\n",
VAL_INT_3,
$logFileName);
chmod($logFileName, 511);
// end of logging response data
}
/*-------------------------------------------------------------------------
* @function_name: データの登録
* @parameter : なし
* @return : なし
-------------------------------------------------------------------------*/
private function forward($result) {
header("Content-type: text/plain");
// 変数宣言部
$url = NO_STRING;
$data = null;
......@@ -145,53 +201,6 @@ class LogicSettlement extends SettlementModelClass {
$data = $this -> getForwardParams($result);
$jsonData = json_encode($data);
$data = http_build_query($data, '', '&');
//log directory
$apiPath = dirname(SYSTEM_PATH).DIRECTORY_SEPARATOR.'api';
$responseUrl = $apiPath.DIRECTORY_SEPARATOR.'Logs'.DIRECTORY_SEPARATOR.'settlement'.DIRECTORY_SEPARATOR.'settlement_response_data';
if(!file_exists($responseUrl)){
mkdir($responseUrl, 0777, true);
}
// callback sender to merchant and response logger
$context = curl_init();
curl_setopt_array($context, [
CURLOPT_URL => $callBack,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true,
CURLOPT_ENCODING => "utf8",
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded",
"Content-length: ".strlen($data)
]
]);
if($err = curl_error($context)){
$cboutput = $err;
}else {
$cboutput = curl_exec($context);
$headerSize = curl_getinfo($context, CURLINFO_HEADER_SIZE);
$responseHeaders = substr($cboutput, 0, $headerSize);
$responseBody = substr($cboutput, $headerSize);
$cboutput = "[Headers]\n\n{$responseHeaders}[Body]\n\n{$responseBody}";
}
//logging response data
$logFileName = $responseUrl.DIRECTORY_SEPARATOR.'Log_H'.date("Y-m-d").'.log';
error_log("\r\n[".date("Y-m-d H:i:s")."][{$this -> getProgramCode()}]\r\n\nReturn URL:\r\n\n{$callBack}\r\n\nContext: {$data}\r\n\nResponse:\r\n\n{$cboutput}\r\n",
VAL_INT_3,
$logFileName);
chmod($logFileName, 511);
// end of logging response data
if(isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
......@@ -203,26 +212,33 @@ class LogicSettlement extends SettlementModelClass {
if(strlen($referer) > VAL_INT_256)
$referer = preg_replace("/\\?.*/", "", $referer);
}
// 転送をする
if($url != NO_STRING && $result == NO_COUNT) { // 正常終了
if($result == NO_COUNT) { // 正常終了
$this -> sendCallbackToIntegrator($callBack, $data);
// this insert command also comtains data that will passed to merchant's system.
$this -> accessModifyCommon('INSERT_LOG_POST', array(
$ip,
$this -> getProgramCode(),
$referer,
"[CALLBACK_SUCCESSFUL]{$jsonData}"));
header('Location: ' . $url);
if($url != NO_STRING)
header("Location: {$url}");
else
echo "Successfully transferred!";
} else { // 異常
$this -> accessModifyCommon('INSERT_LOG_POST', array(
$ip,
$this -> getProgramCode(),
$referer,
"[CALLBACK_ERROR]{$jsonData}"));
if($failUrl != NO_STRING) {
header('Location: ' . $failUrl);
}
if($failUrl != NO_STRING)
header("Location: {$failUrl}");
else
echo "The settlement failed to proceed!";
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment