コード例 #1
0
 public void Generate_DefaultToken()
 {
     var gateway = new BraintreeGateway();
     Assert.IsNotNull(gateway.ClientToken);
     string token = gateway.ClientToken.Generate();
     Assert.IsNotEmpty(token);
 }
コード例 #2
0
ファイル: TestHelper.cs プロジェクト: ronin1/braintree_dotnet
 public static string GenerateDecodedClientToken(BraintreeGateway gateway, ClientTokenRequest request = null)
 {
   var encodedClientToken = gateway.ClientToken.Generate(request);
   var decodedClientToken = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(encodedClientToken));
   var unescapedClientToken = System.Text.RegularExpressions.Regex.Unescape(decodedClientToken);
   return unescapedClientToken;
 }
コード例 #3
0
ファイル: OAuthTest.cs プロジェクト: ronin1/braintree_dotnet
 public void Setup()
 {
     gateway = new BraintreeGateway(
         "client_id$development$integration_client_id",
         "client_secret$development$integration_client_secret"
     );
 }
コード例 #4
0
 public void Generate_RaisesExceptionIfFailOnDuplicatePaymentMethodIsIncludedWithoutCustomerId()
 {
     BraintreeGateway gateway = new BraintreeGateway
     {
         Environment = Environment.DEVELOPMENT,
         MerchantId = "integration_merchant_id",
         PublicKey = "integration_public_key",
         PrivateKey = "integration_private_key"
     };
     Exception exception = null;
     try {
         gateway.ClientToken.generate(
             new ClientTokenRequest
             {
                 Options = new ClientTokenOptionsRequest
                 {
                     FailOnDuplicatePaymentMethod = true
                 }
             }
         );
     } catch (Exception tempException) {
         exception = tempException;
     }
     Assert.IsNotNull(exception);
     Assert.IsTrue(Regex.Match(exception.Message, @"FailOnDuplicatePaymentMethod").Success);
     Assert.IsInstanceOf(typeof(ArgumentException), exception);
 }
コード例 #5
0
        public void CreateTokenFromCode_RaisesIfWrongCredentials()
        {
            gateway = new BraintreeGateway(
                "access_token$development$merchant_id$_oops_this_is_not_a_client_id_and_secret"
            );

            Assert.Throws<ConfigurationException>(() => gateway.OAuth.CreateTokenFromCode(new OAuthCredentialsRequest()));
        }
コード例 #6
0
ファイル: PlanTest.cs プロジェクト: ronin1/braintree_dotnet
 public void Setup()
 {
     gateway = new BraintreeGateway
     {
         //Environment = Environment.DEVELOPMENT,
         //MerchantId = "integration_merchant_id",
         //PublicKey = "integration_public_key",
         //PrivateKey = "integration_private_key"
     };
     service = new BraintreeService(gateway.Configuration); }
 public void Setup()
 {
     gateway = new BraintreeGateway
     {
         Environment = Environment.DEVELOPMENT,
         MerchantId = "integration_merchant_id",
         PublicKey = "integration_public_key",
         PrivateKey = "integration_private_key"
     };
 }
コード例 #8
0
        public void All_RaisesIfMissingCredentials()
        {
            gateway = new BraintreeGateway
            {
                MerchantId = "integration_merchant_id",
                PublicKey = "integration_public_key",
                PrivateKey = "integration_private_key"
            };

            Assert.Throws<ConfigurationException> (() => gateway.AddOn.All());
        }
コード例 #9
0
        public void SetConfigurationEnvironment_WithEnvironment()
        {
            BraintreeGateway gateway = new BraintreeGateway(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            );

            Assert.AreEqual(gateway.Environment, Environment.DEVELOPMENT);
        }
コード例 #10
0
        public void FailsInProduction()
        {
            var productionGateway = new BraintreeGateway
            {
                Environment = Environment.PRODUCTION,
                MerchantId = "integration_merchant_id",
                PublicKey = "integration_public_key",
                PrivateKey = "integration_private_key"
            };

            Assert.Throws<Braintree.Exceptions.TestOperationPerformedInProductionException>(() => productionGateway.TestTransaction.Settle("production_transaction_id"));
        }
