Used to send notifications to external systems when actions are perfomed on calculations stored in Capitex Företagslån.

Configuration

Capitex configuration xml:

Parameter

Type

Description

capitex_companycalc_webhook_call_script

String CDATA

Script return value must start with either OK och NOK.

Available query parameters are:

  • URL for call

    • Script: params.getParameter("callEndpoint")

    • Shorthand: =[callEndpoint]

  • capitex.companycalc.dto.Status

    • Script: params.getParameter("previousStatus")

    • Shorthand: =[previousStatus]

  • capitex.companycalc.dto.Status

    • Script: params.getParameter("currentStatus")

    • Shorthand: =[currentStatus]

  • Id if the calculation

    • Script: params.getParameter("calculationId")

    • Shorthand: =[calculationId]

  • ID of the user

    • Script: params.getParameter("userId")

    • Shorthand: =[userId]

  • Full name of the user

    • Script: params.getParameter("userName")

    • Shorthand: =[userName]

  • Email of the user

    • Script: params.getParameter("userEmail")

    • Shorthand: =[userEmail]

  • C (Create, new), U (Update, save), D (Delete)

    • Script: params.getParameter("reason")

    • Shorthand: =[reason]

  • Any value

    • Script: params.getParameter("any_value_in_capitex_config_xml_file")

    • Shorthand: =[any_value_in_capitex_config_xml_file]

Default script:

<![CDATA[
var endpoint = params.getParameter("callEndpoint");
endpoint = endpoint + "?" + "previousStatus=" + params.getParameter("previousStatus");
endpoint = endpoint + "&" + "currentStatus=" + params.getParameter("currentStatus");
endpoint = endpoint + "&" + "calculationId=" + params.getParameter("calculationId");
endpoint = endpoint + "&" + "reason=" + params.getParameter("reason");
httpclient.setEndpoint(endpoint);
httpclient.method = "GET";
httpclient.call();
if (httpclient.getResponseStatusCode() == 200) {
return "OK " + endpoint;
} else {
return "NOK " + endpoint + " " + httpclient.getResponseStatusCode();
}
]]>

capitex_companycalc_webhook_call_url

String

URL to send webhook call to. If empty call will be turned off If available a GET call will be made to the URL with the appropriate values attached as query parameters.

Call will be made with script assigned in <capitex_companycalc_webhook_call_script> unless shorthand parameter assignment is done in the URL. If shorthand assignment of parameter is available in the URL the content in <capitex_companycalc_webhook_call_script> will be ignored.

Shorthand assigment of parameters in URL is done by adding query parameters being assigned with =[].

https://url.se?id=[calculationId]

Will generate a script:

var endpoint = "https://url.se?id=" + params.getParameter("calculationId") + "";
httpclient.setEndpoint(endpoint);
httpclient.method = "GET";
httpclient.call();
if (httpclient.getResponseStatusCode() == 200) {
    return "OK " + endpoint;
} else {
    return "NOK " + endpoint + " " + httpclient.getResponseStatusCode();
}

capitex_companycalc_webhook_send_on_action

String

Any combination of letters CUD

  • C - Create (Save new)

  • U - Update (Save)

  • D - Delete

Decides what action should trigger a webhook call.

UD will send webhook call on Save and Delete, but not when a calulation is created (first save)

Logging

Response

Each call to external system will be logged. The message returned from the script will be added to the log. If return message starts with OK it will be logged as INFO otherwise as a WARNING.

May 11, 2023 10:49:13 AM capitex.companycalc.services.webhook.Webhook writeLog
INFO: doCall : OK https://iam.capitex.vitec.se/index.html?previousStatus=InProgress&currentStatus=InProgress&calculationId=54af30dd:18809ffdcc2:-8000&reason=U

Information will be added to the response from the service if webhook fails. Information will be added using InfoResponseWithExtraData class in the ExtraData field. Field is a String field which will store a JSON Object and information will be added under the key "webhook".

Service respons on create new calculation (SaveCalculation service).

  • Webhook OK

{
"datatype": "capitex.companycalc.services.dto.InfoResponseWithExtraData",
"information": "-42606744:18b136048e7:-8000",
"ExtraData": null,
"ok": true
}
  • Webhook NOK

{
"datatype": "capitex.companycalc.services.dto.InfoResponseWithExtraData",
"information": "4adf451b:18b1362545c:-8000",
"ExtraData": "{\"webhook\":\"Anrop lyckades, men system för statusuppdatering är ej tillgängligt. Statusuppdatering ej utförd. Kontakta er IT-avdelning för hjälp.\"}",
"ok": true
}

Examples

