๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ–ฅ๏ธ ๋ฐฑ์—”๋“œ/SpringBoot

[KakaoPay] ์นด์นด์˜คํŽ˜์ด ๋‹จ๊ฑด ๊ฒฐ์ œ ๊ณผ์ • ์ค‘ ๊ฒช์€ ์˜ค๋ฅ˜ ๋ชจ์Œ

by OR15A 2024. 3. 29.
์˜ค๋ฅ˜์˜ ์›์ธ๋“ค
  • (๊ตฌ) ์นด์นด์˜คํŽ˜์ด API ์—์„œ 2024์— ์ƒˆ๋กœ ๋ฐ”๋€Œ๋ฉด์„œ ํ•„์š”์—†์–ด์ง„ ํ•„๋“œ๊ฐ’ ๋•Œ๋ฌธ์—
  • Jackson ๋ชจ๋“ˆ 
  • url ์‹ค์ˆ˜
  • key๊ฐ’์„ dev์šฉ์œผ๋กœ ์•ˆ์จ์„œ
  • ํ•„๋“œ ๋ถˆ์ผ์น˜
  • ์ธ์ฆ ํ‚ค ๋ณ€๊ฒฝ๋จ
    • (๊ตฌ)  headers.set("Authorization", "KakaoAK " + kakaoPayConfig.getSecretKeyDev());
    • (์‹ )  headers.set("Authorization", "SECRET_KEY " + kakaoPayConfig.getSecretKeyDev());

 

 

์นด์นด์˜ค๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๊ฒฐ์ œ ์˜ค๋ฅ˜์ฝ”๋“œ ์ •๋ฆฌ ์—‘์…€ํŒŒ์ผ

์นด์นด์˜คํŽ˜์ด ๊ฒฐ์ œ ์˜ค๋ฅ˜์ฝ”๋“œ v1.5.xlsx
0.07MB
์นด์นด์˜ค ์ œ๊ณต  ์˜ค๋ฅ˜์ฝ”๋“œ ์ •๋ฆฌ ์—‘์…€ํŒŒ์ผ

 

 

 

 

๋‚ด๊ฐ€ ๊ฒช์€ ์˜ค๋ฅ˜ ๋ฉ”์„ธ์ง€ ์ •๋ฆฌ

 

์˜ค๋ฅ˜ ๋ฉ”์„ธ์ง€ Create breakpoint ์›์ธ (์ถ”์ธก) ํ•ด๊ฒฐ๋ฐฉ๋ฒ•
org.springframework.web.client.HttpClientErrorException$BadRequest 400 Bad Request: "{"error_code":-400,"error_message":"์ž˜๋ชป๋œ ์š”์ฒญ"}"   url์ˆ˜์ •
String requestUrl = "https://open-api.kakaopay.com/online/v1/payment/ready";

key ์ˆ˜์ •
"SECRET_KEY "
+ kakaoPayConfig.getSecretKeyDev()
org.springframework.web.client.HttpClientErrorException$NotFound 404 Not Found: "{"timestamp":"2024-03-27T14:49:47.670+00:00","status":404,"error":"Not Found","path":"/"}"   url์ˆ˜์ •
String requestUrl = "https://open-api.kakaopay.com/online/v1/payment/ready";

key ์ˆ˜์ •
"SECRET_KEY "
+ kakaoPayConfig.getSecretKeyDev()
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException : Unrecognized field "tms_result" (class com.labmate.riddlebox.dto.kakaopay.PaymentResponseDTO), not marked as ignorable (7 known properties: "android_app_scheme", "ios_app_scheme", "next_redirect_mobile_url", "next_redirect_app_url", "tid", "next_redirect_pc_url", "created_at"]) ๋ฌธ์„œ์— ์—†๋Š” ํ•„๋“œ ๋•Œ๋ฌธ

์นด์นด์˜ค ๋ฌธ์˜์„ผํ„ฐ ๊ธ€๋กœ ์ถ”์ธกํ•˜์ž๋ฉด ์ƒˆ๋กœ์šด API๋กœ ๋ฐ”๊พธ๋ฉด์„œ ํ•„์š”์—†์–ด์ง„ ๊ธฐ์กด API ํ•„๋“œ์ธ๋“ฏ
PaymentResponseDTO์—
private boolean tms_result; ์ถ”๊ฐ€