コード例 #11
0
        public void Setup()
        {
            gateway = new BraintreeGateway
            {
                //Environment = Environment.DEVELOPMENT,
                //MerchantId = "integration_merchant_id",
                //PublicKey = "integration_public_key",
                //PrivateKey = "integration_private_key"
            };

            XmlDocument attributesXml = CreateAttributesXml();
            attributes = new NodeWrapper(attributesXml).GetNode("//disbursement");
        }
コード例 #12
0
ファイル: AddOnTest.cs プロジェクト: kevlut/braintree_dotnet
        public void All_RaisesIfMissingCredentials()
        {
            gateway = new BraintreeGateway
            {
                MerchantId = "integration_merchant_id",
                PublicKey = "integration_public_key",
                PrivateKey = "integration_private_key"
            };

            try {
                gateway.AddOn.All();

                Assert.Fail("Should throw ConfigurationException");
            } catch (ConfigurationException) {}
        }
コード例 #13
0
        public virtual void TestFixtureSetup()
        {
            this.TestCustomer = MerchelloContext.Current.Services.CustomerService.CreateCustomerWithKey(
                Guid.NewGuid().ToString(),
                "first",
                "last",
                "[email protected]");

            this.BraintreeProviderSettings = TestHelper.GetBraintreeProviderSettings();

            AutoMapperMappings.CreateMappings();

            this.Gateway = this.BraintreeProviderSettings.AsBraintreeGateway();

            this.BraintreeApiService = new BraintreeApiService(this.BraintreeProviderSettings);
        }
コード例 #14
0
        public void Create_MultiCurrencyMerchant()
        {
            gateway = new BraintreeGateway(
                "client_id$development$signup_client_id",
                "client_secret$development$signup_client_secret"
            );

            ResultImpl<Merchant> result = gateway.Merchant.Create(new MerchantRequest {
                Email = "[email protected]",
                CountryCodeAlpha3 = "USA",
                PaymentMethods = new string[] {"paypal"},
                CompanyName = "Ziarog LTD",
                Currencies = new string[] {"GBP", "USD"},
                PayPalAccount = new PayPalOnlyAccountRequest {
                    ClientId = "paypal_client_id",
                    ClientSecret = "paypal_client_secret"
                }
            });

            Assert.IsTrue(result.IsSuccess());
            Assert.IsFalse(string.IsNullOrEmpty(result.Target.Id));
            Assert.AreEqual("[email protected]", result.Target.Email);
            Assert.AreEqual("Ziarog LTD", result.Target.CompanyName);
            Assert.AreEqual("USA", result.Target.CountryCodeAlpha3);
            Assert.AreEqual("US", result.Target.CountryCodeAlpha2);
            Assert.AreEqual("840", result.Target.CountryCodeNumeric);
            Assert.AreEqual("United States of America", result.Target.CountryName);

            Assert.IsTrue(result.Target.Credentials.AccessToken.StartsWith("access_token$"));
            Assert.IsTrue(result.Target.Credentials.RefreshToken.StartsWith("refresh_token$"));
            Assert.IsTrue(result.Target.Credentials.ExpiresAt > DateTime.Now);
            Assert.AreEqual("bearer", result.Target.Credentials.TokenType);

            Assert.AreEqual(2, result.Target.MerchantAccounts.Length);

            var usdMerchantAccount = (from ma in result.Target.MerchantAccounts where ma.Id == "USD" select ma).ToArray()[0];
            Assert.AreEqual("USD", usdMerchantAccount.CurrencyIsoCode);
            Assert.IsTrue(usdMerchantAccount.IsDefault.Value);

            var gbpMerchantAccount = (from ma in result.Target.MerchantAccounts where ma.Id == "GBP" select ma).ToArray()[0];
            Assert.AreEqual("GBP", gbpMerchantAccount.CurrencyIsoCode);
            Assert.IsFalse(gbpMerchantAccount.IsDefault.Value);
        }
