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

[KakaoPay] ์นด์นด์˜คํŽ˜์ด ๋‹จ๊ฑด ๊ฒฐ์ œ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ฐฉ๋ฒ• (2024 ์‹ ๊ทœ API ๋ฒ„์ „)

by OR15A 2024. 3. 29.
์‚ฌ์ „์ค€๋น„
 

์นด์นด์˜คํŽ˜์ด | ๊ฐœ๋ฐœ์ž์„ผํ„ฐ

์ƒˆ๋กœ์šด ๊ธฐํšŒ์™€ ๊ฐ€์น˜๋ฅผ ํ•จ๊ป˜ ๋งŒ๋“ค์–ด๋ด์š”

developers.kakaopay.com

  • ํ‚ค ๋ฐœ๊ธ‰๋ฐ›๊ธฐ

 

ํฌ๋Ÿผ

์นด์นด์˜คํŽ˜์ด ๊ฐœ๋ฐœ์ž์„ผํ„ฐ ์ด์šฉ ๊ด€๋ จ ์งˆ๋ฌธ ๋ฐ ๋‹ต๋ณ€์„ ๊ณต์œ ํ•˜๋Š” ์ปค๋ฎค๋‹ˆํ‹ฐ์ž…๋‹ˆ๋‹ค.

developers.kakaopay.com

 

 

2024 ์นด์นด์˜คํŽ˜์ด API ์ธ์ฆ์‹œ ์‚ฌ์šฉํ•  ๊ฐ’
  • ์ธ์ฆ ์Šคํ‚ค๋งˆ 
    • (๊ตฌ) "KakaoAK "   ->  (์‹ ) " SECRET_KEY "
  • Secret Key๊ฐ’์€ ํ…Œ์ŠคํŠธ์˜ ๊ฒฝ์šฐ Secret Key(dev) ์‚ฌ์šฉํ•˜๊ธฐ
 

 

 

์นด์นด์˜คํŽ˜์ด ๊ฒฐ์ œ ๊ตฌํ˜„ ๊ณผ์ •

 

  • OrderInfoDTO : ์‚ฌ์šฉ์ž ์ฃผ๋ฌธ ์ •๋ณด
  • KakaoPaymentReadyRequestDTO : ์นด์นด์˜ค ๊ฒฐ์ œ ์ค€๋น„ ์š”์ฒญ์— ํ•„์š”ํ•œ Body๊ฐ’
  • PaymentInfo : ๊ฒฐ์ œ์ •๋ณด ์—”ํ‹ฐํ‹ฐ

[ ์˜ˆ์‹œ ์ฝ”๋“œ ๋”๋ณด๊ธฐ ๐Ÿ”ฝ ]

๋”๋ณด๊ธฐ

OrderInfoDTO

@ToString
@Getter
@Setter
@NoArgsConstructor
public class OrderInfoDTO {

    private Integer point_100_Quantity;
    private Integer point_1000_Quantity;
    private String paymentMethod; // ๊ฒฐ์ œ ๋ฐฉ๋ฒ•
    private String paymentId; // ๊ฒฐ์ œID

    public OrderInfoDTO(Integer point_100_Quantity, Integer point_1000_Quantity, String paymentMethod, String paymentId) {
        this.point_100_Quantity = point_100_Quantity;
        this.point_1000_Quantity = point_1000_Quantity;
        this.paymentMethod = paymentMethod;
        this.paymentId = paymentId;
    }
}

 

 

KakaoPaymentReadyRequestDTO

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class KakaoPaymentReadyRequestDTO {

    private String cid;
    private String cid_secret;
    private String partner_order_id;
    private String partner_user_id;
    private String item_name;
    private String item_code;
    private Integer quantity;
    private Integer total_amount;
    private Integer tax_free_amount;
    private Integer vat_amount;
    private Integer green_deposit;
    private String approval_url;
    private String cancel_url;
    private String fail_url;
    private List<String> available_cards;
    private String payment_method_type;
    private Integer install_month;
    private String use_share_installment;
    private Map<String, String> custom_json;
}

 

PaymentInfo

