Skip to content

Commit

Permalink
Merge pull request #92 from uphold/support/merchant-origin-transactio…
Browse files Browse the repository at this point in the history
…n-model

Add `Merchant` model to transaction origin
  • Loading branch information
SandroMachado authored Jul 18, 2017
2 parents a7a18d9 + 84ef816 commit 9909ade
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public void createTransactionShouldReturnTheTransaction() throws Exception {
"\"currency\": \"BTC\"," +
"\"description\": \"Foo Bar\"," +
"\"fee\": \"0.00\"," +
"\"merchant\": {" +
"\"city\": \"foo\"," +
"\"country\": \"biz\"," +
"\"name\": \"foobiz\"," +
"\"state\": \"fuzbiz\"," +
"\"zipCode\": \"fizbaz\"" +
"}," +
"\"rate\": \"1.00\"," +
"\"type\": \"card\"," +
"\"username\": \"foobar\"" +
Expand Down Expand Up @@ -181,6 +188,11 @@ public Promise<Transaction> call(UpholdRestAdapter adapter) {
Assert.assertEquals(transaction.getOrigin().getCurrency(), "BTC");
Assert.assertEquals(transaction.getOrigin().getDescription(), "Foo Bar");
Assert.assertEquals(transaction.getOrigin().getFee(), "0.00");
Assert.assertEquals(transaction.getOrigin().getMerchant().getCity(), "foo");
Assert.assertEquals(transaction.getOrigin().getMerchant().getCountry(), "biz");
Assert.assertEquals(transaction.getOrigin().getMerchant().getName(), "foobiz");
Assert.assertEquals(transaction.getOrigin().getMerchant().getState(), "fuzbiz");
Assert.assertEquals(transaction.getOrigin().getMerchant().getZipCode(), "fizbaz");
Assert.assertEquals(transaction.getOrigin().getRate(), "1.00");
Assert.assertEquals(transaction.getOrigin().getType(), "card");
Assert.assertEquals(transaction.getOrigin().getUsername(), "foobar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ public void getOriginShouldReturnTheOrigin() {
put("originCurrency", "bar");
put("originDescription", "biz");
put("originFee", "foobuz");
put("originMerchantCity", "bar");
put("originMerchantCountry", "foo");
put("originMerchantName", "buz");
put("originMerchantState", "fiz");
put("originMerchantZipCode", "biz");
put("originRate", "buz");
put("originSourcesAmount", "fuzbiz,fizbuz");
put("originSourcesId", "foo,bar");
Expand All @@ -610,6 +615,11 @@ public void getOriginShouldReturnTheOrigin() {
Assert.assertEquals(transaction.getOrigin().getCurrency(), "bar");
Assert.assertEquals(transaction.getOrigin().getDescription(), "biz");
Assert.assertEquals(transaction.getOrigin().getFee(), "foobuz");
Assert.assertEquals(transaction.getOrigin().getMerchant().getCity(), "bar");
Assert.assertEquals(transaction.getOrigin().getMerchant().getCountry(), "foo");
Assert.assertEquals(transaction.getOrigin().getMerchant().getName(), "buz");
Assert.assertEquals(transaction.getOrigin().getMerchant().getState(), "fiz");
Assert.assertEquals(transaction.getOrigin().getMerchant().getZipCode(), "biz");
Assert.assertEquals(transaction.getOrigin().getRate(), "buz");
Assert.assertEquals(transaction.getOrigin().getSources().size(), 2);
Assert.assertEquals(transaction.getOrigin().getSources().get(0).getAmount(), "fuzbiz");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public static Transaction loadTransaction(HashMap<String, String> fields) {
put("originCurrency", faker.lorem().fixedString(3));
put("originDescription", faker.name().fullName());
put("originFee", faker.numerify("123456789"));
put("originMerchantCity", faker.address().cityPrefix());
put("originMerchantCountry", faker.address().country());
put("originMerchantName", faker.name().fullName());
put("originMerchantState", faker.address().stateAbbr());
put("originMerchantZipCode", faker.address().zipCode());
put("originRate", faker.numerify("123456789"));
put("originSourcesAmount", String.format("%s,%s,%s", faker.numerify("123456789"), faker.numerify("123456789"), faker.numerify("123456789")));
put("originSourcesId", String.format("%s,%s,%s", faker.lorem().fixedString(24), faker.lorem().fixedString(24), faker.lorem().fixedString(24)));
Expand Down Expand Up @@ -221,8 +226,8 @@ public static Transaction loadTransaction(HashMap<String, String> fields) {
}

Denomination denomination = new Denomination(fakerFields.get("denominationAmount"), fakerFields.get("denominationCurrency"), fakerFields.get("denominationPair"), fakerFields.get("denominationRate"));
Merchant merchant = new Merchant(fakerFields.get("destinationMerchantCity"), fakerFields.get("destinationMerchantCountry"), fakerFields.get("destinationMerchantName"), fakerFields.get("destinationMerchantState"), fakerFields.get("destinationMerchantZipCode"));
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"), merchant,fakerFields.get("destinationRate"), fakerFields.get("destinationType"), fakerFields.get("destinationUsername"));
Merchant destinationMerchant = new Merchant(fakerFields.get("destinationMerchantCity"), fakerFields.get("destinationMerchantCountry"), fakerFields.get("destinationMerchantName"), fakerFields.get("destinationMerchantState"), fakerFields.get("destinationMerchantZipCode"));
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"), destinationMerchant,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")));
}};
Expand All @@ -237,7 +242,8 @@ public static Transaction loadTransaction(HashMap<String, String> fields) {
ArrayList<com.uphold.uphold_android_sdk.model.transaction.Normalized> normalized = new ArrayList<com.uphold.uphold_android_sdk.model.transaction.Normalized>() {{
add(new com.uphold.uphold_android_sdk.model.transaction.Normalized(fakerFields.get("normalizedAmount"), fakerFields.get("normalizedCommission"), fakerFields.get("normalizedCurrency"), fakerFields.get("normalizedFee"), fakerFields.get("normalizedRate")));
}};
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"));
Merchant originMerchant = new Merchant(fakerFields.get("originMerchantCity"), fakerFields.get("originMerchantCountry"), fakerFields.get("originMerchantName"), fakerFields.get("originMerchantState"), fakerFields.get("originMerchantZipCode"));
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"), originMerchant, 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, fees, fakerFields.get("transactionMessage"), fakerFields.get("transactionNetwork"), normalized, origin, parameters, fakerFields.get("transactionRefundedById"), fakerFields.get("transactionStatus"), fakerFields.get("transactionType"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Origin implements Serializable {
private final String currency;
private final String description;
private final String fee;
private final Merchant merchant;
private final String rate;
private final List<Source> sources;
private final String type;
Expand All @@ -35,13 +36,14 @@ public class Origin implements Serializable {
* @param currency The currency from the origin of the transaction.
* @param description The description from the origin of the transaction.
* @param fee The fee from the origin of the transaction.
* @param merchant The merchant from the origin of the transaction.
* @param rate The rate from the origin of the transaction.
* @param sources The sources from the origin of the transaction.
* @param type The type from the origin of the transaction.
* @param username The username from the origin of the transaction.
*/

public Origin(String AccountId, String cardId, String accountType, String amount, String base, String commission, String currency, String description, String fee, String rate, List<Source> sources, String type, String username) {
public Origin(String AccountId, String cardId, String accountType, String amount, String base, String commission, String currency, String description, String fee, Merchant merchant, String rate, List<Source> sources, String type, String username) {
this.AccountId = AccountId;
this.CardId = cardId;
this.accountType = accountType;
Expand All @@ -51,6 +53,7 @@ public Origin(String AccountId, String cardId, String accountType, String amount
this.currency = currency;
this.description = description;
this.fee = fee;
this.merchant = merchant;
this.rate = rate;
this.sources = sources;
this.type = type;
Expand Down Expand Up @@ -147,6 +150,16 @@ public String getFee() {
return fee;
}

/**
* Gets the merchant from the origin of the transaction.
*
* @return the merchant from the origin of the transaction.
*/

public Merchant getMerchant() {
return merchant;
}

/**
* Gets the rate from the origin of the transaction.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public class TransactionTest {
@Test
public void shouldBeSerializable() {
Denomination denomination = new Denomination("foo", "bar", "fuz", "buz");
Merchant merchant = new Merchant("foo", "bar", "biz", "buz", "foobar");
Destination destination = new Destination("fizbiz", "foobar", "biz", "foobiz", "foobuz", "fizbuz", "fizbiz", "foo", "bar", merchant, "fiz", "biz", "buz");
Merchant destinationMerchant = new Merchant("foo", "bar", "biz", "buz", "foobar");
Destination destination = new Destination("fizbiz", "foobar", "biz", "foobiz", "foobuz", "fizbuz", "fizbiz", "foo", "bar", destinationMerchant, "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");
Merchant originMerchant = new Merchant("fuz", "biz", "boz", "baz", "foobiz");
Origin origin = new Origin("biz", "foo", "fiz", "bar", "foobar", "foobiz", "fiz", "biz", "fuzbuz", originMerchant, "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");
Expand Down Expand Up @@ -94,6 +95,11 @@ public void shouldBeSerializable() {
Assert.assertEquals(transaction.getOrigin().getCurrency(), deserializedTransaction.getOrigin().getCurrency());
Assert.assertEquals(transaction.getOrigin().getDescription(), deserializedTransaction.getOrigin().getDescription());
Assert.assertEquals(transaction.getOrigin().getFee(), deserializedTransaction.getOrigin().getFee());
Assert.assertEquals(transaction.getOrigin().getMerchant().getCity(), deserializedTransaction.getOrigin().getMerchant().getCity());
Assert.assertEquals(transaction.getOrigin().getMerchant().getCountry(), deserializedTransaction.getOrigin().getMerchant().getCountry());
Assert.assertEquals(transaction.getOrigin().getMerchant().getName(), deserializedTransaction.getOrigin().getMerchant().getName());
Assert.assertEquals(transaction.getOrigin().getMerchant().getState(), deserializedTransaction.getOrigin().getMerchant().getState());
Assert.assertEquals(transaction.getOrigin().getMerchant().getZipCode(), deserializedTransaction.getOrigin().getMerchant().getZipCode());
Assert.assertEquals(transaction.getOrigin().getRate(), deserializedTransaction.getOrigin().getRate());
Assert.assertEquals(transaction.getOrigin().getSources().size(), deserializedTransaction.getOrigin().getSources().size());
Assert.assertEquals(transaction.getOrigin().getSources().get(0).getAmount(), deserializedTransaction.getOrigin().getSources().get(0).getAmount());
Expand Down

0 comments on commit 9909ade

Please sign in to comment.