コード例 #15
0
 public void Generate_RaisesExceptionIfFailOnDuplicatePaymentMethodIsIncludedWithoutCustomerId()
 {
     var gateway = new BraintreeGateway();
     try {
         gateway.ClientToken.Generate(
             new ClientTokenRequest
             {
                 Options = new ClientTokenOptionsRequest
                 {
                     FailOnDuplicatePaymentMethod = true
                 }
             }
         );
         Assert.Fail("Should raise ArgumentException");
     } catch (ArgumentException e) {
         Match match = Regex.Match(e.Message, @"FailOnDuplicatePaymentMethod");
         Assert.IsTrue(match.Success);
     }
 }
コード例 #16
0
        public void Setup()
        {
            gateway = new BraintreeGateway
            {
                //Environment = Environment.DEVELOPMENT,
                //MerchantId = "integration_merchant_id",
                //PublicKey = "integration_public_key",
                //PrivateKey = "integration_private_key"
            };

            CustomerRequest request = new CustomerRequest
            {
                CreditCard = new CreditCardRequest
                {
                    CardholderName = "Fred Jones",
                    Number = "5555555555554444",
                    ExpirationDate = "05/12"
                }
            };

            customer = gateway.Customer.Create(request).Target;
            creditCard = customer.CreditCards[0];
        }
コード例 #17
0
        public void Setup()
        {
            gateway = new BraintreeGateway
            {
                Environment = Environment.DEVELOPMENT,
                MerchantId = "integration_merchant_id",
                PublicKey = "integration_public_key",
                PrivateKey = "integration_private_key"
            };

            partnerMerchantGateway = new BraintreeGateway
            (
                Environment.DEVELOPMENT,
                "integration_merchant_public_id",
                "oauth_app_partner_user_public_key",
                "oauth_app_partner_user_private_key"
            );

            oauthGateway = new BraintreeGateway
            (
                "client_id$development$integration_client_id",
                "client_secret$development$integration_client_secret"
            );
        }
コード例 #18
0
        public void Generate_GeneratedFingerprintIsAcceptedByGateway()
        {
            var gateway = new BraintreeGateway();
            var clientToken = TestHelper.GenerateDecodedClientToken(gateway);
            var authorizationFingerprint = TestHelper.extractParamFromJson("authorizationFingerprint", clientToken);

            var encodedFingerprint = HttpUtility.UrlEncode(authorizationFingerprint, Encoding.UTF8);
            var url = "v1/payment_methods.json";
            url += "?authorizationFingerprint=" + encodedFingerprint;
            url += "&sharedCustomerIdentifierType=testing";
            url += "&sharedCustomerIdentifier=test-identifier";

            HttpWebResponse response = new BraintreeTestHttpService().Get(gateway.MerchantId, url);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            response.Close();
        }
コード例 #19
0
 public void Generate_ThrowExceptionWhenCustomerNotFound()
 {
     var gateway = new BraintreeGateway();
     string encodedClientToken = "";
     try
     {
         encodedClientToken += gateway.ClientToken.Generate(
             new ClientTokenRequest
             {
                 CustomerId = "NON_EXISTENT_CUSTOMER_ID"
             }
         );
         Assert.Fail("Should raise ArgumentException");
     } catch (ArgumentException e) {
         Match match = Regex.Match(e.Message, @"customer_id");
         Assert.IsTrue(match.Success);
     }
 }
コード例 #20
0
        public void Generate_GatewayRespectsMakeDefault()
        {
            var gateway = new BraintreeGateway();
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());
            string customerId = result.Target.Id;

            var request = new CreditCardRequest
            {
                CustomerId = customerId,
                Number = "5555555555554444",
                ExpirationDate = "05/2099"
            };
            Result<CreditCard> creditCardResult = gateway.CreditCard.Create(request);
            Assert.IsTrue(creditCardResult.IsSuccess());

            var clientToken = TestHelper.GenerateDecodedClientToken(gateway,
                new ClientTokenRequest
                {
                    CustomerId = customerId,
                    Options = new ClientTokenOptionsRequest
                    {
                        MakeDefault = true
                    }
                }
            );
            var authorizationFingerprint = TestHelper.extractParamFromJson("authorizationFingerprint", clientToken);

            var builder = new RequestBuilder("");
            builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint).
                AddTopLevelElement("shared_customer_identifier_type", "testing").
                AddTopLevelElement("shared_customer_identifier", "test-identifier").
                AddTopLevelElement("credit_card[number]", "4111111111111111").
                AddTopLevelElement("credit_card[expiration_month]", "11").
                AddTopLevelElement("credit_card[expiration_year]", "2099");

            HttpWebResponse response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString());
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            response.Close();

            Customer customer = gateway.Customer.Find(customerId);
            Assert.AreEqual(2, customer.CreditCards.Length);
            foreach (CreditCard creditCard in customer.CreditCards)
            {
                if (creditCard.LastFour == "1111") {
                    Assert.IsTrue(creditCard.IsDefault.Value);
                }
            }
        }
