hyeonga_code

[JAVA/SPRING] payciUpdateOrderStatus(), againPayment(), certificationByImpUid()_포트원/아임포트 결제 적용 IamportClient<> 이해하기 본문

Spring

[JAVA/SPRING] payciUpdateOrderStatus(), againPayment(), certificationByImpUid()_포트원/아임포트 결제 적용 IamportClient<> 이해하기

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

2024.02.14

portone에서 제공하는 github의 IamportRestTest.java

https://github.com/iamport/iamport-rest-client-java/blob/master/src/test/java/com/siot/IamportRestClient/IamportRestTest.java

 

직접 실행해보면서 어떻게 돌아가는지 확인해봄

 

-- payciUpdateOrderStatus()

---- 페이코 결제의 주문 상태를 업데이트하는 테스트 코드

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
    public void testPaycoUpdateOrderStatus() {
        System.err.println(">>> testPaycoUpdateOrderStatus");
        client = new IamportClient(" [ REST API Key ] "" [ Rest API Secret ] ");
        String test_api_key = [ REST API Key ] ";
        String test_api_secret = " [ Rest API Secret ] ";
        IamportPaycoClient payco = new IamportPaycoClient(test_api_key, test_api_secret);
 
        //유효하지 않은 status
        try {
            IamportResponse<OrderStatus> payment_response = payco.updateOrderStatus("imp_436389624339""asdf");
 
            payment_response = payco.updateOrderStatus("imp_436389624339""CANCELED");
            System.err.println("getMessage : " + payment_response.getMessage());
            System.err.println("getResponse : " + payment_response.getResponse());
            OrderStatus result = payment_response.getResponse();
            System.err.println("_____getStatus : " + result.getStatus());
        } 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();
        }
    }

 

@@실행결과

-- 페이코는 연동하지 않아 확인하지 못함

>>> testPaycoUpdateOrderStatus
파라미터 정보가 유효하지 않습니다. 
orderProductStatus field reject, 
expected OrderProductStatusType{
	PAYMENT_WAITNG,PAYED,DELIVERY_READY,
    DELIVERY_START,
    DELIVERING,DELIVERY_COMPLETE,
    CANCEL_REQUEST,
    EXCHANGE_WAIT
    ,EXCHANGE_COMPLETE,
    RETURN_WAIT,
    RETURN_COMPLETE,
    PURCHASE_DECISION,
    OUTSELLER_REFUND,
    CANCELED
    }, but [asdf]

 

 

-- certificationByImpUid()

---- 해당 결제를 검증하고 검증 결과를 반환하는 메소드

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
    public void testCertificationByImpUid() {
        System.err.println(">>> testCertificationByImpUid");
        client = new IamportClient("imp_apikey""ekKoeW8RyKuT0zgaZsUtXXTLQ4AhPFW3ZGseDA6bkA5lamv9OqDMnxyeB9wqOsuO9W3Mx9YSJ4dTqJ3f");
//        String test_imp_uid = "imp_339323965143";
        // origin 검증을 위해 is not null인 imp_uid로 변경
        String test_imp_uid = "imp_992536806181";
 
        try {
            IamportResponse<Certification> certification_response = client.certificationByImpUid(test_imp_uid);
            System.err.println("getMessage : " + certification_response.getMessage());
            System.err.println("getResponse : " + certification_response.getResponse());
            Certification result = certification_response.getResponse();
            System.err.println("_____getCarrier : " + result.getCarrier());
            System.err.println("_____getGender : " + result.getGender());
            System.err.println("_____getImpUid : " + result.getImpUid());
            System.err.println("_____getMerchantUid : " + result.getMerchantUid());
            System.err.println("_____getName : " + result.getName());
            System.err.println("_____getOrigin : " + result.getOrigin());
            System.err.println("_____getPgProvider : " + result.getPgProvider());
            System.err.println("_____getPgTid : " + result.getPgTid());
            System.err.println("_____getPhone : " + result.getPhone());
            System.err.println("_____getUniqueInSite : " + result.getUniqueInSite());
            System.err.println("_____getUniqueInSite : " + result.getUniqueInSite());
            System.err.println("_____getUniqueKey : " + result.getUniqueKey());
            System.err.println("_____getBirth : " + result.getBirth());
            System.err.println("_____getCertifiedAt : " + result.getCertifiedAt());
        } 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)
>>> testCertificationByImpUid
인증결과가 존재하지 않습니다.

