hyeonga_code

[JAVA/SPRING] 포트원/아임포트 결제 적용 IamportResponse<Payment> 본문

Spring

[JAVA/SPRING] 포트원/아임포트 결제 적용 IamportResponse<Payment>

hyeonga 2024. 2. 15. 06:59
반응형

2024.02.13 - 2024.02.14

> portone 가입

> 결제연동 > 대표상점 store_id 생성됩니다.

> 테스트 연동가능

> 포트원 개발자 센터에서 연동 가능

 

-- 포트원의 개발자용 페이지에서도 Spring에서 사용하는 방법은 자세하게 나와있지 않아 고생했다.

-- 구글링을 하다가 찾은 IamportResponse<Payment> 는 직접 작성한 파일인 줄 알았는데 제공되는 라이브러리였다.

>> pom.xml파일에 추가

<!-- 아임포트 결제 -->
        <dependency>
            <groupId>com.github.iamport</groupId>
            <artifactId>iamport-rest-client-java</artifactId>
            <version>0.2.23</version>
        </dependency>
    </dependencies>
	
<!--  JitPack (아임포트 결제) -->
	<repositories>
            <repository>
                <id>jitpack.io</id>
                <url>https://jitpack.io</url>
            </repository>
	</repositories>

 

 

 

IamportResponse.class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.siot.IamportRestClient.response;
 
import com.google.gson.annotations.SerializedName;
 
public class IamportResponse<T> {
 
    @SerializedName("code")
    int code;
    
    @SerializedName("message")
    String message;
    
    @SerializedName("response")
    T response;
 
    public int getCode() {
        return code;
    }
 
    public String getMessage() {
        return message;
    }
 
    public T getResponse() {
        return response;
    }
    
}
 

 

 

Payment.class 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package com.w2.client.controller;
 
import java.math.BigDecimal;
import java.util.Date;
 
import com.google.gson.annotations.SerializedName;
import com.siot.IamportRestClient.response.PaymentCancelDetail;
 
public class Payment {
 
    @SerializedName("imp_uid")    // 결제를 요청한 고유 식별자
    String imp_uid;
 
    @SerializedName("merchant_uid")    // 판매자가 생성한 고유 식별자
    String merchant_uid;
 
