diff --git a/doc/model/Invoice.html b/doc/model/Invoice.html index 76ef360..9367ce0 100644 --- a/doc/model/Invoice.html +++ b/doc/model/Invoice.html @@ -93,7 +93,7 @@ model Class Invoice
 java.lang.Object
-  extended by model.Invoice
+  extended by model.Invoice.Invoice
 

diff --git a/doc/model/InvoiceBuyer.html b/doc/model/InvoiceBuyer.html index 15a98c5..f0fa0c5 100644 --- a/doc/model/InvoiceBuyer.html +++ b/doc/model/InvoiceBuyer.html @@ -93,7 +93,7 @@ model Class InvoiceBuyer
 java.lang.Object
-  extended by model.InvoiceBuyer
+  extended by model.Invoice.Buyer
 

diff --git a/doc/model/InvoiceFlags.html b/doc/model/InvoiceFlags.html index 4b7dbff..86cff26 100644 --- a/doc/model/InvoiceFlags.html +++ b/doc/model/InvoiceFlags.html @@ -93,7 +93,7 @@ model Class InvoiceFlags
 java.lang.Object
-  extended by model.InvoiceFlags
+  extended by model.Invoice.InvoiceFlags
 

diff --git a/doc/model/InvoicePaymentUrls.html b/doc/model/InvoicePaymentUrls.html index bf4bd0b..b01ad10 100644 --- a/doc/model/InvoicePaymentUrls.html +++ b/doc/model/InvoicePaymentUrls.html @@ -93,7 +93,7 @@ model Class InvoicePaymentUrls
 java.lang.Object
-  extended by model.InvoicePaymentUrls
+  extended by model.Invoice.InvoicePaymentUrls
 

diff --git a/doc/model/InvoiceTransaction.html b/doc/model/InvoiceTransaction.html index 4519feb..790c2ff 100644 --- a/doc/model/InvoiceTransaction.html +++ b/doc/model/InvoiceTransaction.html @@ -93,7 +93,7 @@ model Class InvoiceTransaction
 java.lang.Object
-  extended by model.InvoiceTransaction
+  extended by model.Invoice.InvoiceTransaction
 