コード例 #21
0
        public void Generate_GatewayRespectsVerifyCard()
        {
            var gateway = new BraintreeGateway();
            Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
            Assert.IsTrue(result.IsSuccess());

            string customerId = result.Target.Id;
            var clientToken = TestHelper.GenerateDecodedClientToken(gateway,
                new ClientTokenRequest
                {
                    CustomerId = customerId,
                    Options = new ClientTokenOptionsRequest
                    {
                        VerifyCard = true
                    }
                }
            );
            var authorizationFingerprint = TestHelper.extractParamFromJson("authorizationFingerprint", clientToken);

            var builder = new RequestBuilder("");
            builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint).
                AddTopLevelElement("shared_customer_identifier_type", "testing").
                AddTopLevelElement("shared_customer_identifier", "test-identifier").
                AddTopLevelElement("credit_card[number]", "4000111111111115").
                AddTopLevelElement("credit_card[expiration_month]", "11").
                AddTopLevelElement("credit_card[expiration_year]", "2099");

            HttpWebResponse response = new BraintreeTestHttpService().Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString());
            Assert.AreEqual(422, (int)response.StatusCode);
            response.Close();

            Customer customer = gateway.Customer.Find(customerId);
            Assert.AreEqual(0, customer.CreditCards.Length);
        }
コード例 #22
0
 public void Generate_DefaultsToVersionTwo()
 {
     var gateway = new BraintreeGateway();
     var encodedClientToken = gateway.ClientToken.Generate();
     var decodedClientToken = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(encodedClientToken));
     int version = TestHelper.extractIntParamFromJson("version", decodedClientToken);
     Assert.AreEqual(2, version);
 }
コード例 #23
0
        public void FailsInProduction()
        {
            var productionGateway = new BraintreeGateway
            {
                Environment = Environment.PRODUCTION,
                MerchantId = "integration_merchant_id",
                PublicKey = "integration_public_key",
                PrivateKey = "integration_private_key"
            };

            productionGateway.TestTransaction.Settle("production_transaction_id");
        }
コード例 #24
0
ファイル: OAuthTest.cs プロジェクト: ronin1/braintree_dotnet
        public void CreateTokenFromCode_RaisesIfWrongCredentials()
        {
            try {
                gateway = new BraintreeGateway(
                    "access_token$development$merchant_id$_oops_this_is_not_a_client_id_and_secret"
                );

                gateway.OAuth.CreateTokenFromCode(new OAuthCredentialsRequest());

                Assert.Fail("Should throw ConfigurationException");
            } catch (ConfigurationException) {}
        }
