public void Should_Not_Successfully_Process_A_Transaction()
        {
            var amount = System.Math.Round(new System.Random().NextDouble() * 100, 2);
            var postTransactionRequestModel = new PostTransactionRequestModel
            {
                Payer                 = "John Smith",
                EmailAddress          = "*****@*****.**",
                Amount                = amount,
                CreditCardInformation = new CreditCardInformationModel
                {
                    AccountHolder = "John Smith",
                    CardNumber    = "4242424242424242",
                    Cvc           = "123",
                    Month         = 12,
                    Year          = System.DateTime.Now.Year + 2,
                    PostalCode    = "54321"
                },
                AttributeValues = new System.Collections.Generic.Dictionary <string, string> {
                    { "phoneNumber", "512-234-1233" }, { "agentCode", "213498" }
                },
                Comments = "Sample comments",
                PayerFee = amount * .10
            };

            try
            {
                var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, null);

                // Should not be able to delete a token.
                Assert.Fail();
            }
            catch (ApiException)
            {
            }
        }
Example #2
0
        public void Should_Successfully_Issue_Full_Refund()
        {
            var amount = new System.Random().Next(10, 1000);
            var postTransactionRequestModel = new PostTransactionRequestModel
            {
                Payer                  = "John Smith",
                EmailAddress           = "*****@*****.**",
                Amount                 = amount,
                BankAccountInformation = new BankAccountInformationModel
                {
                    AccountHolder = "John Smith",
                    FirstName     = "John",
                    LastName      = "Smith",
                    AccountNumber = "4242424242424242",
                    RoutingNumber = "111000025",
                    AccountType   = AccountType.Personalsavings
                },
                Comments = "Sample comments"
            };

            var response = _transactionsApi.TransactionsPost(postTransactionRequestModel);

            // Should return a valid Id.
            Assert.IsTrue(response.Id > 0);

            var refundResponse = _transactionsApi.TransactionsRefund(response.Id.Value, new PostRefundTransactionRequestModel {
                SendReceipt = false
            });
            var refundTransaction = _transactionsApi.TransactionsGet(refundResponse.Id);

            Assert.IsNotNull(refundTransaction);
            Assert.AreEqual(refundTransaction.Amount * -1, postTransactionRequestModel.Amount + 3);
        }
Example #3
0
        public void Should_Create_Transaction_Then_Update_Existing_Transaction_Successfully_With_Impersonation_Key()
        {
            var amount = new System.Random().Next(10, 1000);
            var postTransactionRequestModel = new PostTransactionRequestModel
            {
                Payer                  = "John Smith",
                EmailAddress           = "*****@*****.**",
                Amount                 = amount,
                BankAccountInformation = new BankAccountInformationModel
                {
                    AccountHolder = "John Smith",
                    FirstName     = "John",
                    LastName      = "Smith",
                    AccountNumber = "4545454",
                    RoutingNumber = "111000025",
                    AccountType   = AccountType.Personalsavings
                },
                Comments = "Sample comments"
            };

            var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, TestApiSettings.InvoicesImpersonationAccountKey);

            // Should return a valid Id.
            Assert.IsTrue(response.Id > 0);

            var updateInvoicesRequestModel = new UpdateInvoicesRequestModel()
            {
                Id = response.Id.Value,
                AttributeValues = new Dictionary <string, string>()
                {
                    ["accountCode"] = "123",
                    ["postalCode"]  = "78701"
                },
                PaidInvoices = new List <PaidInvoiceModel>()
                {
                    new PaidInvoiceModel()
                    {
                        Id         = "112121",
                        PaidAmount = postTransactionRequestModel.Amount.Value / 2
                    },
                    new PaidInvoiceModel()
                    {
                        Id         = "112122",
                        PaidAmount = postTransactionRequestModel.Amount - (postTransactionRequestModel.Amount.Value / 2)
                    }
                }
            };

            bool success = GetApi(true).InvoicesUpdate(updateInvoicesRequestModel, TestApiSettings.InvoicesImpersonationAccountKey);

            // Should post successfully.
            Assert.IsTrue(success);
        }