diff --git a/doc/model/class-use/Invoice.html b/doc/model/class-use/Invoice.html index e9d36c4..a80982c 100644 --- a/doc/model/class-use/Invoice.html +++ b/doc/model/class-use/Invoice.html @@ -4,7 +4,7 @@ -Uses of Class model.Invoice + Uses of Class model.Invoice.Invoice diff --git a/doc/model/class-use/InvoiceBuyer.html b/doc/model/class-use/InvoiceBuyer.html index 19c52fe..6114ea5 100644 --- a/doc/model/class-use/InvoiceBuyer.html +++ b/doc/model/class-use/InvoiceBuyer.html @@ -4,7 +4,7 @@ -Uses of Class model.InvoiceBuyer + Uses of Class model.Invoice.Buyer diff --git a/doc/model/class-use/InvoiceFlags.html b/doc/model/class-use/InvoiceFlags.html index 03a2872..c4b4f9b 100644 --- a/doc/model/class-use/InvoiceFlags.html +++ b/doc/model/class-use/InvoiceFlags.html @@ -4,7 +4,7 @@ -Uses of Class model.InvoiceFlags + Uses of Class model.Invoice.InvoiceFlags diff --git a/doc/model/class-use/InvoicePaymentUrls.html b/doc/model/class-use/InvoicePaymentUrls.html index 4e7f3ed..3f6f739 100644 --- a/doc/model/class-use/InvoicePaymentUrls.html +++ b/doc/model/class-use/InvoicePaymentUrls.html @@ -4,7 +4,7 @@ -Uses of Class model.InvoicePaymentUrls + Uses of Class model.Invoice.InvoicePaymentUrls diff --git a/doc/model/class-use/InvoiceTransaction.html b/doc/model/class-use/InvoiceTransaction.html index 97636ec..2cb0aca 100644 --- a/doc/model/class-use/InvoiceTransaction.html +++ b/doc/model/class-use/InvoiceTransaction.html @@ -4,7 +4,7 @@ -Uses of Class model.InvoiceTransaction + Uses of Class model.Invoice.InvoiceTransaction diff --git a/src/controller/BitPay.java b/src/controller/BitPay.java index d5ae0ae..3f2da51 100644 --- a/src/controller/BitPay.java +++ b/src/controller/BitPay.java @@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import model.*; +import model.Invoice.Invoice; +import model.Invoice.PaymentTotal; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.ParseException; @@ -445,7 +447,7 @@ public class BitPay { * Checks whether a BitPay invoice has been paid in full. * Returns true if the amountPaid >= paymentTotals, returns false otherwise * - * @param Invoice A Bitpay invoice object + * @param invoice A Bitpay invoice object * @return true if the amountPaid >= paymentTotals, returns false otherwise */ @@ -456,9 +458,16 @@ public class BitPay { if (transactionCurrency == null){ return false; } - Hashtable paymentTotals = invoice.getPaymentTotals(); - if (amountPaid < paymentTotals.get(transactionCurrency)){ - return false; + PaymentTotal paymentTotals = invoice.getPaymentTotals(); + if (transactionCurrency.equals("BTC")) { + if (amountPaid < paymentTotals.getBTC()) { + return false; + } + } + else if (transactionCurrency.equals("BCH")) { + if (amountPaid < paymentTotals.getBCH()) { + return false; + } } return true; } diff --git a/src/model/Currency.java b/src/model/Currency.java new file mode 100644 index 0000000..34da363 --- /dev/null +++ b/src/model/Currency.java @@ -0,0 +1,196 @@ +package model; + +import java.lang.reflect.Field; + +public class Currency { + + // Crypto + public static final String BCH = "BCH"; + public static final String BTC = "BTC"; + public static final String ETH = "ETH"; + public static final String USDC = "USDC"; + public static final String GUSD = "GUSD"; + public static final String PAX = "PAX"; + + // FIAT + public static final String AED = "AED"; + public static final String AFN = "AFN"; + public static final String ALL = "ALL"; + public static final String AMD = "AMD"; + public static final String ANG = "ANG"; + public static final String AOA = "AOA"; + public static final String ARS = "ARS"; + public static final String AUD = "AUD"; + public static final String AWG = "AWG"; + public static final String AZN = "AZN"; + public static final String BAM = "BAM"; + public static final String BBD = "BBD"; + public static final String BDT = "BDT"; + public static final String BGN = "BGN"; + public static final String BHD = "BHD"; + public static final String BIF = "BIF"; + public static final String BMD = "BMD"; + public static final String BND = "BND"; + public static final String BOB = "BOB"; + public static final String BOV = "BOV"; + public static final String BRL = "BRL"; + public static final String BSD = "BSD"; + public static final String BTN = "BTN"; + public static final String BWP = "BWP"; + public static final String BYR = "BYR"; + public static final String BZD = "BZD"; + public static final String CAD = "CAD"; + public static final String CDF = "CDF"; + public static final String CHE = "CHE"; + public static final String CHF = "CHF"; + public static final String CHW = "CHW"; + public static final String CLF = "CLF"; + public static final String CLP = "CLP"; + public static final String CNY = "CNY"; + public static final String COP = "COP"; + public static final String COU = "COU"; + public static final String CRC = "CRC"; + public static final String CUC = "CUC"; + public static final String CUP = "CUP"; + public static final String CVE = "CVE"; + public static final String CZK = "CZK"; + public static final String DJF = "DJF"; + public static final String DKK = "DKK"; + public static final String DOP = "DOP"; + public static final String DZD = "DZD"; + public static final String EGP = "EGP"; + public static final String ERN = "ERN"; + public static final String ETB = "ETB"; + public static final String EUR = "EUR"; + public static final String FJD = "FJD"; + public static final String FKP = "FKP"; + public static final String GBP = "GBP"; + public static final String GEL = "GEL"; + public static final String GHS = "GHS"; + public static final String GIP = "GIP"; + public static final String GMD = "GMD"; + public static final String GNF = "GNF"; + public static final String GTQ = "GTQ"; + public static final String GYD = "GYD"; + public static final String HKD = "HKD"; + public static final String HNL = "HNL"; + public static final String HRK = "HRK"; + public static final String HTG = "HTG"; + public static final String HUF = "HUF"; + public static final String IDR = "IDR"; + public static final String ILS = "ILS"; + public static final String INR = "INR"; + public static final String IQD = "IQD"; + public static final String IRR = "IRR"; + public static final String ISK = "ISK"; + public static final String JMD = "JMD"; + public static final String JOD = "JOD"; + public static final String JPY = "JPY"; + public static final String KES = "KES"; + public static final String KGS = "KGS"; + public static final String KHR = "KHR"; + public static final String KMF = "KMF"; + public static final String KPW = "KPW"; + public static final String KRW = "KRW"; + public static final String KWD = "KWD"; + public static final String KYD = "KYD"; + public static final String KZT = "KZT"; + public static final String LAK = "LAK"; + public static final String LBP = "LBP"; + public static final String LKR = "LKR"; + public static final String LRD = "LRD"; + public static final String LSL = "LSL"; + public static final String LYD = "LYD"; + public static final String MAD = "MAD"; + public static final String MDL = "MDL"; + public static final String MGA = "MGA"; + public static final String MKD = "MKD"; + public static final String MMK = "MMK"; + public static final String MNT = "MNT"; + public static final String MOP = "MOP"; + public static final String MRU = "MRU"; + public static final String MUR = "MUR"; + public static final String MVR = "MVR"; + public static final String MWK = "MWK"; + public static final String MXN = "MXN"; + public static final String MXV = "MXV"; + public static final String MYR = "MYR"; + public static final String MZN = "MZN"; + public static final String NAD = "NAD"; + public static final String NGN = "NGN"; + public static final String NIO = "NIO"; + public static final String NOK = "NOK"; + public static final String NPR = "NPR"; + public static final String NZD = "NZD"; + public static final String OMR = "OMR"; + public static final String PAB = "PAB"; + public static final String PEN = "PEN"; + public static final String PGK = "PGK"; + public static final String PHP = "PHP"; + public static final String PKR = "PKR"; + public static final String PLN = "PLN"; + public static final String PYG = "PYG"; + public static final String QAR = "QAR"; + public static final String RON = "RON"; + public static final String RSD = "RSD"; + public static final String RUB = "RUB"; + public static final String RWF = "RWF"; + public static final String SAR = "SAR"; + public static final String SBD = "SBD"; + public static final String SCR = "SCR"; + public static final String SDG = "SDG"; + public static final String SEK = "SEK"; + public static final String SGD = "SGD"; + public static final String SHP = "SHP"; + public static final String SLL = "SLL"; + public static final String SOS = "SOS"; + public static final String SRD = "SRD"; + public static final String SSP = "SSP"; + public static final String STN = "STN"; + public static final String SVC = "SVC"; + public static final String SYP = "SYP"; + public static final String SZL = "SZL"; + public static final String THB = "THB"; + public static final String TJS = "TJS"; + public static final String TMT = "TMT"; + public static final String TND = "TND"; + public static final String TOP = "TOP"; + public static final String TRY = "TRY"; + public static final String TTD = "TTD"; + public static final String TWD = "TWD"; + public static final String TZS = "TZS"; + public static final String UAH = "UAH"; + public static final String UGX = "UGX"; + public static final String USD = "USD"; + public static final String USN = "USN"; + public static final String UYI = "UYI"; + public static final String UYU = "UYU"; + public static final String UZS = "UZS"; + public static final String VEF = "VEF"; + public static final String VND = "VND"; + public static final String VUV = "VUV"; + public static final String WST = "WST"; + public static final String XAF = "XAF"; + public static final String XCD = "XCD"; + public static final String XDR = "XDR"; + public static final String XOF = "XOF"; + public static final String XPF = "XPF"; + public static final String XSU = "XSU"; + public static final String XUA = "XUA"; + public static final String YER = "YER"; + public static final String ZAR = "ZAR"; + public static final String ZMW = "ZMW"; + public static final String ZWL = "ZWL"; + + public static boolean isValid(String value) + { + try { + Class currencyClass = Currency.class; + Field symbol = currencyClass.getField(value); + return symbol!=null; + } + catch (Exception ex) { + return false; + } + } +} diff --git a/src/model/InvoiceBuyer.java b/src/model/Invoice/Buyer.java similarity index 76% rename from src/model/InvoiceBuyer.java rename to src/model/Invoice/Buyer.java index 97e3b48..9682d2c 100644 --- a/src/model/InvoiceBuyer.java +++ b/src/model/Invoice/Buyer.java @@ -1,21 +1,22 @@ -package model; +package model.Invoice; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; -public class InvoiceBuyer { +public class Buyer { - private String _name = ""; - private String _address1 = ""; - private String _address2 = ""; - private String _locality = ""; - private String _region = ""; - private String _postalCode = ""; - private String _country = ""; - private String _email = ""; - private String _phone = ""; + private String _name; + private String _address1; + private String _address2; + private String _locality; + private String _region; + private String _postalCode; + private String _country; + private String _email; + private String _phone; + private boolean _notify; - public InvoiceBuyer() {} + public Buyer() {} @JsonProperty("name") @JsonInclude(JsonInclude.Include.NON_DEFAULT) @@ -105,15 +106,26 @@ public class InvoiceBuyer { this._email = email; } - @JsonProperty("phone") - @JsonInclude(JsonInclude.Include.NON_DEFAULT) + @JsonProperty("phone") + @JsonInclude(JsonInclude.Include.NON_DEFAULT) public String getPhone() { return _phone; } - - @JsonProperty("phone") + + @JsonProperty("phone") public void setPhone(String phone) { this._phone = phone; } + + @JsonProperty("notify") + @JsonInclude(JsonInclude.Include.NON_DEFAULT) + public boolean getNotify() { + return _notify; + } + + @JsonProperty("notify") + public void setNotify(boolean notify) { + this._notify = notify; + } } diff --git a/src/model/Invoice.java b/src/model/Invoice/Invoice.java similarity index 60% rename from src/model/Invoice.java rename to src/model/Invoice/Invoice.java index 28b074a..499ab13 100644 --- a/src/model/Invoice.java +++ b/src/model/Invoice/Invoice.java @@ -1,4 +1,4 @@ -package model; +package model.Invoice; import java.util.Hashtable; import java.util.List; @@ -6,24 +6,17 @@ import java.util.List; import com.fasterxml.jackson.annotation.*; import controller.BitPayException; +import model.Currency; @JsonIgnoreProperties(ignoreUnknown=true) public class Invoice { - public static final String STATUS_NEW = "new"; - public static final String STATUS_PAID = "paid"; - public static final String STATUS_CONFIRMED = "confirmed"; - public static final String STATUS_COMPLETE = "complete"; - public static final String STATUS_INVALID = "invalid"; - public static final String EXSTATUS_FALSE = "false"; - public static final String EXSTATUS_PAID_OVER = "paidOver"; - public static final String EXSTATUS_PAID_PARTIAL = "paidPartial"; - + private String _currency; + private String _guid = ""; private String _token = ""; - + private Double _price; - private String _currency; private String _posData = ""; private String _notificationURL = ""; private String _transactionSpeed = ""; @@ -34,26 +27,34 @@ public class Invoice { private String _itemDesc = ""; private String _itemCode = ""; private boolean _physical = false; - private InvoiceBuyer _buyer; - + private List _paymentCurrencies; + private long _acceptanceWindow; + private Buyer _buyer; + private String _id; private String _url; private String _status; + private String _lowFeeDetected; private String _invoiceTime; private long _expirationTime; private long _currentTime; private List _transactions; private String _exceptionStatus; - private InvoicePaymentUrls _paymentUrls = new InvoicePaymentUrls(); + private String _refundAddressRequestPending; + private InvoiceBuyerProvidedInfo _invoiceBuyerProvidedInfo = new InvoiceBuyerProvidedInfo(); + private SupportedTransactionCurrencies _supportedTransactionCurrencies = new SupportedTransactionCurrencies(); + private MinerFees _minerFees = new MinerFees(); + private PaymentCodes _paymentCodes = new PaymentCodes(); private boolean _extendedNotifications = false; private String _transactionCurrency; private long _amountPaid; private Hashtable > _exchangeRates; - private Hashtable _paymentTotals; - private Hashtable _paymentSubtotals; + private PaymentTotal _paymentTotals; + private PaymentTotal _paymentSubtotals; + private PaymentTotal _paymentDisplayTotals; + private PaymentTotal _paymentDisplaySubTotals; - /** * Constructor, create an empty Invoice object. */ @@ -115,10 +116,9 @@ public class Invoice { @JsonProperty("currency") public void setCurrency(String _currency) throws BitPayException { - if (_currency.length() != 3) - { - throw new BitPayException("Error: currency code must be exactly three characters"); - } + if (!Currency.isValid(_currency)) + throw new BitPayException("Error: currency code must be a type of Model.Currency"); + this._currency = _currency; } @@ -202,6 +202,17 @@ public class Invoice { this._fullNotifications = _fullNotifications; } + @JsonProperty("extendedNotifications") + @JsonInclude(JsonInclude.Include.NON_DEFAULT) + public boolean getExtendedNotifications() { + return _extendedNotifications; + } + + @JsonProperty("extendedNotifications") + public void setExtendedNotifications(boolean _extendedNotifications) { + this._extendedNotifications = _extendedNotifications; + } + @JsonProperty("notificationEmail") @JsonInclude(JsonInclude.Include.NON_DEFAULT) public String getNotificationEmail() { @@ -235,29 +246,42 @@ public class Invoice { this._physical = _physical; } + @JsonProperty("paymentCurrencies") + @JsonInclude(JsonInclude.Include.NON_DEFAULT) + public List getPaymentCurrencies() { + return _paymentCurrencies; + } + + @JsonProperty("paymentCurrencies") + public void setPaymentCurrencies(List _paymentCurrencies) { + this._paymentCurrencies = _paymentCurrencies; + } + + @JsonProperty("acceptanceWindow") + @JsonInclude(JsonInclude.Include.NON_DEFAULT) + public long getAcceptanceWindow() { + return _acceptanceWindow; + } + + @JsonProperty("acceptanceWindow") + public void setAcceptanceWindow(long _acceptanceWindow) { + this._acceptanceWindow = _acceptanceWindow; + } + + // Buyer data + // + @JsonProperty("buyer") @JsonInclude(JsonInclude.Include.NON_DEFAULT) - public InvoiceBuyer getBuyer() { + public Buyer getBuyer() { return _buyer; } @JsonProperty("buyer") - public void setBuyer(InvoiceBuyer _buyer) { + public void setBuyer(Buyer _buyer) { this._buyer = _buyer; } - - @JsonProperty("extendedNotifications") - @JsonInclude(JsonInclude.Include.NON_DEFAULT) - public boolean getExtendedNotifications() { - return _extendedNotifications; - } - - @JsonProperty("extendedNotifications") - public void setExtendedNotifications(boolean _extendedNotifications) { - this._extendedNotifications = _extendedNotifications; - } - // Response fields // @@ -281,16 +305,22 @@ public class Invoice { this._url = _url; } - @JsonIgnore + @JsonIgnore public String getStatus() { return _status; } - - @JsonProperty("status") + + @JsonProperty("status") public void setStatus(String _status) { this._status = _status; } + @JsonIgnore + public String getLowFeeDetected() { return _lowFeeDetected; } + + @JsonProperty("lowFeeDetected") + public void setLowFeeDetected(String _lowFeeDetected) { this._lowFeeDetected = _lowFeeDetected; } + @JsonIgnore public String getInvoiceTime() { return _invoiceTime; @@ -341,65 +371,123 @@ public class Invoice { this._exceptionStatus = _exceptionStatus; } - @JsonIgnore - public InvoicePaymentUrls getPaymentUrls() { - return _paymentUrls; - } - - @JsonProperty("paymentUrls") - public void setPaymentUrls(InvoicePaymentUrls _paymentUrls) { - this._paymentUrls = _paymentUrls; - } + @JsonIgnore + public String getRefundAddressRequestPending() { + return _refundAddressRequestPending; + } + + @JsonProperty("refundAddressRequestPending") + public void setRefundAddressRequestPending(String _refundAddressRequestPending) { + this._refundAddressRequestPending = _refundAddressRequestPending; + } @JsonIgnore - public String getTransactionCurrency() { - return _transactionCurrency; - } - - @JsonProperty("transactionCurrency") - public void setTransactionCurrency(String _transactionCurrency) { - this._transactionCurrency = _transactionCurrency; - } - - @JsonIgnore - public long getAmountPaid() { - return _amountPaid; - } - - @JsonProperty("amountPaid") - public void setAmountPaid(long _amountPaid) { - this._amountPaid = _amountPaid; - } + public InvoiceBuyerProvidedInfo getInvoiceBuyerProvidedInfo() { + return _invoiceBuyerProvidedInfo; + } + + @JsonProperty("invoiceBuyerProvidedInfo") + public void setInvoiceBuyerProvidedInfo(InvoiceBuyerProvidedInfo _invoiceBuyerProvidedInfo) { + this._invoiceBuyerProvidedInfo = _invoiceBuyerProvidedInfo; + } + + @JsonIgnore + public SupportedTransactionCurrencies getSupportedTransactionCurrencies() { + return _supportedTransactionCurrencies; + } + + @JsonProperty("supportedTransactionCurrencies") + public void setSupportedTransactionCurrencies(SupportedTransactionCurrencies _supportedTransactionCurrencies) { + this._supportedTransactionCurrencies = _supportedTransactionCurrencies; + } + + @JsonIgnore + public MinerFees getMinerFees() { + return _minerFees; + } + + @JsonProperty("minerFees") + public void setMinerFees(MinerFees _minerFees) { + this._minerFees = _minerFees; + } + + @JsonIgnore + public String getTransactionCurrency() { + return _transactionCurrency; + } + + @JsonProperty("transactionCurrency") + public void setTransactionCurrency(String _transactionCurrency) { + this._transactionCurrency = _transactionCurrency; + } + + @JsonIgnore + public PaymentCodes getPaymentCodes() { + return _paymentCodes; + } + + @JsonProperty("paymentCodes") + public void setPaymentCodes(PaymentCodes _paymentCodes) { + this._paymentCodes = _paymentCodes; + } + + @JsonIgnore + public PaymentTotal getPaymentSubtotals() { + return _paymentSubtotals; + } + + @JsonProperty("paymentSubtotals") + public void setPaymentSubtotals(PaymentTotal _paymentSubtotals) { + this._paymentSubtotals = _paymentSubtotals; + } + + @JsonIgnore + public PaymentTotal getPaymentTotals() { + return _paymentTotals; + } + + @JsonProperty("paymentTotals") + public void setPaymentTotals(PaymentTotal _paymentTotals) { + this._paymentTotals = _paymentTotals; + } + + @JsonIgnore + public PaymentTotal getPaymentDisplayTotals() { + return _paymentDisplayTotals; + } + + @JsonProperty("paymentDisplayTotals") + public void setPaymentDisplayTotals(PaymentTotal _paymentDisplayTotals) { + this._paymentDisplayTotals = _paymentDisplayTotals; + } + + @JsonIgnore + public PaymentTotal getPaymentDisplaySubTotals() { + return _paymentDisplaySubTotals; + } + + @JsonProperty("paymentDisplaySubTotals") + public void setPaymentDisplaySubTotals(PaymentTotal _paymentDisplaySubTotals) { + this._paymentDisplaySubTotals = _paymentDisplaySubTotals; + } + + @JsonIgnore + public long getAmountPaid() { + return _amountPaid; + } + + @JsonProperty("amountPaid") + public void setAmountPaid(long _amountPaid) { + this._amountPaid = _amountPaid; + } @JsonIgnore public Hashtable > getExchangeRates() { return _exchangeRates; } - - @JsonProperty("exchangeRates") + + @JsonProperty("exchangeRates") public void setExchangeRates(Hashtable > _exchangeRates) { this._exchangeRates = _exchangeRates; } - - @JsonIgnore - public Hashtable getPaymentTotals() { - return _paymentTotals; - } - - @JsonProperty("paymentTotals") - public void setPaymentTotals(Hashtable _paymentTotals) { - this._paymentTotals = _paymentTotals; - } - - @JsonIgnore - public Hashtable getPaymentSubtotals() { - return _paymentSubtotals; - } - - @JsonProperty("paymentSubtotals") - public void setPaymentSubtotals(Hashtable _paymentSubtotals) { - this._paymentSubtotals = _paymentSubtotals; - } - - } diff --git a/src/model/Invoice/InvoiceBuyerProvidedInfo.java b/src/model/Invoice/InvoiceBuyerProvidedInfo.java new file mode 100644 index 0000000..d9e1c21 --- /dev/null +++ b/src/model/Invoice/InvoiceBuyerProvidedInfo.java @@ -0,0 +1,42 @@ +package model.Invoice; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class InvoiceBuyerProvidedInfo { + private String _name; + private String _phoneNumber; + private String _emailAddress; + + public InvoiceBuyerProvidedInfo() {} + + @JsonIgnore + public String getName() { + return _name; + } + + @JsonProperty("name") + public void setName(String name) { + this._name = name; + } + + @JsonIgnore + public String getPhoneNumber() { + return _phoneNumber; + } + + @JsonProperty("phoneNumber") + public void setPhoneNumber(String phoneNumber) { + this._phoneNumber = phoneNumber; + } + + @JsonIgnore + public String getEmailAddress() { + return _emailAddress; + } + + @JsonProperty("emailAddress") + public void setEmailAddress(String emailAddress) { + this._emailAddress = emailAddress; + } +} diff --git a/src/model/Invoice/InvoiceStatus.java b/src/model/Invoice/InvoiceStatus.java new file mode 100644 index 0000000..ca9cf5c --- /dev/null +++ b/src/model/Invoice/InvoiceStatus.java @@ -0,0 +1,11 @@ +package model.Invoice; + +public class InvoiceStatus { + + public static final String New = "new"; + public static final String Funded = "funded"; + public static final String Processing = "processing"; + public static final String Complete = "complete"; + public static final String Failed = "failed"; + public static final String Cancelled = "cancelled"; +} diff --git a/src/model/InvoiceTransaction.java b/src/model/Invoice/InvoiceTransaction.java similarity index 95% rename from src/model/InvoiceTransaction.java rename to src/model/Invoice/InvoiceTransaction.java index 3c46848..ef1e14c 100644 --- a/src/model/InvoiceTransaction.java +++ b/src/model/Invoice/InvoiceTransaction.java @@ -1,4 +1,4 @@ -package model; +package model.Invoice; import java.util.Date; @@ -35,16 +35,6 @@ public class InvoiceTransaction { this._confirmations = confirmations; } - @JsonIgnore - public Date getTime() { - return _time; - } - - @JsonProperty("time") - public void setTime(Date time) { - this._time = time; - } - @JsonIgnore public Date getReceivedTime() { return _receivedTime; @@ -65,4 +55,14 @@ public class InvoiceTransaction { this._txid = txid; } + @JsonIgnore + public Date getTime() { + return _time; + } + + @JsonProperty("time") + public void setTime(Date time) { + this._time = time; + } + } diff --git a/src/model/Invoice/MinerFees.java b/src/model/Invoice/MinerFees.java new file mode 100644 index 0000000..a798d63 --- /dev/null +++ b/src/model/Invoice/MinerFees.java @@ -0,0 +1,32 @@ +package model.Invoice; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class MinerFees { + + private MinerFeesItem _btc = new MinerFeesItem(); + private MinerFeesItem _bch = new MinerFeesItem(); + + public MinerFees() {} + + @JsonIgnore + public MinerFeesItem getBtc() { + return _btc; + } + + @JsonProperty("BTC") + public void setBtc(MinerFeesItem btc) { + this._btc = btc; + } + + @JsonIgnore + public MinerFeesItem getBch() { + return _bch; + } + + @JsonProperty("BCH") + public void setBch(MinerFeesItem bch) { + this._bch = bch; + } +} diff --git a/src/model/Invoice/MinerFeesItem.java b/src/model/Invoice/MinerFeesItem.java new file mode 100644 index 0000000..2ff9f46 --- /dev/null +++ b/src/model/Invoice/MinerFeesItem.java @@ -0,0 +1,32 @@ +package model.Invoice; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class MinerFeesItem { + + private Double _satoshisPerByte; + private Double _totalFee; + + public MinerFeesItem() {} + + @JsonIgnore + public Double getSatoshisPerByte() { + return _satoshisPerByte; + } + + @JsonProperty("satoshisPerByte") + public void setSatoshisPerByte(Double satoshisPerByte) { + this._satoshisPerByte = satoshisPerByte; + } + + @JsonIgnore + public Double getTotalFee() { + return _totalFee; + } + + @JsonProperty("totalFee") + public void setTotalFee(Double totalFee) { + this._totalFee = totalFee; + } +} diff --git a/src/model/Invoice/PaymentCode.java b/src/model/Invoice/PaymentCode.java new file mode 100644 index 0000000..f2e6e60 --- /dev/null +++ b/src/model/Invoice/PaymentCode.java @@ -0,0 +1,32 @@ +package model.Invoice; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class PaymentCode { + + private String _bip72b; + private String _bip73; + + public PaymentCode() {} + + @JsonIgnore + public String getBip72b() { + return _bip72b; + } + + @JsonProperty("BIP72b") + public void setBip72b(String bip72b) { + this._bip72b = bip72b; + } + + @JsonIgnore + public String getBip73() { + return _bip73; + } + + @JsonProperty("BIP73") + public void setBip73(String bip73) { + this._bip73 = bip73; + } +} diff --git a/src/model/Invoice/PaymentCodes.java b/src/model/Invoice/PaymentCodes.java new file mode 100644 index 0000000..290ea93 --- /dev/null +++ b/src/model/Invoice/PaymentCodes.java @@ -0,0 +1,32 @@ +package model.Invoice; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class PaymentCodes { + + private PaymentCode _btc = new PaymentCode(); + private PaymentCode _bch = new PaymentCode(); + + public PaymentCodes() {} + + @JsonIgnore + public PaymentCode getBtc() { + return _btc; + } + + @JsonProperty("BTC") + public void setBtc(PaymentCode btc) { + this._btc = btc; + } + + @JsonIgnore + public PaymentCode getBch() { + return _bch; + } + + @JsonProperty("BCH") + public void setBch(PaymentCode bch) { + this._bch = bch; + } +} diff --git a/src/model/Invoice/PaymentTotal.java b/src/model/Invoice/PaymentTotal.java new file mode 100644 index 0000000..3954044 --- /dev/null +++ b/src/model/Invoice/PaymentTotal.java @@ -0,0 +1,32 @@ +package model.Invoice; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class PaymentTotal { + + private Double _btc; + private Double _bch; + + public PaymentTotal() {} + + @JsonIgnore + public Double getBTC() { + return _btc; + } + + @JsonProperty("BTC") + public void setBtc(Double btc) { + this._btc = btc; + } + + @JsonIgnore + public Double getBCH() { + return _bch; + } + + @JsonProperty("BCH") + public void setBch(Double bch) { + this._bch = bch; + } +} diff --git a/src/model/Invoice/SupportedTransactionCurrencies.java b/src/model/Invoice/SupportedTransactionCurrencies.java new file mode 100644 index 0000000..2eb755e --- /dev/null +++ b/src/model/Invoice/SupportedTransactionCurrencies.java @@ -0,0 +1,32 @@ +package model.Invoice; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SupportedTransactionCurrencies { + + private SupportedTransactionCurrency _btc = new SupportedTransactionCurrency(); + private SupportedTransactionCurrency _bch = new SupportedTransactionCurrency(); + + public SupportedTransactionCurrencies() {} + + @JsonIgnore + public SupportedTransactionCurrency getBtc() { + return _btc; + } + + @JsonProperty("BTC") + public void setBtc(SupportedTransactionCurrency btc) { + this._btc = btc; + } + + @JsonIgnore + public SupportedTransactionCurrency getBch() { + return _bch; + } + + @JsonProperty("BCH") + public void setBch(SupportedTransactionCurrency bch) { + this._bch = bch; + } +} diff --git a/src/model/Invoice/SupportedTransactionCurrency.java b/src/model/Invoice/SupportedTransactionCurrency.java new file mode 100644 index 0000000..071a8ed --- /dev/null +++ b/src/model/Invoice/SupportedTransactionCurrency.java @@ -0,0 +1,21 @@ +package model.Invoice; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SupportedTransactionCurrency { + + private boolean _enabled; + + public SupportedTransactionCurrency() {} + + @JsonIgnore + public boolean getEnabled() { + return _enabled; + } + + @JsonProperty("enabled") + public void setNotify(boolean enabled) { + this._enabled = enabled; + } +} diff --git a/src/model/InvoiceFlags.java b/src/model/InvoiceFlags.java deleted file mode 100644 index 1c94933..0000000 --- a/src/model/InvoiceFlags.java +++ /dev/null @@ -1,22 +0,0 @@ -package model; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class InvoiceFlags { - - private boolean _refundable = false; - - public InvoiceFlags() {} - - @JsonIgnore - public boolean getRefundable() { - return _refundable; - } - - @JsonProperty("refundable") - public void setRefundable(boolean refundable) { - this._refundable = refundable; - } - -} diff --git a/src/model/InvoicePaymentUrls.java b/src/model/InvoicePaymentUrls.java deleted file mode 100644 index 7ccbf04..0000000 --- a/src/model/InvoicePaymentUrls.java +++ /dev/null @@ -1,54 +0,0 @@ -package model; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class InvoicePaymentUrls { - - private String _BIP21 = ""; - private String _BIP72 = ""; - private String _BIP72b = ""; - private String _BIP73 = ""; - - public InvoicePaymentUrls() {} - - @JsonIgnore - public String getBIP21() { - return _BIP21; - } - - @JsonProperty("BIP21") - public void setBIP21(String BIP21) { - this._BIP21 = BIP21; - } - - @JsonIgnore - public String getBIP72() { - return _BIP72; - } - - @JsonProperty("BIP72") - public void setBIP72(String BIP72) { - this._BIP72 = BIP72; - } - - @JsonIgnore - public String getBIP72b() { - return _BIP72b; - } - - @JsonProperty("BIP72b") - public void setBIP72b(String BIP72b) { - this._BIP72b = BIP72b; - } - - @JsonIgnore - public String getBIP73() { - return _BIP73; - } - - @JsonProperty("BIP73") - public void setBIP73(String BIP73) { - this._BIP73 = BIP73; - } -} diff --git a/src/model/RefundHelper.java b/src/model/RefundHelper.java index 31a443e..d43c163 100644 --- a/src/model/RefundHelper.java +++ b/src/model/RefundHelper.java @@ -1,5 +1,7 @@ package model; +import model.Invoice.Invoice; + public class RefundHelper { private Refund _refund; diff --git a/src/test/BitPayTest.java b/src/test/BitPayTest.java index e8f19c2..0cc4af9 100644 --- a/src/test/BitPayTest.java +++ b/src/test/BitPayTest.java @@ -5,6 +5,9 @@ import controller.BitPayException; import controller.BitPayLogger; import controller.KeyUtils; import model.*; +import model.Invoice.Invoice; +import model.Invoice.Buyer; +import model.Invoice.InvoiceStatus; import org.bitcoinj.core.ECKey; import org.junit.Before; import org.junit.BeforeClass; @@ -138,14 +141,14 @@ public class BitPayTest { @Test public void testShouldGetInvoiceStatus() { - Invoice invoice = new Invoice(50.0, "USD"); + Invoice invoice = new Invoice(2.0, "EUR"); try { basicInvoice = bitpay.createInvoice(invoice); } catch (BitPayException e) { e.printStackTrace(); fail(e.getMessage()); } - assertEquals(Invoice.STATUS_NEW, basicInvoice.getStatus()); + assertEquals(InvoiceStatus.New, basicInvoice.getStatus()); } @Test @@ -209,7 +212,7 @@ public class BitPayTest { @Test public void testShouldCreateInvoiceWithAdditionalParams() { - InvoiceBuyer buyer = new InvoiceBuyer(); + Buyer buyer = new Buyer(); buyer.setName("Satoshi"); buyer.setEmail("satoshi@buyeremaildomain.com"); @@ -224,7 +227,7 @@ public class BitPayTest { e.printStackTrace(); fail(e.getMessage()); } - assertEquals(Invoice.STATUS_NEW, invoice.getStatus()); + assertEquals(InvoiceStatus.New, invoice.getStatus()); assertEquals(100.0, invoice.getPrice(), EPSILON); assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", invoice.getPosData()); assertEquals("Satoshi", invoice.getBuyer().getName()); diff --git a/src/test/BitPayTest2.java b/src/test/BitPayTest2.java index 7af6d3d..928ef72 100644 --- a/src/test/BitPayTest2.java +++ b/src/test/BitPayTest2.java @@ -3,7 +3,8 @@ package test; import controller.BitPay; import controller.BitPayException; import controller.BitPayLogger; -import model.Invoice; +import model.Invoice.Invoice; +import model.Currency; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -11,6 +12,7 @@ import org.junit.Test; import java.net.UnknownHostException; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class BitPayTest2 { @@ -34,7 +36,7 @@ public class BitPayTest2 { // time should result in the authorized client (this test) running to completion. clientName += " on " + java.net.InetAddress.getLocalHost(); BitPay bitpay = new BitPay(clientName, BitPay.BITPAY_TEST_URL); //this tests the old way of creating keys/clients - + if (!bitpay.clientIsAuthorized(BitPay.FACADE_POS)) { // Get POS facade authorization code. @@ -42,7 +44,7 @@ public class BitPayTest2 { // this device and input into and approved by the desired merchant account. To // generate invoices a POS facade is required. String pairingCode = bitpay.requestClientAuthorization(BitPay.FACADE_POS); - + // Signal the device operator that this client needs to be paired with a merchant account. _log.info("Client is requesting POS facade access. Go to " + BitPay.BITPAY_TEST_URL + " and pair this client with your merchant account using the pairing code: " + pairingCode); throw new BitPayException("Error: client is not authorized."); @@ -60,4 +62,12 @@ public class BitPayTest2 { } assertNotNull(invoice.getId()); } + + @Test + public void testCurrency() + { + boolean validCurrency; + validCurrency = Currency.isValid("EUR"); + assertTrue(validCurrency); + } }