             XCTAssertTrue(transaction.isSucessful())
         }
     }
-    
+
+    func testDoesNotReturnsTokenWhenCalledWithInvalidParams() {
+        let asyncExpectation = expectation(description: "requestToken")
+        let card = Card(name: "Invalid John Doe", number: "000000", cvv: "123", expiryMonth: "12", expiryYear: "21")
+        let encryptedMessage = Helpers.randomAlphanumeric(64)
+        let expectedRequestMessage = buildRequestMessage(withMerchantId: publicMerchantId!, withCard: card, withAmount: totalAmount!)
+        let aurusEncryption = AurusEncryptionStub(whenEncryptCalledWith: expectedRequestMessage, thenReturn: encryptedMessage)
+        let expectedRequestBody = "{\"request\": \"" + encryptedMessage + "\"}"
+        let kushki = Kushki(publicMerchantId: publicMerchantId!,
+                            currency: "USD",
+                            environment: KushkiEnvironment.testing,
+                            aurusEncryption: aurusEncryption)
+        stub(condition: isHost("uat.aurusinc.com")
+            && isPath("/kushki/api/v1/tokens")
+            && isMethodPOST()) { request in
+                let nsUrlRequest = request as NSURLRequest
+                let requestBody = String(data: nsUrlRequest.ohhttpStubs_HTTPBody(), encoding: .utf8)
+                XCTAssertEqual(expectedRequestBody, requestBody)
+                let responseBody = [
+                    "response_code": "017",
+                    "response_text": "Tarjeta no válida",
+                    "transaction_token_validity": "",
+                    "transaction_token": ""
+                ]
+                return OHHTTPStubsResponse(jsonObject: responseBody, statusCode: 402, headers: nil)
+        }
+        var transaction = Transaction(code: "", text: "", token: "")
+        kushki.requestToken(card: card, totalAmount: totalAmount!) { returnedTransaction in
+            transaction = returnedTransaction
+            asyncExpectation.fulfill()
+        }
+        self.waitForExpectations(timeout: 5) { error in
+            XCTAssertEqual("", transaction.token)
+            XCTAssertFalse(transaction.isSucessful())
+        }
+    }
+
     private func buildRequestMessage(withMerchantId publicMerchantId: String, withCard card: Card, withAmount totalAmount: Double) -> String {
         let requestDictionary:[String : Any] = [
             "merchant_identifier": publicMerchantId,

@testable import kushki_ios

class KushkiTests: XCTestCase {
    override func setUp() {
        super.setUp()
    }
    
    override func tearDown() {

                return OHHTTPStubsResponse(jsonObject: responseBody, statusCode: 200, headers: nil)
        }
        var transaction = Transaction(code: "", text: "", token: "")
        kushki.requestToken(card: card, totalAmount: totalAmount!) { returnedTransaction in
            transaction = returnedTransaction
            asyncExpectation.fulfill()
        }
