Skip to content

Commit

Permalink
Merge pull request #102 from Riskified/Otp
Browse files Browse the repository at this point in the history
TIS-775 Otp
  • Loading branch information
mooseriskified committed Aug 14, 2024
2 parents a74b9be + 2c5044d commit dcb0580
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Riskified.SDK/Model/Internal/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ internal class Notification
[JsonProperty(PropertyName = "policy_protect", Required = Required.Default)]
public PolicyProtect PolicyProtect { get; set; }

[JsonProperty(PropertyName = "recovery_eligibility", Required = Required.Default)]
public RecoveryEligibility RecoveryEligibility { get; set; }


}
}
19 changes: 19 additions & 0 deletions Riskified.SDK/Model/OrderElements/ChannelMethod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace Riskified.SDK.Model.OrderElements
{
public class ChannelMethod
{
public ChannelMethod(ChannelType channelType, string senderName)
{
ChannelType = channelType;
SenderName = senderName;
}

[JsonProperty(PropertyName = "channel_type")]
public ChannelType ChannelType { get; set; }

[JsonProperty(PropertyName = "sender_name")]
public string SenderName { get; set; }
}
}
10 changes: 10 additions & 0 deletions Riskified.SDK/Model/OrderElements/ChannelType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.Serialization;

namespace Riskified.SDK.Model.OrderElements
{
public enum ChannelType
{
[EnumMember(Value = "Sms")]
sms
}
}
38 changes: 38 additions & 0 deletions Riskified.SDK/Model/OrderElements/OtpInitiate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Newtonsoft.Json;
using Riskified.SDK.Utils;

namespace Riskified.SDK.Model.OrderElements
{
public class OtpInitiate : IJsonSerializable
{
public OtpInitiate(string id, string challengeAccessToken, string localizationLanguage, string contactDetails, ChannelMethod channelMethod)
{
Id = id;
ChallengeAccesstoken = challengeAccessToken;
LocalizationLanguage = localizationLanguage;
ContactDetails = contactDetails;
ChannelMethod = channelMethod;
}

[JsonProperty(PropertyName = "id")]
public string Id { get; set; }

[JsonProperty(PropertyName = "challenge_access_token")]
public string ChallengeAccesstoken { get; set; }

[JsonProperty(PropertyName = "localization_language")]
public string LocalizationLanguage { get; set; }

[JsonProperty(PropertyName = "contact_details")]
public string ContactDetails { get; set; }

[JsonProperty(PropertyName = "channel_method")]
public ChannelMethod ChannelMethod { get; set; }

public void Validate(Validations validationType = Validations.Weak)
{
InputValidators.ValidateValuedString(Id, "Merchant Order ID");
}
}
}
35 changes: 35 additions & 0 deletions Riskified.SDK/Model/OrderElements/RecoveryEligibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Newtonsoft.Json;
using Riskified.SDK.Utils;

namespace Riskified.SDK.Model.OrderElements
{
public class RecoveryEligibility : IJsonSerializable
{
public RecoveryEligibility(string id, string status, string verifiedAt, string challengeType)
{
Id = id;
Status = status;
VerifiedAt = verifiedAt;
ChallengeType = challengeType;

}

public void Validate(Validations validationType = Validations.Weak)
{
throw new NotImplementedException();
}

[JsonProperty(PropertyName = "id")]
public string Id { get; set; }

[JsonProperty(PropertyName = "status")]
public string Status { get; set; }

[JsonProperty(PropertyName = "verified_at")]
public string VerifiedAt { get; set; }

[JsonProperty(PropertyName = "challenge_type")]
public string ChallengeType { get; set; }
}
}
3 changes: 3 additions & 0 deletions Riskified.SDK/Model/OrderNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal OrderNotification(OrderWrapper<Notification> notificationInfo)
DecisionCode = notificationInfo.Order.DecisionCode;
Warnings = notificationInfo.Warnings;
PolicyProtect = notificationInfo.Order.PolicyProtect;
RecoveryEligibility = notificationInfo.Order.RecoveryEligibility;


}
Expand All @@ -36,6 +37,7 @@ internal OrderNotification(OrderCheckoutWrapper<Notification> notificationInfo)
Action = notificationInfo.Order.Action;
AuthenticationType = notificationInfo.Order.AuthenticationType;
PolicyProtect = notificationInfo.Order.PolicyProtect;
RecoveryEligibility = notificationInfo.Order.RecoveryEligibility;

//PolicyProtect = notificationInfo.Order.polc
}
Expand All @@ -53,5 +55,6 @@ internal OrderNotification(OrderCheckoutWrapper<Notification> notificationInfo)
public AuthenticationType AuthenticationType { get; private set; }
public Advice Advice { get; private set; }
public PolicyProtect PolicyProtect { get; private set; }
public RecoveryEligibility RecoveryEligibility { get; private set; }
}
}
14 changes: 14 additions & 0 deletions Riskified.SDK/Orders/OrdersGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Riskified.SDK.Model.AccountActionElements;
using System.Collections.Generic;
using Riskified.SDK.Model.Internal;
using Riskified.SDK.Model.OrderElements;
using Riskified.SDK.Model.OtpElements;

