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); }
public void AppendOtherObjectsWithCanBeConvertedToStrings() { string actual = new QueryString(). Append("foo", 10). Append("bar", "20.00").ToString(); Assert.AreEqual("foo=10&bar=20.00", actual); }
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); }
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); }
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); }
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(); }
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(); }
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; }
public void Append() { string actual = new QueryString().Append("foo", "f").Append("bar", "b").ToString(); Assert.AreEqual("foo=f&bar=b", actual); }