Skip to content

Commit

Permalink
Merge pull request #5 from Riskified/decision_endpoint
Browse files Browse the repository at this point in the history
Decision endpoint
  • Loading branch information
itaywaxman committed Mar 4, 2015
2 parents 92fd8ba + 9df0fc5 commit 6af5141
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Riskified.SDK.Sample/OrderTransmissionExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void SendOrdersToRiskifiedExample()
"'d' for cancel\n" +
"'r' for partial refund\n" +
"'f' for fulfill\n" +
"'x' for decision\n" +
"'h' for historical sending\n" +
"'q' to quit";
Console.WriteLine(menu);
Expand Down Expand Up @@ -143,6 +144,13 @@ public static void SendOrdersToRiskifiedExample()
OrderFulfillment orderFulfillment = GenerateFulfillment(int.Parse(fulfillOrderId));
res = gateway.Fulfill(orderFulfillment);

break;
case "x":
Console.Write("Decision order id: ");
string decisionOrderId = Console.ReadLine();
OrderDecision orderDecision = GenerateDecision(int.Parse(decisionOrderId));
res = gateway.Decision(orderDecision);

break;
case "h":
int startOrderNum = orderNum;
Expand Down Expand Up @@ -201,6 +209,12 @@ public static void SendOrdersToRiskifiedExample()

}

private static OrderDecision GenerateDecision(int p)
{
OrderDecision orderDecision = new OrderDecision(p, new DecisionDetails(ExternalStatusType.ChargedbackFraud, DateTime.Now, "used proxy and stolen credit card."));
return orderDecision;
}


private static OrderCheckout GenerateOrderCheckout(int orderNum)
{
Expand Down
5 changes: 5 additions & 0 deletions Riskified.SDK/Model/OrderCheckout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public override void Validate(Validations validationType = Validations.Weak)
InputValidators.ValidateDateNotDefault(ClosedAt.Value, "Closed At");
}

if (Decision != null)
{
Decision.Validate(validationType);
}

}

}
Expand Down
38 changes: 38 additions & 0 deletions Riskified.SDK/Model/OrderDecision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Newtonsoft.Json;
using Riskified.SDK.Model.OrderElements;
using Riskified.SDK.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Riskified.SDK.Model
{
public class OrderDecision : AbstractOrder
{
public OrderDecision(int merchantOrderId, DecisionDetails decision)
: base(merchantOrderId)
{
this.Decision = decision;
}

/// <summary>
/// Validates the objects fields content
/// </summary>
/// <param name="isWeak">Should use weak validations or strong</param>
/// <exception cref="OrderFieldBadFormatException">throws an exception if one of the parameters doesn't match the expected format</exception>
public override void Validate(Validations validationType = Validations.Weak)
{
base.Validate(validationType);
InputValidators.ValidateObjectNotNull(this.Decision, "Decision");
this.Decision.Validate(validationType);
}

/// <summary>
/// An object containing information about the decision the merchant made on the order.
/// </summary>
[JsonProperty(PropertyName = "decision")]
public DecisionDetails Decision { get; set; }
}
}
79 changes: 79 additions & 0 deletions Riskified.SDK/Model/OrderElements/DecisionDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Riskified.SDK.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Riskified.SDK.Model.OrderElements
{

public class DecisionDetails : IJsonSerializable
{

public DecisionDetails(ExternalStatusType externalStatus, DateTime? decidedAt, string reason = null, float? amount = null, string currency = null, string notes = null)
{
this.ExternalStatus = externalStatus;
this.DecidedAt = decidedAt;

// Optional fields
this.Reason = reason;
this.Amount = amount;
this.Currency = currency;
this.Notes = Notes;
}

public void Validate(Utils.Validations validationType = Validations.Weak)
{
InputValidators.ValidateObjectNotNull(this.ExternalStatus, "External Status");
if(this.DecidedAt != null)
{
InputValidators.ValidateDateNotDefault(DecidedAt.Value, "Decided At");
}

if(Currency != null)
{
InputValidators.ValidateCurrency(this.Currency);
}
}

/// <summary>
/// The external status, meaning the merchant decision on the order
/// </summary>
[JsonProperty(PropertyName = "external_status")]
[JsonConverter(typeof(StringEnumConverter))]
public ExternalStatusType ExternalStatus { get; set; }

/// <summary>
/// The date when the order was decided.
/// </summary>
[JsonProperty(PropertyName = "decided_at")]
public DateTime? DecidedAt { get; set; }

/// <summary>
/// A reason for the decision.
/// </summary>
[JsonProperty(PropertyName = "reason")]
public string Reason { get; set; }

/// <summary>
/// The amount the decision is relevant on.
/// </summary>
[JsonProperty(PropertyName = "amount")]
public float? Amount { get; set; }

/// <summary>
/// The three letter code (ISO 4217) for the currency used for the payment.
/// </summary>
[JsonProperty(PropertyName = "currency")]
public string Currency { get; set; }

/// <summary>
/// Free text for describing the decision.
/// </summary>
[JsonProperty(PropertyName = "notes")]
public string Notes { get; set; }
}
}
27 changes: 27 additions & 0 deletions Riskified.SDK/Model/OrderElements/ExternalStatusType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Riskified.SDK.Model
{
public enum ExternalStatusType
{
[EnumMember(Value = "approved")]
Approved,
[EnumMember(Value = "checkout")]
Checkout,
[EnumMember(Value = "cancelled")]
Cancelled,
[EnumMember(Value = "declined")]
Declined,
[EnumMember(Value = "declined_fraud")]
DeclinedFraud,
[EnumMember(Value = "chargedback_fraud")]
ChargedbackFraud,
[EnumMember(Value = "chargedback_not_fraud")]
ChargedbackNotFraud
}
}
7 changes: 7 additions & 0 deletions Riskified.SDK/Model/OrderElements/LineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public void Validate(Validations validationType = Validations.Weak)
[JsonProperty(PropertyName = "event_sub_category_name")]
public string EventSubCategoryName { get; set; }


