From 66d72cc2125e0767e47da7d4ac0098329e4f9f85 Mon Sep 17 00:00:00 2001 From: Giwon Date: Fri, 25 Mar 2022 09:02:21 +0900 Subject: [PATCH 1/4] feat : add card-info CVS --- .../com/siot/IamportRestClient/request/CardInfo.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/siot/IamportRestClient/request/CardInfo.java b/src/main/java/com/siot/IamportRestClient/request/CardInfo.java index 521c1de..8ab2a91 100644 --- a/src/main/java/com/siot/IamportRestClient/request/CardInfo.java +++ b/src/main/java/com/siot/IamportRestClient/request/CardInfo.java @@ -6,6 +6,7 @@ public class CardInfo { protected String expiry; protected String birth; protected String pwd_2digit; + protected String cvs; public CardInfo(String card_number, String expiry, String birth, String pwd_2digit) { this.card_number = card_number; @@ -13,5 +14,12 @@ public CardInfo(String card_number, String expiry, String birth, String pwd_2dig this.birth = birth; this.pwd_2digit = pwd_2digit; } - + + public CardInfo(String card_number, String expiry, String birth, String pwd_2digit, String cvs) { + this.card_number = card_number; + this.expiry = expiry; + this.birth = birth; + this.pwd_2digit = pwd_2digit; + this.cvs = cvs; + } } From 14466d2928ae3f7a2d2f13847f2f61a906f608a3 Mon Sep 17 00:00:00 2001 From: Giwon Date: Fri, 25 Mar 2022 09:03:04 +0900 Subject: [PATCH 2/4] feat : add paymentwall parameter --- .../request/AgainPaymentData.java | 14 ++ .../request/OnetimePaymentData.java | 207 ++++++++++-------- 2 files changed, 131 insertions(+), 90 deletions(-) diff --git a/src/main/java/com/siot/IamportRestClient/request/AgainPaymentData.java b/src/main/java/com/siot/IamportRestClient/request/AgainPaymentData.java index 9898982..212b690 100644 --- a/src/main/java/com/siot/IamportRestClient/request/AgainPaymentData.java +++ b/src/main/java/com/siot/IamportRestClient/request/AgainPaymentData.java @@ -19,6 +19,9 @@ public class AgainPaymentData { @SerializedName("vat") private BigDecimal vat; + @SerializedName("currency") + private BigDecimal currency; + @SerializedName("name") private String name; @@ -37,6 +40,9 @@ public class AgainPaymentData { @SerializedName("buyer_postcode") private String buyer_postcode; + @SerializedName("browser_ip") + private String browser_ip; + @SerializedName("card_quota") private int card_quota; @@ -120,4 +126,12 @@ public ExtraNaverUseCfmEntry getExtra() { public void setExtra(ExtraNaverUseCfmEntry extra) { this.extra = extra; } + + public void setBrowser_ip(String browser_ip) { + this.browser_ip = browser_ip; + } + + public void setCurrency(BigDecimal currency) { + this.currency = currency; + } } diff --git a/src/main/java/com/siot/IamportRestClient/request/OnetimePaymentData.java b/src/main/java/com/siot/IamportRestClient/request/OnetimePaymentData.java index d936178..24f33eb 100644 --- a/src/main/java/com/siot/IamportRestClient/request/OnetimePaymentData.java +++ b/src/main/java/com/siot/IamportRestClient/request/OnetimePaymentData.java @@ -6,94 +6,121 @@ public class OnetimePaymentData { - @SerializedName("merchant_uid") - private String merchant_uid; - - @SerializedName("amount") - private BigDecimal amount; - - @SerializedName("vat") - private BigDecimal vat; - - @SerializedName("customer_uid") - private String customer_uid; - - @SerializedName("name") - private String name; - - @SerializedName("buyer_name") - private String buyer_name; - - @SerializedName("buyer_email") - private String buyer_email; - - @SerializedName("buyer_tel") - private String buyer_tel; - - @SerializedName("buyer_addr") - private String buyer_addr; - - @SerializedName("buyer_postcode") - private String buyer_postcode; - - @SerializedName("card_quota") - private int card_quota; - - @SerializedName("card_number") - protected String card_number; - - @SerializedName("expiry") - protected String expiry; - - @SerializedName("birth") - protected String birth; - - @SerializedName("pwd_2digit") - protected String pwd_2digit; - - public OnetimePaymentData(String merchant_uid, BigDecimal amount, CardInfo card) { - this.merchant_uid = merchant_uid; - this.amount = amount; - this.card_number = card.card_number; - this.expiry = card.expiry; - this.birth = card.birth; - this.pwd_2digit = card.pwd_2digit; - } - - public void setVat(BigDecimal vat) { - this.vat = vat; - } - - public void setCustomer_uid(String customer_uid) { - this.customer_uid = customer_uid; - } - - public void setName(String name) { - this.name = name; - } - - public void setBuyerName(String buyer_name) { - this.buyer_name = buyer_name; - } - - public void setBuyerEmail(String buyer_email) { - this.buyer_email = buyer_email; - } - - public void setBuyerTel(String buyer_tel) { - this.buyer_tel = buyer_tel; - } - - public void setBuyerAddr(String buyer_addr) { - this.buyer_addr = buyer_addr; - } - - public void setBuyerPostcode(String buyer_postcode) { - this.buyer_postcode = buyer_postcode; - } - - public void setCardQuota(int card_quota) { - this.card_quota = card_quota; - } - + @SerializedName("merchant_uid") + private String merchant_uid; + + @SerializedName("amount") + private BigDecimal amount; + + @SerializedName("vat") + private BigDecimal vat; + + @SerializedName("customer_uid") + private String customer_uid; + + @SerializedName("currency") + private BigDecimal currency; + + @SerializedName("name") + private String name; + + @SerializedName("buyer_name") + private String buyer_name; + + @SerializedName("buyer_email") + private String buyer_email; + + @SerializedName("buyer_tel") + private String buyer_tel; + + @SerializedName("buyer_addr") + private String buyer_addr; + + @SerializedName("buyer_postcode") + private String buyer_postcode; + + @SerializedName("browser_ip") + private String browser_ip; + + @SerializedName("secure_3d_charge_id") + private String secure_3d_charge_id; + + @SerializedName("secure_3d_token") + private String secure_3d_token; + + @SerializedName("card_quota") + private int card_quota; + + @SerializedName("card_number") + protected String card_number; + + @SerializedName("expiry") + protected String expiry; + + @SerializedName("birth") + protected String birth; + + @SerializedName("pwd_2digit") + protected String pwd_2digit; + + public OnetimePaymentData(String merchant_uid, BigDecimal amount, CardInfo card) { + this.merchant_uid = merchant_uid; + this.amount = amount; + this.card_number = card.card_number; + this.expiry = card.expiry; + this.birth = card.birth; + this.pwd_2digit = card.pwd_2digit; + } + + public void setVat(BigDecimal vat) { + this.vat = vat; + } + + public void setCustomer_uid(String customer_uid) { + this.customer_uid = customer_uid; + } + + public void setName(String name) { + this.name = name; + } + + public void setBuyerName(String buyer_name) { + this.buyer_name = buyer_name; + } + + public void setBuyerEmail(String buyer_email) { + this.buyer_email = buyer_email; + } + + public void setBuyerTel(String buyer_tel) { + this.buyer_tel = buyer_tel; + } + + public void setBuyerAddr(String buyer_addr) { + this.buyer_addr = buyer_addr; + } + + public void setBuyerPostcode(String buyer_postcode) { + this.buyer_postcode = buyer_postcode; + } + + public void setCardQuota(int card_quota) { + this.card_quota = card_quota; + } + + public void setCurrency(BigDecimal currency) { + this.currency = currency; + } + + public void setBrowser_ip(String browser_ip) { + this.browser_ip = browser_ip; + } + + public void setSecure_3d_charge_id(String secure_3d_charge_id) { + this.secure_3d_charge_id = secure_3d_charge_id; + } + + public void setSecure_3d_token(String secure_3d_token) { + this.secure_3d_token = secure_3d_token; + } } From 119f0b6fa94e959faef3e5bc92d97de11db2b5d8 Mon Sep 17 00:00:00 2001 From: Giwon Date: Wed, 30 Mar 2022 16:40:44 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix=20:=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/siot/IamportRestClient/request/CardInfo.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/siot/IamportRestClient/request/CardInfo.java b/src/main/java/com/siot/IamportRestClient/request/CardInfo.java index 8ab2a91..9f72520 100644 --- a/src/main/java/com/siot/IamportRestClient/request/CardInfo.java +++ b/src/main/java/com/siot/IamportRestClient/request/CardInfo.java @@ -6,7 +6,7 @@ public class CardInfo { protected String expiry; protected String birth; protected String pwd_2digit; - protected String cvs; + protected String cvc; public CardInfo(String card_number, String expiry, String birth, String pwd_2digit) { this.card_number = card_number; @@ -15,11 +15,11 @@ public CardInfo(String card_number, String expiry, String birth, String pwd_2dig this.pwd_2digit = pwd_2digit; } - public CardInfo(String card_number, String expiry, String birth, String pwd_2digit, String cvs) { + public CardInfo(String card_number, String expiry, String birth, String pwd_2digit, String cvc) { this.card_number = card_number; this.expiry = expiry; this.birth = birth; this.pwd_2digit = pwd_2digit; - this.cvs = cvs; + this.cvc = cvc; } } From c2ee29b3999fcf366f620f2b2449d28e70a9d42f Mon Sep 17 00:00:00 2001 From: Giwon Date: Wed, 30 Mar 2022 17:51:17 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat=20:=20schedule=20Get=20Method=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20schedule=20Response=20Object?= =?UTF-8?q?=20parameter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/siot/IamportRestClient/Iamport.java | 42 +- .../siot/IamportRestClient/IamportClient.java | 16 + .../request/GetScheduleData.java | 69 + .../IamportRestClient/response/Schedule.java | 253 ++- .../response/ScheduleList.java | 60 + .../IamportRestClient/IamportRestTest.java | 1495 +++++++++-------- 6 files changed, 1142 insertions(+), 793 deletions(-) create mode 100644 src/main/java/com/siot/IamportRestClient/request/GetScheduleData.java create mode 100644 src/main/java/com/siot/IamportRestClient/response/ScheduleList.java diff --git a/src/main/java/com/siot/IamportRestClient/Iamport.java b/src/main/java/com/siot/IamportRestClient/Iamport.java index 45337b6..0eb8c7d 100644 --- a/src/main/java/com/siot/IamportRestClient/Iamport.java +++ b/src/main/java/com/siot/IamportRestClient/Iamport.java @@ -10,6 +10,7 @@ import com.siot.IamportRestClient.response.naver.NaverProductOrder; import com.siot.IamportRestClient.response.naver.NaverReview; +import org.junit.runners.Parameterized; import retrofit2.Call; import retrofit2.http.*; @@ -18,25 +19,25 @@ public interface Iamport { @POST("/users/getToken") Call> token( @Body AuthData auth); - + @GET("/payments/{imp_uid}/balance") Call> balance_by_imp_uid( @Header("Authorization") String token, @Path("imp_uid") String imp_uid ); - + @GET("/payments/{imp_uid}") Call> payment_by_imp_uid( @Header("Authorization") String token, @Path("imp_uid") String imp_uid ); - + @GET("/payments/status/{payment_status}") Call>> payments_by_status( @Header("Authorization") String token, @Path("payment_status") String payment_status ); - + @POST("/payments/cancel") Call> cancel_payment( @Header("Authorization") String token, @@ -69,25 +70,36 @@ Call> post_billing_customer( @Path("customer_uid") String customer_uid, @Body BillingCustomerData billing_data ); - + @POST("/subscribe/payments/onetime") Call> onetime_payment( @Header("Authorization") String token, @Body OnetimePaymentData onetime_data ); - + @POST("/subscribe/payments/again") Call> again_payment( @Header("Authorization") String token, @Body AgainPaymentData again_data ); - + + @GET("/subscribe/payments/schedule") + Call> get_payment_schedule( + @Header("Authorization") String token, +// @Query("_token") String token, + @Query("schedule_from") int schedule_from, + @Query("schedule_to") int schedule_to, + @Query("schedule_status") String schedule_status, + @Query("page") int page, + @Query("limit") int limit + ); + @POST("/subscribe/payments/schedule") Call>> schedule_subscription( @Header("Authorization") String token, @Body ScheduleData schedule_data ); - + @POST("/subscribe/payments/unschedule") Call>> unschedule_subscription( @Header("Authorization") String token, @@ -99,14 +111,14 @@ Call> get_billing_customer( @Header("Authorization") String token, @Path("customer_uid") String customer_uid ); - + /* 본인인증 결과 (certification result) */ @GET("/certifications/{imp_uid}") Call> certification_by_imp_uid( @Header("Authorization") String token, @Path("imp_uid") String imp_uid ); - + @POST("/escrows/logis/{imp_uid}") Call> post_escrow_logis( @Header("Authorization") String token, @@ -119,32 +131,32 @@ Call>> naver_product_orders( @Header("Authorization") String token, @Path("imp_uid") String imp_uid ); - + @GET("/naver/product-orders/{product_order_id}") Call> naver_single_product_order( @Header("Authorization") String token, @Path("product_order_id") String product_order_id ); - + @GET("/naver/reviews") Call>> naver_reviews( @Header("Authorization") String token ); - + @POST("/payments/{imp_uid}/naver/cancel") Call>> naver_cancel( @Header("Authorization") String token, @Path("imp_uid") String imp_uid, @Body NaverCancelData naver_cancel_data ); - + @POST("/payments/{imp_uid}/naver/ship") Call>> naver_ship( @Header("Authorization") String token, @Path("imp_uid") String imp_uid, @Body NaverShipData naver_ship_data ); - + @POST("/payments/{imp_uid}/naver/place") Call>> naver_place( @Header("Authorization") String token, diff --git a/src/main/java/com/siot/IamportRestClient/IamportClient.java b/src/main/java/com/siot/IamportRestClient/IamportClient.java index f4c5d66..e4ca5d6 100644 --- a/src/main/java/com/siot/IamportRestClient/IamportClient.java +++ b/src/main/java/com/siot/IamportRestClient/IamportClient.java @@ -179,6 +179,22 @@ public IamportResponse againPayment(AgainPaymentData againData) throws return response.body(); } + public IamportResponse getPaymentSchedule(GetScheduleData getScheduleData) throws IamportResponseException, IOException { + AccessToken auth = getAuth().getResponse(); + Call> call = this.iamport.get_payment_schedule(auth.getToken(), + getScheduleData.getSchedule_from(), + getScheduleData.getSchedule_to(), + getScheduleData.getSchedule_status(), + getScheduleData.getPage(), + getScheduleData.getLimit() + ); + + Response> response = call.execute(); + if ( !response.isSuccessful() ) throw new IamportResponseException( getExceptionMessage(response), new HttpException(response) ); + + return response.body(); + } + public IamportResponse> subscribeSchedule(ScheduleData scheduleData) throws IamportResponseException, IOException { AccessToken auth = getAuth().getResponse(); Call>> call = this.iamport.schedule_subscription(auth.getToken(), scheduleData); diff --git a/src/main/java/com/siot/IamportRestClient/request/GetScheduleData.java b/src/main/java/com/siot/IamportRestClient/request/GetScheduleData.java new file mode 100644 index 0000000..69f0efc --- /dev/null +++ b/src/main/java/com/siot/IamportRestClient/request/GetScheduleData.java @@ -0,0 +1,69 @@ +package com.siot.IamportRestClient.request; + +import com.google.gson.annotations.SerializedName; + +public class GetScheduleData { + + @SerializedName("schedule_from") + private int schedule_from; + + @SerializedName("schedule_to") + private int schedule_to; + + @SerializedName("schedule_status") + private String schedule_status; + + @SerializedName("page") + private int page; + + @SerializedName("limit") + private int limit; + + public GetScheduleData(int schedule_from, int schedule_to, String schedule_status, int page, int limit) { + this.schedule_from = schedule_from; + this.schedule_to = schedule_to; + this.schedule_status = schedule_status; + this.page = page; + this.limit = limit; + } + + public int getSchedule_from() { + return schedule_from; + } + + public void setSchedule_from(int schedule_from) { + this.schedule_from = schedule_from; + } + + public int getSchedule_to() { + return schedule_to; + } + + public void setSchedule_to(int schedule_to) { + this.schedule_to = schedule_to; + } + + public String getSchedule_status() { + return schedule_status; + } + + public void setSchedule_status(String schedule_status) { + this.schedule_status = schedule_status; + } + + public int getPage() { + return page; + } + + public void setPage(int page) { + this.page = page; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } +} diff --git a/src/main/java/com/siot/IamportRestClient/response/Schedule.java b/src/main/java/com/siot/IamportRestClient/response/Schedule.java index 89a3219..ddb2c58 100644 --- a/src/main/java/com/siot/IamportRestClient/response/Schedule.java +++ b/src/main/java/com/siot/IamportRestClient/response/Schedule.java @@ -7,39 +7,222 @@ public class Schedule { - @SerializedName("customer_uid") - private String customer_uid; - - @SerializedName("merchant_uid") - private String merchant_uid; - - @SerializedName("schedule_at") - private Date schedule_at; - - @SerializedName("amount") - private BigDecimal amount; - - public Schedule(String customer_uid, String merchant_uid, Date schedule_at, BigDecimal amount) { - this.customer_uid = customer_uid; - this.merchant_uid = merchant_uid; - this.schedule_at = schedule_at; - this.amount = amount; - } - - public String getCustomerUid() { - return customer_uid; - } - - public String getMerchantUid() { - return merchant_uid; - } - - public Date getScheduleAt() { - return schedule_at; - } - - public BigDecimal getAmount() { - return amount; - } - + @SerializedName("customer_uid") + private String customer_uid; + + @SerializedName("merchant_uid") + private String merchant_uid; + + @SerializedName("imp_uid") + private String imp_uid; + + @SerializedName("schedule_at") + private Date schedule_at; + + @SerializedName("executed_at") + private Date executed_at; + + @SerializedName("revoked_at") + private Date revoked_at; + + @SerializedName("amount") + private BigDecimal amount; + + @SerializedName("name") + private String name; + + @SerializedName("buyer_name") + private String buyer_name; + + @SerializedName("buyer_email") + private String buyer_email; + @SerializedName("buyer_tel") + private String buyer_tel; + @SerializedName("buyer_addr") + private String buyer_addr; + @SerializedName("buyer_postcode") + private String buyer_postcode; + @SerializedName("custom_data") + private String custom_data; + @SerializedName("schedule_status") + private String schedule_status; + @SerializedName("payment_status") + private String payment_status; + @SerializedName("fail_reason") + private String fail_reason; + + public Schedule(String customer_uid, String merchant_uid, String imp_uid, Date schedule_at, Date executed_at, Date revoked_at, BigDecimal amount, String name, String buyer_name, String buyer_email, String buyer_tel, String buyer_addr, String buyer_postcode, String custom_data, String schedule_status, String payment_status, String fail_reason) { + this.customer_uid = customer_uid; + this.merchant_uid = merchant_uid; + this.imp_uid = imp_uid; + this.schedule_at = schedule_at; + this.executed_at = executed_at; + this.revoked_at = revoked_at; + this.amount = amount; + this.name = name; + this.buyer_name = buyer_name; + this.buyer_email = buyer_email; + this.buyer_tel = buyer_tel; + this.buyer_addr = buyer_addr; + this.buyer_postcode = buyer_postcode; + this.custom_data = custom_data; + this.schedule_status = schedule_status; + this.payment_status = payment_status; + this.fail_reason = fail_reason; + } + + public Schedule(String customer_uid, String merchant_uid, Date schedule_at, BigDecimal amount) { + this.customer_uid = customer_uid; + this.merchant_uid = merchant_uid; + this.schedule_at = schedule_at; + this.amount = amount; + } + + public String getCustomerUid() { + return customer_uid; + } + + public String getMerchantUid() { + return merchant_uid; + } + + public Date getScheduleAt() { + return schedule_at; + } + + public BigDecimal getAmount() { + return amount; + } + + public String getCustomer_uid() { + return customer_uid; + } + + public void setCustomer_uid(String customer_uid) { + this.customer_uid = customer_uid; + } + + public String getMerchant_uid() { + return merchant_uid; + } + + public void setMerchant_uid(String merchant_uid) { + this.merchant_uid = merchant_uid; + } + + public String getImp_uid() { + return imp_uid; + } + + public void setImp_uid(String imp_uid) { + this.imp_uid = imp_uid; + } + + public Date getSchedule_at() { + return schedule_at; + } + + public void setSchedule_at(Date schedule_at) { + this.schedule_at = schedule_at; + } + + public Date getExecuted_at() { + return executed_at; + } + + public void setExecuted_at(Date executed_at) { + this.executed_at = executed_at; + } + + public Date getRevoked_at() { + return revoked_at; + } + + public void setRevoked_at(Date revoked_at) { + this.revoked_at = revoked_at; + } + + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBuyer_name() { + return buyer_name; + } + + public void setBuyer_name(String buyer_name) { + this.buyer_name = buyer_name; + } + + public String getBuyer_email() { + return buyer_email; + } + + public void setBuyer_email(String buyer_email) { + this.buyer_email = buyer_email; + } + + public String getBuyer_tel() { + return buyer_tel; + } + + public void setBuyer_tel(String buyer_tel) { + this.buyer_tel = buyer_tel; + } + + public String getBuyer_addr() { + return buyer_addr; + } + + public void setBuyer_addr(String buyer_addr) { + this.buyer_addr = buyer_addr; + } + + public String getBuyer_postcode() { + return buyer_postcode; + } + + public void setBuyer_postcode(String buyer_postcode) { + this.buyer_postcode = buyer_postcode; + } + + public String getCustom_data() { + return custom_data; + } + + public void setCustom_data(String custom_data) { + this.custom_data = custom_data; + } + + public String getSchedule_status() { + return schedule_status; + } + + public void setSchedule_status(String schedule_status) { + this.schedule_status = schedule_status; + } + + public String getPayment_status() { + return payment_status; + } + + public void setPayment_status(String payment_status) { + this.payment_status = payment_status; + } + + public String getFail_reason() { + return fail_reason; + } + + public void setFail_reason(String fail_reason) { + this.fail_reason = fail_reason; + } } diff --git a/src/main/java/com/siot/IamportRestClient/response/ScheduleList.java b/src/main/java/com/siot/IamportRestClient/response/ScheduleList.java new file mode 100644 index 0000000..fe316fa --- /dev/null +++ b/src/main/java/com/siot/IamportRestClient/response/ScheduleList.java @@ -0,0 +1,60 @@ +package com.siot.IamportRestClient.response; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class ScheduleList { + @SerializedName("total") + private int total; + + @SerializedName("previous") + private int previous; + + + @SerializedName("next") + private int next; + + + @SerializedName("list") + private List list; + + public ScheduleList(int total, int previous, int next, List list) { + this.total = total; + this.previous = previous; + this.next = next; + this.list = list; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } + + public int getPrevious() { + return previous; + } + + public void setPrevious(int previous) { + this.previous = previous; + } + + public int getNext() { + return next; + } + + public void setNext(int next) { + this.next = next; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } +} diff --git a/src/test/java/com/siot/IamportRestClient/IamportRestTest.java b/src/test/java/com/siot/IamportRestClient/IamportRestTest.java index 1dbafea..5d32561 100644 --- a/src/test/java/com/siot/IamportRestClient/IamportRestTest.java +++ b/src/test/java/com/siot/IamportRestClient/IamportRestTest.java @@ -32,704 +32,704 @@ * Unit test for simple App. */ public class IamportRestTest { - - IamportClient client; - - private IamportClient getNaverTestClient() { - String test_api_key = "5978210787555892"; - String test_api_secret = "9e75ulp4f9Wwj0i8MSHlKFA9PCTcuMYE15Kvr9AHixeCxwKkpsFa7fkWSd9m0711dLxEV7leEAQc6Bxv"; - - return new IamportClient(test_api_key, test_api_secret); - } - - private IamportClient getBillingTestClient() { - String test_api_key = "7544324362787472"; - String test_api_secret = "9frnPjLAQe3evvAaJl3xLOODfO3yBk7LAy9pRV0H93VEzwPjRSQDHFhWtku5EBRea1E1WEJ6IEKhbAA3"; - - return new IamportClient(test_api_key, test_api_secret); - } - - @Before - public void setup() { - String test_api_key = "imp_apikey"; - String test_api_secret = "ekKoeW8RyKuT0zgaZsUtXXTLQ4AhPFW3ZGseDA6bkA5lamv9OqDMnxyeB9wqOsuO9W3Mx9YSJ4dTqJ3f"; - client = new IamportClient(test_api_key, test_api_secret); - } - - @Test - public void testGetToken() { - try { - IamportResponse auth_response = client.getAuth(); - - assertNotNull(auth_response.getResponse()); - assertNotNull(auth_response.getResponse().getToken()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - //서버 연결 실패 - e.printStackTrace(); - } - } - - @Test - public void testPaymentBalanceByImpUid() { - String test_imp_uid = "imp_011115679124"; - try { - IamportResponse payment_response = client.paymentBalanceByImpUid(test_imp_uid); - - assertNotNull(payment_response.getResponse()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testPaymentByImpUid() { - String test_imp_uid = "imp_448280090638"; - try { - IamportResponse payment_response = client.paymentByImpUid(test_imp_uid); - - assertNotNull(payment_response.getResponse()); - assertEquals(test_imp_uid, payment_response.getResponse().getImpUid()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - String test_imp_uid_cancelled = "imp_138841716839"; - try { - IamportResponse cancelled_response = client.paymentByImpUid(test_imp_uid_cancelled); - - Payment cancelled = cancelled_response.getResponse(); - PaymentCancelDetail[] cancelDetail = cancelled.getCancelHistory(); - - assertEquals(cancelDetail.length, 1); - assertNotNull(cancelDetail[0].getPgTid()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testPaymentsByStatusAll() { - try { - IamportResponse> r_response = client.paymentsByStatus("ready"); - IamportResponse> p_response = client.paymentsByStatus("paid"); - IamportResponse> f_response = client.paymentsByStatus("failed"); - IamportResponse> c_response = client.paymentsByStatus("cancelled"); - IamportResponse> all_response = client.paymentsByStatus("all"); - - assertNotNull(all_response.getResponse()); - assertNotNull(r_response.getResponse()); - assertNotNull(p_response.getResponse()); - assertNotNull(f_response.getResponse()); - assertNotNull(c_response.getResponse()); - - assertTrue(all_response.getResponse().getTotal() == - r_response.getResponse().getTotal() + p_response.getResponse().getTotal() + f_response.getResponse().getTotal() + c_response.getResponse().getTotal()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testCancelPaymentAlreadyCancelledImpUid() { - String test_already_cancelled_imp_uid = "imp_448280090638"; - CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true); //imp_uid를 통한 전액취소 - - try { - IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); - - assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testCancelPaymentChecksumByImpUid() { - String test_already_cancelled_imp_uid = "imp_448280090638"; - CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true); //imp_uid를 통한 전액취소 - cancel_data.setChecksum(BigDecimal.valueOf(500)); // checksum 으로 검증 추가 - - try { - IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); - - assertNull(payment_response.getResponse()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testCancelPaymentAlreadyCancelledMerchantUid() { - String test_already_cancelled_merchant_uid = "merchant_1448280088556"; - CancelData cancel_data = new CancelData(test_already_cancelled_merchant_uid, false); //merchant_uid를 통한 전액취소 - cancel_data.setEscrowConfirmed(true); //에스크로 구매확정 후 취소인 경우 true설정 - - try { - IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); - - assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 - System.out.println(payment_response.getMessage()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testPartialCancelPaymentAlreadyCancelledImpUid() { - String test_already_cancelled_imp_uid = "imp_448280090638"; - CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true, BigDecimal.valueOf(500)); //imp_uid를 통한 500원 부분취소 - - try { - IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); - - assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 - System.out.println(payment_response.getMessage()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testPartialCancelPaymentAlreadyCancelledMerchantUid() { - String test_already_cancelled_merchant_uid = "merchant_1448280088556"; - CancelData cancel_data = new CancelData(test_already_cancelled_merchant_uid, false, BigDecimal.valueOf(500)); //merchant_uid를 통한 500원 부분취소 - - try { - IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); - - assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 - System.out.println(payment_response.getMessage()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - @Test - public void testCancelVbankPaymentAlreadyCancelledImpUid() { - String test_already_cancelled_imp_uid = "imp_1416557733458"; - CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true, BigDecimal.valueOf(500)); //imp_uid를 통한 500원 부분취소 - - try { - IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); - - assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 - System.out.println(payment_response.getMessage()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - @Test - public void testPartialCancelVbankPaymentAlreadyCancelledMerchantUid() { - String test_already_cancelled_merchant_uid = "merchant_1416557727868"; - CancelData cancel_data = new CancelData(test_already_cancelled_merchant_uid, false, BigDecimal.valueOf(500)); //merchant_uid를 통한 500원 부분취소 - - try { - IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); - - assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 - System.out.println(payment_response.getMessage()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - @Test - public void testPaycoUpdateOrderStatus() { - String test_api_key = "2966106337421865"; - String test_api_secret = "rZfEkQvBL6hRaWexFEQQwrrylIHTnSzORPscFYNq54hf1wNHaDyH4ZfqHXj5PTTHJmTokHPpM6FNDsvN"; - IamportPaycoClient payco = new IamportPaycoClient(test_api_key, test_api_secret); - - //유효하지 않은 status - try { - IamportResponse payment_response = payco.updateOrderStatus("imp_436389624339", "asdf"); - assertNull(payment_response); - - payment_response = payco.updateOrderStatus("imp_436389624339", "CANCELED"); - assertEquals(payment_response.getResponse().getStatus(), "CANCELED"); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testCertificationByImpUid() { + + IamportClient client; + + private IamportClient getNaverTestClient() { + String test_api_key = "5978210787555892"; + String test_api_secret = "9e75ulp4f9Wwj0i8MSHlKFA9PCTcuMYE15Kvr9AHixeCxwKkpsFa7fkWSd9m0711dLxEV7leEAQc6Bxv"; + + return new IamportClient(test_api_key, test_api_secret); + } + + private IamportClient getBillingTestClient() { + String test_api_key = "7544324362787472"; + String test_api_secret = "9frnPjLAQe3evvAaJl3xLOODfO3yBk7LAy9pRV0H93VEzwPjRSQDHFhWtku5EBRea1E1WEJ6IEKhbAA3"; + + return new IamportClient(test_api_key, test_api_secret); + } + + @Before + public void setup() { + String test_api_key = "imp_apikey"; + String test_api_secret = "ekKoeW8RyKuT0zgaZsUtXXTLQ4AhPFW3ZGseDA6bkA5lamv9OqDMnxyeB9wqOsuO9W3Mx9YSJ4dTqJ3f"; + client = new IamportClient(test_api_key, test_api_secret); + } + + @Test + public void testGetToken() { + try { + IamportResponse auth_response = client.getAuth(); + + assertNotNull(auth_response.getResponse()); + assertNotNull(auth_response.getResponse().getToken()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + //서버 연결 실패 + e.printStackTrace(); + } + } + + @Test + public void testPaymentBalanceByImpUid() { + String test_imp_uid = "imp_011115679124"; + try { + IamportResponse payment_response = client.paymentBalanceByImpUid(test_imp_uid); + + assertNotNull(payment_response.getResponse()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testPaymentByImpUid() { + String test_imp_uid = "imp_448280090638"; + try { + IamportResponse payment_response = client.paymentByImpUid(test_imp_uid); + + assertNotNull(payment_response.getResponse()); + assertEquals(test_imp_uid, payment_response.getResponse().getImpUid()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + String test_imp_uid_cancelled = "imp_138841716839"; + try { + IamportResponse cancelled_response = client.paymentByImpUid(test_imp_uid_cancelled); + + Payment cancelled = cancelled_response.getResponse(); + PaymentCancelDetail[] cancelDetail = cancelled.getCancelHistory(); + + assertEquals(cancelDetail.length, 1); + assertNotNull(cancelDetail[0].getPgTid()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testPaymentsByStatusAll() { + try { + IamportResponse> r_response = client.paymentsByStatus("ready"); + IamportResponse> p_response = client.paymentsByStatus("paid"); + IamportResponse> f_response = client.paymentsByStatus("failed"); + IamportResponse> c_response = client.paymentsByStatus("cancelled"); + IamportResponse> all_response = client.paymentsByStatus("all"); + + assertNotNull(all_response.getResponse()); + assertNotNull(r_response.getResponse()); + assertNotNull(p_response.getResponse()); + assertNotNull(f_response.getResponse()); + assertNotNull(c_response.getResponse()); + + assertTrue(all_response.getResponse().getTotal() == + r_response.getResponse().getTotal() + p_response.getResponse().getTotal() + f_response.getResponse().getTotal() + c_response.getResponse().getTotal()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testCancelPaymentAlreadyCancelledImpUid() { + String test_already_cancelled_imp_uid = "imp_448280090638"; + CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true); //imp_uid를 통한 전액취소 + + try { + IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); + + assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testCancelPaymentChecksumByImpUid() { + String test_already_cancelled_imp_uid = "imp_448280090638"; + CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true); //imp_uid를 통한 전액취소 + cancel_data.setChecksum(BigDecimal.valueOf(500)); // checksum 으로 검증 추가 + + try { + IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); + + assertNull(payment_response.getResponse()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testCancelPaymentAlreadyCancelledMerchantUid() { + String test_already_cancelled_merchant_uid = "merchant_1448280088556"; + CancelData cancel_data = new CancelData(test_already_cancelled_merchant_uid, false); //merchant_uid를 통한 전액취소 + cancel_data.setEscrowConfirmed(true); //에스크로 구매확정 후 취소인 경우 true설정 + + try { + IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); + + assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 + System.out.println(payment_response.getMessage()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testPartialCancelPaymentAlreadyCancelledImpUid() { + String test_already_cancelled_imp_uid = "imp_448280090638"; + CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true, BigDecimal.valueOf(500)); //imp_uid를 통한 500원 부분취소 + + try { + IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); + + assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 + System.out.println(payment_response.getMessage()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testPartialCancelPaymentAlreadyCancelledMerchantUid() { + String test_already_cancelled_merchant_uid = "merchant_1448280088556"; + CancelData cancel_data = new CancelData(test_already_cancelled_merchant_uid, false, BigDecimal.valueOf(500)); //merchant_uid를 통한 500원 부분취소 + + try { + IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); + + assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 + System.out.println(payment_response.getMessage()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void testCancelVbankPaymentAlreadyCancelledImpUid() { + String test_already_cancelled_imp_uid = "imp_1416557733458"; + CancelData cancel_data = new CancelData(test_already_cancelled_imp_uid, true, BigDecimal.valueOf(500)); //imp_uid를 통한 500원 부분취소 + + try { + IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); + + assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 + System.out.println(payment_response.getMessage()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void testPartialCancelVbankPaymentAlreadyCancelledMerchantUid() { + String test_already_cancelled_merchant_uid = "merchant_1416557727868"; + CancelData cancel_data = new CancelData(test_already_cancelled_merchant_uid, false, BigDecimal.valueOf(500)); //merchant_uid를 통한 500원 부분취소 + + try { + IamportResponse payment_response = client.cancelPaymentByImpUid(cancel_data); + + assertNull(payment_response.getResponse()); // 이미 취소된 거래는 response가 null이다 + System.out.println(payment_response.getMessage()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void testPaycoUpdateOrderStatus() { + String test_api_key = "2966106337421865"; + String test_api_secret = "rZfEkQvBL6hRaWexFEQQwrrylIHTnSzORPscFYNq54hf1wNHaDyH4ZfqHXj5PTTHJmTokHPpM6FNDsvN"; + IamportPaycoClient payco = new IamportPaycoClient(test_api_key, test_api_secret); + + //유효하지 않은 status + try { + IamportResponse payment_response = payco.updateOrderStatus("imp_436389624339", "asdf"); + assertNull(payment_response); + + payment_response = payco.updateOrderStatus("imp_436389624339", "CANCELED"); + assertEquals(payment_response.getResponse().getStatus(), "CANCELED"); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testCertificationByImpUid() { // String test_imp_uid = "imp_339323965143"; - // origin 검증을 위해 is not null인 imp_uid로 변경 - String test_imp_uid = "imp_992536806181"; - - try { - IamportResponse certification_response = client.certificationByImpUid(test_imp_uid); - - assertNotNull(certification_response.getResponse()); - assertEquals(test_imp_uid, certification_response.getResponse().getImpUid()); - assertEquals("http://kicc.iamport.kr/pages/certi", certification_response.getResponse().getOrigin()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testPostEscrowLogis() { - 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 response = client.postEscrowLogis(imp_uid, new EscrowLogisData(invoice, receiver, sender)); - assertNotNull(response.getResponse()); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testGetBillingCustomer() { - IamportClient billingClient = getBillingTestClient(); - String testCustomerUid = "customer_1234"; - - try { - IamportResponse billingCustomerResponse = billingClient.getBillingCustomer(testCustomerUid); - - BillingCustomer billingCustomer = billingCustomerResponse.getResponse(); - - assertEquals(billingCustomer.getCardCode(), CardConstant.CODE_SHINHAN); - assertEquals(billingCustomer.getPgProvider(), "nice"); - assertNotNull(billingCustomer.getCardNumber()); - assertNotNull(billingCustomer.getCardName()); - - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO : API credential 이 잘못된 경우 - break; - case 404 : - //TODO : customer_uid 에 해당되는 빌링등록정보가 존재하지 않는 경우 - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testNaverProductOrders() { - IamportClient naverClient = getNaverTestClient(); - - String impUid = "imp_630554823245"; - - try { - IamportResponse> r = naverClient.naverProductOrders(impUid); - List productOrders = r.getResponse(); - - assertNotNull(productOrders); - assertTrue(!productOrders.isEmpty()); - - String productOrderId = productOrders.get(0).getProductOrderId(); - IamportResponse rr = naverClient.naverProductOrderSingle(productOrderId); - NaverProductOrder firstOrder = rr.getResponse(); - - assertEquals(firstOrder.getProductOrderId(), productOrderId); - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testNaverCancelOrders() { - String impUid = "imp_964732188684"; - NaverCancelData cancelData = new NaverCancelData(NaverCancelData.REASON_SOLD_OUT); - - IamportClient naverClient = getNaverTestClient(); - try { - IamportResponse> r = naverClient.naverCancelOrders(impUid, cancelData); - List productOrders = r.getResponse(); - - for (NaverProductOrder naverProductOrder : productOrders) { - assertEquals(naverProductOrder.getProductOrderStatus(), "CANCELED"); - } - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testNaverShippingOrders() { - Calendar cal = Calendar.getInstance(); - cal.set(2018, 10, 9, 12, 0, 0); - - String impUid = "imp_964732188684"; - NaverShipData shippingData = new NaverShipData(NaverShipData.METHOD_DELIVERY, cal.getTime()); - - IamportClient naverClient = getNaverTestClient(); - try { - IamportResponse> r = naverClient.naverShippingOrders(impUid, shippingData); - List productOrders = r.getResponse(); - - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testNaverRequestReturnOrders() { - String impUid = "imp_964732188684"; - NaverRequestReturnData requestReturnData = new NaverRequestReturnData(NaverRequestReturnData.DELIVERY_METHOD_RETURN_INDIVIDUAL); - requestReturnData.setDeliveryCompany(NaverRequestReturnData.DELIVERY_COMPANY_CH1); //기타 택배 - requestReturnData.setTrackingNumber("1234123412341234"); - - IamportClient naverClient = getNaverTestClient(); - try { - IamportResponse> r = naverClient.naverRequestReturnOrders(impUid, requestReturnData); - List productOrders = r.getResponse(); - - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testNaverApproveReturnOrders() { - String impUid = "imp_964732188684"; - NaverApproveReturnData approveReturnData = new NaverApproveReturnData(); - - IamportClient naverClient = getNaverTestClient(); - try { - IamportResponse> r = naverClient.naverApproveReturnOrders(impUid, approveReturnData); - List productOrders = r.getResponse(); - - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testNaverRejectReturnOrders() { - String impUid = "imp_964732188684"; - NaverRejectReturnData rejectReturnData = new NaverRejectReturnData("죄송합니다만, 주문제작 상품이라 반품이 불가능합니다."); - - IamportClient naverClient = getNaverTestClient(); - try { - IamportResponse> r = naverClient.naverRejectReturnOrders(impUid, rejectReturnData); - List productOrders = r.getResponse(); - - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testNaverWithholdReturnOrders() { - String impUid = "imp_964732188684"; - NaverWithholdReturnData withholdReturnData = new NaverWithholdReturnData("내부 확인 중에 있으니 곧 안내드리겠습니다."); - - IamportClient naverClient = getNaverTestClient(); - try { - IamportResponse> r = naverClient.naverWithholdReturnOrders(impUid, withholdReturnData); - List productOrders = r.getResponse(); - - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testNaverResolveReturnOrders() { - String impUid = "imp_964732188684"; - NaverResolveReturnData resolveReturnData = new NaverResolveReturnData(); - - IamportClient naverClient = getNaverTestClient(); - try { - IamportResponse> r = naverClient.naverResolveReturnOrders(impUid, resolveReturnData); - List productOrders = r.getResponse(); - - } catch (IamportResponseException e) { - System.out.println(e.getMessage()); - - switch(e.getHttpStatusCode()) { - case 401 : - //TODO - break; - case 500 : - //TODO - break; - } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - -// @Test + // origin 검증을 위해 is not null인 imp_uid로 변경 + String test_imp_uid = "imp_992536806181"; + + try { + IamportResponse certification_response = client.certificationByImpUid(test_imp_uid); + + assertNotNull(certification_response.getResponse()); + assertEquals(test_imp_uid, certification_response.getResponse().getImpUid()); + assertEquals("http://kicc.iamport.kr/pages/certi", certification_response.getResponse().getOrigin()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testPostEscrowLogis() { + 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 response = client.postEscrowLogis(imp_uid, new EscrowLogisData(invoice, receiver, sender)); + assertNotNull(response.getResponse()); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testGetBillingCustomer() { + IamportClient billingClient = getBillingTestClient(); + String testCustomerUid = "customer_1234"; + + try { + IamportResponse billingCustomerResponse = billingClient.getBillingCustomer(testCustomerUid); + + BillingCustomer billingCustomer = billingCustomerResponse.getResponse(); + + assertEquals(billingCustomer.getCardCode(), CardConstant.CODE_SHINHAN); + assertEquals(billingCustomer.getPgProvider(), "nice"); + assertNotNull(billingCustomer.getCardNumber()); + assertNotNull(billingCustomer.getCardName()); + + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO : API credential 이 잘못된 경우 + break; + case 404: + //TODO : customer_uid 에 해당되는 빌링등록정보가 존재하지 않는 경우 + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNaverProductOrders() { + IamportClient naverClient = getNaverTestClient(); + + String impUid = "imp_630554823245"; + + try { + IamportResponse> r = naverClient.naverProductOrders(impUid); + List productOrders = r.getResponse(); + + assertNotNull(productOrders); + assertTrue(!productOrders.isEmpty()); + + String productOrderId = productOrders.get(0).getProductOrderId(); + IamportResponse rr = naverClient.naverProductOrderSingle(productOrderId); + NaverProductOrder firstOrder = rr.getResponse(); + + assertEquals(firstOrder.getProductOrderId(), productOrderId); + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNaverCancelOrders() { + String impUid = "imp_964732188684"; + NaverCancelData cancelData = new NaverCancelData(NaverCancelData.REASON_SOLD_OUT); + + IamportClient naverClient = getNaverTestClient(); + try { + IamportResponse> r = naverClient.naverCancelOrders(impUid, cancelData); + List productOrders = r.getResponse(); + + for (NaverProductOrder naverProductOrder : productOrders) { + assertEquals(naverProductOrder.getProductOrderStatus(), "CANCELED"); + } + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNaverShippingOrders() { + Calendar cal = Calendar.getInstance(); + cal.set(2018, 10, 9, 12, 0, 0); + + String impUid = "imp_964732188684"; + NaverShipData shippingData = new NaverShipData(NaverShipData.METHOD_DELIVERY, cal.getTime()); + + IamportClient naverClient = getNaverTestClient(); + try { + IamportResponse> r = naverClient.naverShippingOrders(impUid, shippingData); + List productOrders = r.getResponse(); + + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNaverRequestReturnOrders() { + String impUid = "imp_964732188684"; + NaverRequestReturnData requestReturnData = new NaverRequestReturnData(NaverRequestReturnData.DELIVERY_METHOD_RETURN_INDIVIDUAL); + requestReturnData.setDeliveryCompany(NaverRequestReturnData.DELIVERY_COMPANY_CH1); //기타 택배 + requestReturnData.setTrackingNumber("1234123412341234"); + + IamportClient naverClient = getNaverTestClient(); + try { + IamportResponse> r = naverClient.naverRequestReturnOrders(impUid, requestReturnData); + List productOrders = r.getResponse(); + + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNaverApproveReturnOrders() { + String impUid = "imp_964732188684"; + NaverApproveReturnData approveReturnData = new NaverApproveReturnData(); + + IamportClient naverClient = getNaverTestClient(); + try { + IamportResponse> r = naverClient.naverApproveReturnOrders(impUid, approveReturnData); + List productOrders = r.getResponse(); + + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNaverRejectReturnOrders() { + String impUid = "imp_964732188684"; + NaverRejectReturnData rejectReturnData = new NaverRejectReturnData("죄송합니다만, 주문제작 상품이라 반품이 불가능합니다."); + + IamportClient naverClient = getNaverTestClient(); + try { + IamportResponse> r = naverClient.naverRejectReturnOrders(impUid, rejectReturnData); + List productOrders = r.getResponse(); + + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNaverWithholdReturnOrders() { + String impUid = "imp_964732188684"; + NaverWithholdReturnData withholdReturnData = new NaverWithholdReturnData("내부 확인 중에 있으니 곧 안내드리겠습니다."); + + IamportClient naverClient = getNaverTestClient(); + try { + IamportResponse> r = naverClient.naverWithholdReturnOrders(impUid, withholdReturnData); + List productOrders = r.getResponse(); + + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNaverResolveReturnOrders() { + String impUid = "imp_964732188684"; + NaverResolveReturnData resolveReturnData = new NaverResolveReturnData(); + + IamportClient naverClient = getNaverTestClient(); + try { + IamportResponse> r = naverClient.naverResolveReturnOrders(impUid, resolveReturnData); + List productOrders = r.getResponse(); + + } catch (IamportResponseException e) { + System.out.println(e.getMessage()); + + switch (e.getHttpStatusCode()) { + case 401: + //TODO + break; + case 500: + //TODO + break; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + // @Test // public void testOnetimePayment() { // CardInfo card = new CardInfo("1234123412341234", "201901", "801231", "00"); // OnetimePaymentData onetime_data = new OnetimePaymentData(getRandomMerchantUid(), BigDecimal.valueOf(1004), card); @@ -737,11 +737,11 @@ public void testNaverResolveReturnOrders() { // onetime_data.setBuyerName("구매자"); // onetime_data.setBuyerEmail("iamport@siot.do"); // onetime_data.setBuyerTel("16705176"); -// +// // IamportResponse payment_response = client.onetimePayment(onetime_data); // assertEquals(payment_response.getResponse().getStatus(), "paid"); // } -// +// // @Test // public void testAgainPayment() throws IOException, IamportResponseException { // String test_customer_uid = "customer_123456"; @@ -767,56 +767,65 @@ public void testNaverResolveReturnOrders() { // e.printStackTrace(); // } // } - @Test - public void testAgainPayment() throws IOException, IamportResponseException { - 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_response = client.againPayment(again_data); - assertEquals(payment_response.getResponse().getStatus(), "paid"); - } -// + @Test + public void testAgainPayment() throws IOException, IamportResponseException { + 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_response = client.againPayment(again_data); + assertEquals(payment_response.getResponse().getStatus(), "paid"); + } + + @Test + public void testGetPaymentSchedule() throws IOException, IamportResponseException { + + GetScheduleData getScheduleData = new GetScheduleData(1643497892, 1648595492, null, 1, 20); + + IamportResponse schedule_response = client.getPaymentSchedule(getScheduleData); + System.out.println(schedule_response.getResponse().getList().get(0).getCustomerUid()); + } +// // @Test // public void testSubscribeScheduleAndUnschedule() { // String test_customer_uid = "customer_123456"; // ScheduleData schedule_data = new ScheduleData(test_customer_uid); -// +// // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, 2018); // cal.set(Calendar.MONTH, Calendar.OCTOBER); // cal.set(Calendar.DAY_OF_MONTH, 25); // Date d1 = cal.getTime(); -// +// // cal.set(Calendar.YEAR, 2018); // cal.set(Calendar.MONTH, Calendar.NOVEMBER); // cal.set(Calendar.DAY_OF_MONTH, 25); // Date d2 = cal.getTime(); -// +// // cal.set(Calendar.YEAR, 2018); // cal.set(Calendar.MONTH, Calendar.DECEMBER); // cal.set(Calendar.DAY_OF_MONTH, 25); // Date d3 = cal.getTime(); -// +// // schedule_data.addSchedule(new ScheduleEntry(getRandomMerchantUid(), d1, BigDecimal.valueOf(1004))); // schedule_data.addSchedule(new ScheduleEntry(getRandomMerchantUid(), d2, BigDecimal.valueOf(1005))); // schedule_data.addSchedule(new ScheduleEntry(getRandomMerchantUid(), d3, BigDecimal.valueOf(1006))); -// +// // System.out.println("예약 요청"); // IamportResponse> schedule_response = client.subscribeSchedule(schedule_data); -// +// // List schedules = schedule_response.getResponse(); // List req_schedules = schedule_data.getSchedules(); -// +// // for (int i = 0; i < 3; i++) { // assertEquals(schedules.get(i).getCustomerUid(), test_customer_uid); // assertEquals(schedules.get(i).getMerchantUid(), req_schedules.get(i).getMerchantUid()); // assertDateEquals(schedules.get(i).getScheduleAt(), req_schedules.get(i).getScheduleAt()); // assertEquals(schedules.get(i).getAmount(), req_schedules.get(i).getAmount()); // } -// +// // try { // //1초 후 등록된 예약 unschedule by multiple merchant_uid // Thread.sleep(1000); @@ -824,69 +833,69 @@ public void testAgainPayment() throws IOException, IamportResponseException { // UnscheduleData unschedule_data = new UnscheduleData(test_customer_uid); // unschedule_data.addMerchantUid( req_schedules.get(0).getMerchantUid() ); // unschedule_data.addMerchantUid( req_schedules.get(2).getMerchantUid() ); -// +// // IamportResponse> unschedule_response = client.unsubscribeSchedule(unschedule_data); // List cancelled_schedule = unschedule_response.getResponse(); -// +// // assertNotNull(cancelled_schedule); // assertEquals(cancelled_schedule.get(0).getMerchantUid(), req_schedules.get(0).getMerchantUid()); // assertEquals(cancelled_schedule.get(1).getMerchantUid(), req_schedules.get(2).getMerchantUid()); -// +// // //1초 후 등록된 예약 unschedule by single multiple_uid // Thread.sleep(1000); // System.out.println("단일 merchant_uid 예약 취소 요청"); // unschedule_data = new UnscheduleData(test_customer_uid); // unschedule_data.addMerchantUid( req_schedules.get(1).getMerchantUid()); -// +// // unschedule_response = client.unsubscribeSchedule(unschedule_data); // cancelled_schedule = unschedule_response.getResponse(); -// +// // assertNotNull(cancelled_schedule); // assertEquals(cancelled_schedule.get(0).getMerchantUid(), req_schedules.get(1).getMerchantUid()); -// +// // } catch (InterruptedException e) { // e.printStackTrace(); // } // } -// +// // @Test // public void testSubscribeDuplicatedSchedule() { // String test_customer_uid = "iamportjangbora"; // ScheduleData schedule_data = new ScheduleData(test_customer_uid); -// +// // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.YEAR, 2018); // cal.set(Calendar.MONTH, Calendar.OCTOBER); // cal.set(Calendar.DAY_OF_MONTH, 25); // Date d1 = cal.getTime(); -// +// // cal.set(Calendar.YEAR, 2018); // cal.set(Calendar.MONTH, Calendar.NOVEMBER); // cal.set(Calendar.DAY_OF_MONTH, 25); // Date d2 = cal.getTime(); -// +// // cal.set(Calendar.YEAR, 2018); // cal.set(Calendar.MONTH, Calendar.DECEMBER); // cal.set(Calendar.DAY_OF_MONTH, 25); // Date d3 = cal.getTime(); -// +// // schedule_data.addSchedule(new ScheduleEntry("scheduled_merchant_1$$$", d1, BigDecimal.valueOf(1004))); // schedule_data.addSchedule(new ScheduleEntry("scheduled_merchant_2$$$", d2, BigDecimal.valueOf(1005))); // schedule_data.addSchedule(new ScheduleEntry("scheduled_merchant_3$$$", d3, BigDecimal.valueOf(1006))); -// +// // IamportResponse> schedule_response = client.subscribeSchedule(schedule_data); -// +// // assertEquals(1, schedule_response.getCode()); //중복된 merchant_uid이므로 schedule에 실패함 // } - - private String getRandomMerchantUid() { - DateFormat df = new SimpleDateFormat("$$hhmmssSS"); - int n = (int) (Math.random() * 100) + 1; - - return df.format(new Date()) + "_" + n; - } - - private void assertDateEquals(Date d1, Date d2) { - assertEquals(d1.getTime() / 1000L, d2.getTime() / 1000L); - } + + private String getRandomMerchantUid() { + DateFormat df = new SimpleDateFormat("$$hhmmssSS"); + int n = (int) (Math.random() * 100) + 1; + + return df.format(new Date()) + "_" + n; + } + + private void assertDateEquals(Date d1, Date d2) { + assertEquals(d1.getTime() / 1000L, d2.getTime() / 1000L); + } }