Example #4
0
        public void Should_Fail_With_Invalid_Authorization_Id()
        {
            var amount = System.Math.Round(new System.Random().NextDouble() * 100, 2);
            var postTransactionRequestModel = new PostTransactionRequestModel
            {
                Payer           = "John Smith",
                EmailAddress    = "*****@*****.**",
                Amount          = amount,
                AuthorizationId = "INVALID_ID"
            };

            var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, null);

            Assert.AreEqual(PaymentResponseCode.InvalidAuthorization, response.PaymentResponseCode);
        }
Example #5
0
        public void Should_Fail_To_Use_An_Invalid_Token_In_Credit_Card_Transaction()
        {
            var postTransactionRequestModel = new PostTransactionRequestModel
            {
                Payer        = "John Smith",
                EmailAddress = "*****@*****.**",
                Amount       = System.Math.Round(new System.Random().NextDouble() * 1000, 2),
                TokenId      = "INVALID_TOKEN",
                Comments     = "Sample comments"
            };

            var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, null);

            Assert.AreEqual(PaymentResponseCode.InvalidToken, response.PaymentResponseCode);
            Assert.IsNotNull(response.Message);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        public void Should_Successfully_Process_And_Void_Credit_Card()
        {
            var amount = System.Math.Round(new System.Random().NextDouble() * 100, 2);
            var postTransactionRequestModel = new PostTransactionRequestModel
            {
                Payer                 = "John Smith",
                EmailAddress          = "*****@*****.**",
                Amount                = amount,
                CreditCardInformation = new CreditCardInformationModel
                {
                    AccountHolder = "John Smith",
                    CardNumber    = "4242424242424242",
                    Cvc           = "123",
                    Month         = 12,
                    Year          = System.DateTime.Now.Year + 2,
                    PostalCode    = "54321"
                },
                AttributeValues = new System.Collections.Generic.Dictionary <string, string> {
                    { "phoneNumber", "512-234-1233" }, { "agentCode", "213498" }
                },
                Comments = "Sample comments",
                PayerFee = amount * .10
            };

            var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, null);

            // Should return a valid Id.
            Assert.IsTrue(response.Id > 0);

            // Should successfully void a transaction.
            Assert.AreEqual(ReversalResponseCode.Success, _transactionsApi.TransactionsVoid(response.Id.Value, new PostVoidTransactionRequestModel {
                SendReceipt = false
            }).ReversalResponseCode);

            var getTransactionResponseModel = _transactionsApi.TransactionsGet(response.Id.Value);

            Assert.IsNotNull(getTransactionResponseModel);
            Assert.AreEqual("512-234-1233", getTransactionResponseModel.AttributeValues.Single(x => x.ParameterName == "phoneNumber").Value);
            Assert.IsNotNull(getTransactionResponseModel.Events.SingleOrDefault(x => x.EventType == EventType.Sale));
            Assert.IsNotNull(getTransactionResponseModel.Events.SingleOrDefault(x => x.EventType == EventType.Void));

            // Should not be able to void the transaction more than once.
            Assert.AreEqual(ReversalResponseCode.PreviouslyVoided, _transactionsApi.TransactionsVoid(response.Id.Value, new PostVoidTransactionRequestModel {
                SendReceipt = false
            }).ReversalResponseCode);
        }
Example #9
0
        public void Should_Successfully_Process_And_Void_Ach()
        {
            var postTransactionRequestModel = new PostTransactionRequestModel
            {
                Payer                  = "John Smith",
                EmailAddress           = "*****@*****.**",
                Amount                 = System.Math.Round(new System.Random().NextDouble() * 100, 2),
                BankAccountInformation = new BankAccountInformationModel
                {
                    AccountHolder = "John Smith",
                    FirstName     = "John",
                    LastName      = "Smith",
                    AccountNumber = "4242424242424242",
                    RoutingNumber = "111000025",
                    AccountType   = AccountType.Personalsavings
                },
                AttributeValues = new System.Collections.Generic.Dictionary <string, string> {
                    { "phoneNumber", "512-234-1233" }, { "agentCode", "213498" }
                },
                Comments = "Sample comments"
            };

            var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, null);

            // Should return a valid Id.
            Assert.IsTrue(response.Id > 0);

            // Should successfully void a transaction.
            Assert.AreEqual(ReversalResponseCode.Success, _transactionsApi.TransactionsVoid(response.Id.Value, new PostVoidTransactionRequestModel {
                SendReceipt = false
            }).ReversalResponseCode);

            var getTransactionResponseModel = _transactionsApi.TransactionsGet(response.Id.Value);

            Assert.IsNotNull(getTransactionResponseModel);
            Assert.AreEqual("512-234-1233", getTransactionResponseModel.AttributeValues.Single(x => x.ParameterName == "phoneNumber").Value);
            Assert.IsNotNull(getTransactionResponseModel.Events.SingleOrDefault(x => x.EventType == EventType.Sale));
            Assert.IsNotNull(getTransactionResponseModel.Events.SingleOrDefault(x => x.EventType == EventType.Void));

            // Should not be able to void the transaction more than once.
            Assert.AreEqual(ReversalResponseCode.PreviouslyVoided, _transactionsApi.TransactionsVoid(response.Id.Value, new PostVoidTransactionRequestModel {
                SendReceipt = false
            }).ReversalResponseCode);
        }
