Ejemplo n.º 1
0
        public static String QueryStringForTR(Request trParams, Request req, String postURL, BraintreeService service)
        {
            String trData = TrUtil.BuildTrData(trParams, "http://example.com", service);
            String postData = "tr_data=" + HttpUtility.UrlEncode(trData, Encoding.UTF8) + "&";
            postData += req.ToQueryString();

            var request = WebRequest.Create(postURL) as HttpWebRequest;

            request.Method = "POST";
            request.KeepAlive = false;

            byte[] buffer = Encoding.UTF8.GetBytes(postData);
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = buffer.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(buffer, 0, buffer.Length);
            requestStream.Close();

            var response = request.GetResponse() as HttpWebResponse;
            String query = response.ResponseUri.Query;

            response.Close();

            return query;
        }
Ejemplo n.º 2
0
 public void Setup()
 {
     service = new BraintreeService(new Configuration(
         Environment.DEVELOPMENT,
         "integration_merchant_id",
         "integration_public_key",
         "integration_private_key"
     ));
 }
 public void GetWebProxy_ReturnsNullIfNotSpecified()
 {
     BraintreeService service = new BraintreeService(new Configuration(
         Environment.DEVELOPMENT,
         "integration_merchant_id",
         "integration_public_key",
         "integration_private_key"
     ));
     Assert.AreEqual(null, service.GetWebProxy());
 }
Ejemplo n.º 4
0
 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); }
Ejemplo n.º 5
0
        public void Setup()
        {
            configuration = new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
                );

            service = new BraintreeService(configuration);
        }
Ejemplo n.º 6
0
        public void GetAuthorizationHeader_ReturnsBase64EncodePublicAndPrivateKeys()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                                                                Environment.DEVELOPMENT,
                                                                "integration_merchant_id",
                                                                "integration_public_key",
                                                                "integration_private_key"
                                                                ));

            Assert.AreEqual("Basic aW50ZWdyYXRpb25fcHVibGljX2tleTppbnRlZ3JhdGlvbl9wcml2YXRlX2tleQ==", service.GetAuthorizationHeader());
        }
Ejemplo n.º 7
0
 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);
 }
Ejemplo n.º 8
0
        public void BaseMerchantURL_ReturnsSandboxURL()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                                                                Environment.SANDBOX,
                                                                "integration_merchant_id",
                                                                "integration_public_key",
                                                                "integration_private_key"
                                                                ));

            Assert.AreEqual("https://api.sandbox.braintreegateway.com:443/merchants/integration_merchant_id", service.BaseMerchantURL());
        }
Ejemplo n.º 9
0
        public void BaseMerchantURL_ReturnsProductionURL()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                                                                Environment.PRODUCTION,
                                                                "integration_merchant_id",
                                                                "integration_public_key",
                                                                "integration_private_key"
                                                                ));

            Assert.AreEqual("https://api.braintreegateway.com:443/merchants/integration_merchant_id", service.BaseMerchantURL());
        }
Ejemplo n.º 10
0
        public void Proxy_ReturnsNullIfNotSpecified()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                                                                Environment.DEVELOPMENT,
                                                                "integration_merchant_id",
                                                                "integration_public_key",
                                                                "integration_private_key"
                                                                ));

            Assert.AreEqual(null, service.GetWebProxy());
        }
Ejemplo n.º 11
0
        public static string CreateGrant(BraintreeGateway gateway, string merchantId, string scope)
        {
            var     service = new BraintreeService(gateway.Configuration);
            XmlNode node    = service.Post("/oauth_testing/grants", new OAuthGrantRequest
            {
                MerchantId = merchantId,
                Scope      = scope
            });

            return(node["code"].InnerText);
        }
        public void WebProxy_ReturnsWebProxyConfiguration()
        {
            Configuration configuration = new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            );

            configuration.WebProxy = new WebProxy(new Uri("http://localhost:3000"));
            BraintreeService service = new BraintreeService(configuration);
            Assert.AreEqual(configuration.WebProxy, service.GetWebProxy());
        }
        public void GetHttpRequest_returnsAHttpRequestSetupForBraintree()
        {
            configuration.WebProxy = new WebProxy(new Uri("http://localhost:3000"));
            BraintreeService service = new BraintreeService(configuration);
            var request = service.GetHttpRequest("https://www.example.com", "POST");

            Assert.AreEqual(configuration.WebProxy, request.Proxy);
            Assert.AreEqual("POST", request.Method.ToString());
            Assert.AreEqual("https://www.example.com/", request.RequestUri.ToString());
            Assert.IsFalse(request.KeepAlive);
            Assert.AreEqual(configuration.Timeout, request.Timeout);
            Assert.AreEqual(configuration.Timeout, request.ReadWriteTimeout);
        }
        public void WebProxy_ReturnsWebProxyConfiguration()
        {
            Configuration configuration = new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
                );

            configuration.WebProxy = new WebProxy(new Uri("http://localhost:3000"));
            BraintreeService service = new BraintreeService(configuration);

            Assert.AreEqual(configuration.WebProxy, service.GetWebProxy());
        }