@Entity
@Getter
@NoArgsConstructor
@Table(name = "payment_info")
public class PaymentInfo extends BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "payment_info_id")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private RBUser user; // ์‚ฌ์šฉ์ž ID

    private String aid; // ์š”์ฒญ ๊ณ ์œ  ๋ฒˆํ˜ธ - ์Šน์ธ/์ทจ์†Œ๊ฐ€ ๊ตฌ๋ถ„๋œ ๊ฒฐ์ œ๋ฒˆํ˜ธ
    private String tid; // ๊ฒฐ์ œ ๊ณ ์œ  ๋ฒˆํ˜ธ - ์Šน์ธ/์ทจ์†Œ๊ฐ€ ๋™์ผํ•œ ๊ฒฐ์ œ๋ฒˆํ˜ธ
    private String partnerOrderId; // ๊ฐ€๋งน์  ์ฃผ๋ฌธ๋ฒˆํ˜ธ
    private String partnerUserId; // ๊ฐ€๋งน์  ํšŒ์› ID

    @Enumerated(EnumType.STRING) // Enum ๊ฐ’์„ ๋ฌธ์ž์—ด๋กœ ์ €์žฅ
    private PaymentStatus status; // ๊ฒฐ์ œ ์ƒํƒœ

    private String itemName;
    private String itemCode;
    private Integer totalPointAmount; // ๊ณ ๊ฐ์ด ๊ตฌ๋งคํ•˜๋Š” ์ด ํฌ์ธํŠธ ๊ธˆ์•ก
    private Integer totalAmount; // ์ƒํ’ˆ ์ด์•ก, ์„ ํƒ์  ์‚ฌ์šฉ

    private LocalDateTime createdAt; // ๊ฒฐ์ œ ์ค€๋น„ ์š”์ฒญ ์‹œ๊ฐ
    private LocalDateTime approvedAt; // ๊ฒฐ์ œ ์Šน์ธ ์‹œ๊ฐ

    @Embedded
    private Amount amount;
    @Embedded
    private CardInfo cardInfo;


    public void setUser(RBUser user) {
        if (this.user != null) {
            this.user.getGameRecords().remove(this);
        }
        this.user = user;
    }

    public void firstPaymentInformation(RBUser user, String partnerOrderId, String partnerUserId,
                                        String itemName, String itemCode, Integer totalAmount, Integer totalPointAmount) {
        this.user = user;
        this.partnerOrderId = partnerOrderId;
        this.partnerUserId = partnerUserId;
        this.itemName = itemName;
        this.itemCode = itemCode;
        this.totalAmount = totalAmount;
        this.totalPointAmount = totalPointAmount;

    }

    public void updatePaymentStatus(PaymentStatus status) {
        this.status = status;
    }

    public void secondPaymentInformation(String tid, LocalDateTime createdAt) {
        this.tid = tid;
        this.createdAt = createdAt;
    }

    public void thirdPaymentInformation(String aid, Amount amount, CardInfo cardInfo, LocalDateTime approvedAt) {
        this.aid = aid;
        this.amount = amount;
        this.cardInfo = cardInfo;
        this.approvedAt = approvedAt;
    }


}

 

 

  • KakaoPaymentReadyResponseDTO : ๊ฒฐ์ œ ์ค€๋น„์— ๋Œ€ํ•œ ์‘๋‹ต

[ ์˜ˆ์‹œ ์ฝ”๋“œ ๋”๋ณด๊ธฐ ๐Ÿ”ฝ ]

๋”๋ณด๊ธฐ

 

KakaoPaymentReadyResponseDTO

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class KakaoPaymentReadyResponseDTO {

    private String tid;
    private String next_redirect_app_url;
    private String next_redirect_mobile_url;
    private String next_redirect_pc_url;
    private String android_app_scheme;
    private String ios_app_scheme;
    private boolean tms_result;
    private LocalDateTime created_at;

}

  • KakaoPaymentApproveRequestDTO :  ๊ฒฐ์ œ ์Šน์ธ์„ ์œ„ํ•œ ์š”์ฒญ body

[ ์˜ˆ์‹œ ์ฝ”๋“œ ๋”๋ณด๊ธฐ ๐Ÿ”ฝ ]

๋”๋ณด๊ธฐ

 

KakaoPaymentApproveRequestDTO 

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class KakaoPaymentApproveRequestDTO {

    private String cid; // ๊ฐ€๋งน์  ์ฝ”๋“œ
    private String cid_secret; // ๊ฐ€๋งน์  ์ฝ”๋“œ ์ธ์ฆํ‚ค
    private String tid; // ๊ฒฐ์ œ ๊ณ ์œ ๋ฒˆํ˜ธ
    private String partner_order_id; // ๊ฐ€๋งน์  ์ฃผ๋ฌธ๋ฒˆํ˜ธ
    private String partner_user_id; // ๊ฐ€๋งน์  ํšŒ์› id
    private String pg_token; // ๊ฒฐ์ œ์Šน์ธ ์š”์ฒญ์„ ์ธ์ฆํ•˜๋Š” ํ† ํฐ
    private String payload; // ๊ฒฐ์ œ ์Šน์ธ ์š”์ฒญ์— ๋Œ€ํ•ด ์ €์žฅํ•˜๊ณ  ์‹ถ์€ ๊ฐ’
    private Integer total_amount; // ์ƒํ’ˆ ์ด์•ก

    public KakaoPaymentApproveRequestDTO(String cid, String tid, String partner_order_id, String partner_user_id, String pg_token) {
        this.cid = cid;
        this.tid = tid;
        this.partner_order_id = partner_order_id;
        this.partner_user_id = partner_user_id;
        this.pg_token = pg_token;
    }
}

  • KakaoPaymentApproveResponseDTO : ์„ฑ๊ณต ์‹œ ์‘๋‹ต bady ๋‹ด๊ธฐ

[ ์˜ˆ์‹œ ์ฝ”๋“œ ๋”๋ณด๊ธฐ ๐Ÿ”ฝ ]

๋”๋ณด๊ธฐ

