From 5cf0edb2466fc28d4588b1e8b50a915d2ea98117 Mon Sep 17 00:00:00 2001 From: Sandro Machado Date: Wed, 23 Dec 2015 12:46:09 +0000 Subject: [PATCH] Add transaction fees model --- .../test/integration/model/CardTest.java | 25 ++++-- .../test/util/Fixtures.java | 11 ++- .../uphold_android_sdk/model/Transaction.java | 21 ++++- .../model/transaction/Fee.java | 85 +++++++++++++++++++ .../test/unit/model/TransactionTest.java | 20 +++-- 5 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 src/app/src/main/java/com/uphold/uphold_android_sdk/model/transaction/Fee.java diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/CardTest.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/CardTest.java index c9cb68e..76a865c 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/CardTest.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/CardTest.java @@ -1,10 +1,10 @@ package com.uphold.uphold_android_sdk.test.integration.model; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.SmallTest; + import com.darylteo.rx.promises.java.Promise; import com.darylteo.rx.promises.java.functions.RepromiseFunction; - -import junit.framework.Assert; - import com.uphold.uphold_android_sdk.client.restadapter.UpholdRestAdapter; import com.uphold.uphold_android_sdk.model.Card; import com.uphold.uphold_android_sdk.model.Transaction; @@ -13,13 +13,12 @@ import com.uphold.uphold_android_sdk.test.BuildConfig; import com.uphold.uphold_android_sdk.test.util.Fixtures; import com.uphold.uphold_android_sdk.test.util.MockRestAdapter; + +import junit.framework.Assert; + import org.junit.Test; import org.junit.runner.RunWith; -import android.support.test.runner.AndroidJUnit4; -import android.test.suitebuilder.annotation.SmallTest; - -import java.lang.String; import java.util.HashMap; import java.util.List; @@ -89,6 +88,13 @@ public void createTransactionShouldReturnTheTransaction() throws Exception { "\"currency\": \"BTC\"," + "\"fee\": \"1.00\"," + "\"rate\": \"2.00\"" + + "}]," + + "\"fees\": [{" + + "\"type\": \"deposit\"," + + "\"amount\": \"0.30\"," + + "\"target\": \"origin\"," + + "\"currency\": \"USD\"," + + "\"percentage\": \"2.75\"" + "}]" + "}"; MockRestAdapter adapter = new MockRestAdapter<>("foobar", responseString, null); @@ -121,6 +127,11 @@ public Promise call(UpholdRestAdapter adapter) { Assert.assertEquals(transaction.getDenomination().getCurrency(), "BTC"); Assert.assertEquals(transaction.getDenomination().getPair(), "BTCBTC"); Assert.assertEquals(transaction.getDenomination().getRate(), "1.00"); + Assert.assertEquals(transaction.getFees().get(0).getAmount(), "0.30"); + Assert.assertEquals(transaction.getFees().get(0).getCurrency(), "USD"); + Assert.assertEquals(transaction.getFees().get(0).getPercentage(), "2.75"); + Assert.assertEquals(transaction.getFees().get(0).getTarget(), "origin"); + Assert.assertEquals(transaction.getFees().get(0).getType(), "deposit"); Assert.assertEquals(transaction.getOrigin().getAccountId(), "fiz"); Assert.assertEquals(transaction.getOrigin().getCardId(), "bar"); Assert.assertEquals(transaction.getOrigin().getAccountType(), "biz"); diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/util/Fixtures.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/util/Fixtures.java index 669eeca..7915eec 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/util/Fixtures.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/util/Fixtures.java @@ -8,6 +8,7 @@ import com.uphold.uphold_android_sdk.model.card.Normalized; import com.uphold.uphold_android_sdk.model.transaction.Denomination; import com.uphold.uphold_android_sdk.model.transaction.Destination; +import com.uphold.uphold_android_sdk.model.transaction.Fee; import com.uphold.uphold_android_sdk.model.transaction.Origin; import com.uphold.uphold_android_sdk.model.transaction.Parameters; import com.uphold.uphold_android_sdk.model.transaction.Source; @@ -122,6 +123,11 @@ public static Transaction loadTransaction(HashMap fields) { put("destinationRate", faker.lorem().fixedString(3)); put("destinationType", faker.lorem().fixedString(6)); put("destinationUsername", faker.lorem().fixedString(10)); + put("feeAmount", faker.numerify("123456789")); + put("feeCurrency", faker.lorem().fixedString(3)); + put("feePercentage", faker.numerify("123456789")); + put("feeTarget", faker.lorem().fixedString(10)); + put("feeType", faker.lorem().fixedString(10)); put("normalizedAmount", faker.numerify("123456789")); put("normalizedCommission", faker.numerify("123456789")); put("normalizedCurrency", faker.lorem().fixedString(3)); @@ -164,6 +170,9 @@ public static Transaction loadTransaction(HashMap fields) { Denomination denomination = new Denomination(fakerFields.get("denominationAmount"), fakerFields.get("denominationCurrency"), fakerFields.get("denominationPair"), fakerFields.get("denominationRate")); Destination destination = new Destination(fakerFields.get("destinationAccountId"), fakerFields.get("destinationCardId"), fakerFields.get("destinationAccountType"), fakerFields.get("destinationAmount"), fakerFields.get("destinationBase"), fakerFields.get("destinationCommission"), fakerFields.get("destinationCurrency"), fakerFields.get("destinationDescription"), fakerFields.get("destinationFee"), fakerFields.get("destinationRate"), fakerFields.get("destinationType"), fakerFields.get("destinationUsername")); + ArrayList fees = new ArrayList() {{ + add(new Fee(fakerFields.get("feeAmount"), fakerFields.get("feeCurrency"), fakerFields.get("feePercentage"), fakerFields.get("feeTarget"), fakerFields.get("feeType"))); + }}; ArrayList sources = new ArrayList() {{ ArrayList ids = new ArrayList<>(Arrays.asList(fakerFields.get("originSourcesId").split(","))); ArrayList amount = new ArrayList<>(Arrays.asList(fakerFields.get("originSourcesAmount").split(","))); @@ -178,7 +187,7 @@ public static Transaction loadTransaction(HashMap fields) { Origin origin = new Origin(fakerFields.get("originAccountId"), fakerFields.get("originCardId"), fakerFields.get("originAccountType"), fakerFields.get("originAmount"), fakerFields.get("originBase"), fakerFields.get("originCommission"), fakerFields.get("originCurrency"), fakerFields.get("originDescription"), fakerFields.get("originFee"), fakerFields.get("originRate"), sources, fakerFields.get("originType"), fakerFields.get("originUsername")); Parameters parameters = new Parameters(fakerFields.get("parametersCurrency"), fakerFields.get("parametersMargin"), fakerFields.get("parametersPair"), fakerFields.get("parametersProgress"), fakerFields.get("parametersRate"), fakerFields.get("parametersRefunds"), Integer.parseInt(fakerFields.get("parametersTtl")), fakerFields.get("parametersTxid"), fakerFields.get("parametersType")); - return new Transaction(fakerFields.get("transactionId"), fakerFields.get("transactionCreatedAt"), denomination, destination, fakerFields.get("transactionMessage"), normalized, origin, parameters, fakerFields.get("transactionRefundedById"), fakerFields.get("transactionStatus"), fakerFields.get("transactionType")); + return new Transaction(fakerFields.get("transactionId"), fakerFields.get("transactionCreatedAt"), denomination, destination, fees, fakerFields.get("transactionMessage"), normalized, origin, parameters, fakerFields.get("transactionRefundedById"), fakerFields.get("transactionStatus"), fakerFields.get("transactionType")); } public static TransactionRequest loadTransactionRequest(){ diff --git a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/Transaction.java b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/Transaction.java index eb69bfb..a9e21bd 100644 --- a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/Transaction.java +++ b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/Transaction.java @@ -1,19 +1,19 @@ package com.uphold.uphold_android_sdk.model; -import com.darylteo.rx.promises.java.Promise; +import android.text.TextUtils; +import com.darylteo.rx.promises.java.Promise; import com.uphold.uphold_android_sdk.client.retrofitpromise.RetrofitPromise; import com.uphold.uphold_android_sdk.exception.LogicException; import com.uphold.uphold_android_sdk.model.transaction.Denomination; import com.uphold.uphold_android_sdk.model.transaction.Destination; +import com.uphold.uphold_android_sdk.model.transaction.Fee; import com.uphold.uphold_android_sdk.model.transaction.Normalized; import com.uphold.uphold_android_sdk.model.transaction.Origin; import com.uphold.uphold_android_sdk.model.transaction.Parameters; import com.uphold.uphold_android_sdk.model.transaction.TransactionCommitRequest; import com.uphold.uphold_android_sdk.service.UserCardService; -import android.text.TextUtils; - import java.io.Serializable; import java.util.List; @@ -27,6 +27,7 @@ public class Transaction extends BaseModel implements Serializable { private final String createdAt; private final Denomination denomination; private final Destination destination; + private final List fees; private final String message; private final List normalized; private final Origin origin; @@ -42,6 +43,7 @@ public class Transaction extends BaseModel implements Serializable { * @param createdAt The date and time the transaction was initiated. * @param denomination The funds to be transfered. * @param destination The recipient of the funds. + * @param fees The transaction fees. * @param message A message or note provided by the user at the time the transaction was initiated, with the intent of communicating additional information and context about the nature/purpose of the transaction. * @param normalized The transaction details normalized. * @param origin The sender of the funds. @@ -51,11 +53,12 @@ public class Transaction extends BaseModel implements Serializable { * @param type The nature of the transaction. */ - public Transaction(String id, String createdAt, Denomination denomination, Destination destination, String message, List normalized, Origin origin, Parameters params, String refundedById, String status, String type) { + public Transaction(String id, String createdAt, Denomination denomination, Destination destination, List fees, String message, List normalized, Origin origin, Parameters params, String refundedById, String status, String type) { this.id = id; this.createdAt = createdAt; this.denomination = denomination; this.destination = destination; + this.fees = fees; this.message = message; this.normalized = normalized; this.origin = origin; @@ -181,6 +184,16 @@ public Destination getDestination() { return destination; } + /** + * Gets the transaction fees. + * + * @return the transaction fees. + */ + + public List getFees() { + return fees; + } + /** * Gets the message or note provided by the user at the time the transaction was initiated, with the intent of communicating additional information and context about the nature/purpose of the transaction. * diff --git a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/transaction/Fee.java b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/transaction/Fee.java new file mode 100644 index 0000000..d07ae44 --- /dev/null +++ b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/transaction/Fee.java @@ -0,0 +1,85 @@ +package com.uphold.uphold_android_sdk.model.transaction; + +import java.io.Serializable; + +/** + * Fee model. + */ + +public class Fee implements Serializable { + + private final String amount; + private final String currency; + private final String percentage; + private final String target; + private final String type; + + /** + * Constructor. + * + * @param amount The amount. + * @param currency The currency. + * @param percentage The percentage. + * @param target The target. + * @param type The type. + */ + + public Fee(String amount, String currency, String percentage, String target, String type) { + this.amount = amount; + this.currency = currency; + this.percentage = percentage; + this.target = target; + this.type = type; + } + + /** + * Gets the amount. + * + * @return the amount. + */ + + public String getAmount() { + return amount; + } + + /** + * Gets the currency. + * + * @return the currency. + */ + + public String getCurrency() { + return currency; + } + + /** + * Gets the percentage. + * + * @return the percentage. + */ + + public String getPercentage() { + return percentage; + } + + /** + * Gets the target. + * + * @return the target, + */ + + public String getTarget() { + return target; + } + + /** + * Gets the type. + * + * @return the type. + */ + + public String getType() { + return type; + } + +} diff --git a/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/TransactionTest.java b/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/TransactionTest.java index 36d4342..0d7d4e0 100644 --- a/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/TransactionTest.java +++ b/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/TransactionTest.java @@ -1,15 +1,17 @@ package com.uphold.uphold_android_sdk.test.unit.model; -import junit.framework.Assert; - -import org.apache.commons.lang3.SerializationUtils; import com.uphold.uphold_android_sdk.model.Transaction; -import com.uphold.uphold_android_sdk.model.transaction.Normalized; import com.uphold.uphold_android_sdk.model.transaction.Denomination; import com.uphold.uphold_android_sdk.model.transaction.Destination; +import com.uphold.uphold_android_sdk.model.transaction.Fee; +import com.uphold.uphold_android_sdk.model.transaction.Normalized; import com.uphold.uphold_android_sdk.model.transaction.Origin; import com.uphold.uphold_android_sdk.model.transaction.Parameters; import com.uphold.uphold_android_sdk.model.transaction.Source; + +import junit.framework.Assert; + +import org.apache.commons.lang3.SerializationUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -28,14 +30,17 @@ public class TransactionTest { public void shouldBeSerializable() { Denomination denomination = new Denomination("foo", "bar", "fuz", "buz"); Destination destination = new Destination("fizbiz", "foobar", "biz", "foobiz", "foobuz", "fizbuz", "fizbiz", "foo", "bar", "fiz", "biz", "buz"); + Fee fee = new Fee("foo", "bar", "fuz", "buz", "biz"); + List fees = new ArrayList<>(); List normalizeds = new ArrayList<>(); List sources = new ArrayList<>(); Origin origin = new Origin("biz", "foo", "fiz", "bar", "foobar", "foobiz", "fiz", "biz", "fuzbuz", "fuz", sources, "buz", "FOOBAR"); Parameters parameters = new Parameters("foobar", "foobiz", "foobuz", "fizbiz", "fuz", "fiz", 1, "foo", "bar"); Normalized normalized = new Normalized("foo", "bar", "fiz", "biz", "fixbiz"); Source source = new Source("FUZBUZ", "FIZBIZ"); - Transaction transaction = new Transaction("foobar", "foobiz", denomination, destination, "fuzbuz", normalizeds, origin, parameters, "fizbiz", "foobuz", "foo"); + Transaction transaction = new Transaction("foobar", "foobiz", denomination, destination, fees, "fuzbuz", normalizeds, origin, parameters, "fizbiz", "foobuz", "foo"); + fees.add(fee); normalizeds.add(normalized); sources.add(source); @@ -59,6 +64,11 @@ public void shouldBeSerializable() { Assert.assertEquals(transaction.getDestination().getRate(), deserializedTransaction.getDestination().getRate()); Assert.assertEquals(transaction.getDestination().getType(), deserializedTransaction.getDestination().getType()); Assert.assertEquals(transaction.getDestination().getUsername(), deserializedTransaction.getDestination().getUsername()); + Assert.assertEquals(transaction.getFees().get(0).getAmount(), deserializedTransaction.getFees().get(0).getAmount()); + Assert.assertEquals(transaction.getFees().get(0).getCurrency(), deserializedTransaction.getFees().get(0).getCurrency()); + Assert.assertEquals(transaction.getFees().get(0).getPercentage(), deserializedTransaction.getFees().get(0).getPercentage()); + Assert.assertEquals(transaction.getFees().get(0).getTarget(), deserializedTransaction.getFees().get(0).getTarget()); + Assert.assertEquals(transaction.getFees().get(0).getType(), deserializedTransaction.getFees().get(0).getType()); Assert.assertEquals(transaction.getId(), deserializedTransaction.getId()); Assert.assertEquals(transaction.getMessage(), deserializedTransaction.getMessage()); Assert.assertEquals(transaction.getNormalized().size(), 1);