namespace Riskified.SDK.Orders
{
Expand Down Expand Up @@ -264,6 +266,12 @@ public OrderNotification Chargeback(OrderChargeback orderChargeback)
return SendOrder(orderChargeback, HttpUtils.BuildUrl(_env, "/api/chargeback"));
}

public OtpWidgetNotification InitiateOtp(OtpInitiate otpInitiate)
{
return SendInitiateOtp(otpInitiate, HttpUtils.BuildUrl(_env, "/recover/v1/otp/initiate", FlowStrategy.Otp));

}

/// <summary>
/// Validates the list of historical orders and sends them in batches to Riskified Servers.
/// The FinancialStatus field of each order should contain the latest order status as described at "http://apiref.riskified.com/net/#actions-historical"
Expand Down Expand Up @@ -360,6 +368,12 @@ private AccountActionNotification SendAccountAction(AbstractAccountAction accoun
return transactionResult;
}

private OtpWidgetNotification SendInitiateOtp(OtpInitiate otpInitiate, Uri riskifiedEndpointUrl)
{
var transactionResult = HttpUtils.JsonPostAndParseResponseToObject<OtpWidgetNotification, OtpInitiate>(riskifiedEndpointUrl, otpInitiate, _authToken, _shopDomain);
return transactionResult;
}

/// <summary>
/// Validates the Order object fields
/// Sends the order to riskified server endpoint as configured in the ctor
Expand Down
4 changes: 2 additions & 2 deletions Riskified.SDK/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// [assembly: AssemblyVersion("1.0.*")]


[assembly: AssemblyVersion("3.8.0")]
[assembly: AssemblyFileVersion("3.8.0")]
[assembly: AssemblyVersion("3.9.0")]
[assembly: AssemblyFileVersion("3.9.0")]


13 changes: 12 additions & 1 deletion Riskified.SDK/Utils/HttpUtils.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Riskified.SDK.Exceptions;
using Riskified.SDK.Logging;

Expand Down Expand Up @@ -85,7 +87,15 @@ private static HttpWebResponse PostObject<TReqObj>(Uri riskifiedWebhookUrl, TReq
string jsonStr;
try
{
jsonStr = JsonConvert.SerializeObject(jsonObj,new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore});
//jsonStr = JsonConvert.SerializeObject(jsonObj,new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore});
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter> { new StringEnumConverter() } // Adding the StringEnumConverter
};

jsonStr = JsonConvert.SerializeObject(jsonObj, settings);
Console.WriteLine(jsonStr);
}
catch (Exception e)
{
Expand Down Expand Up @@ -158,6 +168,7 @@ private static WebRequest GeneratePostRequest(Uri url, string body, string authT
request.ContentType = "application/"+ Enum.GetName(typeof(HttpBodyType),bodyType).ToLower();
request.UserAgent = "Riskified.SDK_NET/" + AssemblyVersion;
request.Accept = string.Format("application/vnd.riskified.com; version={0}", ServerApiVersion);
request.Accept = string.Format("application/json");
request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
byte[] bodyBytes = Encoding.UTF8.GetBytes(body);
request.ContentLength = bodyBytes.Length;
Expand Down
3 changes: 3 additions & 0 deletions Riskified.SDK/Utils/RiskifiedEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum FlowStrategy
Default,
Sync,
Account,
Otp,
Deco
}

Expand All @@ -42,12 +43,14 @@ static EnvironmentsUrls()
SandboxUrl.Add(FlowStrategy.Default, "https://sandbox.riskified.com");
SandboxUrl.Add(FlowStrategy.Account, "https://api-sandbox.riskified.com");
SandboxUrl.Add(FlowStrategy.Deco, "https://sandboxw.decopayments.com");
SandboxUrl.Add(FlowStrategy.Otp, "https://otp-sandbox.self-veri.com");
EnvToUrl.Add(RiskifiedEnvironment.Sandbox, SandboxUrl);

ProductionUrl.Add(FlowStrategy.Default, "https://wh.riskified.com");
ProductionUrl.Add(FlowStrategy.Sync, "https://wh-sync.riskified.com");
ProductionUrl.Add(FlowStrategy.Account, "https://api.riskified.com");
ProductionUrl.Add(FlowStrategy.Deco, "https://w.decopayments.com");
ProductionUrl.Add(FlowStrategy.Otp, "https://otp.self-veri.com");
EnvToUrl.Add(RiskifiedEnvironment.Production, ProductionUrl);
}

Expand Down

0 comments on commit dcb0580

Please sign in to comment.