Пример #1
0
        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);
            }
        }
Пример #2
0
        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));

            try
            {
                _tokensApi.TokensDelete(id);

                // Should not be able to delete a token.
                Assert.Fail();
            }
            catch (ApiException)
            {
            }
        }
Пример #3
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);
        }
Пример #4
0
        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);
        }
        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));
        }
Пример #6
0
        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);
        }