이니시스 결제의 취소/부분취소, 현금영수증 발행 등을 사용하기 위한 API 입니다.
해당 서비스는 OPEN API형태로 구성되어 있습니다. 제공된 샘플은 API 구동을 위한 최소한의 샘플링이오니 참고부탁드립니다.
* 참고) 1. INIAPI 응답파라미터는 추후 요건에 의해 추가될 수 있습니다. 2. 실패 응답시 일부 파라미터 응답이 null 일 수 있습니다.
<?php
header("Content-Type: text/html; charset=utf-8");
//step1. 요청을 위한 파라미터 설정
$key = "ItEQKi3rY7uvDS8l"; // INIpayTest 의 INIAPI key
$type = "Refund";
$paymethod = "Card";
$timestamp = date("YmdHis");
$clientIp = "192.0.0.1";
$mid = "INIpayTest";
$tid = "StdpayCARDINIpayTest20210101111111111111"; // 40byte 승인 TID 입력
$msg = "거래취소요청";
$hashData = hash("sha512",$key.$type.$paymethod.$timestamp.$clientIp.$mid.$tid); // hash 암호화
//step2. key=value 로 post 요청
$data = array(
'type' => $type,
'paymethod' => $paymethod,
'timestamp' => $timestamp,
'clientIp' => $clientIp,
'mid' => $mid,
'tid' => $tid,
'msg' => $msg,
'hashData' => $hashData
);
$url ="https://iniapi.inicis.com/api/v1/refund"; // 전송 URL
$ch = curl_init(); //curl 초기화
curl_setopt($ch, CURLOPT_URL, $url); // 전송 URL 지정하기
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //요청 결과를 문자열로 반환
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //connection timeout 10초
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //POST data
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=utf-8')); // 전송헤더 설정
curl_setopt($ch, CURLOPT_POST, 1); // post 전송
$response = curl_exec($ch);
curl_close($ch);
//step3. 요청 결과
echo $response;
?>
//*JSP 경우 아래 통신, Hash 에 필요한 암호화 lib 는 별도 제공하지 않습니다. 관련 사이트 참고및 직접 구현 부탁드립니다.
<%@page import="java.util.RequestMap"%>
<%@page import="TestPage.HttpConnectionUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="TestPage.SHA_512_Util"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%
Date date_now = new Date(System.currentTimeMillis()); // 현재시간을 가져와 Date형으로 저장한다//년월일시분초 14자리 포멧
SimpleDateFormat fourteen_format = new SimpleDateFormat("yyyyMMddHHmmss");
//step1. 요청을 위한 파라미터 설정
String Key="ItEQKi3rY7uvDS8l"; // INIpayTest 의 INIAPI key
String type="Refund";
String paymethod="Card";
String timestamp=fourteen_format.format(date_now);
String clientIp="192.0.0.1";
String mid="INIpayTest";
String tid="StdpayCARDINIpayTest20210101111111111111"; // 40byte 승인 TID 입력
String msg="거래취소요청";
//Hash 암호화
String data_hash=key+type+paymethod+timestamp+clientIp+mid+tid;
SHA_512_Util SHA_512=new SHA_512_Util();
String hashData = SHA_512.getSHA_512(data_hash); // SHA_512_Util 을 이용하여 hash암호화(해당 LIB는 직접구현 필요)
// 전송 URL
String APIURL="https://iniapi.inicis.com/api/v1/refund"; // 전송 URL
RequestMap<String, String> CashReceiptsMap = new RequestMap<String, String>();
CashReceiptsMap.put("type" ,type);
CashReceiptsMap.put("paymethod" ,paymethod);
CashReceiptsMap.put("timestamp" ,timestamp);
CashReceiptsMap.put("clientIp" ,clientIp);
CashReceiptsMap.put("mid" ,mid);
CashReceiptsMap.put("tid" ,tid);
CashReceiptsMap.put("msg" ,msg);
CashReceiptsMap.put("hashData" ,hashData);
//step2. key=value 로 post 요청
HttpConnectionUtil httpUtil=new HttpConnectionUtil();
try{
String authResultString = "";
authResultString = httpUtil.postRequest(APIURL , CashReceiptsMap);
System.out.println(authResultString);
//step3. 요청 결과
out.println("<h1>"+authResultString+"</h2>");
}catch (Exception ex) {
System.out.println(ex);
}
%>
import datetime
import hashlib
import requests
now = datetime.datetime.now()
timestamp = now.strftime("%Y%m%d%H%M%S")
key = 'ItEQKi3rY7uvDS8l'
type = 'Refund'
paymethod = 'Card'
clientIp = '192.0.0.1'
mid = 'INIpayTest'
tid = 'StdpayCARDINIpayTest20210101111111111111'
msg = '거래취소요청'
plaintext = key + type + paymethod + timestamp + clientIp + mid + tid
hashData = hashlib.sha512(str(plaintext).encode("utf-8")).hexdigest()
datas = {
'type': type,
'paymethod': paymethod,
'timestamp': timestamp,
'clientIp': clientIp,
'mid': mid,
'tid': tid,
'msg': msg,
'hashData': hashData
}
url = "https://iniapi.inicis.com/api/v1/refund"
headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
response = requests.post(url, data=datas, headers=headers, timeout=2)
print(response.text)
<?php
header("Content-Type: text/html; charset=utf-8");
//step1. 요청을 위한 파라미터 설정
$key = "ItEQKi3rY7uvDS8l"; // INIpayTest 의 INIAPI key
$iv = "HYb3yQ4f65QL89=="; // INIpayTest 의 테스트 IV
$type = "Issue";
$paymethod = "Receipt";
$timestamp = date("YmdHis");
$clientIp = "192.0.0.1";
$mid = "INIpayTest";
$url = "test.com";
$goodName = "현금영수증테스트";
$buyerName = "홍길동";
$buyerEmail = "test@test.com";
$crPrice = "1000";
$supPrice = "900";
$tax = "100";
$srcvPrice = "0";
$useOpt = "0";
$regNum = "0100001234"; // 현금영수증 신분확인 파라미터, AES 암호화 대상
$encrypted1 = base64_encode(openssl_encrypt($regNum, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, $iv)); // AES 암호화
$hashData = hash("sha512",$key.$type.$paymethod.$timestamp.$clientIp.$mid.$crPrice.$supPrice.$srcvPrice.$encrypted1); // hash 암호화
//step2. key=value 로 post 요청
$data = array(
'type' => $type,
'paymethod' => $paymethod,
'timestamp' => $timestamp,
'clientIp' => $clientIp,
'mid' => $mid,
'url' => $url,
'goodName' => $goodName,
'buyerName' => $buyerName,
'buyerEmail' => $buyerEmail,
'crPrice' => $crPrice,
'supPrice' => $supPrice,
'tax' => $tax,
'srcvPrice' => $srcvPrice,
'regNum' => $encrypted1,
'useOpt' => $useOpt,
'hashData' => $hashData
);
$url ="https://iniapi.inicis.com/api/v1/receipt"; // 전송 URL
$ch = curl_init(); //curl 초기화
curl_setopt($ch, CURLOPT_URL, $url); // 전송 URL 지정하기
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //요청 결과를 문자열로 반환
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //connection timeout 10초
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); //POST data
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=utf-8')); // 전송헤더 설정curl_setopt($ch, CURLOPT_POST, 1); // post 전송
$response = curl_exec($ch);
curl_close($ch);
//step3. 요청 결과
echo $response;
?>
//*JSP 경우 아래 통신, AES , Hash 에 필요한 암호화 lib 는 별도 제공하지 않습니다. 관련 사이트 참고및 직접 구현 부탁드립니다.
<%@page import="java.util.RequestMap"%>
<%@page import="TestPage.HttpConnectionUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="TestPage.SHA_512_Util"%>
<%@page import="TestPage.AES128Util"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%
Date date_now = new Date(System.currentTimeMillis()); // 현재시간을 가져와 Date형으로 저장한다//년월일시분초 14자리 포멧
SimpleDateFormat fourteen_format = new SimpleDateFormat("yyyyMMddHHmmss");
//step1. 요청을 위한 파라미터 설정
String Key="ItEQKi3rY7uvDS8l"; // INIpayTest 의 INIAPI key
String IV="HYb3yQ4f65QL89"; // INIpayTest 의 테스트 IV
String type="Issue";
String paymethod="Receipt";
String timestamp=fourteen_format.format(date_now);
String clientIp="192.0.0.1";
String mid="INIpayTest";
String goodName="테스트";
String buyerName="홍길동";
String buyerEmail="test@test.com";
String crPrice="1000";
String supPrice="900";
String tax="100";
String srcvPrice="0";
String useOpt="0";
//AES 암호화
String regNum_aes="0100001234"; // 현금영수증 신분확인 파라미터, AES 암호화 대상
AES128Util AES128=new AES128Util();
String regNum=AES128.encAES(regNum_aes); // AES128Util 을 이용하여 AES암호화(해당 LIB는 직접구현 필요)
//Hash 암호화
String data_hash=key+type+paymethod+timestamp+clientIp+mid+crPrice+supPrice+srcvPrice+regNum;
SHA_512_Util SHA_512=new SHA_512_Util();
String hashData = SHA_512.getSHA_512(data_hash); // SHA_512_Util 을 이용하여 hash암호화(해당 LIB는 직접구현 필요)
String APIURL="https://iniapi.inicis.com/api/v1/receipt"; // 전송 URL
RequestMap<String, String> CashReceiptsMap = new RequestMap<String, String>();
CashReceiptsMap.put("type" ,type);
CashReceiptsMap.put("paymethod" ,paymethod);
CashReceiptsMap.put("timestamp" ,timestamp);
CashReceiptsMap.put("clientIp" ,clientIp);
CashReceiptsMap.put("mid" ,mid);
CashReceiptsMap.put("goodName" ,goodName);
CashReceiptsMap.put("buyerName" ,buyerName);
CashReceiptsMap.put("buyerEmail" ,buyerEmail);
CashReceiptsMap.put("crPrice" ,crPrice);
CashReceiptsMap.put("supPrice" ,supPrice);
CashReceiptsMap.put("tax" ,tax);
CashReceiptsMap.put("srcvPrice" ,srcvPrice);
CashReceiptsMap.put("useOpt" ,useOpt);
CashReceiptsMap.put("regNum" ,regNum);
CashReceiptsMap.put("hashData" ,hashData);
//step2. key=value 로 post 요청
HttpConnectionUtil httpUtil=new HttpConnectionUtil();
try{
String authResultString = "";
authResultString = httpUtil.postRequest(APIURL , CashReceiptsMap);
System.out.println(authResultString);
//step3. 요청 결과
out.println("<h1>"+authResultString+"</h2>");
}catch (Exception ex) {
System.out.println(ex);
}
%>