최신글
hyeonga_code
[JAVA/SPRING] 결제취소(부분취소)_포트원/아임포트 결제 적용 IamportClient<> 이해하기 본문
반응형
2024.02.14
portone에서 제공하는 github의 IamportRestTest.java
직접 실행해보면서 어떻게 돌아가는지 확인해봄
-- canclePaymentAlreadyCancelledImpUid()
---- 부분 결제 취소 메소드
---- 이미 취소된 결제건을 부분 취소 테스트를 할 수 있는 코드도 포함
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
|
public void testPartialCancelPaymentAlreadyCancelledImpUid() {
System.err.println(">>> testPartialCancelPaymentAlreadyCancelledImpUid");
client = new IamportClient(" [ REST API Key ] ", " [ Rest API Secret ] ");
String test_already_cancelled_imp_uid = "imp_136646192122";
CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true, BigDecimal.valueOf(50)); //imp_uid를 통한 50원 부분취소
try {
IamportResponse<Payment> payment_response = client.cancelPaymentByImpUid(cancel_data);
System.err.println(payment_response.getMessage());
System.err.println("getMessage : " + payment_response.getMessage());
System.err.println("getResponse : " + payment_response.getResponse());
setPayment(payment_response.getResponse());
} catch (IamportResponseException e) {
System.err.println(e.getMessage());
switch (e.getHttpStatusCode()) {
case 401:
//TODO
break;
case 500:
//TODO
break;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
|
@@실행결과
1)
>>> testPartialCancelPaymentAlreadyCancelledImpUid
취소할 결제건이 존재하지 않습니다.
getMessage : 취소할 결제건이 존재하지 않습니다.
getResponse : null
===== Payment =====
2)
>>> testPartialCancelPaymentAlreadyCancelledImpUid
null
getMessage : null
getResponse : com.siot.IamportRestClient.response.Payment@61c953eb
===== Payment =====
____getApplyNum :
____getBankCode : null
____getBankName : null
____getBuyerAddr : 주소
____getBuyerEmail : email@email.com
____getBuyerName : 이름
____getBuyerPostcode : 우편번호
____getBuyerTel : 전화번호
____getCancelReason : 취소요청api
____getCardCode : null
____getCardName : null
____getCardNumber : null
____getCardQuota : 0
____getCardType : 0
____getChannel : pc
____getCurrency : KRW
____getCustomData : null
____getCustomerUid : null
____getCustomerUidUsage : null
____getEmbPgProvider : null
____getFailReason : null
____getImpUid : imp_136646192122
____getMerchantUid : nobody_1707897645494
____getName : 주문상품이름
____getPayMethod : point
____getPgProvider : kakaopay
____getPgTid : T5cc732e196d5d205936
____getReceiptUrl : https://mockup-pg-web.kakao.com/v1/confirmation/p/T5cc732e196d5d205936/81f949266ab9eaacca9c13323396be5ab9553a620c85d7b641d88b2ad547642f
____getStartedAt : 1707897646
____getStatus : cancelled
____getVbankCode : null
____getVbankHolder : null
____getVbankIssuedAt : 0
____getAmount : 100
____getCancelAmount : 50
____getPaidAt : Wed Feb 14 17:01:00 KST 2024
=================
-- canclePaymentByMerchantUid()
---- merchantUid를 이용한 부분 결제 취소
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
|
public void testPartialCancelPaymentAlreadyCancelledMerchantUid() {
System.err.println(">>> testPartialCancelPaymentAlreadyCancelledMerchantUid");
client = new IamportClient(" [ REST API Key ] ", " [ Rest API Secret ] ");
String test_already_cancelled_merchant_uid = "nobody_1707897645494";
CancelData cancel_data = new CancelData(test_already_cancelled_merchant_uid, false, BigDecimal.valueOf(10)); //merchant_uid를 통한 500원 부분취소
try {
IamportResponse<Payment> payment_response = client.cancelPaymentByImpUid(cancel_data);
System.err.println(payment_response.getMessage());
System.err.println("getMessage : " + payment_response.getMessage());
System.err.println("getResponse : " + payment_response.getResponse());
setPayment(payment_response.getResponse());
} catch (IamportResponseException e) {
System.err.println(e.getMessage());
switch (e.getHttpStatusCode()) {
case 401:
//TODO
break;
case 500:
//TODO
break;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
|
@@실행결과
1)
>>> testPartialCancelPaymentAlreadyCancelledMerchantUid
취소할 결제건이 존재하지 않습니다.
getMessage : 취소할 결제건이 존재하지 않습니다.
getResponse : null
===== Payment =====
2)
>>> testPartialCancelPaymentAlreadyCancelledMerchantUid
null
getMessage : null
getResponse : com.siot.IamportRestClient.response.Payment@500ebc6
===== Payment =====
____getApplyNum :
____getBankCode : null
____getBankName : null
____getBuyerAddr : 주소
____getBuyerEmail : email@email.com
____getBuyerName : 이름
____getBuyerPostcode : 우편번호
____getBuyerTel : 전화번호
____getCancelReason : 취소요청api
____getCardCode : null
____getCardName : null
____getCardNumber : null
____getCardQuota : 0
____getCardType : 0
____getChannel : pc
____getCurrency : KRW
____getCustomData : null
____getCustomerUid : null
____getCustomerUidUsage : null
____getEmbPgProvider : null
____getFailReason : null
____getImpUid : imp_136646192122
____getMerchantUid : nobody_1707897645494
____getName : 주문상품이름
____getPayMethod : point
____getPgProvider : kakaopay
____getPgTid : T5cc732e196d5d205936
____getReceiptUrl : https://mockup-pg-web.kakao.com/v1/confirmation/p/T5cc732e196d5d205936/81f949266ab9eaacca9c13323396be5ab9553a620c85d7b641d88b2ad547642f
____getStartedAt : 1707897646
____getStatus : cancelled
____getVbankCode : null
____getVbankHolder : null
____getVbankIssuedAt : 0
____getAmount : 100
____getCancelAmount : 70
____getPaidAt : Wed Feb 14 17:01:00 KST 2024
=================
반응형