결제 취소하기

결제 취소 API로 승인된 결제를 (부분)취소하고 환불 처리를 할 수 있습니다.

결제 취소 API 요청

승인된 결제를 취소하려면 결제 승인 요청 결과로 발급 받은 transaction_id 가 필요합니다.
결제 취소 API 엔드포인트에 transaction_id를 Path 파라미터로 추가해서 API를 호출하세요.

요청
                      
curl --request POST 'https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel' \
--header 'Authorization: Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=' \
--header 'Content-Type: application/json' \
--data '{
  "mid" : "1849705C64",
  "refund" : {
    "refund_type" : "F",
    "refund_amount" : "1",
    "refund_id" : "1849705C64",
    "reason" : "단순변심"
  },
  "payment" : {
    "order_id" : "20220829170258",
    "currency" : "USD",
    "amount" : "1",
    "balance" : "1",
    "lang" : "EN"
  }
}'
                      
                    
                      
RestTemplate restTemplate = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
headers.add("Authorization", "Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=");

URI url = URI.create("https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel");

String body = "{\n" +
              "\"mid\" : \"1849705C64\",\n" +
              "\"refund\" : {\n" +
              "\"refund_type\" : \"F\",\n" +
              "\"refund_amount\" : \"1\",\n" +
              "\"refund_id\" : \"1849705C64\",\n" +
              "\"reason\" : \"단순변심\"\n" +
              "},\n" +
              "\"payment\" : {\n" +
              "\"order_id\" : \"20220829170258\",\n" +
              "\"currency\" : \"USD\",\n" +
              "\"amount\" : \"1\",\n" +
              "\"balance\" : \"1\",\n" +
              "\"lang\" : \"EN\"\n" +
              " }\n" +
			        "}";

HttpEntity<String> entity = new HttpEntity<>(body, headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);

System.out.println(response.getBody());
                      
                    
                      
<?php
$url = 'https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel';
$data = '{
  "mid" : "1849705C64",
  "refund" : {
    "refund_type" : "F",
    "refund_amount" : "1",
    "refund_id" : "1849705C64",
    "reason" : "단순변심"
  },
  "payment" : {
    "order_id" : "20220829170258",
    "currency" : "USD",
    "amount" : "1",
    "balance" : "1",
    "lang" : "EN"
  }
}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo='));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response  = curl_exec($ch);

echo $response;
curl_close($ch);
?>
                      
                    
                      
import requests
import json

url = "https://api.eximbay//v1/payments/{transaction_id}/cancel"
headers = {
  "Authorization": "Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=",
  "Content-Type": "application/json"
}

request = {
  "mid" : "1849705C64",
  "refund" : {
    "refund_type" : "F",
    "refund_amount" : "1",
    "refund_id" : "1849705C64",
    "reason" : "단순변심"
  },
  "payment" : {
    "order_id" : "20220829170258",
    "currency" : "USD",
    "amount" : "1",
    "balance" : "1",
    "lang" : "EN"
  }
}

response = requests.post(url, headers=headers, data=json.dumps(request))

print(response.text)
                      
                    
                      
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel',
  'headers': {
    'Authorization': 'Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "mid": "1849705C64",
    "refund": {
      "refund_type": "F",
      "refund_amount": "1",
      "refund_id": "1849705C64",
      "reason": "단순변심"
    },
    "payment": {
      "order_id": "20220829170258",
      "currency": "USD",
      "amount": "1",
      "balance": "1",
      "lang": "EN"
    }
  })

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
                      
                    
                        
string uri = "https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel";
string body = "{\n" +
              "\"mid\" : \"1849705C64\",\n" +
              "\"refund\" : {\n" +
              "\"refund_type\" : \"F\",\n" +
              "\"refund_amount\" : \"1\",\n" +
              "\"refund_id\" : \"1849705C64\",\n" +
              "\"reason\" : \"단순변심\"\n" +
              "},\n" +
              "\"payment\" : {\n" +
              "\"oreder_id\" : \"20220829170258\",\n" +
              "\"currency\" : \"USD\",\n" +
              "\"amount\" : \"1\",\n" +
              "\"balance\" : \"1\",\n" +
              "\"lang\" : \"EN\"\n" +
              " }\n" +
			        "}";

WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
webClient.Headers[HttpRequestHeader.Authorization] = "Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=";
webClient.Encoding = UTF8Encoding.UTF8;
string responseJSON = webClient.UploadString(uri, body);

Console.Write(responseJSON);
                        
                    
                        
val restTemplate =  RestTemplate()
val headers = HttpHeaders()
headers.add("Content-Type", "application/json")
headers.add("Authorization", "Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=")

var url = URI.create("https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel")

val body = "{\n" +
            "\"mid\" : \"1849705C64\",\n" +
            "\"refund\" : {\n" +
            "\"refund_type\" : \"F\",\n" +
            "\"refund_amount\" : \"1\",\n" +
            "\"refund_id\" : \"1849705C64\",\n" +
            "\"reason\" : \"단순변심\"\n" +
            "},\n" +
            "\"payment\" : {\n" +
            "\"oreder_id\" : \"20220829170258\",\n" +
            "\"currency\" : \"USD\",\n" +
            "\"amount\" : \"1\",\n" +
            "\"balance\" : \"1\",\n" +
            "\"lang\" : \"EN\"\n" +
            " }\n" +
            "}"

var entity = HttpEntity<String>(body, headers)
var response = restTemplate.exchange(url, HttpMethod.POST, entity, String::class.java)

println(response.body)
                        
                    

응답으로 Refund 객체에 취소 정보가 돌아옵니다.

                  
{
  "rescode": "0000",
  "resmsg": "Success.",
  "mid": "1849705C64",
  "refund": {
      "refund_amount": "1.00",
      "refund_id": "1849705C64",
      "refund_date": "20220922113927",
      "refund_transaction_id": "1849705C6420220922000014"
  },
  "payment": {
      "order_id": "20220922113330",
      "currency": "USD",
      "amount": "1.00",
      "transaction_id": "1849705C6420220922000013",
      "balance": "0.00",
      "base_amount": "1.00",
      "base_rate": "1.000000",
      "dcc_rate": "1.000000",
      "payment_method" : "P101"
  },
  "foreign": {
      "foregin_currency": "USD",
      "foregin_amount": "1.00",
      "foregin_rate": "0"
  }
}
                  
                

부분 취소 요청

결제 취소 API로 결제 금액의 일부만 취소할 수도 있습니다. 부분 취소는 refund_typeP로 설정해서 API를 요청하면 됩니다.

요청
                      
curl --request POST 'https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel' \
--header 'Authorization: Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=' \
--header 'Content-Type: application/json' \
--data '{
"mid" : "1849705C64",
"refund" : {
"refund_type" : "P",
"refund_amount" : "0.5",
"refund_id" : "1849705C64",
"reason" : "단순변심"
},
"payment" : {
"order_id" : "20220829170258",
"currency" : "USD",
"amount" : "1",
"balance" : "1",
"lang" : "EN"
}
}'
                      
                    
                      
RestTemplate restTemplate = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
headers.add("Authorization", "Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=");

URI url = URI.create("https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel");

String body = "{\n" +
  "\"mid\" : \"1849705C64\",\n" +
  "\"refund\" : {\n" +
  "\"refund_type\" : \"P\",\n" +
  "\"refund_amount\" : \"0.5\",\n" +
  "\"refund_id\" : \"1849705C64\",\n" +
  "\"reason\" : \"단순변심\"\n" +
  "},\n" +
  "\"payment\" : {\n" +
  "\"oreder_id\" : \"20220829170258\",\n" +
  "\"currency\" : \"USD\",\n" +
  "\"amount\" : \"1\",\n" +
  "\"balance\" : \"1\",\n" +
  "\"lang\" : \"EN\"\n" +
  " }\n" +
			        "}";