    @SerializedName("pay_method"// 결제 방법(신용카드, 계좌이체, 가상계좌)
    String pay_method;
 
    @SerializedName("channel")    // 결제가 이루어진 채널(웹, 모바일 앱)
    String channel;
 
    @SerializedName("pg_provider")    // 결제를 처리하는 PG 제공자
    String pg_provider;
 
    @SerializedName("emb_pg_provider")    // 결제를 처리하는 PG제공자 중 결제창을 내장한 PG 제공자
    String emb_pg_provider;
 
    @SerializedName("pg_tid")    // PG에서 생성한 결제 고유 식별자
    String pg_tid;
 
    @SerializedName("escrow"// 에스크로 방식으로 이루어졌는지의 여부
    boolean escrow;
 
    @SerializedName("apply_num")    // 결제 요청 번호
    String apply_num;
 
    @SerializedName("bank_code")    // 은행 코드
    String bank_code;
 
    @SerializedName("bank_name")    // 은행 이름
    String bank_name;
 
    @SerializedName("card_code")    // 카드사 코드
    String card_code;
 
    @SerializedName("card_name")    // 카드사 이름
    String card_name;
 
    @SerializedName("card_number")    // 카드 번호
    String card_number;
 
    @SerializedName("card_quota")    // 카드 한도
    int card_quota;
 
    @SerializedName("card_type")    // 카드 종류
    int card_type;
 
    @SerializedName("vbank_code")    // 가상계좌 은행 코드
    String vbank_code;
 
    @SerializedName("vbank_name")    // 가상계좌 은행 이름
    String vbank_name;
 
    @SerializedName("vbank_num")    // 가상계좌 번호
    String vbank_num;
 
    @SerializedName("vbank_holder")    // 가상계좌 예금주 이름
    String vbank_holder;
 
    @SerializedName("vbank_date")    // 가상계좌 유효기간
    long vbank_date;
 
    @SerializedName("vbank_issued_at")    // 가상계좌 발급 시간
    long vbank_issued_at;
 
    @SerializedName("name")    // 결제 이름
    String name;
 
    @SerializedName("amount")    // 결제 금액
    BigDecimal amount;
 
    @SerializedName("cancel_amount")    // 결제 취소 금액
    BigDecimal cancel_amount;
 
    @SerializedName("currency")    // 결제 통화
    String currency;
 
    @SerializedName("buyer_name")    // 구매자 이름
    String buyer_name;
 
    @SerializedName("buyer_email")    // 구매자 이메일
    String buyer_email;
 
    @SerializedName("buyer_tel")    // 구매자 전화번호
    String buyer_tel;
 
    @SerializedName("buyer_addr")    // 구매자 주소
    String buyer_addr;
 
    @SerializedName("buyer_postcode")    // 구매자 우편변호
    String buyer_postcode;
 
    @SerializedName("custom_data")    // 판매자 설정 사용자 정의 데이터
    String custom_data;
 
    @SerializedName("status")    // 결제 상태(결제대기중, 결제완료, 결제실패)
    String status;
 
    @SerializedName("started_at")    // 결제 시작 시간
    long started_at;
 
    @SerializedName("paid_at")    // 결제 완료 시간
    long paid_at;
 
    @SerializedName("failed_at")    // 결제 실패 시간
    long failed_at;
 
    @SerializedName("cancelled_at")    // 결제 취소 시간
    long cancelled_at;
 
    @SerializedName("fail_reason")    // 결제 실패 사유
    String fail_reason;
 
    @SerializedName("cancel_reason")    // 결제 취소 사유
    String cancel_reason;
 
    @SerializedName("receipt_url")    // 결제 영수증 URL
    String receipt_url;
 
    @SerializedName("cancel_history")    // 결제 취소 내역 저장
    PaymentCancelDetail[] cancel_history;
 
    @SerializedName("cash_receipt_issued")    // 현금 영수증 발행 여부
    boolean cash_receipt_issued;
 
    @SerializedName("customer_uid")    // 고객의 고유 식별자
    String customer_uid;
 
    @SerializedName("customer_uid_usage")    // 고객의 고유 식별자 사용 여부
    String customer_uid_usage;
 
    public String getImpUid() {
        return imp_uid;
    }
 
    public String getMerchantUid() {
        return merchant_uid;
    }
 
    public String getPayMethod() {
        return pay_method;
    }
 
    public String getChannel() {
        return channel;
    }
 
    public String getPgProvider() {
        return pg_provider;
    }
 
    public String getEmbPgProvider() {
        return emb_pg_provider;
    }
 
    public String getPgTid() {
        return pg_tid;
    }
 
    public boolean isEscrow() {
        return escrow;
    }
 
    public String getApplyNum() {
        return apply_num;
    }
 
    public String getBankCode() {
        return bank_code;
    }
 
    public String getBankName() {
        return bank_name;
    }
 
    public String getCardCode() {
        return card_code;
    }
 
    public String getCardName() {
        return card_name;
    }
 
    public String getCardNumber() {
        return card_number;
    }
 
    public int getCardQuota() {
        return card_quota;
    }
 
    public int getCardType() {
        return card_type;
    }
 
    public String getVbankCode() {
        return vbank_code;
    }
 
    public String getVbankName() {
        return vbank_name;
    }
 
    public String getVbankNum() {
        return vbank_num;
    }
 
    public String getVbankHolder() {
        return vbank_holder;
    }
 
    public Date getVbankDate() {
        return new Date( vbank_date * 1000L );
    }
 
    public long getVbankIssuedAt() {
        return vbank_issued_at;
    }
 
    public String getName() {
        return name;
    }
 
    public BigDecimal getAmount() {
        return amount;
    }
 
    public BigDecimal getCancelAmount() {
        return cancel_amount;
    }
 
    public String getCurrency() {
        return currency;
    }
 
    public String getBuyerName() {
        return buyer_name;
    }
 
    public String getBuyerEmail() {
        return buyer_email;
    }
 
    public String getBuyerTel() {
        return buyer_tel;
    }
 
    public String getBuyerAddr() {
        return buyer_addr;
    }
 
    public String getBuyerPostcode() {
        return buyer_postcode;
    }
 
    public String getCustomData() {
        return custom_data;
    }
 
    public String getStatus() {
        return status;
    }
    public long getStartedAt() {
        return started_at;
    }
 
    public Date getPaidAt() {
        return new Date( paid_at * 1000L );
    }
 
    public Date getFailedAt() {
        return new Date( failed_at * 1000L );
    }
 
    public Date getCancelledAt() {
        return new Date( cancelled_at * 1000L );
    }
 
    public String getFailReason() {
        return fail_reason;
    }
 
    public String getCancelReason() {
        return cancel_reason;
    }
 
    public String getReceiptUrl() {
        return receipt_url;
    }
 
    public PaymentCancelDetail[] getCancelHistory() {
        return cancel_history;
    }
 
    public boolean isCashReceiptIssued() {
        return cash_receipt_issued;
    }
 
    public String getCustomerUid() {
        return customer_uid;
    }
 
    public String getCustomerUidUsage() {
        return customer_uid_usage;
    }
}
 

 

 

IMP.request_pay({ // 요청 객체
		pg: "kakaopay",
		pay_method: "card",
		metchant_uid: "order123", // 주문번호
		name: "주문상품이름",
		amount: 100,
		buyer_email: "email@email.com",
		buyer_name: "이름",
		buyer_tel: "전화번호",
		buyer_addr: "주소",
		buyer_postcode: "우편번호"
	}, function(rsp){
		console.log("결제 : " + rsp);
		$("#resultDiv").html("paymentId : " + rsp.merchant_uid + "<br>paymentDate : " + rsp.paid_at + "<br>paymentStatus : " + rsp.status + "<br>imp_uid : " + rsp.imp_uid);				
				
		//결제검증
		$.ajax({
			type: "POST",
			url: "verifyIamport.do?imp_uid=" + rsp.imp_uid
		}).done(function(data){
			
			// 확인용
			$(data).find("amount").each(function(){
			    console.log($(this).text());
			});
			
			// data.response.amount > undefined라서 이렇게 검증하려 함
			let result = $(data).find("amount").text();
			
			if(rsp.paid_amount == result){
				alert("검증 완료");
			} else {
				alert("결제 실패");
			}
		});
	});

 

>>> 결제 시

 

Controller.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.w2.client.controller;
 
import java.io.IOException;
 
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import com.siot.IamportRestClient.IamportClient;
import com.siot.IamportRestClient.exception.IamportResponseException;
import com.siot.IamportRestClient.response.IamportResponse;
import com.siot.IamportRestClient.response.Payment;
 
import lombok.RequiredArgsConstructor;
 
@RestController
@RequiredArgsConstructor
@PropertySource("classpath:config/webserverdb.properties")
public class PaymentController {
    @Value("${imp.api.key}")
    private String apiKey;
    
    @Value("${imp.api.secretKey}")
    private String secretKey;
    
    private IamportClient iamportClient;
    
    @RequestMapping("sample.do")
    public String samplePayment() {
        return "test";
    }
    
    @ResponseBody
    @RequestMapping("verifyIamport.do")
    public IamportResponse<Payment> paymentByImpUid(@Param("imp_uid"String imp_uid) throws IamportResponseException, IOException {
        iamportClient = new IamportClient(apiKey, secretKey);
        IamportResponse<Payment> result = iamportClient.paymentByImpUid(imp_uid);
        
        Payment paymentInfo = result.getResponse();
        System.err.println("1 > " + paymentInfo.getImpUid());
            // 1 > imp_664201047605
 
        System.err.println("2 > " + paymentInfo.getMerchantUid());
            // 2 > nobody_1707884200668
 
        System.err.println("3 > " + paymentInfo.getPayMethod());
            // 3 > point
 
        System.err.println("4 > " + paymentInfo.getChannel());
            // 4 > pc
 
        System.err.println("5 > " + paymentInfo.getPgProvider());
            // 5 > kakaopay
 
        System.err.println("6 > " + paymentInfo.getEmbPgProvider());
            // 6 > null
 
        System.err.println("7 > " + paymentInfo.getPgTid());
            // 7 > T5cc3ea91c025b0fe915
 
        System.err.println("8 > " + paymentInfo.isEscrow());
            // 8 > false
 
        System.err.println("9 > " + paymentInfo.getApplyNum());
            // 9 > 
 
        System.err.println("10 > " + paymentInfo.getBankCode());
            // 10 > null
 
        System.err.println("11 > " + paymentInfo.getBankName());
            // 11 > null
 
        System.err.println("12 > " + paymentInfo.getCardCode());
            // 12 > null
 
        System.err.println("13 > " + paymentInfo.getCardName());
            // 13 > null
 
        System.err.println("14 > " + paymentInfo.getCardNumber());
            // 14 > null
 
        System.err.println("15 > " + paymentInfo.getCardQuota());
            // 15 > 0
 
        System.err.println("16 > " + paymentInfo.getCardType());
            // 16 > 0
 
        System.err.println("17 > " + paymentInfo.getBankCode());
            // 17 > null
 
        System.err.println("18 > " + paymentInfo.getBankName());
            // 18 > null
 
        System.err.println("19 > " + paymentInfo.getVbankNum());
            // 19 > null
 
        System.err.println("20 > " + paymentInfo.getVbankHolder());
            // 20 > null
 
        System.err.println("21 > " + paymentInfo.getVbankDate());
            // 21 > Thu Jan 01 09:00:00 KST 1970
 
        System.err.println("22 > " + paymentInfo.getVbankIssuedAt());
            // 22 > 0
 
        System.err.println("23 > " + paymentInfo.getName());
            // 23 > 주문상품이름
 
        System.err.println("24 > " + paymentInfo.getAmount());
            // 24 > 100
 
        System.err.println("25 > " + paymentInfo.getCancelAmount());
            // 25 > 0
 
        System.err.println("26 > " + paymentInfo.getCurrency());
            // 26 > KRW
 
        System.err.println("27 > " + paymentInfo.getBuyerName());
            // 27 > 이름
 
        System.err.println("28 > " + paymentInfo.getBuyerEmail());
            // 28 > email@email.com
 
        System.err.println("29 > " + paymentInfo.getBuyerTel());
            // 29 > 전화번호
 
        System.err.println("30 > " + paymentInfo.getBuyerAddr());
            // 30 > 주소
 
        System.err.println("31 > " + paymentInfo.getBuyerPostcode());
            // 31 > 우편번호
 
        System.err.println("32 > " + paymentInfo.getCustomData());
            // 32 > null
 
        System.err.println("33 > " + paymentInfo.getStatus());
            // 33 > paid
 
        System.err.println("34 > " + paymentInfo.getStartedAt());
            // 34 > 1707884201 
 
        System.err.println("35 > " + paymentInfo.getPaidAt());
            // 35 > Wed Feb 14 13:16:52 KST 2024
 
        System.err.println("36 > " + paymentInfo.getFailedAt());
            // 36 > Thu Jan 01 09:00:00 KST 1970
 
        System.err.println("37 > " + paymentInfo.getCancelledAt());
            // 37 > Thu Jan 01 09:00:00 KST 1970
 
        System.err.println("38 > " + paymentInfo.getFailReason());
            // 38 > null
 
        System.err.println("39 > " + paymentInfo.getCancelReason());
            // 39 > nul
 
        System.err.println("40 > " + paymentInfo.getReceiptUrl());
            // 40 > https://mockup-pg-web.kakao.com/v1/confirmation/p/T5cc3ea91c025b0fe915/7732ccacaf781fff6e50bd496b7d58a75f109fcdc0e768a5649d0f9ae2b118c9
 
        return result;
    }
}
 

 

 

하루종일 구글링하고 찾아보고 시도해본 결과

다른 사람들이 사후 검증 시 사용한 data.response.amount는 사용할 수 없었다.

amount가 정의되지 않았다는 오류가 계속해서 발생했다.

다른 방법을 찾아보다가 Payment 에 속한 요소 중 원하는 요소만 꺼내서 사용할 수 있는

let result = $(data).find("amount").text();

를 사용하여 값을 꺼내올 수 있었다. 

data.amount

data.payment.amount

data.response.amount 전부 처리 되지 않던 이유는 뭘까 아직도 의문이다.

 

 

>> test.jsp 전체 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>WeatherWear 사용자</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
 
<!-- 1. 결제창 연동 > 라이브러리 추가 -->
    <script src="https://cdn.iamport.kr/v1/iamport.js"></script>
    <!-- jQuery -->
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js" ></script>
    <!-- iamport.payment.js -->
    <script type="text/javascript" src="https://cdn.iamport.kr/js/iamport.payment-1.2.0.js"></script>
 
<script>
$(document).ready(function(){
    let IMP = window.IMP;
    
    // 2. 객체 초기화(중복 안됨)
    IMP.init("imp21162314");
    /*
    -- 하위 가맹점 결제창 호출 방법
    IMP.agency('가맹점 식별코드', '티어코드')
    */
})
 
 
//3. 결제 요청
function requestPay(){
        /*
    IMP.request_pay({ // 요청 객체
        pg: "kakaopay",
        pay_method: "card",
        metchant_uid: "order123", // 주문번호
        name: "주문상품이름",
        amount: 100,
        buyer_email: "email@email.com",
        buyer_name: "이름",
        buyer_tel: "전화번호",
        buyer_addr: "주소",
        buyer_postcode: "우편번호",
        m_redirect_url: "sample.do" // redirect하는 경우 callback은 실행되지 않습니다.
        
        */
        /*
        >> Query String으로 전송됨
        -- URL뒤에 데이터를 전달하는 방법으로 get 요청과 유사
        -- 결제 결과를 수신받을 endpoint url 주소를 m_redirect_url에 설정하기
        > 결제 완료/가상계좌 발급완료
        curl https://myservice.com/payments/complete?imp_uid=결제건을_특정하는_포트원_번호&merchant_uid=가맹점_고유_주문번호&imp_success=true
        > 결제 실패
        curl https://myservice.com/payments/complete?imp_uid=결제건을_특정하는_포트원_번호&merchant_uid=가맹점_고유_주문번호&imp_success=false&error_code=에러_코드(현재_정리된_체계는_없음)&error_msg=에러_메시지
        
        imp_uid : 포트원 결제 고유번호
        merchant_uid : 가맹점 주문번호
        imp_success : 결제 성공여부
        error_code : 오류 코드
        error_msg : 오류 메세지
        
        > 결제완료
        결제 성공(결제 상태: paid, imp_success: true);
        결제 실패(결제 상태: failed, imp_success: false);
        가상계좌 발급(결제상태: ready, imp_success: true);
        결제창 안열림
        결제 종료
        결제 중단
        
        결제 정보를 서버에 전달하여 위변조 여부를 검증한 후 결제 성공 여부를 판단해야 함
            */
        
 
            /*
        }, async function(rsp){
            if(rsp.success === false){
                alert("결제에 실패했습니다. 에러내용 : ${error_msg}");
                return;
            } else if(rsp.success){
                // DB 저장 요청
                
                if(response.status == 200){ // DB 저장 성공
                    alert("DB 저장 성공");
                    window.location.reload();
                } else {
                    alert("DB 저장 실패 > 결제 요청 승인");
                }
                $("#resultDiv").html("paymentId : " + rsp.merchant_uid + "<br>paymentMethod : " + rsp.paymentMethod + "<br>paymentDate : " + rsp.paid_at + "<br>paymentStatus : " + rsp.status + "<br>imp_uid : " + rsp.imp_uid);                
            }
        
            // 결제정보 사후 검증 API 호출
            const res = await axios.post({
                url: "/payments/complete",
                method: "post",
                headers: { "Content-Type": "application/json"},
                data: { imp_uid: rsp.imp_uid, merchant_uid: rsp.merchant_uid},
            })
            
            console.log("res");
            
            switch(res.status){
            case "vbankIssued" : // 가상계좌 발급 시 로직
                $("#resultDiv").html("가상계좌");
                break;
            case "success": // 결제 성공시 로직
                $("#resultDiv").html("결제성공");
                break;
            }
        });
                */
    
    IMP.request_pay({ // 요청 객체
        pg: "kakaopay",
        pay_method: "card",
        metchant_uid: "order123"// 주문번호
        name"주문상품이름",
        amount: 100,
        buyer_email: "email@email.com",
        buyer_name: "이름",
        buyer_tel: "전화번호",
        buyer_addr: "주소",
        buyer_postcode: "우편번호"
    }, function(rsp){
        console.log("결제 : " + rsp);
        $("#resultDiv").html("paymentId : " + rsp.merchant_uid + "<br>paymentDate : " + rsp.paid_at + "<br>paymentStatus : " + rsp.status + "<br>imp_uid : " + rsp.imp_uid);                
                
        //결제검증
        $.ajax({
            type: "POST",
            url: "verifyIamport.do?imp_uid=" + rsp.imp_uid
        }).done(function(data){
            
            // 확인용
            $(data).find("amount").each(function(){
                console.log($(this).text());
            });
            
            // data.response.amount > undefined라서 이렇게 검증하려 함
            let result = $(data).find("amount").text();
            
            if(rsp.paid_amount == result){
                alert("검증 완료");
            } else {
                alert("결제 실패");
            }
        });
    });
}
 
</script>
</head>
<body class="hold-transition sidebar-collapse layout-top-nav">
    <div class="wrapper">
<button onclick="requestPay()">카카오 결제하기</button>
<div id="resultDiv"></div><hr>
    </div>
</body>
</html>

 

반응형