public void Should_Successfully_Store_Credit_Card_Token_With_Impersonation() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = System.DateTime.Now.Year, PostalCode = "54321" } }; var id = _tokensApi.TokensPost(postTokenRequestModel, TestApiSettings.ImpersonationAccountKey); // Should return a valid Id. Assert.IsTrue(!string.IsNullOrWhiteSpace(id)); try { _tokensApi.TokensDelete(id, TestApiSettings.ImpersonationAccountKey); // Should not be able to delete a token. Assert.Fail(); } catch (ApiException) { } }
public void Should_Successfully_Store_Credit_Card_Token() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = System.DateTime.Now.Year, PostalCode = "54321" } }; var id = _tokensApi.TokensPost(postTokenRequestModel); // Should return a valid Id. Assert.IsTrue(!string.IsNullOrWhiteSpace(id)); // Should successfully delete a token. Assert.IsTrue(_tokensApi.TokensDelete(id)); }
public void Should_Fail_To_Authorize_With_Invalid_Credentials() { try { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", BankAccountInformation = new BankAccountInformationModel { RoutingNumber = "111000025", AccountNumber = "1234567890" } }; _tokensApi.Configuration.DefaultHeader["Authorization"] = null; _tokensApi.TokensPost(postTokenRequestModel); Assert.Fail(); } catch (ApiException apiException) { Assert.AreEqual(401, apiException.ErrorCode); } }
public void Should_Create_Get_And_Delete_With_Impersonation() { // setup var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(TestApiSettings.Key + ":" + TestApiSettings.Secret); var autoPayApi = new AutoPayApi(TestApiSettings.Uri); var tokensApi = new TokensApi(TestApiSettings.Uri); var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = DateTime.Now.Year + 1, PostalCode = "54321" } }; autoPayApi.Configuration.AddDefaultHeader("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes)); tokensApi.Configuration.AddDefaultHeader("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes)); //Create Token var tokenId = tokensApi.TokensPost(postTokenRequestModel, TestApiSettings.InvoicesImpersonationAccountKey); var id = Guid.NewGuid(); var autopayRequestModel = new PostAutoPayRequestModel { EmailAddress = "*****@*****.**", AttributeValues = new Dictionary <string, string>() { ["accountCode"] = "123", ["postalCode"] = "78701", ["uniqueId"] = id.ToString() }, PublicTokenId = tokenId }; // Create and get autopay var createdId = autoPayApi.AutoPayPost(autopayRequestModel, TestApiSettings.InvoicesImpersonationAccountKey); var gotten = autoPayApi.AutoPayGet(createdId.Value, TestApiSettings.InvoicesImpersonationAccountKey); autoPayApi.AutoPayCancel(createdId.Value, TestApiSettings.InvoicesImpersonationAccountKey); Assert.IsNotNull(gotten); Assert.AreEqual(tokenId, gotten.TokenId); }
public void Should_Successfully_Use_A_Token_In_Credit_Card_Transaction() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = System.DateTime.Now.Year, PostalCode = "54321" }, AttributeValues = new System.Collections.Generic.Dictionary <string, string> { { "parameter1", "parameter value 1" }, { "parameter2", "parameter value 2" } } }; var tokenId = _tokensApi.TokensPost(postTokenRequestModel); var getTokenResponseModel = _tokensApi.TokensGet(tokenId); Assert.IsNotNull(getTokenResponseModel); Assert.AreEqual(2, getTokenResponseModel.AttributeValues.Count); Assert.AreEqual("parameter value 1", getTokenResponseModel.AttributeValues.Single(x => x.ParameterName == "parameter1").Value); Assert.AreEqual("parameter value 2", getTokenResponseModel.AttributeValues.Single(x => x.ParameterName == "parameter2").Value); // Should return a valid Id. Assert.IsTrue(!string.IsNullOrWhiteSpace(tokenId)); var postTransactionRequestModel = new PostTransactionRequestModel { Payer = "John Smith", EmailAddress = "*****@*****.**", Amount = System.Math.Round(new System.Random().NextDouble() * 1000, 2), TokenId = tokenId, Comments = "Sample comments", SendReceipt = false }; var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, null); // Should return a valid Id. Assert.IsTrue(response.Id > 0); Assert.AreEqual(PaymentResponseCode.Success, response.PaymentResponseCode); }
public void Should_Successfully_Use_Authorization_Id_With_Impersonation() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4242424242424242", Cvc = "123", Month = 12, Year = 2020, PostalCode = "54321" } }; var amount = System.Math.Round(new System.Random().NextDouble() * 100, 2); var tokenId = _tokensApi.TokensPost(postTokenRequestModel, TestApiSettings.ImpersonationAccountKey); var authorizationId = _transactionsApi.TransactionsAuthorize(new PostAuthorizeTransactionRequestModel { Amount = amount, TokenId = tokenId }, TestApiSettings.ImpersonationAccountKey); Assert.IsNotNull(authorizationId, TestApiSettings.ImpersonationAccountKey); var postTransactionRequestModel = new PostTransactionRequestModel { Payer = "John Smith", EmailAddress = "*****@*****.**", Amount = amount, AuthorizationId = authorizationId }; // This attempt should fail without the same impersonation key. var transactionResponse = _transactionsApi.TransactionsPost(postTransactionRequestModel); Assert.AreEqual(PaymentResponseCode.InvalidAuthorization, transactionResponse.PaymentResponseCode); // This attempt should succeed with the the correct impersonation key. transactionResponse = _transactionsApi.TransactionsPost(postTransactionRequestModel, TestApiSettings.ImpersonationAccountKey); Assert.AreEqual(PaymentResponseCode.Success, transactionResponse.PaymentResponseCode); }
private string CreateToken(string impersonationKey) { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = 2017 } }; return(_tokensApi.TokensPost(postTokenRequestModel, impersonationKey)); }
public async Task Post_WhenUserNotValid_Returns_Unauthorized_Status() { // Arrange var requestModel = new PostTokenRequestModel { Username = "******", Audience = "integration test", Password = "******" }; MockUserRepository.Setup(m => m.GetUserAsync(requestModel.Username, WellKnownUserIds.TokenApi)).ReturnsAsync(null as UserDto); // Act var response = await HttpClient.PostAsync("api/token", Stringify(requestModel)); // Assert response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); }
public void Should_Create_And_Delete() { // Setup var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(TestApiSettings.InvoiceKey + ":" + TestApiSettings.InvoiceSecret); var autoPayApi = new AutoPayApi(TestApiSettings.Uri); var tokensApi = new TokensApi(TestApiSettings.Uri); var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = DateTime.Now.Year + 1, PostalCode = "54321" } }; autoPayApi.Configuration.AddDefaultHeader("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes)); tokensApi.Configuration.AddDefaultHeader("Authorization", "Basic " + System.Convert.ToBase64String(plainTextBytes)); // Create Token var tokenId = tokensApi.TokensPost(postTokenRequestModel); var autopayRequestModel = new PostAutoPayRequestModel { EmailAddress = "*****@*****.**", AttributeValues = new Dictionary <string, string>() { ["accountCode"] = "123", ["postalCode"] = "78702" }, PublicTokenId = tokenId }; var createdId = autoPayApi.AutoPayPost(autopayRequestModel); var result = autoPayApi.AutoPayCancel(createdId.Value); Assert.IsTrue(result); }
public void Should_Not_Successfully_Store_An_Invalid_Credit_Card_Token() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", BankAccountInformation = new BankAccountInformationModel { RoutingNumber = "111000025", AccountNumber = "12345XX67890", FirstName = "John", LastName = "Smith", AccountHolder = "ACME Corp", AccountType = AccountType.Corporatesavings } }; var tokenId = _tokensApi.TokensPost(postTokenRequestModel); }
public void Should_Not_Successfully_Store_An_Invalid_Bank_Account_Token() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922F90123", Cvc = "123", Month = 12, Year = System.DateTime.Now.Year, PostalCode = "54321" } }; var tokenId = _tokensApi.TokensPost(postTokenRequestModel); }
public void Should_Successfully_Use_Authorization_Id() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4242424242424242", Cvc = "123", Month = 12, Year = 2020, PostalCode = "54321" } }; var amount = System.Math.Round(new System.Random().NextDouble() * 100, 2); var tokenId = _tokensApi.TokensPost(postTokenRequestModel); var authorizationId = _transactionsApi.TransactionsAuthorize(new PostAuthorizeTransactionRequestModel { Amount = amount, TokenId = tokenId }); Assert.IsNotNull(authorizationId); var postTransactionRequestModel = new PostTransactionRequestModel { Payer = "John Smith", EmailAddress = "*****@*****.**", Amount = amount, AuthorizationId = authorizationId }; var transactionResponse = _transactionsApi.TransactionsPost(postTransactionRequestModel, null); Assert.AreEqual(PaymentResponseCode.Success, transactionResponse.PaymentResponseCode); }
public void Should_Use_A_Different_Public_Id_For_Duplicate_Tokens() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390123", Cvc = "123", Month = 12, Year = System.DateTime.Now.Year + 1 } }; var firstTokenId = _tokensApi.TokensPost(postTokenRequestModel); var secondTokenId = _tokensApi.TokensPost(postTokenRequestModel); // Should return a different Id. Assert.AreNotEqual(firstTokenId, secondTokenId); }
public void Should_Successfully_Use_A_Token_In_An_Corporate_Checking_Transaction() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", BankAccountInformation = new BankAccountInformationModel { RoutingNumber = "111000025", AccountNumber = "1234567890", FirstName = "John", LastName = "Smith", AccountHolder = "ACME Corp", AccountType = AccountType.Corporatechecking } }; var tokenId = _tokensApi.TokensPost(postTokenRequestModel); // Should return a valid Id. Assert.IsTrue(!string.IsNullOrWhiteSpace(tokenId)); var postTransactionRequestModel = new PostTransactionRequestModel { Payer = "John Smith", EmailAddress = "*****@*****.**", Amount = System.Math.Round(new System.Random().NextDouble() * 1000, 2), TokenId = tokenId, Comments = "Sample comments", SendReceipt = false }; var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, null); // Should return a valid Id. Assert.IsTrue(response.Id > 0); Assert.AreEqual(PaymentResponseCode.Success, response.PaymentResponseCode); }
public async Task Post_WhenCredentialsNotValid_Returns_Unauthorized_Status() { // Arrange var requestModel = new PostTokenRequestModel { Username = "******", Audience = "integration test", Password = "******" }; var mockUserDto = new UserDto { Id = Guid.NewGuid() }; MockUserRepository.Setup(m => m.GetUserAsync(requestModel.Username, WellKnownUserIds.TokenApi)).ReturnsAsync(mockUserDto); MockCredentialValidator.Setup(m => m.ValidateAsync(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <Guid>())).ReturnsAsync(false); // Act var response = await HttpClient.PostAsync("api/token", Stringify(requestModel)); // Assert response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); }
public void Should_Successfully_Create_Token_With_Impersonation() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", BankAccountInformation = new BankAccountInformationModel { RoutingNumber = "111000025", AccountNumber = "1234567890", FirstName = "John", LastName = "Smith", AccountHolder = "ACME Corp", AccountType = AccountType.Corporatechecking } }; var tokenId = _tokensApi.TokensPost(postTokenRequestModel, TestApiSettings.ImpersonationAccountKey); // Should return a valid Id. Assert.IsTrue(!string.IsNullOrWhiteSpace(tokenId)); try { // Should not get the token when impersonation is off. Assert.IsNull(_tokensApi.TokensGet(tokenId, null)); Assert.Fail(); } catch (ApiException exception) { Assert.AreEqual(404, exception.ErrorCode); } // Should get the token when impersonation is on. Assert.IsNotNull(_tokensApi.TokensGet(tokenId, TestApiSettings.ImpersonationAccountKey)); }
public void Should_Not_Successfully_Authorization_With_Ach_Token() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", BankAccountInformation = new BankAccountInformationModel { AccountHolder = "John Doe", AccountNumber = "1234567890", RoutingNumber = "111000025", AccountType = AccountType.Corporatesavings } }; var amount = System.Math.Round(new System.Random().NextDouble() * 100, 2); var tokenId = _tokensApi.TokensPost(postTokenRequestModel); try { var authorizationId = _transactionsApi.TransactionsAuthorize(new PostAuthorizeTransactionRequestModel { Amount = amount, TokenId = tokenId }); Assert.Fail(); } catch (ApiException) { } catch { Assert.Fail(); } }
public void Should_Not_Store_Invalid_Credit_Card_Token() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", CreditCardInformation = new CreditCardInformationModel { AccountHolder = "John Doe", CardNumber = "4457119922390", Cvc = "123" } }; try { _tokensApi.TokensPost(postTokenRequestModel); Assert.Fail(); } catch (ApiException) { } }
public void Should_Successfully_Store_And_Delete_An_Ach_Token() { var postTokenRequestModel = new PostTokenRequestModel { Payer = "John Doe", EmailAddress = "*****@*****.**", BankAccountInformation = new BankAccountInformationModel { FirstName = "John", LastName = "Smith", RoutingNumber = "111000025", AccountNumber = "1234567890", AccountType = AccountType.Corporatechecking } }; var id = _tokensApi.TokensPost(postTokenRequestModel); // Should return a valid Id. Assert.IsTrue(!string.IsNullOrWhiteSpace(id)); // Should successfully delete a token. Assert.IsTrue(_tokensApi.TokensDelete(id)); }
public async Task Post_Returns_Ok_Status_And_Token() { // Arrange var requestModel = new PostTokenRequestModel { Username = "******", Audience = "integration test", Password = "******" }; var mockUserDto = new UserDto { Id = Guid.NewGuid() }; MockUserRepository.Setup(m => m.GetUserAsync(requestModel.Username, WellKnownUserIds.TokenApi)).ReturnsAsync(mockUserDto); MockUserRepository.Setup(m => m.GetRegisteredApplicationAsync(requestModel.Username, requestModel.Audience)).ReturnsAsync(new RegisteredApplicationDto { RegisteredOwner = "userId" }); MockCredentialValidator.Setup(m => m.ValidateAsync(mockUserDto.Id, requestModel.Password, It.IsAny <Guid>())).ReturnsAsync(true); // Act var response = await HttpClient.PostAsync("api/token", Stringify(requestModel)); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var content = await response.Content.ReadAsStringAsync(); var responseModel = JsonConvert.DeserializeObject <PostTokenResponseModel>(content); responseModel.Token.Should().NotBeNullOrEmpty(); responseModel.Issuer.Should().Be("http://www.techniqly.com/token/v1"); DateTimeOffset.FromUnixTimeSeconds(responseModel.ValidFrom).LocalDateTime.Should().BeBefore(DateTime.Now); DateTimeOffset.FromUnixTimeSeconds(responseModel.ValidTo).LocalDateTime.Should().BeAfter(DateTime.Now).And.BeBefore(DateTime.Now.AddDays(30)); }
/// <summary> /// Stores a token for either ACH or credit card payments. /// </summary> /// <exception cref="epay3.Web.Api.Sdk.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="postTokenRequestModel">The details of the token to be created.</param> /// <param name="impersonationAccountKey">The key that allows impersonation of another account for which the token is being processed. Only specify a value if the account being impersonated is different from the account that is submitting this request.</param> /// <returns></returns> public string TokensPost(PostTokenRequestModel postTokenRequestModel, string impersonationAccountKey = null) { // verify the required parameter 'postTransactionRequestModel' is set if (postTokenRequestModel == null) { throw new ApiException(400, "Missing required parameter 'postTokenRequestModel' when calling TokensApi->TokensPost"); } var localVarPath = "/api/v1/Tokens"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new Dictionary <String, String>(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json", "application/xml", "text/xml" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (impersonationAccountKey != null) { localVarHeaderParams.Add("impersonationAccountKey", Configuration.ApiClient.ParameterToString(impersonationAccountKey)); // header parameter } if (postTokenRequestModel.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(postTokenRequestModel); // http body (model) parameter } else { localVarPostBody = postTokenRequestModel; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (localVarStatusCode >= 400) { var errorResponseModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ErrorResponseModel>(localVarResponse.Content); throw new ApiException(localVarStatusCode, errorResponseModel != null ? errorResponseModel.Message : null); } else if (localVarStatusCode == 0) { throw new ApiException(localVarStatusCode, localVarResponse.ErrorMessage, localVarResponse.ErrorMessage); } return(localVarResponse.Headers.First(x => x.Name == "Location").Value.ToString().Split('/').Last()); }