diff --git a/README.md b/README.md index c0c0006..f9038d1 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,16 @@ card.createTransaction(transactionTransferRequest).then { (transaction: Transact /// Do something with the error. }) +/// A transaction to a destination (card id, crypto address, email, phone number or username) with reference. +let transactionTransferRequest = TransactionTransferRequest(denomination: transactionDenominationRequest, destination: "foo@bar.com", reference: "123456") + +card.createTransaction(transactionTransferRequest).then { (transaction: Transaction) -> () in + /// Commit the transaction. + transaction.commit(TransactionCommitRequest("Commit message")) +}.error({ (error: ErrorType) -> Void in + /// Do something with the error. +}) + /// A deposit from an ACH or SEPA account. let transactionDepositRequest = TransactionDepositRequest(denomination: transactionDenominationRequest, origin: "accountId") diff --git a/Source/Model/Card/Address.swift b/Source/Model/Card/Address.swift index 59459e7..c1fffca 100644 --- a/Source/Model/Card/Address.swift +++ b/Source/Model/Card/Address.swift @@ -10,15 +10,20 @@ open class Address: Mappable { /// The network of the created address. public private(set) final var network: String? + /// The tag of the created address if available. + public private(set) final var tag: String? + /** Constructor. - parameter id: The id of the created address. - parameter network: The network of the created address. + - parameter tag: The tag of the created address. */ - public init(id: String, network: String) { + public init(id: String, network: String, tag: String) { self.id = id self.network = network + self.tag = tag } // MARK: Required by the ObjectMapper. @@ -39,6 +44,7 @@ open class Address: Mappable { open func mapping(map: Map) { self.id <- map["id"] self.network <- map["network"] + self.tag <- map["tag"] } } diff --git a/Source/Model/Transaction.swift b/Source/Model/Transaction.swift index 6dfcc47..03a9f6c 100644 --- a/Source/Model/Transaction.swift +++ b/Source/Model/Transaction.swift @@ -36,6 +36,9 @@ open class Transaction: BaseModel, Mappable { /// Other parameters of this transaction. public private(set) final var params: Parameters? + /// The reference of this transaction. + public private(set) final var reference: String? + /// When a transaction is cancelled this contains the transaction ID of the transaction which refunds the amount back to the user. public private(set) final var refundedById: String? @@ -69,11 +72,12 @@ open class Transaction: BaseModel, Mappable { - parameter normalized: The transaction details normalized. - parameter origin: The sender of the funds. - parameter params: Other parameters of this transaction. + - parameter reference: The reference of the transaction. - parameter refundedById: When a transaction is cancelled this contains the transaction ID of the transaction which refunds the amount back to the user. - parameter status: The current status of the transaction. - parameter type: The nature of the transaction. */ - public init(id: String, createdAt: String, denomination: Denomination, destination: Destination, fees: [Fee], message: String, network: String, normalized: [NormalizedTransaction], origin: Origin, params: Parameters, refundedById: String, status: String, type: String) { + public init(id: String, createdAt: String, denomination: Denomination, destination: Destination, fees: [Fee], message: String, network: String, normalized: [NormalizedTransaction], origin: Origin, params: Parameters, reference: String, refundedById: String, status: String, type: String) { self.id = id self.createdAt = createdAt self.denomination = denomination @@ -84,6 +88,7 @@ open class Transaction: BaseModel, Mappable { self.normalized = normalized self.origin = origin self.params = params + self.reference = reference self.refundedById = refundedById self.status = status self.type = type @@ -115,6 +120,7 @@ open class Transaction: BaseModel, Mappable { normalized <- map["normalized"] origin <- map["origin"] params <- map["params"] + reference <- map["reference"] refundedById <- map["RefundedById"] status <- map["status"] type <- map["type"] diff --git a/Source/Model/Transaction/TransactionTransferRequest.swift b/Source/Model/Transaction/TransactionTransferRequest.swift index 01fedbf..c12882d 100644 --- a/Source/Model/Transaction/TransactionTransferRequest.swift +++ b/Source/Model/Transaction/TransactionTransferRequest.swift @@ -7,6 +7,9 @@ open class TransactionTransferRequest: TransactionRequest { /// The destination of the transaction request. public private(set) final var destination: String? + /// The reference of the transaction request. + public private(set) final var reference: String? + /** Constructor. @@ -19,6 +22,20 @@ open class TransactionTransferRequest: TransactionRequest { self.destination = destination } + /** + Constructor. + + - parameter denomination: The denomination of the transaction request. + - parameter destination: The destination of the transaction request. + - parameter reference: The reference of the transaction request. + */ + public init(denomination: TransactionDenominationRequest, destination: String, reference: String) { + super.init(denomination: denomination) + + self.destination = destination + self.reference = reference + } + // MARK: Required by the ObjectMapper. /** @@ -39,6 +56,7 @@ open class TransactionTransferRequest: TransactionRequest { super.mapping(map: map) self.destination <- map["destination"] + self.reference <- map["reference"] } } diff --git a/Tests/IntegrationTests/ModelTests/CardTest.swift b/Tests/IntegrationTests/ModelTests/CardTest.swift index c503f3b..ece0df3 100644 --- a/Tests/IntegrationTests/ModelTests/CardTest.swift +++ b/Tests/IntegrationTests/ModelTests/CardTest.swift @@ -56,11 +56,12 @@ class CardTest: UpholdTestCase { let testExpectation = expectation(description: "User test: create address.") let card: Card = Fixtures.loadCard() - card.adapter = MockRestAdapter(body: "{\"id\": \"foo\",\"network\": \"bar\"}") + card.adapter = MockRestAdapter(body: "{\"id\": \"foo\",\"network\": \"bar\",\"tag\": \"foobar\"}") card.createAddress(addressRequest: AddressRequest(network: "bitcoin")).then { (address: Address) -> Void in XCTAssertEqual(address.id, "foo", "Failed: Wrong adrress id.") XCTAssertEqual(address.network, "bar", "Failed: Wrong address network.") + XCTAssertEqual(address.tag, "foobar", "Failed: Wrong address network.") testExpectation.fulfill() }.catch(execute: { (_: Error) in @@ -102,6 +103,7 @@ class CardTest: UpholdTestCase { "\"message\": \"foobar\"," + "\"network\": \"qux\"," + "\"status\": \"pending\"," + + "\"reference\": \"123456\"," + "\"RefundedById\": \"foobiz\"," + "\"createdAt\": \"2014-08-27T00:01:11.616Z\"," + "\"denomination\": {" + @@ -361,6 +363,29 @@ class CardTest: UpholdTestCase { wait() } + func testCreateTransactionTransferWithReferenceShouldReturnTheTransaction() { + let testExpectation = expectation(description: "Card test: create transaction transfer.") + + let card: Card = Fixtures.loadCard() + let json: String = "{" + + "\"id\": \"foobar\"," + + "}" + card.adapter = MockRestAdapter(body: json) + let transactionDenominationRequest = TransactionDenominationRequest(amount: "foo", currency: "bar") + let transactionRequest = TransactionTransferRequest(denomination: transactionDenominationRequest, destination: "foobiz", reference: "123456") + + card.createTransaction(transactionRequest: transactionRequest).then { (transaction: Transaction) -> Void in + XCTAssertEqual(transaction.id, "foobar", "Failed: Wrong transaction id.") + XCTAssertEqual(transactionRequest.destination, "foobiz", "Failed: Wrong transaction destination.") + + testExpectation.fulfill() + }.catch(execute: { (_: Error) in + XCTFail("User test: create transaction transfer error.") + }) + + wait() + } + func testCreateTransactionTransferShouldReturnUnexpectedResponseError() { let testExpectation = expectation(description: "Card test: create transaction transfer.") diff --git a/Tests/UtilTests/Fixtures.swift b/Tests/UtilTests/Fixtures.swift index 08dbdc5..8a1748d 100644 --- a/Tests/UtilTests/Fixtures.swift +++ b/Tests/UtilTests/Fixtures.swift @@ -185,6 +185,7 @@ public class Fixtures { "transactionId": faker.lorem.characters(amount: 24), "transactionMessage": faker.lorem.characters(amount: 24), "transactionNetwork": faker.lorem.characters(amount: 24), + "transactionReference": faker.lorem.numerify("123456789"), "transactionRefundedById": faker.lorem.characters(amount: 24), "transactionRefunds": faker.lorem.characters(amount: 24), "transactionStatus": faker.lorem.characters(amount: 24), @@ -212,7 +213,7 @@ public class Fixtures { 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, node: originNode, 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"]!) + 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, reference: fakerFields["transactionReference"]!, refundedById: fakerFields["transactionRefundedById"]!, status: fakerFields["transactionStatus"]!, type: fakerFields["transactionType"]!) } /**