コード例 #25
0
        public void Create_CreateCustomerUsingAccessToken()
        {
            var createRequest = new CustomerRequest()
            {
                FirstName = "Michael",
                LastName = "Angelo",
                Company = "Some Company",
                Email = "[email protected]",
                Phone = "312.555.1111",
                Fax = "312.555.1112",
                Website = "www.example.com",
            };

            //BraintreeGateway oauthGateway = new BraintreeGateway(
            //    "client_id$development$integration_client_id",
            //    "client_secret$development$integration_client_secret"
            //);
            //string code = OAuthTestHelper.CreateGrant(oauthGateway, "integration_merchant_id", "read_write");
            BraintreeGateway oauthGateway = new BraintreeGateway(
                "client_id$" + Environment.CONFIGURED.EnvironmentName + "$integration_client_id",
                "client_secret$" + Environment.CONFIGURED.EnvironmentName + "$integration_client_secret"
            );            
            string code = OAuthTestHelper.CreateGrant(oauthGateway, gateway.Configuration.MerchantId, "read_write");

            ResultImpl<OAuthCredentials> accessTokenResult = oauthGateway.OAuth.CreateTokenFromCode(new OAuthCredentialsRequest {
                Code = code,
                Scope = "read_write"
            });

            gateway = new BraintreeGateway(accessTokenResult.Target.AccessToken);

            Customer customer = gateway.Customer.Create(createRequest).Target;
            Assert.AreEqual("Michael", customer.FirstName);
            Assert.AreEqual("Angelo", customer.LastName);
            Assert.AreEqual("Some Company", customer.Company);
            Assert.AreEqual("[email protected]", customer.Email);
            Assert.AreEqual("312.555.1111", customer.Phone);
            Assert.AreEqual("312.555.1112", customer.Fax);
            Assert.AreEqual("www.example.com", customer.Website);
            Assert.AreEqual(DateTime.Now.Year, customer.CreatedAt.Value.Year);
            Assert.AreEqual(DateTime.Now.Year, customer.UpdatedAt.Value.Year);
        }
コード例 #26
0
        public void PaymentMethodGrantAndRevoke()
        {
            Result<Customer> result = partnerMerchantGateway.Customer.Create(new CustomerRequest());
            var token = partnerMerchantGateway.PaymentMethod.Create(new PaymentMethodRequest
                {
                  PaymentMethodNonce = Nonce.Transactable,
                  CustomerId = result.Target.Id
                 }).Target.Token;
            string code = OAuthTestHelper.CreateGrant(oauthGateway, "integration_merchant_id", "grant_payment_method");
            ResultImpl<OAuthCredentials> accessTokenResult = oauthGateway.OAuth.CreateTokenFromCode(new OAuthCredentialsRequest {
                    Code = code,
                    Scope = "grant_payment_method"
                });

            BraintreeGateway accessTokenGateway = new BraintreeGateway(accessTokenResult.Target.AccessToken);
            PaymentMethodGrantRequest grantRequest = new PaymentMethodGrantRequest()
            {
                AllowVaulting = false,
                IncludeBillingPostalCode = true
            };
            Result<PaymentMethodNonce> grantResult = accessTokenGateway.PaymentMethod.Grant(token, grantRequest);
            Assert.IsTrue(grantResult.IsSuccess());
            Assert.IsNotNull(grantResult.Target.Nonce);

            Result<PaymentMethod> revokeResult = accessTokenGateway.PaymentMethod.Revoke(token);
            Assert.IsTrue(revokeResult.IsSuccess());
        }
コード例 #27
0
 public void Setup()
 {
     gateway = new BraintreeGateway();
     service = new BraintreeService(gateway.Configuration);
 }
コード例 #28
0
 public void Generate_SupportsVersionOption()
 {
     var gateway = new BraintreeGateway();
     var clientToken = gateway.ClientToken.Generate(
         new ClientTokenRequest
         {
             Version = 1
         }
     );
     int version = TestHelper.extractIntParamFromJson("version", clientToken);
     Assert.AreEqual(1, version);
 }
コード例 #29
0
 public void Setup()
 {
     gateway = new BraintreeGateway();
 }
コード例 #30
0
        public void RevokeAccessToken_RevokesAccessToken()
        {
            string code = OAuthTestHelper.CreateGrant(gateway, "integration_merchant_id", "read_write");

            ResultImpl<OAuthCredentials> accessTokenResult = gateway.OAuth.CreateTokenFromCode(new OAuthCredentialsRequest {
                Code = code,
                Scope = "read_write"
            });

            string accessToken = accessTokenResult.Target.AccessToken;
            ResultImpl<OAuthResult> result = gateway.OAuth.RevokeAccessToken(accessToken);
            Assert.IsTrue(result.Target.Result.Value);

            try {
                gateway = new BraintreeGateway(
                    accessToken
                );

                gateway.Customer.Create();

                Assert.Fail("Should throw AuthenticationException");
            } catch (AuthenticationException) {}
        }