Example #10
0
        public void Should_Honor_Impersonation_For_Transactions()
        {
            var amount = System.Math.Round(new System.Random().NextDouble() * 100, 2);
            var postTransactionRequestModel = new PostTransactionRequestModel
            {
                Payer                  = "John Smith",
                EmailAddress           = "*****@*****.**",
                Amount                 = amount,
                BankAccountInformation = new BankAccountInformationModel
                {
                    AccountHolder = "John Smith",
                    FirstName     = "John",
                    LastName      = "Smith",
                    AccountNumber = "4242424242424242",
                    RoutingNumber = "111000025",
                    AccountType   = AccountType.Personalsavings
                },
                Comments           = "Sample comments",
                InitiatingPartyFee = amount * .20
            };

            var response = _transactionsApi.TransactionsPost(postTransactionRequestModel, TestApiSettings.ImpersonationAccountKey);

            // Should return a valid Id.
            Assert.IsTrue(response.Id > 0);
            Assert.AreEqual(PaymentResponseCode.Success, response.PaymentResponseCode);

            // Should get the transaction even when impersonation is off.
            Assert.IsNotNull(_transactionsApi.TransactionsGet(response.Id, null));
            // Should get the transaction when impersonation is on.
            Assert.IsNotNull(_transactionsApi.TransactionsGet(response.Id, TestApiSettings.ImpersonationAccountKey));

            // Should not be able to void with the impersonation key.
            Assert.AreNotEqual(ReversalResponseCode.Success, _transactionsApi.TransactionsVoid(response.Id.Value, new PostVoidTransactionRequestModel {
                SendReceipt = false
            }, null));

            // Should be able to void with the impersonation key.
            Assert.AreEqual(ReversalResponseCode.Success, _transactionsApi.TransactionsVoid(response.Id.Value, new PostVoidTransactionRequestModel {
                SendReceipt = false
            }, TestApiSettings.ImpersonationAccountKey).ReversalResponseCode);
        }
Example #11
0
        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);
        }
Example #12
0
        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);
        }
Example #13
0
        /// <summary>
        /// Submit a sale transaction for either ACH or credit card.
        /// </summary>
        /// <exception cref="epay3.Web.Api.Sdk.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="postTransactionRequestModel">The details of the transaction to be processed.</param>
        /// <param name="impersonationAccountKey">The key that allows impersonation of another account for which the transaction is being processed. Only specify a value if the account being impersonated is different from the account that is submitting this request.</param>
        /// <returns>PostTransactionResponseModel</returns>
        public PostTransactionResponseModel TransactionsPost(PostTransactionRequestModel postTransactionRequestModel, string impersonationAccountKey = null)
        {
            // verify the required parameter 'postTransactionRequestModel' is set
            if (postTransactionRequestModel == null)
            {
                throw new ApiException(400, "Missing required parameter 'postTransactionRequestModel' when calling TransactionsApi->TransactionsPost");
            }

            var    localVarPath         = "/api/v1/Transactions";
            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 (postTransactionRequestModel.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(postTransactionRequestModel); // http body (model) parameter
            }
            else
            {
                localVarPostBody = postTransactionRequestModel; // 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)
            {
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <PostTransactionResponseModel>(localVarResponse.Content));
            }
            else 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);
            }

            var id = localVarResponse.Headers.First(x => x.Name == "Location").Value.ToString().Split('/').Last();

            return(new PostTransactionResponseModel
            {
                Id = long.Parse(id),
                PaymentResponseCode = PaymentResponseCode.Success
            });
        }