Ejemplo n.º 15
0
        public void BaseMerchantURL_ReturnsDevelopmentURL()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                                                                Environment.DEVELOPMENT,
                                                                "integration_merchant_id",
                                                                "integration_public_key",
                                                                "integration_private_key"
                                                                ));

            var host     = System.Environment.GetEnvironmentVariable("GATEWAY_HOST") ?? "localhost";
            var port     = System.Environment.GetEnvironmentVariable("GATEWAY_PORT") ?? "3000";
            var expected = String.Format("http://{0}:{1}/merchants/integration_merchant_id", host, port);

            Assert.AreEqual(expected, service.BaseMerchantURL());
        }
Ejemplo n.º 16
0
        public void BaseMerchantURL_ReturnsDevelopmentURL()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            ));

            var host = System.Environment.GetEnvironmentVariable("GATEWAY_HOST") ?? "localhost";
            var port = System.Environment.GetEnvironmentVariable("GATEWAY_PORT") ?? "3000";
            var expected = string.Format("http://{0}:{1}/merchants/integration_merchant_id", host, port);

            Assert.AreEqual(expected, service.BaseMerchantURL());
        }
        public void GetWebProxy_ReturnsProxyConfiguration()
        {
            Configuration configuration = new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
                );

            configuration.WebProxy = new WebProxy(new Uri("http://localhost:3000"));
            BraintreeService service = new BraintreeService(configuration);
            Uri destination          = new Uri("http://0.0.0.0");

            Assert.AreEqual("http://localhost:3000", service.GetWebProxy().GetProxy(destination).OriginalString);
        }
        public void GetWebProxy_ReturnsProxyConfiguration()
        {
            Configuration configuration = new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            );

            configuration.WebProxy = new WebProxy(new Uri("http://localhost:3000"));
            BraintreeService service = new BraintreeService(configuration);
            Uri destination = new Uri("http://0.0.0.0");

            Assert.AreEqual("http://localhost:3000", service.GetWebProxy().GetProxy(destination).OriginalString);
        }
Ejemplo n.º 19
0
        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);

            XmlDocument attributesXml = CreateAttributesXml();

            attributes = new NodeWrapper(attributesXml).GetNode("//disbursement");
        }
        public void ConfigurationWithStringEnvironment_Initializes()
        {
            Configuration config = new Configuration(
                "development",
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
                );
            BraintreeService service = new BraintreeService(config);

            var host     = System.Environment.GetEnvironmentVariable("GATEWAY_HOST") ?? "localhost";
            var port     = System.Environment.GetEnvironmentVariable("GATEWAY_PORT") ?? "3000";
            var expected = string.Format("http://{0}:{1}/merchants/integration_merchant_id", host, port);

            Assert.AreEqual(expected, service.BaseMerchantURL());
        }
        public async Task<AuthenticationInsightResponse> RequestAuthInsight(string paymentMethodToken, string merchantAccountId, decimal amount = -1)
        {
            BraintreeService service = new BraintreeService(gateway.Configuration);
            AuthenticationInsightOptionsRequest options = new AuthenticationInsightOptionsRequest{};

            PaymentMethodNonceRequest paymentMethodNonceRequest = new PaymentMethodNonceRequest
            {
                AuthenticationInsight = true,
                MerchantAccountId = merchantAccountId,
                AuthenticationInsightOptions = options,
            };
            if(amount > 0)
                paymentMethodNonceRequest.AuthenticationInsightOptions.Amount = amount;

            Result<PaymentMethodNonce> nonce = await gateway.PaymentMethodNonce.CreateAsync(paymentMethodToken, paymentMethodNonceRequest);
            return nonce.Target.AuthenticationInsight;
        }
