Esempio n. 1
0
        public void CreateTokenFromCode_ReturnsOAuthCredentials()
        {
            string code = OAuthTestHelper.CreateGrant(gateway, "integration_merchant_id", "read_write");

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

            Assert.IsTrue(result.IsSuccess());
            Assert.IsNotNull(result.Target.AccessToken);
            Assert.IsNotNull(result.Target.RefreshToken);
            Assert.IsNotNull(result.Target.ExpiresAt);
            Assert.AreEqual("bearer", result.Target.TokenType);
        }
Esempio n. 2
0
        public void Create_CreateCustomerUsingAccessToken()
        {
            var createRequest = new CustomerRequest()
            {
                FirstName = "Michael",
                LastName  = "Angelo",
                Company   = "Some Company",
                Email     = "*****@*****.**",
                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");
            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("*****@*****.**", 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);
        }
Esempio n. 3
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) {}
        }