Skip to content

Commit 4e49723

Browse files
authored
Merge pull request #95 from Riskified/policy_protect
TIS-728 added policy protect response
2 parents 37b18bd + 49d05c4 commit 4e49723

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

Riskified.SDK.Sample/OrderTransmissionExample.cs

+27-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Riskified.SDK.Utils;
1212
using Riskified.SDK.Exceptions;
1313
using Riskified.SDK.Model.OrderCheckoutElements;
14+
using System.Text;
1415

1516
namespace Riskified.SDK.Sample
1617
{
@@ -141,7 +142,7 @@ public static void SendOrdersToRiskifiedExample()
141142
case "v":
142143
Console.WriteLine("Order Generated with merchant order number: " + orderNum);
143144
order.Id = orderNum.ToString();
144-
orderNum++;
145+
//orderNum++;
145146
// sending order for synchronous decision
146147
// it will generate a synchronous response with the decision regarding the order
147148
// (for sync flow only)
@@ -292,11 +293,31 @@ public static void SendOrdersToRiskifiedExample()
292293

293294
if (res != null)
294295
{
295-
Console.WriteLine("\n\nOrder sent successfully:" +
296-
"\nStatus at Riskified: " + res.Status +
297-
"\nOrder ID received:" + res.Id +
298-
"\nDescription: " + res.Description +
299-
"\nWarnings: " + (res.Warnings == null ? "---" : string.Join(" \n", res.Warnings)) + "\n\n");
296+
StringBuilder message = new StringBuilder();
297+
298+
// Basic order information
299+
message.AppendLine("\nOrder sent successfully:");
300+
message.AppendLine($"Status at Riskified: {res.Status}");
301+
message.AppendLine($"Order ID received: {res.Id}");
302+
message.AppendLine($"Description: {res.Description}");
303+
// Conditional policy response
304+
if (res.PolicyProtect != null && res.PolicyProtect.Policies.Any())
305+
{
306+
//the example only retrieve the first item, in prod env, merchant should implement policy response it in for loop format.
307+
message.AppendLine($"Policy Response: {res.PolicyProtect.Policies.First().PolicyType}");
308+
}
309+
310+
// Warnings or a placeholder if there are no warnings
311+
if (res.Warnings != null && res.Warnings.Any())
312+
{
313+
message.AppendLine("Warnings: " + string.Join("\n ", res.Warnings));
314+
}
315+
else
316+
{
317+
message.AppendLine("Warnings: ---");
318+
}
319+
Console.WriteLine(message.ToString());
320+
300321
}
301322
if (accRes != null)
302323
{

Riskified.SDK/Model/Internal/Notification.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Newtonsoft.Json;
22
using Riskified.SDK.Model.OrderElements;
3+
using Riskified.SDK.Model.PolicyElements;
34

45
//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.
56
//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.
@@ -40,5 +41,9 @@ internal class Notification
4041
[JsonProperty(PropertyName = "authentication_type", Required = Required.Default)]
4142
public AuthenticationType AuthenticationType { get; set; }
4243

44+
[JsonProperty(PropertyName = "policy_protect", Required = Required.Default)]
45+
public PolicyProtect PolicyProtect { get; set; }
46+
47+
4348
}
4449
}

Riskified.SDK/Model/OrderNotification.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Riskified.SDK.Model.Internal;
22
using Riskified.SDK.Model.OrderElements;
3+
using Riskified.SDK.Model.PolicyElements;
34

45
namespace Riskified.SDK.Model
56
{
@@ -15,6 +16,8 @@ internal OrderNotification(OrderWrapper<Notification> notificationInfo)
1516
Category = notificationInfo.Order.Category;
1617
DecisionCode = notificationInfo.Order.DecisionCode;
1718
Warnings = notificationInfo.Warnings;
19+
PolicyProtect = notificationInfo.Order.PolicyProtect;
20+
1821

1922
}
2023

@@ -30,6 +33,9 @@ internal OrderNotification(OrderCheckoutWrapper<Notification> notificationInfo)
3033
Score = notificationInfo.Order.Score;
3134
Action = notificationInfo.Order.Action;
3235
AuthenticationType = notificationInfo.Order.AuthenticationType;
36+
PolicyProtect = notificationInfo.Order.PolicyProtect;
37+
38+
//PolicyProtect = notificationInfo.Order.polc
3339
}
3440

3541
public string Id { get; private set; }
@@ -43,5 +49,6 @@ internal OrderNotification(OrderCheckoutWrapper<Notification> notificationInfo)
4349
public string[] Warnings { get; private set; }
4450
public int Score { get; set; }
4551
public AuthenticationType AuthenticationType { get; private set; }
52+
public PolicyProtect PolicyProtect { get; private set; }
4653
}
4754
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Riskified.SDK.Utils;
5+
6+
namespace Riskified.SDK.Model.PolicyElements
7+
{
8+
public class PolicyProtect
9+
{
10+
[JsonProperty(PropertyName = "use_cases")]
11+
public List<UseCase> Policies { get; set; }
12+
}
13+
14+
public class UseCase
15+
{
16+
[JsonProperty(PropertyName = "use_case")]
17+
public string PolicyType { get; set; }
18+
19+
[JsonProperty(PropertyName = "decision")]
20+
public string Decision { get; set; }
21+
}
22+
}
23+
24+

Riskified.SDK/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
3434

35-
[assembly: AssemblyVersion("3.4.4")]
36-
[assembly: AssemblyFileVersion("3.4.4")]
35+
[assembly: AssemblyVersion("3.5.0")]
36+
[assembly: AssemblyFileVersion("3.5.0")]
3737

Riskified.SDK/Riskified.SDK.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,14 @@
141141
<Compile Include="Model\OrderCheckoutElements\AuthenticationType.cs" />
142142
<Compile Include="Model\OrderCheckoutElements\AuthenticationResult.cs" />
143143
<Compile Include="Model\OrderElements\Policy.cs" />
144+
<Compile Include="Model\PolicyElements\PolicyProtect.cs" />
144145
</ItemGroup>
145146
<ItemGroup>
146147
<None Include="packages.config" />
147148
</ItemGroup>
148149
<ItemGroup>
149150
<Folder Include="Model\AccountActionElements\" />
151+
<Folder Include="Model\PolicyElements\" />
150152
</ItemGroup>
151153
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
152154
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 commit comments

Comments
 (0)