PortOne(์์ํฌํธ)์ ๊ฒฐ์ ์ทจ์ API๋ ์ด๋ฏธ ์น์ธ๋ ๊ฒฐ์ ์ ๋ํด ํ๋ถ์ ์์ฒญํ๋ ๊ธฐ๋ฅ์ด๋ค.
imp_uid ๋๋ merchant_uid ์ค ํ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํน์ ๊ฒฐ์ ๋ฅผ ์๋ณํด ์ทจ์ํ ์ ์๋ค.
@GetMapping("/payments/cancel")
@ResponseBody
public void payments_cancel(){
log.info("GET/portOne/payment/cancel...");
String url = "<https://api.iamport.kr/payments/cancel>";
HttpHeaders header = new HttpHeaders();
header.add("Content-Type", "application/json");
header.add("Authorization", "Bearer " + this.portOneTokenResponse.getResponse().getAccess_token());
JSONObject params = new JSONObject();
params.put("imp_uid", "imp_************************"); // ๊ฒฐ์ ๊ณ ์ ๋ฒํธ (๋ง์คํน ์ฒ๋ฆฌ)
params.put("merchant_uid", "merchant_************"); // ์์ ์ฃผ๋ฌธ๋ฒํธ (๋ง์คํน ์ฒ๋ฆฌ)
HttpEntity<String> entity = new HttpEntity<>(params.toString(), header);
RestTemplate rt = new RestTemplate();
ResponseEntity<String> response = rt.exchange(url, HttpMethod.POST, entity, String.class);
System.out.println(response.getBody());
}
@GetMapping("/certifications/{imp_uid}")
@ResponseBody
public void certifications(@PathVariable("imp_uid") String imp_uid){
log.info("GET/portOne/certifications/" + imp_uid);
String url = "<https://api.iamport.kr/certifications/>" + imp_uid;
HttpHeaders header = new HttpHeaders();
header.add("Authorization", "Bearer " + this.portOneTokenResponse.getResponse().getAccess_token());
header.add("Content-Type", "application/json");
HttpEntity<?> entity = new HttpEntity<>(header);
RestTemplate rt = new RestTemplate();
ResponseEntity<String> response = rt.exchange(url, HttpMethod.GET, entity, String.class);
System.out.println(response);
}
๋ธ๋ผ์ฐ์ ์์ ํ ์คํธํ ๋๋ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ ฅํ๋ฉด ๋๋ค:
<http://localhost:8090/portOne/certifications/imp_************************>
imp_uid
๋ ์ธ์ฆ ์๋ฃ ํ ์์ํฌํธ์์ ์ฝ๋ฐฑ์ผ๋ก ์ ๋ฌ๋ฐ์ ์ค์ ๊ฐ์ผ๋ก ๊ต์ฒด๊ตฌ๋ถ | ์ค๋ช |
---|---|
API ์ข ๋ฅ | ๊ฒฐ์ ์ทจ์, ๋ณธ์ธ์ธ์ฆ ์กฐํ |
์์ฒญ ๋ฐฉ์ | POST (๊ฒฐ์ ์ทจ์), GET (๋ณธ์ธ์ธ์ฆ) |
์ฃผ์ ํ๋ผ๋ฏธํฐ | imp_uid ๋๋ merchant_uid |
ํค๋ ์ค์ | Content-Type: application/json, Authorization: Bearer access_token |
์ค์ต ํ | imp_uid๋ ์ธ์ฆ ์๋ฃ ํ ์ฝ๋ฐฑ ๋๋ ์๋ต์ผ๋ก ์ ๋ฌ๋จ |
๊ฒฐ์ ์์คํ ์์ ํ๋ถ ์ฒ๋ฆฌ๋ ์ฌ์ฉ์ ๊ฒฝํ๊ณผ ์ง๊ฒฐ๋๋ฉฐ, ๊ธฐ์ ์ ์ผ๋ก๋ ๋ฏผ๊ฐํ ์์ญ์ด๋ค.
์ด๋ฒ ์ค์ต์ ํตํด access_token
๋ฐ๊ธ โ API ์ธ์ฆ โ ํ๋ผ๋ฏธํฐ ๊ตฌ์ฑ โ ์๋ต ํ์ธ๊น์ง ์ ์ฒด ํ๋ฆ์ ์์ ์ตํ ์ ์์๋ค.
ํนํ ๋ณธ์ธ์ธ์ฆ ๊ฒฐ๊ณผ๋ฅผ ์กฐํํ ์ ์๋ค๋ ์ ์ ํฅํ ์ฌ์ฉ์ ๊ณ์ ๋ณดํธ๋ ๊ฐ์ ํ๋ฆ์์๋ ์ค์ํ ๊ธฐ๋ฅ์ด ๋ ์ ์์์ ๋๊ผ๋ค.
์ค์ ํ๋ก์ ํธ์์ ์ ์ ํ๋ถ ์ฒ๋ฆฌ๋ ๋ณธ์ธํ์ธ ๋ก์ง์ ๋ฐ๋ก ์ ์ฉํ ์ ์๋ ๊ธฐ๋ฐ์ด ์กํ ๊ฒ ๊ฐ๋ค.
access_token
ํฌํจํ Authorization ํค๋ ํ์