Skip to content

Commit

Permalink
Merge pull request #6 from iamport/feature/custom-schdule-options
Browse files Browse the repository at this point in the history
feat: schedule API의 선택항목 추가
  • Loading branch information
smc0210 authored May 3, 2021
2 parents ca70ec7 + 5949cc4 commit 3a6c1b3
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
target/
build/
.idea/
*.iml
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pom.xml에 아래의 내용을 추가해주세요.
<dependency>
<groupId>com.github.iamport</groupId>
<artifactId>iamport-rest-client-java</artifactId>
<version>0.2.14</version>
<version>0.2.15</version>
</dependency>
</dependencies>
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.github.iamport</groupId>
<artifactId>iamport-rest-client</artifactId>
<version>0.2.14</version>
<version>0.2.15</version>
<packaging>jar</packaging>

<name>IamportRestClient</name>
Expand Down
164 changes: 137 additions & 27 deletions src/main/java/com/siot/IamportRestClient/request/ScheduleEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,141 @@

public class ScheduleEntry {

@SerializedName("merchant_uid")
private String merchant_uid;

@SerializedName("schedule_at")
private Date schedule_at;

@SerializedName("amount")
private BigDecimal amount;

public ScheduleEntry(String merchant_uid, Date schedule_at, BigDecimal amount) {
this.merchant_uid = merchant_uid;
this.schedule_at = schedule_at;
this.amount = amount;
}

public String getMerchantUid() {
return merchant_uid;
}

public Date getScheduleAt() {
return schedule_at;
}

public BigDecimal getAmount() {
return amount;
}

@SerializedName("merchant_uid")
private String merchant_uid;

@SerializedName("schedule_at")
private Date schedule_at;

@SerializedName("amount")
private BigDecimal amount;

@SerializedName("tax_free")
private BigDecimal tax_free;

@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("notice_url")
private String notice_url;

public ScheduleEntry(String merchant_uid, Date schedule_at, BigDecimal amount) {
this.merchant_uid = merchant_uid;
this.schedule_at = schedule_at;
this.amount = amount;
}

public void setMerchantUid(String merchant_uid) {
this.merchant_uid = merchant_uid;
}

public void setScheduleAt(Date schedule_at) {
this.schedule_at = schedule_at;
}

public void setAmount(BigDecimal amount) {
this.amount = amount;
}

public void setTaxFree(BigDecimal tax_free) {
this.tax_free = tax_free;
}

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 setCustomData(String custom_data) {
this.custom_data = custom_data;
}

public void setNoticeUrl(String notice_url) {
this.notice_url = notice_url;
}

public String getMerchantUid() {
return merchant_uid;
}

public Date getScheduleAt() {
return schedule_at;
}

public BigDecimal getAmount() {
return amount;
}

public BigDecimal getTaxFree() {
return tax_free;
}

public String getName() {
return name;
}

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 getNoticeUrl() {
return notice_url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,37 @@

public class ScheduleEntrySerializer implements JsonSerializer<ScheduleEntry>, JsonDeserializer<Schedule> {

public JsonElement serialize(ScheduleEntry entry, Type typeOfSrc, JsonSerializationContext context) {
final JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("merchant_uid", entry.getMerchantUid());
jsonObject.addProperty("schedule_at", entry.getScheduleAt().getTime() / 1000L);
jsonObject.addProperty("amount", entry.getAmount());

return jsonObject;
}

public Schedule deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {

if ( json.isJsonObject() ) {
JsonObject obj = (JsonObject)json;

long unix_time = obj.get("schedule_at").getAsLong();
Date schedule_dt = new Date( unix_time * 1000L );

return new Schedule(obj.get("customer_uid").getAsString(), obj.get("merchant_uid").getAsString(), schedule_dt, obj.get("amount").getAsBigDecimal());
}

return null;
}
public JsonElement serialize(ScheduleEntry entry, Type typeOfSrc, JsonSerializationContext context) {
final JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("merchant_uid", entry.getMerchantUid());
jsonObject.addProperty("schedule_at", entry.getScheduleAt().getTime() / 1000L);
jsonObject.addProperty("amount", entry.getAmount());
jsonObject.addProperty("tax_free", entry.getTaxFree());
jsonObject.addProperty("name", entry.getName());
jsonObject.addProperty("buyer_name", entry.getBuyerName());
jsonObject.addProperty("buyer_email", entry.getBuyerEmail());
jsonObject.addProperty("buyer_tel", entry.getBuyerTel());
jsonObject.addProperty("buyer_addr", entry.getBuyerAddr());
jsonObject.addProperty("buyer_postcode", entry.getBuyerPostcode());
jsonObject.addProperty("custom_data", entry.getCustomData());
jsonObject.addProperty("notice_url", entry.getNoticeUrl());

return jsonObject;
}

public Schedule deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {

if (json.isJsonObject()) {
JsonObject obj = (JsonObject) json;

long unix_time = obj.get("schedule_at").getAsLong();
Date schedule_dt = new Date(unix_time * 1000L);

return new Schedule(obj.get("customer_uid").getAsString(), obj.get("merchant_uid").getAsString(), schedule_dt, obj.get("amount").getAsBigDecimal());
}

return null;
}

}

0 comments on commit 3a6c1b3

Please sign in to comment.