diff --git a/README.md b/README.md index f256798..522a2cf 100644 --- a/README.md +++ b/README.md @@ -900,3 +900,73 @@ The official Sift .NET client, supporting .NET Standard 2.0+ { // Handle InnerException } + +### Verification + + // send + try + { + VerificationSendResponse res = sift.SendAsync(new VerificationSendRequest + { + UserId = "USER_ID", + BrandName = "MyTopBrand", + VerificationType = "$email", + SendTo = "SEND_TO", + Language = "en", + SiteCountry = "IN", + Event = new VerificationSendEvent() + { + Browser = new Browser() + { + user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + content_language = "en-US", + accept_language = "en-GB", + }, + IP = "192.168.1.1", + Reason = "$automated_rule", + SessionId = "SOME_SESSION_ID", + VerifiedEvent = "$login", + VerifiedEntityId = "SOME_SESSION_ID", + } + } + ).Result; + } + catch (AggregateException ae) + { + // Handle InnerException + } + + // resend + try + { + VerificationReSendResponse res = sift.SendAsync(new VerificationReSendRequest + { + UserId = "USER_ID", + VerifiedEntityId = "SOME_SESSION_ID", + VerifiedEvent = "$login" + + } + ).Result; + } + catch (AggregateException ae) + { + // Handle InnerException + } + + // check + try + { + VerificationCheckResponse res = sift.SendAsync(new VerificationCheckRequest + { + Code = 147222, + UserId = "USER_ID", + VerifiedEvent = "$login", + VerifiedEntityId = "SOME_SESSION_ID" + + } + ).Result; + } + catch (AggregateException ae) + { + // Handle InnerException + } \ No newline at end of file diff --git a/Sift/Request/VerificationRequest.cs b/Sift/Request/VerificationRequest.cs index 37adb02..39a50d4 100644 --- a/Sift/Request/VerificationRequest.cs +++ b/Sift/Request/VerificationRequest.cs @@ -8,7 +8,7 @@ namespace Sift { public class VerificationCheckRequest : SiftRequest { - static readonly String VerificationCheckUrl = @"https://api.sift.com/v1.1/verification/check"; + static readonly String VerificationCheckUrl = @"https://api.sift.com/v1/verification/check"; [JsonIgnore] public override string ApiKey { get; set; } @@ -49,7 +49,7 @@ protected override Uri Url public class VerificationSendRequest : SiftRequest { - static readonly String VerificationSendUrl = @"https://api.sift.com/v1.1/verification/send"; + static readonly String VerificationSendUrl = @"https://api.sift.com/v1/verification/send"; [JsonIgnore] public override string ApiKey { get; set; } @@ -57,7 +57,6 @@ public class VerificationSendRequest : SiftRequest [JsonProperty("$user_id", NullValueHandling = NullValueHandling.Ignore)] public string UserId { get; set; } - [JsonProperty("$send_to", NullValueHandling = NullValueHandling.Ignore)] public string SendTo { get; set; } @@ -67,6 +66,9 @@ public class VerificationSendRequest : SiftRequest [JsonProperty("$brand_name", NullValueHandling = NullValueHandling.Ignore)] public string BrandName { get; set; } + [JsonProperty("$site_country", NullValueHandling = NullValueHandling.Ignore)] + public string SiteCountry { get; set; } + [JsonProperty("$language", NullValueHandling = NullValueHandling.Ignore)] public string Language { get; set; } @@ -97,7 +99,7 @@ protected override Uri Url public class VerificationReSendRequest : SiftRequest { - static readonly String VerificationReSendUrl = @"https://api.sift.com/v1.1/verification/resend"; + static readonly String VerificationReSendUrl = @"https://api.sift.com/v1/verification/resend"; [JsonIgnore] public override string ApiKey { get; set; } @@ -133,7 +135,6 @@ protected override Uri Url } } - public class VerificationSendEvent { [JsonProperty("$session_id", NullValueHandling = NullValueHandling.Ignore)] @@ -142,19 +143,19 @@ public class VerificationSendEvent [JsonProperty("$verified_event", NullValueHandling = NullValueHandling.Ignore)] public string VerifiedEvent { get; set; } + [JsonProperty("$verified_entity_id", NullValueHandling = NullValueHandling.Ignore)] + public string VerifiedEntityId { get; set; } + [JsonProperty("$reason", NullValueHandling = NullValueHandling.Ignore)] public string Reason { get; set; } [JsonProperty("$ip", NullValueHandling = NullValueHandling.Ignore)] public string IP { get; set; } - [JsonProperty("$browser")] - public VerificationSendBrowser Browser { get; set; } - } + [Newtonsoft.Json.JsonProperty("$browser", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public Browser Browser { get; set; } - public class VerificationSendBrowser - { - [JsonProperty("$user_agent", NullValueHandling = NullValueHandling.Ignore)] - public string UserAgent { get; set; } + [Newtonsoft.Json.JsonProperty("$app", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public App App { get; set; } } } diff --git a/Test/Test.cs b/Test/Test.cs index 251962d..695b46d 100644 --- a/Test/Test.cs +++ b/Test/Test.cs @@ -5,6 +5,7 @@ using System.Collections.ObjectModel; using System.IO; using System.Linq; +using Newtonsoft.Json; using System.Security.Cryptography; using System.Text; using Xunit; @@ -178,7 +179,7 @@ public void TestEventRequest() "\"$app_version\":\"1.0\",\"$client_language\":\"en-US\"},\"$brand_name\":\"sift\",\"$site_country\":\"US\",\"$site_domain\":\"sift.com\"," + "\"$ordered_from\":{\"$store_id\":\"123\",\"$store_address\":{\"$name\":\"Bill Jones\",\"$address_1\":\"2100 Main Street\"," + "\"$address_2\":\"Apt 3B\",\"$city\":\"New London\",\"$region\":\"New Hampshire\",\"$country\":\"US\",\"$zipcode\":\"03257\"," + - "\"$phone\":\"1-415-555-6040\"}},\"foo\":\"bar\"}", + "\"$phone\":\"1-415-555-6040\"}},\"foo\":\"bar\"}", createOrder.ToJson()); @@ -807,8 +808,9 @@ public void TestVerificationCheckRequest() ApiKey = apiKey, Code = 655543, - UserId = "vineethk@exalture.com" - + UserId = "haneeshv@exalture.com", + VerifiedEntityId = "SOME_SESSION_ID", + VerifiedEvent = "$login" }; verificationCheckRequest.ApiKey = apiKey; @@ -816,7 +818,7 @@ public void TestVerificationCheckRequest() Assert.Equal(Convert.ToBase64String(Encoding.Default.GetBytes(apiKey)), verificationCheckRequest.Request.Headers.Authorization!.Parameter); - Assert.Equal("https://api.sift.com/v1.1/verification/check", + Assert.Equal("https://api.sift.com/v1/verification/check", verificationCheckRequest.Request.RequestUri!.ToString()); } @@ -829,22 +831,26 @@ public void TestVerificationSendRequest() var sessionId = "sessionId"; var verificationSendRequest = new VerificationSendRequest { - UserId = "vineethk@exalture.com", + UserId = "haneeshv@exalture.com", ApiKey = apiKey, BrandName = "all", VerificationType = "$email", - SendTo = "vineethk@exalture.com", + SendTo = "haneeshv@exalture.com", Language = "en", + SiteCountry = "IN", Event = new VerificationSendEvent() { - Browser = new VerificationSendBrowser() + Browser = new Browser() { - UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" + user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", + content_language = "en-US", + accept_language = "en-GB", }, IP = "192.168.1.1", Reason = "$automated_rule", SessionId = sessionId, - VerifiedEvent = "$login" + VerifiedEvent = "$login", + VerifiedEntityId = "SOME_SESSION_ID" } }; @@ -853,7 +859,7 @@ public void TestVerificationSendRequest() Assert.Equal(Convert.ToBase64String(Encoding.Default.GetBytes(apiKey)), verificationSendRequest.Request.Headers.Authorization!.Parameter); - Assert.Equal("https://api.sift.com/v1.1/verification/send", + Assert.Equal("https://api.sift.com/v1/verification/send", verificationSendRequest.Request.RequestUri!.ToString()); } @@ -864,18 +870,17 @@ public void TestVerificationReSendRequest() var apiKey = "key"; var verificationResendRequest = new VerificationReSendRequest { - UserId = "vineethk@exalture.com", - ApiKey = apiKey - - + UserId = "haneeshv@exalture.com", + ApiKey = apiKey, + VerifiedEntityId = "SOME_SESSION_ID", + VerifiedEvent = "$login" }; verificationResendRequest.ApiKey = apiKey; Assert.Equal(Convert.ToBase64String(Encoding.Default.GetBytes(apiKey)), verificationResendRequest.Request.Headers.Authorization!.Parameter); - - Assert.Equal("https://api.sift.com/v1.1/verification/resend", + Assert.Equal("https://api.sift.com/v1/verification/resend", verificationResendRequest.Request.RequestUri!.ToString()); } @@ -1295,7 +1300,7 @@ public void TestLoginEvent() "\"$social_sign_on_type\":\"$facebook\",\"$username\":\"test_user_name\",\"$ip\":\"128.148.1.135\",\"$browser\":" + "{\"$user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/56.0.2924.87 Safari/537.36\",\"$accept_language\":\"en-US\",\"$content_language\":\"en-GB\"},\"$brand_name\":" + - "\"sift\",\"$site_country\":\"US\",\"$site_domain\":\"sift.com\",\"$account_types\":[\"merchant\",\"premium\"]}", + "\"sift\",\"$site_country\":\"US\",\"$site_domain\":\"sift.com\",\"$account_types\":[\"merchant\",\"premium\"]}", login.ToJson()); EventRequest eventRequest = new EventRequest @@ -1536,7 +1541,7 @@ public void TestUpdateContentMessage() ip = "255.255.255.0", message = new Message() { - body = "Let’s meet at 5pm", + body = "LetÂ’s meet at 5pm", contact_email = "alex_301@domain.com", root_content_id = "listing-123", recipient_user_ids = new ObservableCollection() { "fy9h989sjphh71" }, @@ -1565,7 +1570,7 @@ public void TestUpdateContentMessage() site_domain = "sift.com", }; - string updateMessageBody = "{\"$type\":\"$update_content\",\"$user_id\":\"fyw3989sjpqr71\",\"$content_id\":\"message-23412\",\"$session_id\":\"a234ksjfgn435sfg\",\"$status\":\"$active\",\"$ip\":\"255.255.255.0\",\"$message\":{\"$body\":\"Let’s meet at 5pm\",\"$contact_email\":\"alex_301@domain.com\",\"$root_content_id\":\"listing-123\",\"$recipient_user_ids\":[\"fy9h989sjphh71\"],\"$images\":[{\"$md5_hash\":\"0cc175b9c0f1b6a831c399e269772661\",\"$link\":\"https://www.domain.com/file.png\",\"$description\":\"My hike today!\"},{\"$md5_hash\":\"0cc175b9c0f1b6a831c399e269772661\"}]},\"$browser\":{\"$user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36\",\"$accept_language\":\"en-US\",\"$content_language\":\"en-GB\"},\"$brand_name\":\"sift\",\"$site_country\":\"US\",\"$site_domain\":\"sift.com\"}"; + string updateMessageBody = "{\"$type\":\"$update_content\",\"$user_id\":\"fyw3989sjpqr71\",\"$content_id\":\"message-23412\",\"$session_id\":\"a234ksjfgn435sfg\",\"$status\":\"$active\",\"$ip\":\"255.255.255.0\",\"$message\":{\"$body\":\"LetÂ’s meet at 5pm\",\"$contact_email\":\"alex_301@domain.com\",\"$root_content_id\":\"listing-123\",\"$recipient_user_ids\":[\"fy9h989sjphh71\"],\"$images\":[{\"$md5_hash\":\"0cc175b9c0f1b6a831c399e269772661\",\"$link\":\"https://www.domain.com/file.png\",\"$description\":\"My hike today!\"},{\"$md5_hash\":\"0cc175b9c0f1b6a831c399e269772661\"}]},\"$browser\":{\"$user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36\",\"$accept_language\":\"en-US\",\"$content_language\":\"en-GB\"},\"$brand_name\":\"sift\",\"$site_country\":\"US\",\"$site_domain\":\"sift.com\"}"; Assert.Equal(updateMessageBody, updateContent.ToJson()); @@ -1714,7 +1719,7 @@ public void TestUpdateContentProfile() { md5_hash = "0cc175b9c0f1b6a831c399e269772661", link = "https://www.domain.com/file.png", - description = "Alex’s picture" + description = "AlexÂ’s picture" }, new Image() { @@ -1734,7 +1739,7 @@ public void TestUpdateContentProfile() site_domain = "sift.com", }; - string updateProfileBody = "{\"$type\":\"$update_content\",\"$user_id\":\"fyw3989sjpqr71\",\"$content_id\":\"listing-23412\",\"$session_id\":\"a234ksjfgn435sfg\",\"$status\":\"$active\",\"$ip\":\"255.255.255.0\",\"$profile\":{\"$body\":\"Hi! My name is Alex and I just moved to New London!\",\"$contact_email\":\"alex_301@domain.com\",\"$contact_address\":{\"$name\":\"Alex Smith\",\"$address_1\":\"abc\",\"$address_2\":\"xyz\",\"$city\":\"New London\",\"$region\":\"New Hampshire\",\"$country\":\"US\",\"$zipcode\":\"03257\",\"$phone\":\"1-415-555-6041\"},\"$images\":[{\"$md5_hash\":\"0cc175b9c0f1b6a831c399e269772661\",\"$link\":\"https://www.domain.com/file.png\",\"$description\":\"Alex’s picture\"},{\"$md5_hash\":\"0cc175b9c0f1b6a831c399e269772661\"}],\"$categories\":[\"Friends\",\"Long-term dating\"]},\"$browser\":{\"$user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36\",\"$accept_language\":\"en-US\",\"$content_language\":\"en-GB\"},\"$brand_name\":\"sift\",\"$site_country\":\"US\",\"$site_domain\":\"sift.com\"}"; + string updateProfileBody = "{\"$type\":\"$update_content\",\"$user_id\":\"fyw3989sjpqr71\",\"$content_id\":\"listing-23412\",\"$session_id\":\"a234ksjfgn435sfg\",\"$status\":\"$active\",\"$ip\":\"255.255.255.0\",\"$profile\":{\"$body\":\"Hi! My name is Alex and I just moved to New London!\",\"$contact_email\":\"alex_301@domain.com\",\"$contact_address\":{\"$name\":\"Alex Smith\",\"$address_1\":\"abc\",\"$address_2\":\"xyz\",\"$city\":\"New London\",\"$region\":\"New Hampshire\",\"$country\":\"US\",\"$zipcode\":\"03257\",\"$phone\":\"1-415-555-6041\"},\"$images\":[{\"$md5_hash\":\"0cc175b9c0f1b6a831c399e269772661\",\"$link\":\"https://www.domain.com/file.png\",\"$description\":\"AlexÂ’s picture\"},{\"$md5_hash\":\"0cc175b9c0f1b6a831c399e269772661\"}],\"$categories\":[\"Friends\",\"Long-term dating\"]},\"$browser\":{\"$user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36\",\"$accept_language\":\"en-US\",\"$content_language\":\"en-GB\"},\"$brand_name\":\"sift\",\"$site_country\":\"US\",\"$site_domain\":\"sift.com\"}"; Assert.Equal(updateProfileBody, updateContent.ToJson());