Skip to content

Commit

Permalink
Merge pull request #66 from uphold/feature/transaction-fees-model
Browse files Browse the repository at this point in the history
Add transaction fees model
  • Loading branch information
ruipenso committed Dec 23, 2015
2 parents 9d2c30f + 5cf0edb commit cb2b7b4
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<Transaction> adapter = new MockRestAdapter<>("foobar", responseString, null);
Expand Down Expand Up @@ -121,6 +127,11 @@ public Promise<Transaction> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,6 +123,11 @@ public static Transaction loadTransaction(HashMap<String, String> 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));
Expand Down Expand Up @@ -164,6 +170,9 @@ public static Transaction loadTransaction(HashMap<String, String> 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<Fee> fees = new ArrayList<Fee>() {{
add(new Fee(fakerFields.get("feeAmount"), fakerFields.get("feeCurrency"), fakerFields.get("feePercentage"), fakerFields.get("feeTarget"), fakerFields.get("feeType")));
}};
ArrayList<Source> sources = new ArrayList<Source>() {{
ArrayList<String> ids = new ArrayList<>(Arrays.asList(fakerFields.get("originSourcesId").split(",")));
ArrayList<String> amount = new ArrayList<>(Arrays.asList(fakerFields.get("originSourcesAmount").split(",")));
Expand All @@ -178,7 +187,7 @@ public static Transaction loadTransaction(HashMap<String, String> 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(){
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Fee> fees;
private final String message;
private final List<Normalized> normalized;
private final Origin origin;
Expand All @@ -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.
Expand All @@ -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> normalized, Origin origin, Parameters params, String refundedById, String status, String type) {
public Transaction(String id, String createdAt, Denomination denomination, Destination destination, List<Fee> fees, String message, List<Normalized> 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;
Expand Down Expand Up @@ -181,6 +184,16 @@ public Destination getDestination() {
return destination;
}

/**
* Gets the transaction fees.
*
* @return the transaction fees.
*/

public List<Fee> 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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Fee> fees = new ArrayList<>();
List<Normalized> normalizeds = new ArrayList<>();
List<Source> 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);

Expand All @@ -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);
Expand Down

0 comments on commit cb2b7b4

Please sign in to comment.