Ejemplo n.º 22
0
        public void Find_ExposesThreeDSecureInfo()
        {
            BraintreeService service = new BraintreeService(gateway.Configuration);
            CreditCardRequest creditCardRequest = new CreditCardRequest
            {
                Number = SandboxValues.CreditCardNumber.VISA,
                ExpirationMonth = "05",
                ExpirationYear = "2020"
            };
            string nonce = TestHelper.Generate3DSNonce(service, creditCardRequest);

            PaymentMethodNonce foundNonce = gateway.PaymentMethodNonce.Find(nonce);
            ThreeDSecureInfo info = foundNonce.ThreeDSecureInfo;

            Assert.AreEqual(foundNonce.Nonce, nonce);
            Assert.AreEqual(foundNonce.Type, "CreditCard");
            Assert.AreEqual(info.Enrolled, "Y");
            Assert.AreEqual(info.Status, "authenticate_successful");
            Assert.AreEqual(info.LiabilityShifted, true);
            Assert.AreEqual(info.LiabilityShiftPossible, true);
        }
Ejemplo n.º 23
0
        public void GetAuthorizationSchema_ReturnsBearerHeader()
        {
            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"
            });

            BraintreeGateway gateway            = new BraintreeGateway(accessTokenResult.Target.AccessToken);
            Configuration    oauthConfiguration = gateway.Configuration;
            BraintreeService oauthService       = new BraintreeService(oauthConfiguration);
            string           schema             = oauthService.GetAuthorizationSchema();

            Assert.AreEqual("Bearer", schema);
        }
Ejemplo n.º 24
0
        public void SetWebProxy_DoesNotThrowUriException()
        {
            Configuration configuration = new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
                );

            configuration.WebProxy = new WebProxy("http://localhost:3000");

            BraintreeService service = new BraintreeService(configuration);

            try {
                service.Get(service.MerchantPath() + "/non-existent-route");
                Assert.Fail("Should have thrown exception");
            } catch (System.UriFormatException) {
                Assert.Fail("Setting WebProxy should not throw a URI exception");
            } catch (NotFoundException) {
                // expected
            }
        }
Ejemplo n.º 25
0
        public async Task <ActionResult> Register(string username, string email, string password, string phone, string firstName, string lastName)
        {
            UserManager <IdentityUser> manager = HttpContext.GetOwinContext().Get <UserManager <IdentityUser> >();

            if (ModelState.IsValid)
            {
                var user = new IdentityUser()
                {
                    UserName       = username,
                    Email          = email,
                    EmailConfirmed = false,
                };

                var result = await manager.CreateAsync(user, password);

                if (result.Succeeded)
                {
                    BraintreeService service = new BraintreeService(_braintreeGateway);
                    await service.GetCustomerId(email, phone, firstName, lastName);

                    string confirmationToken = await manager.GenerateEmailConfirmationTokenAsync(user.Id);

                    string confirmationLink = Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/Confirm/" + user.Id + "?token=" + confirmationToken;
                    string htmlContent      = string.Format("<a href=\"{0}\">Confirm Your Account</a>", confirmationLink);
                    await manager.SendEmailAsync(user.Id, "Confirm your Outdoor Gear Rental Account", htmlContent);

                    TempData["EmailAddress"] = email;
                    return(RedirectToAction("ConfirmationSent"));
                }
                else
                {
                    ViewBag.Error = result.Errors;
                }
            }
            return(View());
        }
Ejemplo n.º 26
0
 public void ThrowExceptionIfErrorStatusCodeIsTooManyRequests()
 {
     BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode)429, null);
 }
 public void ThrowExceptionIfErrorStatusCodeIsDownForMaintenance()
 {
     Assert.Throws <DownForMaintenanceException> (() => BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode)503, null));
 }
