Skip to content

Commit

Permalink
Merge pull request #95 from Riskified/policy_protect
Browse files Browse the repository at this point in the history
TIS-728 added policy protect response
  • Loading branch information
beksina authored Apr 18, 2024
2 parents 37b18bd + 49d05c4 commit 4e49723
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
33 changes: 27 additions & 6 deletions Riskified.SDK.Sample/OrderTransmissionExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Riskified.SDK.Utils;
using Riskified.SDK.Exceptions;
using Riskified.SDK.Model.OrderCheckoutElements;
using System.Text;

namespace Riskified.SDK.Sample
{
Expand Down Expand Up @@ -141,7 +142,7 @@ public static void SendOrdersToRiskifiedExample()
case "v":
Console.WriteLine("Order Generated with merchant order number: " + orderNum);
order.Id = orderNum.ToString();
orderNum++;
//orderNum++;
// sending order for synchronous decision
// it will generate a synchronous response with the decision regarding the order
// (for sync flow only)
Expand Down Expand Up @@ -292,11 +293,31 @@ public static void SendOrdersToRiskifiedExample()

if (res != null)
{
Console.WriteLine("\n\nOrder sent successfully:" +
"\nStatus at Riskified: " + res.Status +
"\nOrder ID received:" + res.Id +
"\nDescription: " + res.Description +
"\nWarnings: " + (res.Warnings == null ? "---" : string.Join(" \n", res.Warnings)) + "\n\n");
StringBuilder message = new StringBuilder();

// Basic order information
message.AppendLine("\nOrder sent successfully:");
message.AppendLine($"Status at Riskified: {res.Status}");
message.AppendLine($"Order ID received: {res.Id}");
message.AppendLine($"Description: {res.Description}");
// Conditional policy response
if (res.PolicyProtect != null && res.PolicyProtect.Policies.Any())
{
//the example only retrieve the first item, in prod env, merchant should implement policy response it in for loop format.
message.AppendLine($"Policy Response: {res.PolicyProtect.Policies.First().PolicyType}");
}

// Warnings or a placeholder if there are no warnings
if (res.Warnings != null && res.Warnings.Any())
{
message.AppendLine("Warnings: " + string.Join("\n ", res.Warnings));
}
else
{
message.AppendLine("Warnings: ---");
}
Console.WriteLine(message.ToString());

}
if (accRes != null)
{
Expand Down
5 changes: 5 additions & 0 deletions Riskified.SDK/Model/Internal/Notification.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Riskified.SDK.Model.OrderElements;
using Riskified.SDK.Model.PolicyElements;

//Shop URL is available as a notification parameter depending on your account's setup; please contact your Integration Engineer or Account Manager if you have questions on this.
//It is a NON-best-practice to use shop URL in the notifications programmatically as this field will not be supported long term in API notifications.
Expand Down Expand Up @@ -40,5 +41,9 @@ internal class Notification
[JsonProperty(PropertyName = "authentication_type", Required = Required.Default)]
public AuthenticationType AuthenticationType { get; set; }

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


}
}
7 changes: 7 additions & 0 deletions Riskified.SDK/Model/OrderNotification.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Riskified.SDK.Model.Internal;
using Riskified.SDK.Model.OrderElements;
using Riskified.SDK.Model.PolicyElements;

namespace Riskified.SDK.Model
{
Expand All @@ -15,6 +16,8 @@ internal OrderNotification(OrderWrapper<Notification> notificationInfo)
Category = notificationInfo.Order.Category;
DecisionCode = notificationInfo.Order.DecisionCode;
Warnings = notificationInfo.Warnings;
PolicyProtect = notificationInfo.Order.PolicyProtect;


}

Expand All @@ -30,6 +33,9 @@ internal OrderNotification(OrderCheckoutWrapper<Notification> notificationInfo)
Score = notificationInfo.Order.Score;
Action = notificationInfo.Order.Action;
AuthenticationType = notificationInfo.Order.AuthenticationType;
PolicyProtect = notificationInfo.Order.PolicyProtect;

//PolicyProtect = notificationInfo.Order.polc
}

public string Id { get; private set; }
Expand All @@ -43,5 +49,6 @@ internal OrderNotification(OrderCheckoutWrapper<Notification> notificationInfo)
public string[] Warnings { get; private set; }
public int Score { get; set; }
public AuthenticationType AuthenticationType { get; private set; }
public PolicyProtect PolicyProtect { get; private set; }
}
}
24 changes: 24 additions & 0 deletions Riskified.SDK/Model/PolicyElements/PolicyProtect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Riskified.SDK.Utils;

namespace Riskified.SDK.Model.PolicyElements
{
public class PolicyProtect
{
[JsonProperty(PropertyName = "use_cases")]
public List<UseCase> Policies { get; set; }
}

public class UseCase
{
[JsonProperty(PropertyName = "use_case")]
public string PolicyType { get; set; }

[JsonProperty(PropertyName = "decision")]
public string Decision { get; set; }
}
}


4 changes: 2 additions & 2 deletions Riskified.SDK/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("3.4.4")]
[assembly: AssemblyFileVersion("3.4.4")]
[assembly: AssemblyVersion("3.5.0")]
[assembly: AssemblyFileVersion("3.5.0")]

2 changes: 2 additions & 0 deletions Riskified.SDK/Riskified.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@
<Compile Include="Model\OrderCheckoutElements\AuthenticationType.cs" />
<Compile Include="Model\OrderCheckoutElements\AuthenticationResult.cs" />
<Compile Include="Model\OrderElements\Policy.cs" />
<Compile Include="Model\PolicyElements\PolicyProtect.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Model\AccountActionElements\" />
<Folder Include="Model\PolicyElements\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit 4e49723

Please sign in to comment.