SOAP XML

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:urn="urn:types.ApplicationserviceImpl.services.companycalc.capitex" xmlns:sc0="urn:types.ApplicationserviceImpl.services.companycalc.capitex">
<soapenv:Header/>
<soapenv:Body>
<urn:DeleteCalculation>
<Id_1>
<ID>
76249abe:18809c8af6d:-8000
</ID>
</Id_1>
</urn:DeleteCalculation>
</soapenv:Body>
</soapenv:Envelope>
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<env:Envelope xmlns:ns0="urn:types.ApplicationserviceImpl.services.companycalc.capitex" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sc0="urn:dto.services.companycalc.capitex" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" >
<env:Body >
<ns0:DeleteCalculationResponse >
<result xsi:type="sc0:InfoResponseWithExtraData" >
<information >76249abe:18809c8af6d:-8000</information>
<ok >true</ok>
<ExtraData >{"webhook":"Anrop lyckades, men system för statusuppdatering är ej tillgängligt. Statusuppdatering ej utförd. Kontakta er IT-avdelning för hjälp."}</ExtraData>
</result>
</ns0:DeleteCalculationResponse>
</env:Body>
</env:Envelope>

Java

private static final String WEBHOOK_MESSAGE_ACTION_OK_STATUS_NOK = "Anrop lyckades, men system för statusuppdatering är ej tillgängligt. Statusuppdatering ej utförd. Kontakta er IT-avdelning för hjälp.";
 
public static String fetchExtraData(InfoResponseWithExtraData ifr, String key) throws org.json.simple.parser.ParseException {
String ret = "";
if (ifr != null && ifr.getExtraData() != null && !ifr.getExtraData().isEmpty()) {
JSONObject extradata = (JSONObject)(new JSONParser()).parse(ifr.getExtraData());
if (extradata != null && !extradata.isEmpty() && extradata.get(key) != null) {
ret = extradata.get(key).toString();
}
}
return ret;
}
 
private static String getWebhookExtraData(InfoResponse infoResponse) throws ParseException {
String ret = null;
if (infoResponse instanceof InfoResponseWithExtraData) {
ret = fetchExtraData((InfoResponseWithExtraData)infoResponse, "webhook");
}
return ret;
}
public static ApplicationserviceImplSEI initService() {
/* Creates an instance of the webservice client */
ApplicationserviceImpl appImp = new ApplicationserviceImpl();
ApplicationserviceImplSEI app = appImp.getApplicationserviceImplSEIPort();
 
/* Set endpoint url, username and password (http basic auth) */
Map<String, Object> reqContext = ((BindingProvider) app).getRequestContext();
reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WebServiceTests.ENDPOINT);
reqContext.put(BindingProvider.USERNAME_PROPERTY, WebServiceTests.USERNAME);
reqContext.put(BindingProvider.PASSWORD_PROPERTY, WebServiceTests.PASSWORD);
 
return app;
}
 
public static CompanyCalcInput initInput(ApplicationserviceImplSEI service, String calcName) {
//Create the credit case input
CompanyCalcInput input = new CompanyCalcInput();
input.setCalculationYear(2022);
input.setCalculationMonth(5);
input.setMainCurrency(Currency.SEK);
 
//Settings
input.setCalcSettings(service.getSettings());
 
//Calculation information
CalcInformation calcInformation = new CalcInformation();
input.setCalcInformation(calcInformation);
 
calcInformation.setCalcName(calcName);
 
return input;
}
 
public static Company initCompany(CompanyCalcInput input, String orgnr) {
//Basic company information
Company company = new Company();
input.getCompanies().add(company);
 
company.setID("ID-COMPANY");
CompanyInformation companyInformation = new CompanyInformation();
company.setCompanyInformation(companyInformation);
companyInformation.setOrgNo(orgnr);
 
return company;
}

@Test
public void webhookCUD() throws ParseException {
ApplicationserviceImplSEI service = initService();
CompanyCalcInput input = initInput(service, "webhookCUD");
initCompany(input, "1234567890");
 
InfoResponse infoResponse = service.saveCalculation(input);
assertTrue(infoResponse instanceof InfoResponseWithExtraData);
assertEquals("", getWebhookExtraData(infoResponse));
 
String calculationId = infoResponse.getInformation();
input.getCalcInformation().setCalcID(calculationId);
 
infoResponse = service.saveCalculation(input);
assertTrue(infoResponse instanceof InfoResponseWithExtraData);
assertEquals(WEBHOOK_MESSAGE_ACTION_OK_STATUS_NOK, getWebhookExtraData(infoResponse));
 
Id id = new Id();
id.setID(input.getCalcInformation().getCalcID());
infoResponse = service.deleteCalculation(id);
assertTrue(infoResponse instanceof InfoResponseWithExtraData);
assertEquals(WEBHOOK_MESSAGE_ACTION_OK_STATUS_NOK, getWebhookExtraData(infoResponse));
}