KakaoPaymentApproveResponseDTO

  • money ๊ฒฐ์ œ -> Amount
  • card๊ฒฐ์ œ -> CardInfo

 

KakaoPaymentApproveResponseDTO

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class KakaoPaymentApproveResponseDTO {

    private String aid;
    private String tid;
    private String cid;
    private String sid; // ํ•„๋“œ ์ถ”๊ฐ€  (๊ตฌ API์—์„œ๋งŒ ํ•„์š”ํ–ˆ์Œ)
    private String partnerOrderId;
    private String partnerUserId;
    private String paymentMethodType;
    private String itemName;
    private int quantity;
    private LocalDateTime createdAt;
    private LocalDateTime approvedAt;

    private Amount amount; // ๊ธˆ์•ก ์ •๋ณด
    private CardInfo cardInfo; // ์นด๋“œ ์ •๋ณด, ๊ฒฐ์ œ ์ˆ˜๋‹จ์ด ์นด๋“œ์ผ ๋•Œ๋งŒ ์กด์žฌ

}

 

@Embeddable
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Amount {

    private Integer total;
    private Integer taxFree;
    private Integer vat;
    private Integer point;
    private Integer discount;
    private Integer greenDeposit;
    private Integer taxFreeAmount; // ๋น„๊ณผ์„ธ ๊ธˆ์•ก
    private Integer vatAmount; // ๋ถ€๊ฐ€์„ธ ๊ธˆ์•ก

}
@Embeddable
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CardInfo {
    private String kakaopayPurchaseCorp;
    private String kakaopayPurchaseCorpCode;
    private String kakaopayIssuerCorp;
    private String kakaopayIssuerCorpCode;
    private String bin;
    private String cardType;
    private String installMonth;
    private String approvedId;
    private String cardMid;
    private String interestFreeInstall;
    private String installmentType;
    private String cardItemCode;
}

 

 

  • ์„ค๋ช… ์ด๋ฏธ์ง€ ํ†ตํ•ฉ๋ณธ PDF

์นด์นด์˜คํŽ˜์ด(์™„).pdf
0.62MB

 

 

 

๊ตฌํ˜„ ๊ณผ์ •์—์„œ ๊ฒช์€ ์˜ค๋ฅ˜

2024.03.29 - [๐Ÿ–ฅ๏ธ ๋ฐฑ์—”๋“œ/SpringBoot] - [KakaoPay] ์นด์นด์˜คํŽ˜์ด ๋‹จ๊ฑด ๊ฒฐ์ œ ๊ณผ์ • ์ค‘ ๊ฒช์€ ์˜ค๋ฅ˜ ๋ชจ์Œ

 

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

์˜ค๋ฅ˜์˜ ์›์ธ๋“ค (๊ตฌ) ์นด์นด์˜คํŽ˜์ด API ์—์„œ 2024์— ์ƒˆ๋กœ ๋ฐ”๋€Œ๋ฉด์„œ ํ•„์š”์—†์–ด์ง„ ํ•„๋“œ๊ฐ’ ๋•Œ๋ฌธ์— Jackson ๋ชจ๋“ˆ url ์‹ค์ˆ˜ key๊ฐ’์„ dev์šฉ์œผ๋กœ ์•ˆ์จ์„œ ํ•„๋“œ ๋ถˆ์ผ ์นด์นด์˜ค๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๊ฒฐ์ œ ์˜ค๋ฅ˜์ฝ”๋“œ ์ •๋ฆฌ ์—‘์…€ํŒŒ์ผ

labmate-dev.tistory.com

 

 

 

์ปจํŠธ๋กค๋Ÿฌ ์š”์ฒญ ์˜ˆ์‹œ

2024.03.29 - [๐Ÿ–ฅ๏ธ ๋ฐฑ์—”๋“œ/SpringBoot] - [KakaoPay] ์นด์นด์˜คํŽ˜์ด ๋‹จ๊ฑด ๊ฒฐ์ œ ์ปจํŠธ๋กค๋Ÿฌ ์˜ˆ์‹œ

 

[KakaoPay] ์นด์นด์˜คํŽ˜์ด ๋‹จ๊ฑด ๊ฒฐ์ œ ์ปจํŠธ๋กค๋Ÿฌ ์˜ˆ์‹œ

์•ˆ๋‚ด๊ธ€ ๊ฒฐ์ œ ํ๋ฆ„์„ ๋ณด๊ธฐ ์œ„ํ•ด debug ๋ชจ๋“œ์˜ ๋กœ๊ทธ ์ถœ๋ ฅ์ด ๋งŽ์Šต๋‹ˆ๋‹ค ๊ตฌํ˜„ ์ดˆ๊ธฐ์˜ ์ฝ”๋“œ๋ผ ๋ถ€์กฑํ•œ ๋ถ€๋ถ„์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์–‘ํ•ดํ•ด์ฃผ์„ธ์š”! ํ๋ฆ„์„ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ ๋ชจ๋“  ์ฒ˜๋ฆฌ๋ฅผ ์ง์ ‘ ํ•˜

labmate-dev.tistory.com