Skip to content

Commit

Permalink
Merge pull request #56 from uphold/feature/add-merchant-origin
Browse files Browse the repository at this point in the history
Add merchant model to transaction origin
  • Loading branch information
d-moreira authored Jul 19, 2017
2 parents 5871aa1 + f39a282 commit 7ae7f93
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
8 changes: 7 additions & 1 deletion Source/Model/Transaction/Origin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class Origin: Mappable {
/// The fee from the origin of the transaction.
public private(set) final var fee: String?

/// The merchant from the origin of the transaction.
public private(set) final var merchant: Merchant?

/// The rate from the origin of the transaction.
public private(set) final var rate: String?

Expand All @@ -55,12 +58,13 @@ public class Origin: Mappable {
- parameter currency: The currency from the origin of the transaction.
- parameter description: The description from the origin of the transaction.
- parameter fee: The fee from the origin of the transaction.
- parameter merchant: The merchant from the origin of the transaction.
- parameter rate: The rate from the origin of the transaction.
- parameter sources: The sources from the origin of the transaction.
- parameter type: The type from the origin of the transaction.
- parameter username: The username from the origin of the transaction.
*/
public init(accountId: String, cardId: String, accountType: String, amount: String, base: String, commission: String, currency: String, description: String, fee: String, rate: String, sources: [Source], type: String, username: String) {
public init(accountId: String, cardId: String, accountType: String, amount: String, base: String, commission: String, currency: String, description: String, fee: String, merchant: Merchant, rate: String, sources: [Source], type: String, username: String) {
self.accountId = accountId
self.cardId = cardId
self.accountType = accountType
Expand All @@ -70,6 +74,7 @@ public class Origin: Mappable {
self.currency = currency
self.description = description
self.fee = fee
self.merchant = merchant
self.rate = rate
self.sources = sources
self.type = type
Expand Down Expand Up @@ -101,6 +106,7 @@ public class Origin: Mappable {
currency <- map["currency"]
description <- map["description"]
fee <- map["fee"]
merchant <- map["merchant"]
rate <- map["rate"]
sources <- map["sources"]
type <- map["type"]
Expand Down
22 changes: 17 additions & 5 deletions Tests/Integration/Model/TransactionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ class TransactionTest: UpholdTestCase {
"\"currency\": \"BTC\"," +
"\"description\": \"Fuz Buz\"," +
"\"fee\": \"0.00\"," +
"\"merchant\": {" +
"\"city\": \"foo\"," +
"\"country\": \"bar\"," +
"\"name\": \"foobar\"," +
"\"state\": \"foobiz\"," +
"\"zipCode\": \"foobuz\"," +
"}," +
"\"rate\": \"1.00\"," +
"\"sources\": [{" +
"\"id\": \"fizbuz\"," +
Expand Down Expand Up @@ -443,11 +450,11 @@ class TransactionTest: UpholdTestCase {
XCTAssertEqual(transaction!.destination!.currency!, "BTC", "Failed: Transaction destination currency didn't match.")
XCTAssertEqual(transaction!.destination!.description!, "[email protected]", "Failed: Transaction destination description didn't match.")
XCTAssertEqual(transaction!.destination!.fee!, "0.00", "Failed: Transaction destination fee didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.city!, "foo", "Failed: Transaction destination fee didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.country!, "bar", "Failed: Transaction destination fee didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.name!, "foobar", "Failed: Transaction destination fee didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.state!, "foobiz", "Failed: Transaction destination fee didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.zipCode!, "foobuz", "Failed: Transaction destination fee didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.city!, "foo", "Failed: Transaction destination merchant city didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.country!, "bar", "Failed: Transaction destination merchant country didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.name!, "foobar", "Failed: Transaction destination merchant name didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.state!, "foobiz", "Failed: Transaction destination merchant state didn't match.")
XCTAssertEqual(transaction!.destination!.merchant!.zipCode!, "foobuz", "Failed: Transaction destination merchant zip code didn't match.")
XCTAssertEqual(transaction!.destination!.rate!, "1.00", "Failed: Transaction destination rate didn't match.")
XCTAssertEqual(transaction!.destination!.type!, "email", "Failed: Transaction destination type didn't match.")
XCTAssertEqual(transaction!.destination!.username!, "fizbiz", "Failed: Transaction destination username didn't match.")
Expand All @@ -472,6 +479,11 @@ class TransactionTest: UpholdTestCase {
XCTAssertEqual(transaction!.origin!.currency!, "BTC", "Failed: Transaction origin currency didn't match.")
XCTAssertEqual(transaction!.origin!.description!, "Fuz Buz", "Failed: Transaction origin description didn't match.")
XCTAssertEqual(transaction!.origin!.fee!, "0.00", "Failed: Transaction origin fee didn't match.")
XCTAssertEqual(transaction!.origin!.merchant!.city!, "foo", "Failed: Transaction origin merchant city didn't match.")
XCTAssertEqual(transaction!.origin!.merchant!.country!, "bar", "Failed: Transaction origin merchant country didn't match.")
XCTAssertEqual(transaction!.origin!.merchant!.name!, "foobar", "Failed: Transaction origin merchant name didn't match.")
XCTAssertEqual(transaction!.origin!.merchant!.state!, "foobiz", "Failed: Transaction origin merchant state didn't match.")
XCTAssertEqual(transaction!.origin!.merchant!.zipCode!, "foobuz", "Failed: Transaction origin merchant zip code didn't match.")
XCTAssertEqual(transaction!.origin!.rate!, "1.00", "Failed: Transaction origin rate didn't match.")
XCTAssertEqual(transaction!.origin!.sources!.count, 1, "Failed: Transaction origin type didn't match.")
XCTAssertEqual(transaction!.origin!.sources![0].id!, "fizbuz", "Failed: Transaction origin type didn't match.")
Expand Down
12 changes: 9 additions & 3 deletions Tests/Util/Fixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public class Fixtures {
"originCurrency": faker.lorem.characters(amount: 3),
"originDescription": faker.name.name(),
"originFee": faker.lorem.numerify("123456789"),
"originMerchantCity": faker.address.city(),
"originMerchantCountry": faker.address.county(),
"originMerchantName": faker.company.name(),
"originMerchantState": faker.address.state(),
"originMerchantZipCode": faker.address.postcode(),
"originRate": faker.lorem.numerify("123456789"),
"originSourcesAmount": String(format: "%@,%@,%@", faker.lorem.numerify("123456789"), faker.lorem.numerify("123456789"), faker.lorem.numerify("123456789")),
"originSourcesId": String(format: "%@,%@,%@", faker.lorem.characters(amount: 24), faker.lorem.characters(amount: 24), faker.lorem.characters(amount: 24)),
Expand Down Expand Up @@ -183,18 +188,19 @@ public class Fixtures {
_ = fields.flatMap { (key, value) in fakerFields[key] = value }
}

let merchant = Merchant(city: fakerFields["destinationMerchantCity"]!, country: fakerFields["destinationMerchantCountry"]!, name: fakerFields["destinationMerchantName"]!, state: fakerFields["destinationMerchantState"]!, zipCode: fakerFields["destinationMerchantZipCode"]!)
let destinationMerchant = Merchant(city: fakerFields["destinationMerchantCity"]!, country: fakerFields["destinationMerchantCountry"]!, name: fakerFields["destinationMerchantName"]!, state: fakerFields["destinationMerchantState"]!, zipCode: fakerFields["destinationMerchantZipCode"]!)
let denomination = Denomination(amount: fakerFields["denominationAmount"]!, currency: fakerFields["denominationCurrency"]!, pair: fakerFields["denominationPair"]!, rate: fakerFields["denominationRate"]!)
let destination = Destination(accountId: fakerFields["destinationAccountId"]!, cardId: fakerFields["destinationCardId"]!, accountType: fakerFields["destinationAccountType"]!, amount: fakerFields["destinationAmount"]!, base: fakerFields["destinationBase"]!, commission: fakerFields["destinationCommission"]!, currency: fakerFields["destinationCurrency"]!, description: fakerFields["destinationDescription"]!, fee: fakerFields["destinationFee"]!, merchant: merchant, rate: fakerFields["destinationRate"]!, type: fakerFields["destinationType"]!, username: fakerFields["destinationUsername"]!)
let destination = Destination(accountId: fakerFields["destinationAccountId"]!, cardId: fakerFields["destinationCardId"]!, accountType: fakerFields["destinationAccountType"]!, amount: fakerFields["destinationAmount"]!, base: fakerFields["destinationBase"]!, commission: fakerFields["destinationCommission"]!, currency: fakerFields["destinationCurrency"]!, description: fakerFields["destinationDescription"]!, fee: fakerFields["destinationFee"]!, merchant: destinationMerchant, rate: fakerFields["destinationRate"]!, type: fakerFields["destinationType"]!, username: fakerFields["destinationUsername"]!)
let fees = [Fee(amount: fakerFields["feeAmount"]!, currency: fakerFields["feeCurrency"]!, percentage: fakerFields["feePercentage"]!, target: fakerFields["feeTarget"]!, type: fakerFields["feeType"]!)]
var sources: [Source] = []

for (index, ids) in fakerFields["originSourcesId"]!.componentsSeparatedByString(",").enumerate() {
sources.append(Source(id: ids, amount: fakerFields["originSourcesAmount"]!.componentsSeparatedByString(",")[index]))
}

let originMerchant = Merchant(city: fakerFields["originMerchantCity"]!, country: fakerFields["originMerchantCountry"]!, name: fakerFields["originMerchantName"]!, state: fakerFields["originMerchantState"]!, zipCode: fakerFields["originMerchantZipCode"]!)
let normalized = [NormalizedTransaction(amount: fakerFields["normalizedAmount"]!, commission: fakerFields["normalizedCommission"]!, currency: fakerFields["normalizedCurrency"]!, fee: fakerFields["normalizedFee"]!, rate: fakerFields["normalizedRate"]!)]
let origin = Origin(accountId: fakerFields["originAccountId"]!, cardId: fakerFields["originCardId"]!, accountType: fakerFields["originAccountType"]!, amount: fakerFields["originAmount"]!, base: fakerFields["originBase"]!, commission: fakerFields["originCommission"]!, currency: fakerFields["originCurrency"]!, description: fakerFields["originDescription"]!, fee: fakerFields["originFee"]!, rate: fakerFields["originRate"]!, sources: sources, type: fakerFields["originType"]!, username: fakerFields["originUsername"]!)
let origin = Origin(accountId: fakerFields["originAccountId"]!, cardId: fakerFields["originCardId"]!, accountType: fakerFields["originAccountType"]!, amount: fakerFields["originAmount"]!, base: fakerFields["originBase"]!, commission: fakerFields["originCommission"]!, currency: fakerFields["originCurrency"]!, description: fakerFields["originDescription"]!, fee: fakerFields["originFee"]!, merchant: originMerchant, rate: fakerFields["originRate"]!, sources: sources, type: fakerFields["originType"]!, username: fakerFields["originUsername"]!)
let parameters = Parameters(currency: fakerFields["parametersCurrency"]!, margin: fakerFields["parametersMargin"]!, pair: fakerFields["parametersPair"]!, progress: fakerFields["parametersProgress"]!, rate: fakerFields["parametersRate"]!, refunds: fakerFields["parametersRefunds"]!, ttl: NSString(string: fakerFields["parametersTtl"]!).integerValue, txid: fakerFields["parametersTxid"]!, type: fakerFields["parametersType"]!)

return Transaction(id: fakerFields["transactionId"]!, createdAt: fakerFields["transactionCreatedAt"]!, denomination: denomination, destination: destination, fees: fees, message: fakerFields["transactionMessage"]!, network: fakerFields["transactionNetwork"]!, normalized: normalized, origin: origin, params: parameters, refundedById: fakerFields["transactionRefundedById"]!, status: fakerFields["transactionStatus"]!, type: fakerFields["transactionType"]!)
Expand Down

0 comments on commit 7ae7f93

Please sign in to comment.