Ejemplo n.º 28
0
 public void ThrowExceptionIfErrorStatusCodeIsUpgradeRequired()
 {
     BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode)426, null);
 }
 public void ThrowExceptionIfErrorStatusCodeIsUpgradeRequired()
 {
     Assert.Throws <UpgradeRequiredException>(() => BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode)426, null));
 }
 public void ThrowExceptionIfErrorStatusCodeIsTooManyRequests()
 {
     Assert.Throws <TooManyRequestsException>(() => BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode)429, null));
 }
Ejemplo n.º 31
0
      public static string CreateGrant(BraintreeGateway gateway, string merchantId, string scope)
      {
          var service = new BraintreeService(gateway.Configuration);
          XmlNode node = service.Post("/oauth_testing/grants", new OAuthGrantRequest {
              MerchantId = merchantId,
              Scope = scope
          });

          return node["code"].InnerText;
      }
Ejemplo n.º 32
0
        public void GetAuthorizationHeader_ReturnsBase64EncodePublicAndPrivateKeys()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                Environment.DEVELOPMENT,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            ));

#if netcore
            Assert.AreEqual("aW50ZWdyYXRpb25fcHVibGljX2tleTppbnRlZ3JhdGlvbl9wcml2YXRlX2tleQ==", service.GetAuthorizationHeader());
#else
            Assert.AreEqual("Basic aW50ZWdyYXRpb25fcHVibGljX2tleTppbnRlZ3JhdGlvbl9wcml2YXRlX2tleQ==", service.GetAuthorizationHeader());
#endif
        }
Ejemplo n.º 33
0
 public static void Escrow(BraintreeService service, string transactionId)
 {
   NodeWrapper response = new NodeWrapper(service.Put(service.MerchantPath() + "/transactions/" + transactionId + "/escrow"));
   Assert.IsTrue(response.IsSuccess());
 }
Ejemplo n.º 34
0
 private void MakePastDue(Subscription subscription, int numberOfDays)
 {
     BraintreeService service = new BraintreeService(gateway.Configuration);
     NodeWrapper response = new NodeWrapper(service.Put(service.MerchantPath() + "/subscriptions/" + subscription.Id + "/make_past_due?days_past_due=" + numberOfDays));
     Assert.IsTrue(response.IsSuccess());
 }
Ejemplo n.º 35
0
        public void BaseMerchantURL_ReturnsProductionURL()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                Environment.PRODUCTION,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            ));

            Assert.AreEqual("https://api.braintreegateway.com:443/merchants/integration_merchant_id", service.BaseMerchantURL());
        }
Ejemplo n.º 36
0
 public BraintreeGateway(Configuration configuration)
 {
     Configuration = configuration;
     GraphQLClient = new GraphQLClient(Configuration);
     Service       = new BraintreeService(Configuration);
 }
Ejemplo n.º 37
0
 public void Setup()
 {
     gateway = new BraintreeGateway();
     service = new BraintreeService(gateway.Configuration);
 }
Ejemplo n.º 38
0
        public static string QueryStringForTR(Request trParams, Request req, string postURL, BraintreeService service)
        {
#if netcore
            string trData   = TrUtil.BuildTrData(trParams, "http://example.com", service);
            string postData = "tr_data=" + WebUtility.UrlEncode(trData) + "&";
            postData += req.ToQueryString();

            var request = new HttpRequestMessage(new HttpMethod("POST"), postURL);

            request.Headers.Add("KeepAlive", "false");
            request.Headers.Add("Accept", "application/json");
            byte[] buffer = Encoding.UTF8.GetBytes(postData);
            request.Content = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded");
            request.Content.Headers.Add("Content-Length", buffer.Length.ToString());
            var httpClientHandler = new HttpClientHandler
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
                AllowAutoRedirect      = false,
            };

            HttpResponseMessage response;

            using (var client = new HttpClient(httpClientHandler))
            {
                response = client.SendAsync(request).GetAwaiter().GetResult();
            }

            StreamReader reader       = new StreamReader(response.Content.ReadAsStreamAsync().Result, Encoding.UTF8);
            string       responseBody = reader.ReadToEnd();
            string       query        = response.Headers.Location.Query;
            return(query);
