예제 #1
0
        public static string BuildTrData(Request request, string redirectURL, BraintreeService service)
        {
            var dateString = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss");

            var trContent = new QueryString().
                Append("api_version", service.ApiVersion).
                Append("public_key", service.PublicKey).
                Append("redirect_url", redirectURL).
                Append("time", dateString).
                Append("kind", request.Kind()).
                ToString();

            string requestQueryString = request.ToQueryString();

            if (requestQueryString.Length > 0)
            {
                trContent += "&" + requestQueryString;
            }

            var signatureService = new SignatureService {
              Key = service.PrivateKey,
              Hasher = new Sha1Hasher()
            };
            return signatureService.Sign(trContent);
        }
예제 #2
0
        public void AppendOtherObjectsWithCanBeConvertedToStrings()
        {
            string actual = new QueryString().
                Append("foo", 10).
                Append("bar", "20.00").ToString();

            Assert.AreEqual("foo=10&bar=20.00", actual);
        }
예제 #3
0
        public void AppendWithRequest()
        {
            Request request = new CreditCardRequest
            {
                CVV = "123",
                CardholderName = "Drew"
            };

            string actual = new QueryString().Append("[credit_card]", request).ToString();
            Assert.AreEqual("%5bcredit_card%5d%5bcardholder_name%5d=Drew&%5bcredit_card%5d%5bcvv%5d=123", actual);
        }
예제 #4
0
        public void AppendEmptyStringOrNulls()
        {
            string actual = new QueryString().
                Append("foo", "f").
                Append("", "b").
                Append("bar", "").
                Append("boom", null).
                Append("", "c").ToString();

            Assert.AreEqual("foo=f&bar=", actual);
        }
예제 #5
0
        public void AppendWithNestedRequest()
        {
            Request request = new CreditCardRequest
            {
                CVV = "123",
                CardholderName = "Drew",
                Options = new CreditCardOptionsRequest
                {
                    VerifyCard = true,
                    MakeDefault = true
                }
            };

            string actual = new QueryString().Append("[credit_card]", request).ToString();
            Assert.AreEqual("%5bcredit_card%5d%5bcardholder_name%5d=Drew&%5bcredit_card%5d%5bcvv%5d=123&%5bcredit_card%5d%5boptions%5d%5bmake_default%5d=true&%5bcredit_card%5d%5boptions%5d%5bverify_card%5d=true", actual);
        }
예제 #6
0
        public String ToQueryString()
        {
            string underscoredParent = Parent.Replace("-", "_");

            QueryString qs = new QueryString();
            foreach (KeyValuePair<string, string> pair in TopLevelElements)
            {
                qs.Append(pair);
            }
            foreach (KeyValuePair<string, object> pair in Elements)
            {
                qs.Append(ParentBracketChildString(underscoredParent, pair.Key.Replace("-", "_")), pair.Value);
            }

            return qs.ToString();
        }
예제 #7
0
        public string ToQueryString()
        {
            string underscoredParent = Parent.Replace("-", "_");

            var qs = new QueryString();
            foreach (var pair in topLevelElements)
            {
                qs.Append(pair);
            }
            foreach (var pair in elements)
            {
                qs.Append(ParentBracketChildString(underscoredParent, pair.Key.Replace("-", "_")), pair.Value);
            }

            return qs.ToString();

        }
예제 #8
0
        public static String BuildTrData(Request request, String redirectURL, BraintreeService service)
        {
            String dateString = DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss");

            String trContent = new QueryString().
                Append("api_version", service.ApiVersion).
                Append("public_key", service.PublicKey).
                Append("redirect_url", redirectURL).
                Append("time", dateString).
                Append("kind", request.Kind()).
                ToString();

            String requestQueryString = request.ToQueryString();

            if (requestQueryString.Length > 0)
            {
                trContent += "&" + requestQueryString;
            }

            String trHash = new Crypto().HmacHash(service.PrivateKey, trContent);
            return trHash + "|" + trContent;
        }
예제 #9
0
 public void Append()
 {
     string actual = new QueryString().Append("foo", "f").Append("bar", "b").ToString();
     Assert.AreEqual("foo=f&bar=b", actual);
 }