diff --git a/src/main/java/com/bitpay/sdk/model/bill/Bill.java b/src/main/java/com/bitpay/sdk/model/bill/Bill.java index 7ba32c8c..ec33e2f6 100644 --- a/src/main/java/com/bitpay/sdk/model/bill/Bill.java +++ b/src/main/java/com/bitpay/sdk/model/bill/Bill.java @@ -9,10 +9,14 @@ import com.bitpay.sdk.exceptions.BitPayGenericException; import com.bitpay.sdk.model.Currency; import com.bitpay.sdk.model.ModelConfiguration; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.ZonedDateTime; import java.util.List; @@ -39,7 +43,7 @@ public class Bill { private String country = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private List cc; private String phone = ModelConfiguration.DEFAULT_NON_SENT_VALUE; - private String dueDate = ModelConfiguration.DEFAULT_NON_SENT_VALUE; + private ZonedDateTime dueDate; private Boolean passProcessingFee; private String status = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private String url = ModelConfiguration.DEFAULT_NON_SENT_VALUE; @@ -395,7 +399,8 @@ public void setPhone(final String phone) { */ @JsonProperty("dueDate") @JsonInclude(JsonInclude.Include.NON_DEFAULT) - public String getDueDate() { + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) + public ZonedDateTime getDueDate() { return this.dueDate; } @@ -405,7 +410,8 @@ public String getDueDate() { * @param dueDate the due date */ @JsonProperty("dueDate") - public void setDueDate(final String dueDate) { + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) + public void setDueDate(final ZonedDateTime dueDate) { this.dueDate = dueDate; } @@ -480,6 +486,7 @@ public void setUrl(final String url) { */ @JsonIgnore @JsonInclude(JsonInclude.Include.NON_DEFAULT) + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getCreatedDate() { return this.createdDate; } @@ -490,6 +497,7 @@ public ZonedDateTime getCreatedDate() { * @param createdDate the create date */ @JsonProperty("createdDate") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setCreatedDate(final ZonedDateTime createdDate) { this.createdDate = createdDate; } diff --git a/src/main/java/com/bitpay/sdk/model/invoice/InvoiceTransaction.java b/src/main/java/com/bitpay/sdk/model/invoice/InvoiceTransaction.java index 0a2c2a8b..4ec840a0 100644 --- a/src/main/java/com/bitpay/sdk/model/invoice/InvoiceTransaction.java +++ b/src/main/java/com/bitpay/sdk/model/invoice/InvoiceTransaction.java @@ -6,11 +6,15 @@ package com.bitpay.sdk.model.invoice; import com.bitpay.sdk.model.ModelConfiguration; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.math.BigDecimal; -import java.util.Date; +import java.time.ZonedDateTime; import java.util.Map; /** @@ -26,8 +30,8 @@ public class InvoiceTransaction { private BigDecimal amount; private Integer confirmations; - private Date time; - private Date receivedTime; + private ZonedDateTime time; + private ZonedDateTime receivedTime; private String txid = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private Map exRates; private Integer outputIndex; @@ -84,7 +88,8 @@ public void setConfirmations(final Integer confirmations) { * @return the received time */ @JsonIgnore - public Date getReceivedTime() { + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) + public ZonedDateTime getReceivedTime() { return this.receivedTime; } @@ -94,7 +99,8 @@ public Date getReceivedTime() { * @param receivedTime the received time */ @JsonProperty("receivedTime") - public void setReceivedTime(final Date receivedTime) { + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) + public void setReceivedTime(final ZonedDateTime receivedTime) { this.receivedTime = receivedTime; } @@ -124,7 +130,8 @@ public void setTransactionId(final String txid) { * @return the time */ @JsonIgnore - public Date getTime() { + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) + public ZonedDateTime getTime() { return this.time; } @@ -134,7 +141,8 @@ public Date getTime() { * @param time the time */ @JsonProperty("time") - public void setTime(final Date time) { + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) + public void setTime(final ZonedDateTime time) { this.time = time; } diff --git a/src/main/java/com/bitpay/sdk/model/invoice/MinerFeesItem.java b/src/main/java/com/bitpay/sdk/model/invoice/MinerFeesItem.java index f96990ec..26a75324 100644 --- a/src/main/java/com/bitpay/sdk/model/invoice/MinerFeesItem.java +++ b/src/main/java/com/bitpay/sdk/model/invoice/MinerFeesItem.java @@ -8,7 +8,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import java.math.BigDecimal; /** * The type Miner fees item. @@ -18,8 +17,8 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class MinerFeesItem { - private BigDecimal satoshisPerByte; - private BigDecimal totalFee; + private Integer satoshisPerByte; + private Integer totalFee; private Double fiatAmount; /** @@ -34,7 +33,7 @@ public MinerFeesItem() { * @return the satoshis per byte */ @JsonIgnore - public BigDecimal getSatoshisPerByte() { + public Integer getSatoshisPerByte() { return this.satoshisPerByte; } @@ -44,7 +43,7 @@ public BigDecimal getSatoshisPerByte() { * @param satoshisPerByte the satoshis per byte */ @JsonProperty("satoshisPerByte") - public void setSatoshisPerByte(BigDecimal satoshisPerByte) { + public void setSatoshisPerByte(Integer satoshisPerByte) { this.satoshisPerByte = satoshisPerByte; } @@ -54,7 +53,7 @@ public void setSatoshisPerByte(BigDecimal satoshisPerByte) { * @return the total fee */ @JsonIgnore - public BigDecimal getTotalFee() { + public Integer getTotalFee() { return this.totalFee; } @@ -64,7 +63,7 @@ public BigDecimal getTotalFee() { * @param totalFee the total fee */ @JsonProperty("totalFee") - public void setTotalFee(BigDecimal totalFee) { + public void setTotalFee(Integer totalFee) { this.totalFee = totalFee; } diff --git a/src/main/java/com/bitpay/sdk/model/invoice/Refund.java b/src/main/java/com/bitpay/sdk/model/invoice/Refund.java index 76b72f55..334fd684 100644 --- a/src/main/java/com/bitpay/sdk/model/invoice/Refund.java +++ b/src/main/java/com/bitpay/sdk/model/invoice/Refund.java @@ -6,12 +6,16 @@ package com.bitpay.sdk.model.invoice; import com.bitpay.sdk.model.ModelConfiguration; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.math.BigDecimal; -import java.util.Date; +import java.time.ZonedDateTime; /** * Fully paid invoices can be refunded via the merchant's authorization to issue a refund, @@ -32,31 +36,17 @@ public class Refund { private Boolean buyerPaysRefundFee; private String reference = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private Double refundFee; - private Date lastRefundNotification; + private ZonedDateTime requestDate; + private ZonedDateTime lastRefundNotification; private String notificationUrl = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private String refundAddress = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private String supportRequest = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private String txid = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private String type = ModelConfiguration.DEFAULT_NON_SENT_VALUE; - - /** - * Amount to be refunded in terms of the transaction currency. - */ private BigDecimal transactionAmount; - - /** - * The refund fee expressed in terms of transaction currency. - */ private BigDecimal transactionRefundFee; - - /** - * The currency used for the invoice transaction. - */ private String transactionCurrency = ModelConfiguration.DEFAULT_NON_SENT_VALUE; - - private String id; - private Date requestDate; private String status = ModelConfiguration.DEFAULT_NON_SENT_VALUE; @@ -278,7 +268,8 @@ public void setId(final String id) { */ @JsonIgnore @JsonInclude(JsonInclude.Include.NON_DEFAULT) - public Date getRequestDate() { + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) + public ZonedDateTime getRequestDate() { return this.requestDate; } @@ -288,7 +279,8 @@ public Date getRequestDate() { * @param requestDate the request date */ @JsonProperty("requestDate") - public void setRequestDate(final Date requestDate) { + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) + public void setRequestDate(final ZonedDateTime requestDate) { this.requestDate = requestDate; } @@ -394,7 +386,8 @@ public void setTransactionCurrency(final String transactionCurrency) { */ @JsonIgnore @JsonInclude(JsonInclude.Include.NON_DEFAULT) - public Date getLastRefundNotification() { + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) + public ZonedDateTime getLastRefundNotification() { return this.lastRefundNotification; } @@ -404,7 +397,8 @@ public Date getLastRefundNotification() { * @param lastRefundNotification the last refund notification */ @JsonProperty("lastRefundNotification") - public void setLastRefundNotification(final Date lastRefundNotification) { + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) + public void setLastRefundNotification(final ZonedDateTime lastRefundNotification) { this.lastRefundNotification = lastRefundNotification; } diff --git a/src/main/java/com/bitpay/sdk/model/invoice/RefundStatus.java b/src/main/java/com/bitpay/sdk/model/invoice/RefundStatus.java index a77ff3eb..356d1f0a 100644 --- a/src/main/java/com/bitpay/sdk/model/invoice/RefundStatus.java +++ b/src/main/java/com/bitpay/sdk/model/invoice/RefundStatus.java @@ -16,26 +16,26 @@ public class RefundStatus { * No funds deducted, refund will not proceed automatically - * the status must be changed via Update a Refund Request. */ - public static final String Preview = "preview"; + public static final String PREVIEW = "preview"; /** * Funds deducted/allocated if immediate, * will proceed when transactions are confirmed and the required data is collected. */ - public static final String Created = "created"; + public static final String CREATED = "created"; /** * Refund is in process of being fulfilled. */ - public static final String Pending = "pending"; + public static final String PENDING = "pending"; /** * Refund was canceled by merchant action. Immediate refunds cannot be canceled outside of preview state. */ - public static final String Canceled = "canceled"; + public static final String CANCELED = "canceled"; /** * Refund was successfully processed. */ - public static final String Success = "success"; + public static final String SUCCESS = "success"; /** * Refund failed during processing (this is really more of an internal state). */ - public static final String Failure = "failure"; + public static final String FAILURE = "failure"; } diff --git a/src/main/java/com/bitpay/sdk/model/invoice/RefundWebhook.java b/src/main/java/com/bitpay/sdk/model/invoice/RefundWebhook.java index f189f974..2621a18b 100644 --- a/src/main/java/com/bitpay/sdk/model/invoice/RefundWebhook.java +++ b/src/main/java/com/bitpay/sdk/model/invoice/RefundWebhook.java @@ -6,10 +6,14 @@ package com.bitpay.sdk.model.invoice; import com.bitpay.sdk.model.ModelConfiguration; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Date; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import java.time.ZonedDateTime; /** * The type Refund webhook. @@ -25,11 +29,11 @@ public class RefundWebhook { private String status = ModelConfiguration.DEFAULT_NON_SENT_VALUE; private Double amount; private String currency = ModelConfiguration.DEFAULT_NON_SENT_VALUE; - private Date lastRefundNotification; + private ZonedDateTime lastRefundNotification; private Double refundFee; private Boolean immediate; private Boolean buyerPaysRefundFee; - private Date requestDate; + private ZonedDateTime requestDate; /** * Instantiates a new Refund webhook. @@ -172,7 +176,8 @@ public void setCurrency(String currency) { */ @JsonProperty("lastRefundNotification") @JsonInclude(JsonInclude.Include.NON_DEFAULT) - public Date getLastRefundNotification() { + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) + public ZonedDateTime getLastRefundNotification() { return this.lastRefundNotification; } @@ -182,7 +187,8 @@ public Date getLastRefundNotification() { * @param lastRefundNotification the last refund notification */ @JsonProperty("lastRefundNotification") - public void setLastRefundNotification(Date lastRefundNotification) { + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) + public void setLastRefundNotification(ZonedDateTime lastRefundNotification) { this.lastRefundNotification = lastRefundNotification; } @@ -258,7 +264,8 @@ public void setBuyerPaysRefundFee(Boolean buyerPaysRefundFee) { */ @JsonProperty("requestDate") @JsonInclude(JsonInclude.Include.NON_DEFAULT) - public Date getRequestDate() { + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) + public ZonedDateTime getRequestDate() { return this.requestDate; } @@ -268,7 +275,8 @@ public Date getRequestDate() { * @param requestDate the request date */ @JsonProperty("requestDate") - public void setRequestDate(Date requestDate) { + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) + public void setRequestDate(ZonedDateTime requestDate) { this.requestDate = requestDate; } diff --git a/src/main/java/com/bitpay/sdk/model/ledger/LedgerEntry.java b/src/main/java/com/bitpay/sdk/model/ledger/LedgerEntry.java index 7e285c18..390d5351 100644 --- a/src/main/java/com/bitpay/sdk/model/ledger/LedgerEntry.java +++ b/src/main/java/com/bitpay/sdk/model/ledger/LedgerEntry.java @@ -5,10 +5,15 @@ package com.bitpay.sdk.model.ledger; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import java.math.BigInteger; import java.time.ZonedDateTime; /** @@ -20,12 +25,12 @@ public class LedgerEntry { private String type; - private String amount; + private BigInteger amount; private Integer code; private String description; private ZonedDateTime timestamp; private String txType; - private Integer scale; + private BigInteger scale; private String invoiceId; private Buyer buyer; private Double invoiceAmount; @@ -73,7 +78,7 @@ public void setType(final String type) { * @return the amount */ @JsonIgnore - public String getAmount() { + public BigInteger getAmount() { return this.amount; } @@ -87,7 +92,7 @@ public String getAmount() { * */ @JsonProperty("amount") - public void setAmount(final String amount) { + public void setAmount(final BigInteger amount) { this.amount = amount; } @@ -149,6 +154,7 @@ public void setDescription(final String description) { * @return the timestamp */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getTimestamp() { return this.timestamp; } @@ -159,6 +165,7 @@ public ZonedDateTime getTimestamp() { * @param timestamp the timestamp */ @JsonProperty("timestamp") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setTimestamp(final ZonedDateTime timestamp) { this.timestamp = timestamp; } @@ -192,7 +199,7 @@ public void setTxType(final String txType) { * @return the scale */ @JsonIgnore - public Integer getScale() { + public BigInteger getScale() { return this.scale; } @@ -202,7 +209,7 @@ public Integer getScale() { * @param scale the scale */ @JsonProperty("scale") - public void setScale(final Integer scale) { + public void setScale(final BigInteger scale) { this.scale = scale; } diff --git a/src/main/java/com/bitpay/sdk/model/payout/Payout.java b/src/main/java/com/bitpay/sdk/model/payout/Payout.java index 10faf8e7..d2a6b915 100644 --- a/src/main/java/com/bitpay/sdk/model/payout/Payout.java +++ b/src/main/java/com/bitpay/sdk/model/payout/Payout.java @@ -9,10 +9,14 @@ import com.bitpay.sdk.exceptions.BitPayGenericException; import com.bitpay.sdk.model.Currency; import com.bitpay.sdk.model.ModelConfiguration; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.ZonedDateTime; import java.util.Collections; import java.util.List; @@ -33,8 +37,8 @@ public class Payout { private String token = ModelConfiguration.DEFAULT_NON_SENT_VALUE; - private Double amount = 0.0; - private String currency = ModelConfiguration.DEFAULT_NON_SENT_VALUE; + private Double amount; + private String currency; private ZonedDateTime effectiveDate; private String reference = ModelConfiguration.DEFAULT_NON_SENT_VALUE; @@ -233,6 +237,7 @@ public void setGroupId(final String groupId) { */ @JsonProperty("effectiveDate") @JsonInclude(JsonInclude.Include.NON_DEFAULT) + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getEffectiveDate() { return this.effectiveDate; } @@ -244,6 +249,7 @@ public ZonedDateTime getEffectiveDate() { * @param effectiveDate the effective date */ @JsonProperty("effectiveDate") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setEffectiveDate(final ZonedDateTime effectiveDate) { this.effectiveDate = effectiveDate; } @@ -597,6 +603,7 @@ public void setStatus(final String status) { * @return the request date */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getRequestDate() { return this.requestDate; } @@ -607,6 +614,7 @@ public ZonedDateTime getRequestDate() { * @param requestDate the request date */ @JsonProperty("requestDate") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setRequestDate(final ZonedDateTime requestDate) { this.requestDate = requestDate; } @@ -617,6 +625,7 @@ public void setRequestDate(final ZonedDateTime requestDate) { * @return the date executed */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getDateExecuted() { return this.dateExecuted; } @@ -627,6 +636,7 @@ public ZonedDateTime getDateExecuted() { * @param dateExecuted the date executed */ @JsonProperty("dateExecuted") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setDateExecuted(final ZonedDateTime dateExecuted) { this.dateExecuted = dateExecuted; } diff --git a/src/main/java/com/bitpay/sdk/model/payout/PayoutRecipients.java b/src/main/java/com/bitpay/sdk/model/payout/PayoutRecipients.java index 4bb34eb6..e2bc2835 100644 --- a/src/main/java/com/bitpay/sdk/model/payout/PayoutRecipients.java +++ b/src/main/java/com/bitpay/sdk/model/payout/PayoutRecipients.java @@ -8,7 +8,6 @@ import com.bitpay.sdk.model.ModelConfiguration; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Collections; import java.util.List; /** @@ -18,7 +17,7 @@ */ public class PayoutRecipients { private String guid; - private List recipients = Collections.emptyList(); + private List recipients; private String token = ModelConfiguration.DEFAULT_NON_SENT_VALUE; /** diff --git a/src/main/java/com/bitpay/sdk/model/payout/PayoutTransaction.java b/src/main/java/com/bitpay/sdk/model/payout/PayoutTransaction.java index 5c9a645b..e931d202 100644 --- a/src/main/java/com/bitpay/sdk/model/payout/PayoutTransaction.java +++ b/src/main/java/com/bitpay/sdk/model/payout/PayoutTransaction.java @@ -5,9 +5,13 @@ package com.bitpay.sdk.model.payout; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.ZonedDateTime; /** @@ -76,6 +80,7 @@ public void setAmount(final Double amount) { * @return the date */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getDate() { return this.date; } @@ -87,6 +92,7 @@ public ZonedDateTime getDate() { * @param date the date */ @JsonProperty("date") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setDate(final ZonedDateTime date) { this.date = date; } diff --git a/src/main/java/com/bitpay/sdk/model/payout/PayoutWebhook.java b/src/main/java/com/bitpay/sdk/model/payout/PayoutWebhook.java index 7ac07c91..a2b8fc8c 100644 --- a/src/main/java/com/bitpay/sdk/model/payout/PayoutWebhook.java +++ b/src/main/java/com/bitpay/sdk/model/payout/PayoutWebhook.java @@ -5,7 +5,11 @@ package com.bitpay.sdk.model.payout; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.math.BigDecimal; import java.time.ZonedDateTime; import java.util.Hashtable; @@ -133,18 +137,22 @@ public void setNotificationEmail(String notificationEmail) { this.notificationEmail = notificationEmail; } + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getEffectiveDate() { return this.effectiveDate; } + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setEffectiveDate(ZonedDateTime effectiveDate) { this.effectiveDate = effectiveDate; } + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getRequestDate() { return this.requestDate; } + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setRequestDate(ZonedDateTime requestDate) { this.requestDate = requestDate; } diff --git a/src/main/java/com/bitpay/sdk/model/settlement/InvoiceData.java b/src/main/java/com/bitpay/sdk/model/settlement/InvoiceData.java index 1711d5e1..bf009949 100644 --- a/src/main/java/com/bitpay/sdk/model/settlement/InvoiceData.java +++ b/src/main/java/com/bitpay/sdk/model/settlement/InvoiceData.java @@ -5,9 +5,13 @@ package com.bitpay.sdk.model.settlement; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.ZonedDateTime; import java.util.Map; @@ -23,7 +27,7 @@ public class InvoiceData { private Float price; private String currency; private String transactionCurrency; - private Float overPaidAmount; + private Float overpaidAmount; private Map payoutPercentage; private RefundInfo refundInfo; @@ -59,6 +63,7 @@ public void setOrderId(String orderId) { * @return the date */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getDate() { return this.date; } @@ -69,6 +74,7 @@ public ZonedDateTime getDate() { * @param date the date */ @JsonProperty("date") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setDate(ZonedDateTime date) { this.date = date; } @@ -145,8 +151,8 @@ public void setTransactionCurrency(String transactionCurrency) { * @return the over paid amount */ @JsonIgnore - public Float getOverPaidAmount() { - return this.overPaidAmount; + public Float getOverpaidAmount() { + return this.overpaidAmount; } /** @@ -154,9 +160,9 @@ public Float getOverPaidAmount() { * * @param overPaidAmount the over paid amount */ - @JsonProperty("overPaidAmount") - public void setOverPaidAmount(Float overPaidAmount) { - this.overPaidAmount = overPaidAmount; + @JsonProperty("overpaidAmount") + public void setOverpaidAmount(Float overPaidAmount) { + this.overpaidAmount = overPaidAmount; } /** @@ -185,7 +191,7 @@ public void setPayoutPercentage(Map payoutPercentage) { * @return the amount */ @JsonIgnore - public RefundInfo getAmount() { + public RefundInfo getRefundInfo() { return this.refundInfo; } @@ -195,7 +201,7 @@ public RefundInfo getAmount() { * @param refundInfo the refund info */ @JsonProperty("refundInfo") - public void setAmount(RefundInfo refundInfo) { + public void setRefundInfo(RefundInfo refundInfo) { this.refundInfo = refundInfo; } } diff --git a/src/main/java/com/bitpay/sdk/model/settlement/RefundInfo.java b/src/main/java/com/bitpay/sdk/model/settlement/RefundInfo.java index 6d4cbaf4..b398c60a 100644 --- a/src/main/java/com/bitpay/sdk/model/settlement/RefundInfo.java +++ b/src/main/java/com/bitpay/sdk/model/settlement/RefundInfo.java @@ -21,7 +21,6 @@ public class RefundInfo { private String supportRequest; private String currency; private Hashtable amounts; - private String refundRequestEid; /** * Instantiates a new Refund info. @@ -92,23 +91,4 @@ public Hashtable getAmount() { public void setAmount(Hashtable amounts) { this.amounts = amounts; } - - /** - * Gets Refund Request Eid. - * - * @return Refund Request Eid - */ - public String getRefundRequestEid() { - return this.refundRequestEid; - } - - /** - * Sets Refund Request Eid. - * - * @param refundRequestEid Refund Request Eid - */ - @JsonProperty("refundRequestEid") - public void setRefundRequestEid(String refundRequestEid) { - this.refundRequestEid = refundRequestEid; - } } diff --git a/src/main/java/com/bitpay/sdk/model/settlement/Settlement.java b/src/main/java/com/bitpay/sdk/model/settlement/Settlement.java index 90e235fe..a75e0d42 100644 --- a/src/main/java/com/bitpay/sdk/model/settlement/Settlement.java +++ b/src/main/java/com/bitpay/sdk/model/settlement/Settlement.java @@ -5,9 +5,13 @@ package com.bitpay.sdk.model.settlement; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.ZonedDateTime; import java.util.List; @@ -155,6 +159,7 @@ public void setStatus(String status) { * @return the date created */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getDateCreated() { return this.dateCreated; } @@ -165,6 +170,7 @@ public ZonedDateTime getDateCreated() { * @param dateCreated the date created */ @JsonProperty("dateCreated") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setDateCreated(ZonedDateTime dateCreated) { this.dateCreated = dateCreated; } @@ -175,6 +181,7 @@ public void setDateCreated(ZonedDateTime dateCreated) { * @return the date executed */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getDateExecuted() { return this.dateExecuted; } @@ -185,6 +192,7 @@ public ZonedDateTime getDateExecuted() { * @param dateExecuted the date executed */ @JsonProperty("dateExecuted") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setDateExecuted(ZonedDateTime dateExecuted) { this.dateExecuted = dateExecuted; } @@ -195,6 +203,7 @@ public void setDateExecuted(ZonedDateTime dateExecuted) { * @return the date completed */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getDateCompleted() { return this.dateCompleted; } @@ -205,6 +214,7 @@ public ZonedDateTime getDateCompleted() { * @param dateCompleted the date completed */ @JsonProperty("dateCompleted") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setDateCompleted(ZonedDateTime dateCompleted) { this.dateCompleted = dateCompleted; } @@ -217,6 +227,7 @@ public void setDateCompleted(ZonedDateTime dateCompleted) { * @return the opening date */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getOpeningDate() { return this.openingDate; } @@ -229,6 +240,7 @@ public ZonedDateTime getOpeningDate() { * @param openingDate the opening date */ @JsonProperty("openingDate") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setOpeningDate(ZonedDateTime openingDate) { this.openingDate = openingDate; } @@ -239,6 +251,7 @@ public void setOpeningDate(ZonedDateTime openingDate) { * @return the closing date */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getClosingDate() { return this.closingDate; } @@ -249,6 +262,7 @@ public ZonedDateTime getClosingDate() { * @param closingDate the closing date */ @JsonProperty("closingDate") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setClosingDate(ZonedDateTime closingDate) { this.closingDate = closingDate; } diff --git a/src/main/java/com/bitpay/sdk/model/settlement/SettlementLedgerEntry.java b/src/main/java/com/bitpay/sdk/model/settlement/SettlementLedgerEntry.java index 135670e7..015a3aec 100644 --- a/src/main/java/com/bitpay/sdk/model/settlement/SettlementLedgerEntry.java +++ b/src/main/java/com/bitpay/sdk/model/settlement/SettlementLedgerEntry.java @@ -5,9 +5,13 @@ package com.bitpay.sdk.model.settlement; +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.time.ZonedDateTime; /** @@ -17,13 +21,11 @@ */ @JsonIgnoreProperties(ignoreUnknown = true) public class SettlementLedgerEntry { - private Integer code; private String invoiceId; private Float amount; private ZonedDateTime timestamp; private String description; - private String reference; private InvoiceData invoiceData; /** @@ -98,6 +100,7 @@ public void setAmount(Float amount) { * @return the timestamp */ @JsonIgnore + @JsonSerialize(using = ZonedDateTimeToIso8601Serializer.class) public ZonedDateTime getTimestamp() { return this.timestamp; } @@ -108,6 +111,7 @@ public ZonedDateTime getTimestamp() { * @param timestamp the timestamp */ @JsonProperty("timestamp") + @JsonDeserialize(using = Iso8601ToZonedDateTimeDeserializer.class) public void setTimestamp(ZonedDateTime timestamp) { this.timestamp = timestamp; } @@ -132,26 +136,6 @@ public void setDescription(String description) { this.description = description; } - /** - * Gets reference. - * - * @return the reference - */ - @JsonIgnore - public String getReference() { - return this.reference; - } - - /** - * Sets reference. - * - * @param reference the reference - */ - @JsonProperty("reference") - public void setReference(String reference) { - this.reference = reference; - } - /** * Gets invoice data. * diff --git a/src/main/java/com/bitpay/sdk/t/ClientProvider.java b/src/main/java/com/bitpay/sdk/t/ClientProvider.java new file mode 100644 index 00000000..54886737 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/ClientProvider.java @@ -0,0 +1,25 @@ +package com.bitpay.sdk.t; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.ConfigFilePath; +import com.bitpay.sdk.PosToken; +import com.bitpay.sdk.exceptions.BitPayGenericException; + +public class ClientProvider { + + public static Client create() { + try { + return Client.createClientByConfigFilePath(new ConfigFilePath("some/config/path")); // use BitPaySetup + } catch (BitPayGenericException e) { + throw new RuntimeException(e); + } + } + + public static Client createPos() { + try { + return new Client(new PosToken("someToken")); + } catch (BitPayGenericException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/com/bitpay/sdk/t/General/UseLogger.java b/src/main/java/com/bitpay/sdk/t/General/UseLogger.java new file mode 100644 index 00000000..71ab6fe2 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/General/UseLogger.java @@ -0,0 +1,35 @@ +package com.bitpay.sdk.t.General; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.logger.BitPayLogger; +import com.bitpay.sdk.logger.LoggerProvider; +import com.bitpay.sdk.model.invoice.Invoice; +import com.bitpay.sdk.t.ClientProvider; + +final public class UseLogger { + + public void execute() throws BitPayGenericException, BitPayApiException { + LoggerProvider.setLogger(new BitPayLogger() { + @Override + public void logRequest(String method, String endpoint, String json) { + // some logic + } + + @Override + public void logResponse(String method, String endpoint, String json) { + // some logic + } + + @Override + public void logError(String message) { + // some logic + } + }); + + Client client = ClientProvider.create(); + + Invoice invoice = client.getInvoice("someInvoiceId"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Merchant/BillRequests.java b/src/main/java/com/bitpay/sdk/t/Merchant/BillRequests.java new file mode 100644 index 00000000..167c2bce --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Merchant/BillRequests.java @@ -0,0 +1,57 @@ +package com.bitpay.sdk.t.Merchant; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.bill.Bill; +import com.bitpay.sdk.model.bill.Item; +import com.bitpay.sdk.t.ClientProvider; +import java.util.ArrayList; +import java.util.List; + +public class BillRequests { + + public void createBill() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Bill bill = new Bill(); + bill.setCurrency("USD"); + bill.setEmail("some@email.com"); + bill.setAddress1("SomeAddress"); + bill.setCity("MyCity"); + // ... + + Bill result = client.createBill(bill); + } + + public void getBill() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Bill bill = client.getBill("someBillid"); + + List bills = client.getBills("draft"); + } + + public void updateBill() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Item item = new Item(); + item.setPrice(12.34); + item.setQuantity(2); + item.setDescription("someDescription"); + + List items = new ArrayList<>(); + items.add(item); + + Bill bill = new Bill(); + bill.setItems(items); + + client.updateBill(bill, "someBillId"); + } + + public void deliverBillViaEmail() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + client.deliverBill("someBillId", "myBillToken"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Merchant/InvoiceRequests.java b/src/main/java/com/bitpay/sdk/t/Merchant/InvoiceRequests.java new file mode 100644 index 00000000..f2e0f4a2 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Merchant/InvoiceRequests.java @@ -0,0 +1,69 @@ +package com.bitpay.sdk.t.Merchant; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.invoice.Buyer; +import com.bitpay.sdk.model.invoice.Invoice; +import com.bitpay.sdk.t.ClientProvider; +import java.util.List; + +public class InvoiceRequests { + + public void createInvoice() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Invoice invoice = new Invoice(); + invoice.setFullNotifications(true); + invoice.setExtendedNotifications(true); + invoice.setNotificationUrl("https://test/lJnJg9WW7MtG9GZlPVdj"); + invoice.setRedirectUrl("https://test/lJnJg9WW7MtG9GZlPVdj"); + invoice.setNotificationEmail("my@email.com"); + invoice.setBuyerSms("+12223334445"); + + Buyer buyer = new Buyer(); + buyer.setName("Test"); + buyer.setEmail("test@email.com"); + buyer.setAddress1("168 General Grove"); + buyer.setCountry("AD"); + buyer.setLocality("Port Horizon"); + buyer.setNotify(true); + buyer.setPhone("+990123456789"); + buyer.setPostalCode("KY7 1TH"); + buyer.setRegion("New Port"); + + invoice.setBuyer(buyer); + + Invoice result = client.createInvoice(invoice); + } + + public void getInvoice() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Invoice invoiceById = client.getInvoice("myInvoiceId"); + + Invoice invoiceByGuid = client.getInvoiceByGuid("someGuid"); // we can add a GUID during the invoice creation + + List invoices = client.getInvoices("2023-04-14", "2023-04-17", null, null, null, null); + } + + public void updateInvoice() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Invoice invoice = client.updateInvoice("someInvoiceId", "12312321321", null, null, null); + } + + public void cancelInvoice() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + client.cancelInvoice("invoiceId"); + + client.cancelInvoiceByGuid("invoiceGuid"); + } + + public void requestInvoiceWebhookToBeResent() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + client.requestInvoiceWebhookToBeResent("someInvoiceId"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Merchant/LedgerRequests.java b/src/main/java/com/bitpay/sdk/t/Merchant/LedgerRequests.java new file mode 100644 index 00000000..fcc1c7a7 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Merchant/LedgerRequests.java @@ -0,0 +1,24 @@ +package com.bitpay.sdk.t.Merchant; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.ledger.Ledger; +import com.bitpay.sdk.model.ledger.LedgerEntry; +import com.bitpay.sdk.t.ClientProvider; +import java.util.List; + +public class LedgerRequests { + + public void getLedgers() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + List ledgers = client.getLedgers(); + } + + public void getLedgerEntries() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + List ledgerEntries = client.getLedgerEntries("USD", "2023-08-14", "2023-08-22"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Merchant/RefundRequests.java b/src/main/java/com/bitpay/sdk/t/Merchant/RefundRequests.java new file mode 100644 index 00000000..d03ba6c4 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Merchant/RefundRequests.java @@ -0,0 +1,46 @@ +package com.bitpay.sdk.t.Merchant; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.invoice.Refund; +import com.bitpay.sdk.t.ClientProvider; + +public class RefundRequests { + + public void createRefund() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Refund refund = client.createRefund("myInvoiceId", 12.34, true, true, true, "no"); + } + + public void updateRefund() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Refund updateRefund = client.updateRefund("refundId", "created"); + + Refund updateRefundByGuid = client.updateRefundByGuid("someGuid", "created"); + } + + public void getRefund() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Refund refund = client.getRefund("someRefundId"); + + Refund refundByGuid = client.getRefundByGuid("someGuid"); + } + + public void cancelRefund() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Refund cancelRefund = client.cancelRefund("someRefundId"); + + Refund cancelRefundByGuid = client.cancelRefundByGuid("someGuid"); + } + + public void requestRefundNotificationToBeResent() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Boolean result = client.sendRefundNotification("someRefundId"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Merchant/SettlementRequests.java b/src/main/java/com/bitpay/sdk/t/Merchant/SettlementRequests.java new file mode 100644 index 00000000..a71aff8d --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Merchant/SettlementRequests.java @@ -0,0 +1,25 @@ +package com.bitpay.sdk.t.Merchant; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.settlement.Settlement; +import com.bitpay.sdk.t.ClientProvider; +import java.util.List; + +public class SettlementRequests { + + public void getSettlement() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Settlement settlement = client.getSettlement("someSettlementId"); + + List settlements = client.getSettlements("USD", "2023-08-14", "2023-08-22", null, null, null); + } + + public void fetchReconciliationReport() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + client.getSettlementReconciliationReport("settlementId", "settlementToken"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Payout/PayoutRequests.java b/src/main/java/com/bitpay/sdk/t/Payout/PayoutRequests.java new file mode 100644 index 00000000..1aaba133 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Payout/PayoutRequests.java @@ -0,0 +1,58 @@ +package com.bitpay.sdk.t.Payout; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.payout.Payout; +import com.bitpay.sdk.model.payout.PayoutGroup; +import com.bitpay.sdk.t.ClientProvider; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class PayoutRequests { + + public void createPayout() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Payout payout = new Payout(12.34, "USD", "USD"); + payout.setNotificationEmail("myEmail@email.com"); + payout.setNotificationUrl("https://my-url.com"); + + Payout result = client.submitPayout(payout); + + Collection payoutsCollection = Collections.singletonList(result); + PayoutGroup payouts = client.submitPayouts(payoutsCollection); + } + + public void getPayout() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Payout payout = client.getPayout("somePayoutId"); + + List payouts = client.getPayouts( + "2023-08-14", + "2023-08-22", + null, + null, + null, + null, + null + ); + } + + public void cancelPayout() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Boolean cancelPayout = client.cancelPayout("somePayoutId"); + + // String groupId = payout.getGroupId(); + PayoutGroup cancelPayouts = client.cancelPayouts("someGroupId"); + } + + public void requestPayoutWebhookToBeResent() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + client.requestPayoutNotification("somePayoutId"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Payout/RecipientRequests.java b/src/main/java/com/bitpay/sdk/t/Payout/RecipientRequests.java new file mode 100644 index 00000000..5b63cafa --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Payout/RecipientRequests.java @@ -0,0 +1,51 @@ +package com.bitpay.sdk.t.Payout; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.payout.PayoutRecipient; +import com.bitpay.sdk.model.payout.PayoutRecipients; +import com.bitpay.sdk.t.ClientProvider; +import java.util.ArrayList; +import java.util.List; + +public class RecipientRequests { + + public void inviteRecipients() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + PayoutRecipient recipient1 = new PayoutRecipient(); + PayoutRecipient recipient2 = new PayoutRecipient(); + recipient1.setEmail("alice@email.com"); + recipient1.setLabel("Alice"); + recipient2.setEmail("bob@email.com"); + recipient2.setLabel("Bob"); + List recipients = new ArrayList<>(); + recipients.add(recipient1); + recipients.add(recipient2); + + PayoutRecipients payoutRecipients = new PayoutRecipients(recipients); + + List result = client.submitPayoutRecipients(payoutRecipients); + } + + public void getRecipient() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + PayoutRecipient recipient = client.getPayoutRecipient("someRecipientId"); + + List recipients = client.getPayoutRecipients("invited", null, null); + } + + public void removeRecipient() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Boolean result = client.deletePayoutRecipient("somePayoutRecipientId"); + } + + public void updateRecipient() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Boolean result = client.deletePayoutRecipient("somePayoutRecipientId"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Pos/BillRequests.java b/src/main/java/com/bitpay/sdk/t/Pos/BillRequests.java new file mode 100644 index 00000000..340ec141 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Pos/BillRequests.java @@ -0,0 +1,35 @@ +package com.bitpay.sdk.t.Pos; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.bill.Bill; +import com.bitpay.sdk.t.ClientProvider; + +public class BillRequests { + + public void createBill() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.createPos(); + + Bill bill = new Bill(); + bill.setCurrency("USD"); + bill.setEmail("some@email.com"); + bill.setAddress1("SomeAddress"); + bill.setCity("MyCity"); + // ... + + Bill result = client.createBill(bill); + } + + public void getBill() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.createPos(); + + Bill bill = client.getBill("someBillid"); + } + + public void deliverBillViaEmail() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.createPos(); + + client.deliverBill("someBillId", "myBillToken"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Pos/InvoiceRequests.java b/src/main/java/com/bitpay/sdk/t/Pos/InvoiceRequests.java new file mode 100644 index 00000000..addcfef8 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Pos/InvoiceRequests.java @@ -0,0 +1,44 @@ +package com.bitpay.sdk.t.Pos; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.invoice.Buyer; +import com.bitpay.sdk.model.invoice.Invoice; +import com.bitpay.sdk.t.ClientProvider; + +public class InvoiceRequests { + + public void createInvoice() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.createPos(); + + Invoice invoice = new Invoice(); + invoice.setFullNotifications(true); + invoice.setExtendedNotifications(true); + invoice.setNotificationUrl("https://test/lJnJg9WW7MtG9GZlPVdj"); + invoice.setRedirectUrl("https://test/lJnJg9WW7MtG9GZlPVdj"); + invoice.setNotificationEmail("my@email.com"); + invoice.setBuyerSms("+12223334445"); + + Buyer buyer = new Buyer(); + buyer.setName("Test"); + buyer.setEmail("test@email.com"); + buyer.setAddress1("168 General Grove"); + buyer.setCountry("AD"); + buyer.setLocality("Port Horizon"); + buyer.setNotify(true); + buyer.setPhone("+990123456789"); + buyer.setPostalCode("KY7 1TH"); + buyer.setRegion("New Port"); + + invoice.setBuyer(buyer); + + Invoice result = client.createInvoice(invoice); + } + + public void getInvoice() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.createPos(); + + Invoice invoiceById = client.getInvoice("myInvoiceId"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Public/RateRequests.java b/src/main/java/com/bitpay/sdk/t/Public/RateRequests.java new file mode 100644 index 00000000..cb4ca2f9 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Public/RateRequests.java @@ -0,0 +1,21 @@ +package com.bitpay.sdk.t.Public; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.rate.Rate; +import com.bitpay.sdk.model.rate.Rates; +import com.bitpay.sdk.t.ClientProvider; + +public class RateRequests { + + public void getRate() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + Rates rates = client.getRates(); + + Rates currencyRates = client.getRates("BTC"); + + Rate currencyPairRate = client.getRate("BTC", "USD"); + } +} diff --git a/src/main/java/com/bitpay/sdk/t/Public/WalletRequests.java b/src/main/java/com/bitpay/sdk/t/Public/WalletRequests.java new file mode 100644 index 00000000..a0c347db --- /dev/null +++ b/src/main/java/com/bitpay/sdk/t/Public/WalletRequests.java @@ -0,0 +1,17 @@ +package com.bitpay.sdk.t.Public; + +import com.bitpay.sdk.Client; +import com.bitpay.sdk.exceptions.BitPayApiException; +import com.bitpay.sdk.exceptions.BitPayGenericException; +import com.bitpay.sdk.model.wallet.Wallet; +import com.bitpay.sdk.t.ClientProvider; +import java.util.List; + +public class WalletRequests { + + public void getSupportedWallets() throws BitPayGenericException, BitPayApiException { + Client client = ClientProvider.create(); + + List wallets = client.getSupportedWallets(); + } +} diff --git a/src/main/java/com/bitpay/sdk/util/serializer/Iso8601ToZonedDateTimeDeserializer.java b/src/main/java/com/bitpay/sdk/util/serializer/Iso8601ToZonedDateTimeDeserializer.java new file mode 100644 index 00000000..334a920e --- /dev/null +++ b/src/main/java/com/bitpay/sdk/util/serializer/Iso8601ToZonedDateTimeDeserializer.java @@ -0,0 +1,21 @@ +package com.bitpay.sdk.util.serializer; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.node.TextNode; +import java.io.IOException; +import java.time.ZonedDateTime; + +public class Iso8601ToZonedDateTimeDeserializer extends JsonDeserializer { + @Override + public ZonedDateTime deserialize( + JsonParser jsonParser, + DeserializationContext deserializationContext + ) throws IOException { + TextNode node = jsonParser.getCodec().readTree(jsonParser); + String dateAsString = node.asText(); + + return ZonedDateTime.parse(dateAsString); + } +} diff --git a/src/main/java/com/bitpay/sdk/util/serializer/ZonedDateTimeToIso8601Serializer.java b/src/main/java/com/bitpay/sdk/util/serializer/ZonedDateTimeToIso8601Serializer.java new file mode 100644 index 00000000..d94f1195 --- /dev/null +++ b/src/main/java/com/bitpay/sdk/util/serializer/ZonedDateTimeToIso8601Serializer.java @@ -0,0 +1,30 @@ +package com.bitpay.sdk.util.serializer; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class ZonedDateTimeToIso8601Serializer extends JsonSerializer { + + private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSX"); + + /** + * This method deserialize ZonedDateTime to format yyyy-mm-ddThh:mm:ssZ. + * + * @param zonedDateTime ZonedDateTime + * @param jsonGenerator JsonGenerator + * @param serializerProvider SerializerProvider + * @throws IOException IOException + */ + @Override + public void serialize( + ZonedDateTime zonedDateTime, + JsonGenerator jsonGenerator, + SerializerProvider serializerProvider + ) throws IOException { + jsonGenerator.writeString(zonedDateTime.format(DATE_TIME_FORMATTER)); + } +} diff --git a/src/test/java/com/bitpay/sdk/ClientTest.java b/src/test/java/com/bitpay/sdk/ClientTest.java index 854d7fa2..8c7f79bb 100644 --- a/src/test/java/com/bitpay/sdk/ClientTest.java +++ b/src/test/java/com/bitpay/sdk/ClientTest.java @@ -34,7 +34,8 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.text.ParseException; -import java.text.SimpleDateFormat; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -67,7 +68,6 @@ public class ClientTest { "2LVBntm7z92rnuVjVX5ZVaDoUEaoY4LxhZMMzPAMGyXcejgPXVmZ4Ae3oGaCGBFKQf"; protected static final String PAYOUT_TOKEN = "3tDEActqHSjbc3Hn5MoLH7XTn4hMdGSp6YbmvNDXTr5Y"; protected static final String PAYOUT_ID = "JMwv8wQCXANoU2ZZQ9a9GH"; - private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); @Mock private BitPayClient bitPayClient; @@ -1986,6 +1986,8 @@ private Bill getBillExample(String merchantToken) throws BitPayGenericException items.add(item2); final Bill bill = new Bill(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); + ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-05-21T09:48:02.373Z", formatter); bill.setToken(merchantToken); bill.setNumber("bill1234-ABCD"); bill.setCurrency("USD"); @@ -1999,7 +2001,7 @@ private Bill getBillExample(String merchantToken) throws BitPayGenericException bill.setEmail("23242"); bill.setCc(cc); bill.setPhone("555-123-456"); - bill.setDueDate("2021-5-31"); + bill.setDueDate(zonedDateTime); bill.setPassProcessingFee(true); bill.setItems(items); bill.setToken(merchantToken); diff --git a/src/test/java/com/bitpay/sdk/client/BillClientTest.java b/src/test/java/com/bitpay/sdk/client/BillClientTest.java index 3a52d824..d976cb25 100644 --- a/src/test/java/com/bitpay/sdk/client/BillClientTest.java +++ b/src/test/java/com/bitpay/sdk/client/BillClientTest.java @@ -5,10 +5,12 @@ package com.bitpay.sdk.client; import com.bitpay.sdk.exceptions.BitPayException; +import com.bitpay.sdk.model.Facade; import com.bitpay.sdk.model.bill.Bill; import com.bitpay.sdk.model.bill.Item; -import com.bitpay.sdk.model.Facade; import com.bitpay.sdk.util.TokenContainer; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -45,7 +47,7 @@ public void it_should_create_bill() throws BitPayException { Assertions.assertEquals("23242", result.getZip()); Assertions.assertEquals("jane@doe.com", result.getCc().get(0)); Assertions.assertEquals("555-123-456", result.getPhone()); - Assertions.assertEquals("2021-05-31T00:00:00.000Z", result.getDueDate()); + Assertions.assertEquals("2021-05-31T00:00Z", result.getDueDate().toString()); Assertions.assertTrue(result.getPassProcessingFee()); Assertions.assertEquals("draft", result.getStatus()); Assertions.assertEquals("https://bitpay.com/bill?id=3Zpmji8bRKxWJo2NJbWX5H&resource=bills", result.getUrl()); @@ -89,7 +91,7 @@ public void it_should_return_bill() throws BitPayException { Assertions.assertEquals("23242", result.getZip()); Assertions.assertEquals("jane@doe.com", result.getCc().get(0)); Assertions.assertEquals("555-123-456", result.getPhone()); - Assertions.assertEquals("2021-05-31T00:00:00.000Z", result.getDueDate()); + Assertions.assertEquals("2021-05-31T00:00Z", result.getDueDate().toString()); Assertions.assertTrue(result.getPassProcessingFee()); Assertions.assertEquals("draft", result.getStatus()); Assertions.assertEquals("https://bitpay.com/bill?id=3Zpmji8bRKxWJo2NJbWX5H&resource=bills", result.getUrl()); @@ -133,7 +135,7 @@ public void it_should_return_bills() throws BitPayException { Assertions.assertEquals("23242", result.get(0).getZip()); Assertions.assertEquals("jane@doe.com", result.get(0).getCc().get(0)); Assertions.assertEquals("555-123-456", result.get(0).getPhone()); - Assertions.assertEquals("2021-05-31T00:00:00.000Z", result.get(0).getDueDate()); + Assertions.assertEquals("2021-05-31T00:00Z", result.get(0).getDueDate().toString()); Assertions.assertTrue(result.get(0).getPassProcessingFee()); Assertions.assertEquals("draft", result.get(0).getStatus()); Assertions.assertEquals("https://bitpay.com/bill?id=X6KJbe9RxAGWNReCwd1xRw&resource=bills", result.get(0).getUrl()); @@ -178,7 +180,7 @@ public void it_should_return_bills_by_status() throws BitPayException { Assertions.assertEquals("23242", result.get(0).getZip()); Assertions.assertEquals("jane@doe.com", result.get(0).getCc().get(0)); Assertions.assertEquals("555-123-456", result.get(0).getPhone()); - Assertions.assertEquals("2021-05-31T00:00:00.000Z", result.get(0).getDueDate()); + Assertions.assertEquals("2021-05-31T00:00Z", result.get(0).getDueDate().toString()); Assertions.assertTrue(result.get(0).getPassProcessingFee()); Assertions.assertEquals("draft", result.get(0).getStatus()); Assertions.assertEquals("https://bitpay.com/bill?id=X6KJbe9RxAGWNReCwd1xRw&resource=bills", result.get(0).getUrl()); @@ -233,7 +235,7 @@ public void it_should_update_bill() throws BitPayException { Assertions.assertEquals("23242", result.getZip()); Assertions.assertEquals("jane@doe.com", result.getCc().get(0)); Assertions.assertEquals("555-123-456", result.getPhone()); - Assertions.assertEquals("2021-05-31T00:00:00.000Z", result.getDueDate()); + Assertions.assertEquals("2021-05-31T00:00Z", result.getDueDate().toString()); Assertions.assertTrue(result.getPassProcessingFee()); Assertions.assertEquals("draft", result.getStatus()); Assertions.assertEquals("https://bitpay.com/bill?id=3Zpmji8bRKxWJo2NJbWX5H&resource=bills", result.getUrl()); @@ -282,7 +284,7 @@ public void it_should_deliver_bill() throws BitPayException { } private Bill getBill() { - List cc = new ArrayList(); + List cc = new ArrayList<>(); cc.add("jane@doe.com"); List items = new ArrayList<>(); @@ -298,6 +300,9 @@ private Bill getBill() { items.add(item2); final Bill bill = new Bill(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); + ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-05-21T09:48:02.373Z", formatter); + bill.setToken(AbstractClientTest.MERCHANT_TOKEN); bill.setNumber("bill1234-ABCD"); try { @@ -315,7 +320,7 @@ private Bill getBill() { bill.setEmail("23242"); bill.setCc(cc); bill.setPhone("555-123-456"); - bill.setDueDate("2021-5-31"); + bill.setDueDate(zonedDateTime); bill.setPassProcessingFee(true); bill.setItems(items); diff --git a/src/test/java/com/bitpay/sdk/client/InvoiceClientTest.java b/src/test/java/com/bitpay/sdk/client/InvoiceClientTest.java index d8e248d8..f89ffd17 100644 --- a/src/test/java/com/bitpay/sdk/client/InvoiceClientTest.java +++ b/src/test/java/com/bitpay/sdk/client/InvoiceClientTest.java @@ -55,6 +55,7 @@ public void it_should_create_invoice() throws BitPayException { Assertions.assertEquals("false", result.getExceptionStatus()); Assertions.assertEquals(6, result.getTargetConfirmations()); Assertions.assertEquals(1, result.getTransactions().size()); + Assertions.assertEquals("2021-05-11T11:54:32.978Z", result.getTransactions().get(0).getReceivedTime().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.024436520994387978), result.getTransactions().get(0).getExRates().get("WBTC")); Assertions.assertEquals(BigDecimal.valueOf(739100), result.getTransactions().get(0).getAmount()); Assertions.assertEquals("medium", result.getTransactionSpeed()); diff --git a/src/test/java/com/bitpay/sdk/client/LedgerClientTest.java b/src/test/java/com/bitpay/sdk/client/LedgerClientTest.java index 8293583a..84dae093 100644 --- a/src/test/java/com/bitpay/sdk/client/LedgerClientTest.java +++ b/src/test/java/com/bitpay/sdk/client/LedgerClientTest.java @@ -8,6 +8,7 @@ import com.bitpay.sdk.model.ledger.Ledger; import com.bitpay.sdk.model.ledger.LedgerEntry; import com.bitpay.sdk.util.TokenContainer; +import java.math.BigInteger; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -56,7 +57,7 @@ public void it_should_get_ledger_entries() throws BitPayException { // then Assertions.assertEquals(3, result.size()); Assertions.assertEquals(1023, secondEntry.getCode()); - Assertions.assertEquals("-8000000", secondEntry.getAmount()); + Assertions.assertEquals(BigInteger.valueOf(-8000000), secondEntry.getAmount()); Assertions.assertEquals("Invoice Fee", secondEntry.getDescription()); Assertions.assertEquals("2021-05-10T20:08:52.919Z", secondEntry.getTimestamp().toString()); Assertions.assertEquals("Hpqc63wvE1ZjzeeH4kEycF", secondEntry.getInvoiceId()); diff --git a/src/test/java/com/bitpay/sdk/client/RefundClientTest.java b/src/test/java/com/bitpay/sdk/client/RefundClientTest.java index 5fd9de0e..7c69b7a4 100644 --- a/src/test/java/com/bitpay/sdk/client/RefundClientTest.java +++ b/src/test/java/com/bitpay/sdk/client/RefundClientTest.java @@ -7,8 +7,6 @@ import com.bitpay.sdk.exceptions.BitPayException; import com.bitpay.sdk.model.invoice.Refund; import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Date; import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -43,12 +41,12 @@ public void it_should_create_refund() throws BitPayException { Assertions.assertEquals(false, result.getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund", result.getReference()); Assertions.assertEquals(0.04, result.getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630269935368L).getTime()), result.getLastRefundNotification()); + Assertions.assertEquals("2021-08-29T20:45:35.368Z", result.getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000594), result.getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000020), result.getTransactionRefundFee()); Assertions.assertEquals("BTC", result.getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.getId()); - Assertions.assertEquals(new Date(new Timestamp(1630269934000L).getTime()), result.getRequestDate()); + Assertions.assertEquals("2021-08-29T20:45:34Z", result.getRequestDate().toString()); Assertions.assertEquals("created", result.getStatus()); } @@ -75,12 +73,12 @@ public void it_should_get_refund_by_id() throws BitPayException { Assertions.assertEquals(false, result.getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund", result.getReference()); Assertions.assertEquals(0.04, result.getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630269935368L).getTime()), result.getLastRefundNotification()); + Assertions.assertEquals("2021-08-29T20:45:35.368Z", result.getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000594), result.getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000020), result.getTransactionRefundFee()); Assertions.assertEquals("BTC", result.getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.getId()); - Assertions.assertEquals(new Date(new Timestamp(1630269934000L).getTime()), result.getRequestDate()); + Assertions.assertEquals("2021-08-29T20:45:34Z", result.getRequestDate().toString()); Assertions.assertEquals("created", result.getStatus()); } @@ -107,12 +105,12 @@ public void it_should_get_refund_by_guid() throws BitPayException { Assertions.assertEquals(false, result.getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund", result.getReference()); Assertions.assertEquals(0.04, result.getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630269935368L).getTime()), result.getLastRefundNotification()); + Assertions.assertEquals("2021-08-29T20:45:35.368Z", result.getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000594), result.getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000020), result.getTransactionRefundFee()); Assertions.assertEquals("BTC", result.getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.getId()); - Assertions.assertEquals(new Date(new Timestamp(1630269934000L).getTime()), result.getRequestDate()); + Assertions.assertEquals("2021-08-29T20:45:34Z", result.getRequestDate().toString()); Assertions.assertEquals("created", result.getStatus()); } @@ -140,12 +138,12 @@ public void it_should_get_refunds_by_invoice_id() throws BitPayException { Assertions.assertEquals(false, result.get(0).getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund", result.get(0).getReference()); Assertions.assertEquals(0.02, result.get(0).getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630190973368L).getTime()), result.get(0).getLastRefundNotification()); + Assertions.assertEquals("2021-08-28T22:49:33.368Z", result.get(0).getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000297), result.get(0).getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000010), result.get(0).getTransactionRefundFee()); Assertions.assertEquals("BTC", result.get(0).getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.get(0).getId()); - Assertions.assertEquals(new Date(new Timestamp(1630190973000L).getTime()), result.get(0).getRequestDate()); + Assertions.assertEquals("2021-08-28T22:49:33Z", result.get(0).getRequestDate().toString()); Assertions.assertEquals("canceled", result.get(0).getStatus()); Assertions.assertEquals(10, result.get(1).getAmount()); @@ -156,12 +154,12 @@ public void it_should_get_refunds_by_invoice_id() throws BitPayException { Assertions.assertEquals(false, result.get(1).getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund 2", result.get(1).getReference()); Assertions.assertEquals(0.04, result.get(1).getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630269935368L).getTime()), result.get(1).getLastRefundNotification()); + Assertions.assertEquals("2021-08-29T20:45:35.368Z", result.get(1).getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000594), result.get(1).getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000020), result.get(1).getTransactionRefundFee()); Assertions.assertEquals("BTC", result.get(1).getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.get(1).getId()); - Assertions.assertEquals(new Date(new Timestamp(1630269934000L).getTime()), result.get(1).getRequestDate()); + Assertions.assertEquals("2021-08-29T20:45:34Z", result.get(1).getRequestDate().toString()); Assertions.assertEquals("created", result.get(1).getStatus()); } @@ -187,12 +185,12 @@ public void it_should_update_refund() throws BitPayException { Assertions.assertEquals(false, result.getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund", result.getReference()); Assertions.assertEquals(0.04, result.getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630269935368L).getTime()), result.getLastRefundNotification()); + Assertions.assertEquals("2021-08-29T20:45:35.368Z", result.getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000594), result.getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000020), result.getTransactionRefundFee()); Assertions.assertEquals("BTC", result.getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.getId()); - Assertions.assertEquals(new Date(new Timestamp(1630269934000L).getTime()), result.getRequestDate()); + Assertions.assertEquals("2021-08-29T20:45:34Z", result.getRequestDate().toString()); Assertions.assertEquals("created", result.getStatus()); } @@ -218,12 +216,12 @@ public void it_should_update_refund_by_guid() throws BitPayException { Assertions.assertEquals(false, result.getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund", result.getReference()); Assertions.assertEquals(0.04, result.getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630269935368L).getTime()), result.getLastRefundNotification()); + Assertions.assertEquals("2021-08-29T20:45:35.368Z", result.getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000594), result.getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000020), result.getTransactionRefundFee()); Assertions.assertEquals("BTC", result.getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.getId()); - Assertions.assertEquals(new Date(new Timestamp(1630269934000L).getTime()), result.getRequestDate()); + Assertions.assertEquals("2021-08-29T20:45:34Z", result.getRequestDate().toString()); Assertions.assertEquals("created", result.getStatus()); } @@ -266,12 +264,12 @@ public void it_should_cancel_refund() throws BitPayException { Assertions.assertEquals(false, result.getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund", result.getReference()); Assertions.assertEquals(0.04, result.getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630269935368L).getTime()), result.getLastRefundNotification()); + Assertions.assertEquals("2021-08-29T20:45:35.368Z", result.getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000594), result.getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000020), result.getTransactionRefundFee()); Assertions.assertEquals("BTC", result.getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.getId()); - Assertions.assertEquals(new Date(new Timestamp(1630269934000L).getTime()), result.getRequestDate()); + Assertions.assertEquals("2021-08-29T20:45:34Z", result.getRequestDate().toString()); Assertions.assertEquals("cancelled", result.getStatus()); } @@ -297,12 +295,12 @@ public void it_should_cancel_refund_by_guid() throws BitPayException { Assertions.assertEquals(false, result.getBuyerPaysRefundFee()); Assertions.assertEquals("Test refund", result.getReference()); Assertions.assertEquals(0.04, result.getRefundFee()); - Assertions.assertEquals(new Date(new Timestamp(1630269935368L).getTime()), result.getLastRefundNotification()); + Assertions.assertEquals("2021-08-29T20:45:35.368Z", result.getLastRefundNotification().toString()); Assertions.assertEquals(BigDecimal.valueOf(0.000594), result.getTransactionAmount()); Assertions.assertEquals(BigDecimal.valueOf(0.0000020), result.getTransactionRefundFee()); Assertions.assertEquals("BTC", result.getTransactionCurrency()); Assertions.assertEquals("WoE46gSLkJQS48RJEiNw3L", result.getId()); - Assertions.assertEquals(new Date(new Timestamp(1630269934000L).getTime()), result.getRequestDate()); + Assertions.assertEquals("2021-08-29T20:45:34Z", result.getRequestDate().toString()); Assertions.assertEquals("cancelled", result.getStatus()); } diff --git a/src/test/java/com/bitpay/sdk/client/json/createBillRequest.json b/src/test/java/com/bitpay/sdk/client/json/createBillRequest.json index 36d7edd2..866332b8 100644 --- a/src/test/java/com/bitpay/sdk/client/json/createBillRequest.json +++ b/src/test/java/com/bitpay/sdk/client/json/createBillRequest.json @@ -1 +1 @@ -{"address1":"2630 Hegal Place","address2":"Apt 42","cc":["jane@doe.com"],"city":"Alexandria","country":"US","currency":"USD","dueDate":"2021-5-31","email":"23242","items":[{"description":"Test Item 1","price":6.0,"quantity":1},{"description":"Test Item 2","price":4.0,"quantity":1}],"name":"John Doe","number":"bill1234-ABCD","passProcessingFee":true,"phone":"555-123-456","state":"VA","token":"someMerchantToken","zip":"23242"} \ No newline at end of file +{"address1":"2630 Hegal Place","address2":"Apt 42","cc":["jane@doe.com"],"city":"Alexandria","country":"US","currency":"USD","dueDate":"2021-05-21T09:48:02.37Z","email":"23242","items":[{"description":"Test Item 1","price":6.0,"quantity":1},{"description":"Test Item 2","price":4.0,"quantity":1}],"name":"John Doe","number":"bill1234-ABCD","passProcessingFee":true,"phone":"555-123-456","state":"VA","token":"someMerchantToken","zip":"23242"} \ No newline at end of file diff --git a/src/test/java/com/bitpay/sdk/functional/ClientFunctionalTest.java b/src/test/java/com/bitpay/sdk/functional/ClientFunctionalTest.java index 3deb6e99..f15fceab 100644 --- a/src/test/java/com/bitpay/sdk/functional/ClientFunctionalTest.java +++ b/src/test/java/com/bitpay/sdk/functional/ClientFunctionalTest.java @@ -28,6 +28,7 @@ import java.io.File; import java.io.IOException; import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collection; @@ -387,7 +388,7 @@ public void it_should_test_bills_requests() throws BitPayException { requestedBill.setZip("23242"); requestedBill.setCountry("US"); requestedBill.setPhone("555-123-456"); - requestedBill.setDueDate("2021-5-31"); + requestedBill.setDueDate(ZonedDateTime.now()); requestedBill.setPassProcessingFee(true); requestedBill.setItems(items); diff --git a/src/test/java/com/bitpay/sdk/json/createBillRequest.json b/src/test/java/com/bitpay/sdk/json/createBillRequest.json index ff7ddc02..20cfc9aa 100644 --- a/src/test/java/com/bitpay/sdk/json/createBillRequest.json +++ b/src/test/java/com/bitpay/sdk/json/createBillRequest.json @@ -1 +1 @@ -{"address1":"2630 Hegal Place","address2":"Apt 42","cc":["jane@doe.com"],"city":"Alexandria","country":"US","currency":"USD","dueDate":"2021-5-31","email":"23242","items":[{"description":"Test Item 1","price":6.0,"quantity":1},{"description":"Test Item 2","price":4.0,"quantity":1}],"name":"John Doe","number":"bill1234-ABCD","passProcessingFee":true,"phone":"555-123-456","state":"VA","token":"AKnJyeLF1BjAfgfDbVUzHXk64N1WuDq3R9xtZouQFhSv","zip":"23242"} \ No newline at end of file +{"address1":"2630 Hegal Place","address2":"Apt 42","cc":["jane@doe.com"],"city":"Alexandria","country":"US","currency":"USD","dueDate":"2021-05-21T09:48:02.37Z","email":"23242","items":[{"description":"Test Item 1","price":6.0,"quantity":1},{"description":"Test Item 2","price":4.0,"quantity":1}],"name":"John Doe","number":"bill1234-ABCD","passProcessingFee":true,"phone":"555-123-456","state":"VA","token":"AKnJyeLF1BjAfgfDbVUzHXk64N1WuDq3R9xtZouQFhSv","zip":"23242"} \ No newline at end of file diff --git a/src/test/java/com/bitpay/sdk/json/updateBillRequest.json b/src/test/java/com/bitpay/sdk/json/updateBillRequest.json index ff7ddc02..20cfc9aa 100644 --- a/src/test/java/com/bitpay/sdk/json/updateBillRequest.json +++ b/src/test/java/com/bitpay/sdk/json/updateBillRequest.json @@ -1 +1 @@ -{"address1":"2630 Hegal Place","address2":"Apt 42","cc":["jane@doe.com"],"city":"Alexandria","country":"US","currency":"USD","dueDate":"2021-5-31","email":"23242","items":[{"description":"Test Item 1","price":6.0,"quantity":1},{"description":"Test Item 2","price":4.0,"quantity":1}],"name":"John Doe","number":"bill1234-ABCD","passProcessingFee":true,"phone":"555-123-456","state":"VA","token":"AKnJyeLF1BjAfgfDbVUzHXk64N1WuDq3R9xtZouQFhSv","zip":"23242"} \ No newline at end of file +{"address1":"2630 Hegal Place","address2":"Apt 42","cc":["jane@doe.com"],"city":"Alexandria","country":"US","currency":"USD","dueDate":"2021-05-21T09:48:02.37Z","email":"23242","items":[{"description":"Test Item 1","price":6.0,"quantity":1},{"description":"Test Item 2","price":4.0,"quantity":1}],"name":"John Doe","number":"bill1234-ABCD","passProcessingFee":true,"phone":"555-123-456","state":"VA","token":"AKnJyeLF1BjAfgfDbVUzHXk64N1WuDq3R9xtZouQFhSv","zip":"23242"} \ No newline at end of file diff --git a/src/test/java/com/bitpay/sdk/model/bill/BillTest.java b/src/test/java/com/bitpay/sdk/model/bill/BillTest.java index f95c5c83..62fefc1f 100644 --- a/src/test/java/com/bitpay/sdk/model/bill/BillTest.java +++ b/src/test/java/com/bitpay/sdk/model/bill/BillTest.java @@ -153,7 +153,7 @@ public void it_should_manipulate_phone() { @Test public void it_should_manipulate_dueDate() { - final String dueDate = "2021-05-21T09:51:04.126Z"; + final ZonedDateTime dueDate = ZonedDateTime.now(); Bill testedClass = this.getTestedClass(); testedClass.setDueDate(dueDate); diff --git a/src/test/java/com/bitpay/sdk/model/invoice/InvoiceTransactionTest.java b/src/test/java/com/bitpay/sdk/model/invoice/InvoiceTransactionTest.java index 3a65cc87..ee885aa9 100644 --- a/src/test/java/com/bitpay/sdk/model/invoice/InvoiceTransactionTest.java +++ b/src/test/java/com/bitpay/sdk/model/invoice/InvoiceTransactionTest.java @@ -5,7 +5,7 @@ package com.bitpay.sdk.model.invoice; import java.math.BigDecimal; -import java.util.Date; +import java.time.ZonedDateTime; import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.Assertions; @@ -42,7 +42,7 @@ public void it_should_manipulate_confirmations() { @Test public void it_should_manipulate_time() { // given - Date expected = new Date(); + ZonedDateTime expected = ZonedDateTime.now(); InvoiceTransaction testedClass = this.getTestedClass(); // when @@ -55,7 +55,7 @@ public void it_should_manipulate_time() { @Test public void it_should_manipulate_receivedTime() { // given - Date expected = new Date(); + ZonedDateTime expected = ZonedDateTime.now(); InvoiceTransaction testedClass = this.getTestedClass(); // when diff --git a/src/test/java/com/bitpay/sdk/model/invoice/MinerFeesItemTest.java b/src/test/java/com/bitpay/sdk/model/invoice/MinerFeesItemTest.java index 559b9026..ace9809e 100644 --- a/src/test/java/com/bitpay/sdk/model/invoice/MinerFeesItemTest.java +++ b/src/test/java/com/bitpay/sdk/model/invoice/MinerFeesItemTest.java @@ -13,7 +13,7 @@ public class MinerFeesItemTest { @Test public void it_should_manipulate_satoshisPerByte() { // given - BigDecimal expected = BigDecimal.TEN; + Integer expected = 765; MinerFeesItem testedClass = this.getTestedClass(); // when @@ -26,7 +26,7 @@ public void it_should_manipulate_satoshisPerByte() { @Test public void it_should_manipulate_totalFee() { // given - BigDecimal expected = BigDecimal.TEN; + Integer expected = 654; MinerFeesItem testedClass = this.getTestedClass(); // when diff --git a/src/test/java/com/bitpay/sdk/model/invoice/RefundStatusTest.java b/src/test/java/com/bitpay/sdk/model/invoice/RefundStatusTest.java index ec1a9dcc..6d6eb19a 100644 --- a/src/test/java/com/bitpay/sdk/model/invoice/RefundStatusTest.java +++ b/src/test/java/com/bitpay/sdk/model/invoice/RefundStatusTest.java @@ -11,31 +11,31 @@ public class RefundStatusTest { @Test public void it_should_return_preview_status() { - Assertions.assertSame("preview", RefundStatus.Preview); + Assertions.assertSame("preview", RefundStatus.PREVIEW); } @Test public void it_should_return_created_status() { - Assertions.assertSame("created", RefundStatus.Created); + Assertions.assertSame("created", RefundStatus.CREATED); } @Test public void it_should_return_pending_status() { - Assertions.assertSame("pending", RefundStatus.Pending); + Assertions.assertSame("pending", RefundStatus.PENDING); } @Test public void it_should_return_canceled_status() { - Assertions.assertSame("canceled", RefundStatus.Canceled); + Assertions.assertSame("canceled", RefundStatus.CANCELED); } @Test public void it_should_return_success_status() { - Assertions.assertSame("success", RefundStatus.Success); + Assertions.assertSame("success", RefundStatus.SUCCESS); } @Test public void it_should_return_failure_status() { - Assertions.assertSame("failure", RefundStatus.Failure); + Assertions.assertSame("failure", RefundStatus.FAILURE); } } diff --git a/src/test/java/com/bitpay/sdk/model/invoice/RefundTest.java b/src/test/java/com/bitpay/sdk/model/invoice/RefundTest.java index 5e77db38..7e7bd564 100644 --- a/src/test/java/com/bitpay/sdk/model/invoice/RefundTest.java +++ b/src/test/java/com/bitpay/sdk/model/invoice/RefundTest.java @@ -5,7 +5,7 @@ package com.bitpay.sdk.model.invoice; import java.math.BigDecimal; -import java.util.Date; +import java.time.ZonedDateTime; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -131,7 +131,7 @@ public void it_should_manipulate_refundFee() { @Test public void it_should_manipulate_lastRefundNotification() { // given - Date expected = new Date(); + ZonedDateTime expected = ZonedDateTime.now(); Refund testedClass = this.getTestedClass(); // when @@ -196,7 +196,7 @@ public void it_should_manipulate_id() { @Test public void it_should_manipulate_requestDate() { // given - Date expected = new Date(); + ZonedDateTime expected = ZonedDateTime.now(); Refund testedClass = this.getTestedClass(); // when diff --git a/src/test/java/com/bitpay/sdk/model/invoice/RefundWebhookTest.java b/src/test/java/com/bitpay/sdk/model/invoice/RefundWebhookTest.java index ee0e99c7..39d41ae6 100644 --- a/src/test/java/com/bitpay/sdk/model/invoice/RefundWebhookTest.java +++ b/src/test/java/com/bitpay/sdk/model/invoice/RefundWebhookTest.java @@ -4,7 +4,7 @@ package com.bitpay.sdk.model.invoice; -import java.util.Date; +import java.time.ZonedDateTime; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -91,7 +91,7 @@ public void it_should_manipulate_currency() { @Test public void it_should_manipulate_lastRefundNotification() { // given - Date expected = new Date(); + ZonedDateTime expected = ZonedDateTime.now(); RefundWebhook testedClass = this.getTestedClass(); // when @@ -143,7 +143,7 @@ public void it_should_manipulate_buyerPaysRefundFee() { @Test public void it_should_manipulate_requestDate() { // given - Date expected = new Date(); + ZonedDateTime expected = ZonedDateTime.now(); RefundWebhook testedClass = this.getTestedClass(); // when diff --git a/src/test/java/com/bitpay/sdk/model/ledger/LedgerEntryTest.java b/src/test/java/com/bitpay/sdk/model/ledger/LedgerEntryTest.java index d0fa3ca5..f8e421b8 100644 --- a/src/test/java/com/bitpay/sdk/model/ledger/LedgerEntryTest.java +++ b/src/test/java/com/bitpay/sdk/model/ledger/LedgerEntryTest.java @@ -4,6 +4,7 @@ package com.bitpay.sdk.model.ledger; +import java.math.BigInteger; import java.time.ZonedDateTime; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -27,7 +28,7 @@ public void it_should_change_type() { @Test public void it_should_change_amount() { // given - String expected = "expectedString"; + BigInteger expected = BigInteger.valueOf(123); LedgerEntry testedClass = this.getTestedClass(); // when @@ -93,7 +94,7 @@ public void it_should_change_txType() { @Test public void it_should_change_scale() { // given - Integer expected = 13; + BigInteger expected = BigInteger.valueOf(13); LedgerEntry testedClass = this.getTestedClass(); // when diff --git a/src/test/java/com/bitpay/sdk/model/settlement/InvoiceDataTest.java b/src/test/java/com/bitpay/sdk/model/settlement/InvoiceDataTest.java index e8bb41c4..ee3e50ca 100644 --- a/src/test/java/com/bitpay/sdk/model/settlement/InvoiceDataTest.java +++ b/src/test/java/com/bitpay/sdk/model/settlement/InvoiceDataTest.java @@ -85,10 +85,10 @@ public void it_should_change_overPaidAmount() { InvoiceData testedClass = this.getTestedClass(); // when - testedClass.setOverPaidAmount(expected); + testedClass.setOverpaidAmount(expected); // then - Assertions.assertEquals(expected, testedClass.getOverPaidAmount()); + Assertions.assertEquals(expected, testedClass.getOverpaidAmount()); } @Test @@ -111,10 +111,10 @@ public void it_should_change_refundInfo() { InvoiceData testedClass = this.getTestedClass(); // when - testedClass.setAmount(expected); + testedClass.setRefundInfo(expected); // then - Assertions.assertEquals(expected, testedClass.getAmount()); + Assertions.assertEquals(expected, testedClass.getRefundInfo()); } private InvoiceData getTestedClass() { diff --git a/src/test/java/com/bitpay/sdk/model/settlement/RefundInfoTest.java b/src/test/java/com/bitpay/sdk/model/settlement/RefundInfoTest.java index 5b6fd2ee..244bb592 100644 --- a/src/test/java/com/bitpay/sdk/model/settlement/RefundInfoTest.java +++ b/src/test/java/com/bitpay/sdk/model/settlement/RefundInfoTest.java @@ -49,19 +49,6 @@ public void it_should_change_amounts() { Assertions.assertSame(expected, testedClass.getAmount()); } - @Test - public void it_should_manipulate_refundRequestEid() { - // given - String expected = "someString"; - RefundInfo testedClass = this.getTestedClass(); - - // when - testedClass.setRefundRequestEid(expected); - - // then - Assertions.assertEquals(expected, testedClass.getRefundRequestEid()); - } - private RefundInfo getTestedClass() { return new RefundInfo(); } diff --git a/src/test/java/com/bitpay/sdk/model/settlement/SettlementLedgerEntryTest.java b/src/test/java/com/bitpay/sdk/model/settlement/SettlementLedgerEntryTest.java index 96bd3a14..1ade9901 100644 --- a/src/test/java/com/bitpay/sdk/model/settlement/SettlementLedgerEntryTest.java +++ b/src/test/java/com/bitpay/sdk/model/settlement/SettlementLedgerEntryTest.java @@ -76,19 +76,6 @@ public void it_should_change_description() { Assertions.assertEquals(expected, testedClass.getDescription()); } - @Test - public void it_should_change_reference() { - // given - String expected = "expectedString"; - SettlementLedgerEntry testedClass = this.getTestedClass(); - - // when - testedClass.setReference(expected); - - // then - Assertions.assertEquals(expected, testedClass.getReference()); - } - @Test public void it_should_change_invoiceData() { // given diff --git a/src/test/java/com/bitpay/sdk/util/Iso8601ToZonedDateTimeDeserializerTest.java b/src/test/java/com/bitpay/sdk/util/Iso8601ToZonedDateTimeDeserializerTest.java new file mode 100644 index 00000000..512c5a58 --- /dev/null +++ b/src/test/java/com/bitpay/sdk/util/Iso8601ToZonedDateTimeDeserializerTest.java @@ -0,0 +1,34 @@ +package com.bitpay.sdk.util; + +import com.bitpay.sdk.util.serializer.Iso8601ToZonedDateTimeDeserializer; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.node.TextNode; +import java.io.IOException; +import java.time.ZonedDateTime; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class Iso8601ToZonedDateTimeDeserializerTest { + + @Test + public void it_should_deserialize_date() throws IOException { + // given + Iso8601ToZonedDateTimeDeserializer testedClass = new Iso8601ToZonedDateTimeDeserializer(); + JsonParser jsonParser = Mockito.mock(JsonParser.class); + JsonMapper jsonMapper = Mockito.mock(JsonMapper.class); + TextNode textNode = Mockito.mock(TextNode.class); + DeserializationContext deserializationContext = Mockito.mock(DeserializationContext.class); + Mockito.when(jsonParser.getCodec()).thenReturn(jsonMapper); + Mockito.when(jsonMapper.readTree(jsonParser)).thenReturn(textNode); + Mockito.when(textNode.asText()).thenReturn("1977-05-24T18:07:03.232Z"); + + // when + ZonedDateTime result = testedClass.deserialize(jsonParser, deserializationContext); + + // then + Assertions.assertEquals("1977-05-24T18:07:03.232Z", result.toString()); + } +} diff --git a/src/test/java/com/bitpay/sdk/util/ZonedDateTimeToIso8601SerializerTest.java b/src/test/java/com/bitpay/sdk/util/ZonedDateTimeToIso8601SerializerTest.java new file mode 100644 index 00000000..8b1ef018 --- /dev/null +++ b/src/test/java/com/bitpay/sdk/util/ZonedDateTimeToIso8601SerializerTest.java @@ -0,0 +1,29 @@ +package com.bitpay.sdk.util; + +import com.bitpay.sdk.util.serializer.ZonedDateTimeToIso8601Serializer; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class ZonedDateTimeToIso8601SerializerTest { + + @Test + public void it_should_serialize_date() throws IOException { + // given + ZonedDateTimeToIso8601Serializer testedClass = new ZonedDateTimeToIso8601Serializer(); + JsonGenerator jsonGenerator = Mockito.mock(JsonGenerator.class); + SerializerProvider serializerProvider = Mockito.mock(SerializerProvider.class); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX"); + ZonedDateTime value = ZonedDateTime.parse("2021-05-21T09:48:02.373Z", formatter); + + // when + testedClass.serialize(value, jsonGenerator, serializerProvider); + + // then + Mockito.verify(jsonGenerator, Mockito.times(1)).writeString("2021-05-21T09:48:02.37Z"); + } +}