#else
            string trData   = TrUtil.BuildTrData(trParams, "http://example.com", service);
            string postData = "tr_data=" + HttpUtility.UrlEncode(trData, Encoding.UTF8) + "&";
            postData += req.ToQueryString();

            var request = WebRequest.Create(postURL) as HttpWebRequest;

            request.Method            = "POST";
            request.KeepAlive         = false;
            request.AllowAutoRedirect = false;

            byte[] buffer = Encoding.UTF8.GetBytes(postData);
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = buffer.Length;
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(buffer, 0, buffer.Length);
            requestStream.Close();

            var    response = request.GetResponse() as HttpWebResponse;
            string query    = new Uri(response.GetResponseHeader("Location")).Query;

            response.Close();

            return(query);
#endif
        }
Ejemplo n.º 39
0
 public static void Settle(BraintreeService service, String transactionId)
 {
     NodeWrapper response = new NodeWrapper(service.Put("/transactions/" + transactionId + "/settle"));
     Assert.IsTrue(response.IsSuccess());
 }
Ejemplo n.º 40
0
 public void ThrowExceptionIfErrorStatusCodeIsDownForMaintenance()
 {
     BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode)503, null);
 }
Ejemplo n.º 41
0
        public void ConfigurationWithStringEnvironment_Initializes()
        {
            Configuration config = new Configuration(
                "development",
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            );
            BraintreeService service = new BraintreeService(config);

            var host = System.Environment.GetEnvironmentVariable("GATEWAY_HOST") ?? "localhost";
            var port = System.Environment.GetEnvironmentVariable("GATEWAY_PORT") ?? "3000";
            var expected = string.Format("http://{0}:{1}/merchants/integration_merchant_id", host, port);

            Assert.AreEqual(expected, service.BaseMerchantURL());
        }
Ejemplo n.º 42
0
        public static string QueryStringForTR(Request trParams, Request req, string postURL, BraintreeService service)
        {
            string trData   = TrUtil.BuildTrData(trParams, "http://example.com", service);
            string postData = "tr_data=" + HttpUtility.UrlEncode(trData, Encoding.UTF8) + "&";

            postData += req.ToQueryString();

            var request = WebRequest.Create(postURL) as HttpWebRequest;

            request.Method            = "POST";
            request.KeepAlive         = false;
            request.AllowAutoRedirect = false;

            byte[] buffer = Encoding.UTF8.GetBytes(postData);
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = buffer.Length;
            Stream requestStream = request.GetRequestStream();

            requestStream.Write(buffer, 0, buffer.Length);
            requestStream.Close();

            var    response = request.GetResponse() as HttpWebResponse;
            string query    = new Uri(response.GetResponseHeader("Location")).Query;

            response.Close();

            return(query);
        }
Ejemplo n.º 43
0
 public static string Create3DSVerification(BraintreeService service, string merchantAccountId, ThreeDSecureRequestForTests request)
 {
   string url = "/three_d_secure/create_verification/" + merchantAccountId;
   NodeWrapper response = new NodeWrapper(service.Post(service.MerchantPath() + url, request));
   Assert.IsTrue(response.IsSuccess());
   return response.GetString("three-d-secure-token");
 }
Ejemplo n.º 44
0
        public static void Escrow(BraintreeService service, string transactionId)
        {
            NodeWrapper response = new NodeWrapper(service.Put(service.MerchantPath() + "/transactions/" + transactionId + "/escrow"));

            Assert.IsTrue(response.IsSuccess());
        }
Ejemplo n.º 45
0
 public BraintreeGateway(string accessToken)
 {
     Configuration = new Configuration(accessToken);
     GraphQLClient = new GraphQLClient(Configuration);
     Service       = new BraintreeService(Configuration);
 }
Ejemplo n.º 46
0
 public BraintreeGateway(string clientId, string clientSecret)
 {
     Configuration = new Configuration(clientId, clientSecret);
     GraphQLClient = new GraphQLClient(Configuration);
     Service       = new BraintreeService(Configuration);
 }
Ejemplo n.º 47
0
        public void BaseMerchantURL_ReturnsSandboxURL()
        {
            BraintreeService service = new BraintreeService(new Configuration(
                Environment.SANDBOX,
                "integration_merchant_id",
                "integration_public_key",
                "integration_private_key"
            ));

            Assert.AreEqual("https://api.sandbox.braintreegateway.com:443/merchants/integration_merchant_id", service.BaseMerchantURL());
        }