Here is a simple sample plugin which will add a field to the json for webhooks sent out for debtors created or updated.
The entire plugin code is shown below. The plugin needs to have a Plugin Reference to the REST API plugin, which the attached does.
- Code: Select all
using System;
using System.Diagnostics;
using ServiceStack;
using ServiceStack.Model;
using ServiceStack.Web;
public class CustomiseWebhook : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaRESTAPIPlugin
{
public void Configure(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin, ServiceStack.ServiceStackHost AppHost, Funq.Container Container, JiwaFinancials.Jiwa.JiwaApplication.Manager JiwaApplicationManager)
{
AppHost.RegisterTypedRequestFilter<JiwaFinancials.Jiwa.JiwaServiceModel.WebhooksEventsPOSTRequest>((req, res, dto) => { WebhooksEventsPOSTRequestFilter(req, res, dto); });
}
public void WebhooksEventsPOSTRequestFilter(IRequest req, IResponse res, JiwaFinancials.Jiwa.JiwaServiceModel.WebhooksEventsPOSTRequest dto)
{
if (dto.EventName == "debtor.created" || dto.EventName == "debtor.updated")
{
// dto.Body is the JSON for the debtor. We can modify that, and that is what is used for the webhook.
// We're going to modify it by deserialising it into our own object which inherits from the debtor DTO object, and
// then set our custom field, and then serialise that back to a string.
ExtendedDebtor customDebtorDTO = dto.Body.FromJson<ExtendedDebtor>();
customDebtorDTO.MyCustomField = "This is a Test";
dto.Body = customDebtorDTO.ToJson<ExtendedDebtor>();
}
}
}
public class ExtendedDebtor : JiwaFinancials.Jiwa.JiwaServiceModel.Debtors.Debtor
{
virtual public string MyCustomField { get; set; }
}