Skip to content

Commit

Permalink
Implemented missing fields from Verification API (#55)
Browse files Browse the repository at this point in the history
Changes in Verification API - code restructure and improvements
  • Loading branch information
haneeshv authored Sep 1, 2023
1 parent 9d31e13 commit 9f77091
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 33 deletions.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
25 changes: 13 additions & 12 deletions Sift/Request/VerificationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -49,15 +49,14 @@ 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; }

[JsonProperty("$user_id", NullValueHandling = NullValueHandling.Ignore)]
public string UserId { get; set; }


[JsonProperty("$send_to", NullValueHandling = NullValueHandling.Ignore)]
public string SendTo { get; set; }

Expand All @@ -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; }

Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -133,7 +135,6 @@ protected override Uri Url
}
}


public class VerificationSendEvent
{
[JsonProperty("$session_id", NullValueHandling = NullValueHandling.Ignore)]
Expand All @@ -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; }
}
}
47 changes: 26 additions & 21 deletions Test/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());


Expand Down Expand Up @@ -807,16 +808,17 @@ public void TestVerificationCheckRequest()

ApiKey = apiKey,
Code = 655543,
UserId = "[email protected]"

UserId = "[email protected]",
VerifiedEntityId = "SOME_SESSION_ID",
VerifiedEvent = "$login"
};

verificationCheckRequest.ApiKey = apiKey;

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());
}

Expand All @@ -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"
}
};

Expand All @@ -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());
}

Expand All @@ -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());
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = "[email protected]",
root_content_id = "listing-123",
recipient_user_ids = new ObservableCollection<string>() { "fy9h989sjphh71" },
Expand Down Expand Up @@ -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\":\"[email protected]\",\"$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\":\"[email protected]\",\"$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());

Expand Down Expand Up @@ -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()
{
Expand All @@ -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\":\"[email protected]\",\"$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\":\"[email protected]\",\"$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());

Expand Down

0 comments on commit 9f77091

Please sign in to comment.