๋งค์นญ ์•ˆ๋˜๋Š” ํ•„๋“œ ๋ฌด์‹œํ•˜๊ธฐ
์• ๋„ˆํ…Œ์ด์…˜ ์ถ”๊ฐ€
@JsonIgnoreProperties(ignoreUnknown = true)
org.springframework.web.client.HttpClientErrorException$BadRequest 400 Bad Request: "{"extras":null,"error_message":"totalAmount, taxFreeAmount, vatAmount, greenDeposit is invalid!","error_code":-722}" ์นด์นด์˜ค ์—๋Ÿฌ์ฝ”๋“œ ์„ค๋ช…์œผ๋กœ๋Š” ๊ธˆ์•ก ์ •๋ณด๊ฐ€ ์ž˜๋ชป๋œ ๊ฒฝ์šฐ Amount ํด๋ž˜์Šค์— ํ•„๋“œ ์ถ”๊ฐ€

private Integer taxFreeAmount; // ๋น„๊ณผ์„ธ ๊ธˆ์•ก
private Integer vatAmount; // ๋ถ€๊ฐ€์„ธ ๊ธˆ์•ก
com.fasterxml.jackson.databind.exc.InvalidDefinitionException Java 8 date/time type `java.time.LocalDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling   ์˜์กด์„ฑ ์ถ”๊ฐ€
// Java 8 ๋‚ ์งœ/์‹œ๊ฐ„ ์ง€์›์„ ์œ„ํ•œ Jackson ๋ชจ๋“ˆ ๋“ฑ๋ก
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.0' 

// Java 8 ๋‚ ์งœ/์‹œ๊ฐ„ ๋ชจ๋“ˆ ๋“ฑ๋ก // ObjectMapper ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ
ObjectMapper objectMapper = new ObjectMapper();
// Java 8 ๋‚ ์งœ/์‹œ๊ฐ„ ๋ชจ๋“ˆ ๋“ฑ๋ก
objectMapper.registerModule(new JavaTimeModule());
org.springframework.web.client.HttpClientErrorException$NotFound 404 Not Found: "{"error_code":-404,"error_message":"๋ฆฌ์†Œ์Šค ๋ฏธ์กด์žฌ"}"   URL ์ˆ˜์ •
online์ด ๋น ์ ธ์žˆ์—ˆ์Œ
https://open-api.kakaopay.com/online/v1/payment/approve
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:  Unrecognized field "sid" ๊ฒฐ์ œ์นดํ†ก์€ ์™”์ง€๋งŒ
์˜ค๋ฅ˜๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ๋จ

์ •์˜์•ˆํ•œ ํ•„๋“œ ์žˆ์„ ์ˆ˜๋„ ์žˆ๊ณ , jackson ๋‚ ์งœ์‹œ๊ฐ„ ์ฝ”๋“œ ์ถ”๊ฐ€ ์•ˆํ•ด์„œ ๊ทธ๋Ÿฐ๋“ฏ
// ํ•„๋“œ ์ถ”๊ฐ€
KakaoPaymentApproveResponseDTO
 ์— private String sid; 

์• ๋„ˆํ…Œ์ด์…˜ ์ถ”๊ฐ€
@JsonIgnoreProperties(ignoreUnknown = true)
public class
KakaoPaymentApproveResponseDTO


์ƒ์„ฑ์ž์—์„œ ๋ชจ๋“ˆ ํ•œ๋ฒˆ์— ๋“ฑ๋กํ•ด์„œ Java 8 ๋‚ ์งœ/์‹œ๊ฐ„ API ์ง€์› ํ™œ์„ฑํ™”
this.objectMapper = new ObjectMapper();
this. objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException Unrecognized field "tax_free" ์žˆ๋Š” ํ•„๋“œ ์ธ์‹ ๋ชปํ•จ

Amount ํด๋ž˜์Šค์—์„œ tax_free ํ•„๋“œ๋ฅผ ์ธ์‹ํ•˜์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ

ํด๋ž˜์Šค ๋ณ€์ˆ˜๋ช…์„ ์นด๋ฉœ์ผ€์ด์Šค๋กœ ์ˆ˜์ •(์‹ค์ˆ˜๋กœ db์ฒ˜๋Ÿผ ์„ ์–ธํ•ด๋ฒ„๋ฆผ)
[1] ์• ๋„ˆํ…Œ์ด์…˜ ๋ถ™์ด๊ฑฐ๋‚˜
@JsonProperty("tax_free") private Integer taxFree;


[2]ObjectMapper ์„ค์ • ์ „์ฒด๋ณ€๊ฒฝ this.o
bjectMapper.setPropertyNamingStrategy( PropertyNamingStrategies.SNAKE_CASE);