HttpEntity<String> entity = new HttpEntity<>(body, headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);

System.out.println(response.getBody());
                      
                    
                      
<?php
$url = 'https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel';
$data = '{
"mid" : "1849705C64",
"refund" : {
"refund_type" : "P",
"refund_amount" : "0.5",
"refund_id" : "1849705C64",
"reason" : "단순변심"
},
"payment" : {
"order_id" : "20220829170258",
"currency" : "USD",
"amount" : "1",
"balance" : "1",
"lang" : "EN"
}
}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo='));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response  = curl_exec($ch);

echo $response;
curl_close($ch);
?>
                      
                    
                      
import requests
import json

url = "https://api.eximbay//v1/payments/{transaction_id}/cancel"
headers = {
"Authorization": "Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=",
"Content-Type": "application/json"
}

request = {
"mid" : "1849705C64",
"refund" : {
"refund_type" : "P",
"refund_amount" : "0.5",
"refund_id" : "1849705C64",
"reason" : "단순변심"
},
"payment" : {
"order_id" : "20220829170258",
"currency" : "USD",
"amount" : "1",
"balance" : "1",
"lang" : "EN"
}
}

response = requests.post(url, headers=headers, data=json.dumps(request))

print(response.text)
                      
                    
                      
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel',
'headers': {
'Authorization': 'Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"mid": "1849705C64",
"refund": {
"refund_type": "P",
"refund_amount": "0.5",
"refund_id": "1849705C64",
"reason": "단순변심"
},
"payment": {
"order_id": "20220829170258",
"currency": "USD",
"amount": "1",
"balance": "1",
"lang": "EN"
}
})

};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
                      
                    
                        
string uri = "https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel";
string body = "{\n" +
  "\"mid\" : \"1849705C64\",\n" +
  "\"refund\" : {\n" +
  "\"refund_type\" : \"P\",\n" +
  "\"refund_amount\" : \"0.5\",\n" +
  "\"refund_id\" : \"1849705C64\",\n" +
  "\"reason\" : \"단순변심\"\n" +
  "},\n" +
  "\"payment\" : {\n" +
  "\"oreder_id\" : \"20220829170258\",\n" +
  "\"currency\" : \"USD\",\n" +
  "\"amount\" : \"1\",\n" +
  "\"balance\" : \"1\",\n" +
  "\"lang\" : \"EN\"\n" +
  " }\n" +
			        "}";

WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
webClient.Headers[HttpRequestHeader.Authorization] = "Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=";
webClient.Encoding = UTF8Encoding.UTF8;
string responseJSON = webClient.UploadString(uri, body);

Console.Write(responseJSON);
                        
                    
                        
val restTemplate =  RestTemplate()
val headers = HttpHeaders()
headers.add("Content-Type", "application/json")
headers.add("Authorization", "Basic dGVzdF8xODQ5NzA1QzY0MkMyMTdFMEIyRDo=")

var url = URI.create("https://api-test.eximbay.com/v1/payments/{transaction_id}/cancel")

val body = "{\n" +
"\"mid\" : \"1849705C64\",\n" +
"\"refund\" : {\n" +
"\"refund_type\" : \"P\",\n" +
"\"refund_amount\" : \"0.5\",\n" +
"\"refund_id\" : \"1849705C64\",\n" +
"\"reason\" : \"단순변심\"\n" +
"},\n" +
"\"payment\" : {\n" +
"\"oreder_id\" : \"20220829170258\",\n" +
"\"currency\" : \"USD\",\n" +
"\"amount\" : \"1\",\n" +
"\"balance\" : \"1\",\n" +
"\"lang\" : \"EN\"\n" +
" }\n" +
"}"

var entity = HttpEntity<String>(body, headers)
var response = restTemplate.exchange(url, HttpMethod.POST, entity, String::class.java)

println(response.body)