2)
>>> testCertificationByImpUid
getMessage : null
getResponse : com.siot.IamportRestClient.response.Certification@59837be3
_____getCarrier : null
_____getGender : null
_____getImpUid : imp_992536806181
_____getMerchantUid : merchant_1545326536779
_____getName : null
_____getOrigin : http://kicc.iamport.kr/pages/certi
_____getPgProvider : danal
_____getPgTid : null
_____getPhone : null
_____getUniqueInSite : null
_____getUniqueInSite : null
_____getUniqueKey : null
_____getBirth : Thu Jan 01 09:00:00 KST 1970
_____getCertifiedAt : Thu Jan 01 09:00:00 KST 1970

 

 

-- postEscrowLogis()

---- 에스크로 배송 정보를 등록하고 등록된 배송 정보를 반환

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 testPostEscrowLogis() {
        System.err.println(">>> testPostEscrowLogis");
        client = new IamportClient("imp_apikey""ekKoeW8RyKuT0zgaZsUtXXTLQ4AhPFW3ZGseDA6bkA5lamv9OqDMnxyeB9wqOsuO9W3Mx9YSJ4dTqJ3f");
        String imp_uid = "imp_205852873956";
 
        EscrowLogisPersonData sender = new EscrowLogisPersonData("가맹점""02-1234-1234""서울 용산구""12345");
        EscrowLogisPersonData receiver = new EscrowLogisPersonData("홍길동""010-1234-5678""서울 강남구 삼성동""98765");
 
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, 2018);
        cal.set(Calendar.MONTH, Calendar.JANUARY);
        cal.set(Calendar.DAY_OF_MONTH, 03);
 
        EscrowLogisInvoiceData invoice = new EscrowLogisInvoiceData("LOGEN""123456789", cal.getTime()); //택배사 코드표 : https://github.com/iamport/iamport-manual/blob/master/RESTAPI/logis.md
 
        try {
            IamportResponse<EscrowLogisInvoice> response = client.postEscrowLogis(imp_uid, new EscrowLogisData(invoice, receiver, sender));
 
            System.err.println("getMessage : " + response.getMessage());
            System.err.println("getResponse : " + response.getResponse());
            EscrowLogisInvoice result = response.getResponse();
            System.err.println("EscrowLogisInvoice : " + result);
        } catch (IamportResponseException e) {
            System.err.println(e.getMessage());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

 

 

@@실행결과

---- 샘플과 개인 key로 시도해보았으나 성공하지 못함

1) 
>>> testPostEscrowLogis
존재하지 않는 결제정보입니다.

2) 
>>> testPostEscrowLogis
해당거래건은 배송정보를 등록할 수 없습니다.

3)
>>> testPostEscrowLogis
현재 지원되지 않는 PG사입니다.

 

 

-- againPayment()

---- 결제가 실패한 건에 대해 재결제를 요청하는 메소드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    public void testAgainPayment() throws IOException, IamportResponseException {
        System.err.println(">>> testAgainPayment");
        client = new IamportClient(" [ REST API Key ] "" [ Rest API Secret ] ");
        String test_customer_uid = "customer_123456";
        CardInfo card = new CardInfo("1234123412341234""201901""801231""00");
 
        AgainPaymentData again_data = new AgainPaymentData(test_customer_uid, getRandomMerchantUid(), BigDecimal.valueOf(1005));
        again_data.setExtra(new ExtraNaverUseCfmEntry("20200101"));
        ExtraNaverUseCfmEntry extra = again_data.getExtra();
        IamportResponse<Payment> payment_response = client.againPayment(again_data);
        System.err.println("getMessage : " + payment_response.getMessage());
        System.err.println("getResponse : " + payment_response.getResponse());
        setPayment(payment_response.getResponse());
    }

 

@@실행결과

>>> testAgainPayment
getMessage : 등록되지 않은 구매자입니다.
getResponse : null
===== Payment =====

 

 

-- getPaymentSchedule()

---- 정기결제 목록을 가져오고 가져온 정기결제 목록을 반환

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    public void testGetPaymentSchedule() throws IOException, IamportResponseException {
        System.err.println(">>> testGetPaymentSchedule");
        client = new IamportClient(" [ REST API Key ] ""[ Rest API Secret ]");
 
        GetScheduleData getScheduleData = new GetScheduleData(16434978921648595492null120);
 
        IamportResponse<ScheduleList> schedule_response = client.getPaymentSchedule(getScheduleData);
        System.err.println(schedule_response.getResponse().getList().get(0).getCustomerUid());
        System.err.println("getMessage : " + schedule_response.getMessage());
        System.err.println("getResponse : " + schedule_response.getResponse());
        
        ScheduleList result = schedule_response.getResponse();
        System.err.println("_____getNext : " + result.getNext());
        System.err.println("_____getPrevious : " + result.getPrevious());
        System.err.println("_____getTotal : " + result.getTotal());
        System.err.println("_____getList : " + result.getList());
    }

 

 

@@실행결과

>>> testGetPaymentSchedule

 

반응형