/// <summary>
/// The event category name.
/// </summary>
[JsonProperty(PropertyName = "event_category_name")]
public string EventCategoryName { get; set; }

/// <summary>
/// The event name.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Riskified.SDK/Orders/OrdersGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ public OrderNotification Fulfill(OrderFulfillment orderFulfillment)
return SendOrder(orderFulfillment, HttpUtils.BuildUrl(_riskifiedBaseWebhookUrl, "/api/fulfill"));
}

/// <summary>
/// Validates the decision data
/// Sends a decision message for a specific order (id should already exist) to Riskified server.
/// Update existing order external status. Lets Riskified know what was your decision on your order.
/// </summary>
/// <param name="OrderDecision">The decision details</param>
/// <returns>The order notification result containing status,description and sent order id in case of successful transfer</returns>
/// <exception cref="OrderFieldBadFormatException">On bad format of the order (missing fields data or invalid data)</exception>
/// <exception cref="RiskifiedTransactionException">On errors with the transaction itself (network errors, bad response data)</exception>
public OrderNotification Decision(OrderDecision orderDecision)
{
return SendOrder(orderDecision, HttpUtils.BuildUrl(_riskifiedBaseWebhookUrl, "/api/decision"));
}

/// <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
4 changes: 2 additions & 2 deletions Riskified.SDK/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.3.3")]
[assembly: AssemblyFileVersion("2.0.3.3")]
[assembly: AssemblyVersion("2.0.3.4")]
[assembly: AssemblyFileVersion("2.0.3.4")]
3 changes: 3 additions & 0 deletions Riskified.SDK/Riskified.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\OrderElements\ExternalStatusType.cs" />
<Compile Include="Model\IJsonSerializable.cs" />
<Compile Include="Model\Internal\OrderCheckoutWrapper.cs" />
<Compile Include="Model\Internal\OrdersWrapper.cs" />
Expand All @@ -57,6 +58,8 @@
<Compile Include="Model\OrderCheckoutDenied.cs" />
<Compile Include="Model\OrderCheckoutElements\AuthorizationError.cs" />
<Compile Include="Model\OrderCheckoutElements\AuthorizationErrorCode.cs" />
<Compile Include="Model\OrderDecision.cs" />
<Compile Include="Model\OrderElements\DecisionDetails.cs" />
<Compile Include="Model\OrderElements\FulfillmentDetails.cs" />
<Compile Include="Model\OrderElements\IPaymentDetails.cs" />
<Compile Include="Model\OrderElements\NoChargeDetails.cs" />
Expand Down

0 comments on commit 6af5141

Please sign in to comment.