Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/com/trustly/api/client/NotificationArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public class NotificationArgs<D extends IRequestParamsData> {
public interface NotificationOkHandler {

void handle(String method, String uuid) throws IOException, TrustlyValidationException;

}

@FunctionalInterface
public interface NotificationOkStatusHandler {

void handle(String method, String uuid, String status) throws IOException, TrustlyValidationException;
}

@FunctionalInterface
Expand All @@ -31,11 +38,16 @@ public interface NotificationFailHandler {

private final NotificationOkHandler onOK;
private final NotificationFailHandler onFailed;
private final NotificationOkStatusHandler onOKStatus;

public void respondWithOk() throws TrustlyValidationException, IOException {
this.onOK.handle(this.method, this.uuid);
}

public void respondWithOk(String status) throws TrustlyValidationException, IOException {
this.onOKStatus.handle(this.method, this.uuid, status);
}

public void respondWithFailed(String message) throws TrustlyValidationException, IOException {
this.onFailed.handle(this.method, this.uuid, message);
}
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/trustly/api/client/TrustlyApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.trustly.api.client.NotificationArgs.NotificationFailHandler;
import com.trustly.api.client.NotificationArgs.NotificationOkHandler;
import com.trustly.api.client.NotificationArgs.NotificationOkStatusHandler;
import com.trustly.api.domain.base.IFromTrustlyRequestData;
import com.trustly.api.domain.base.IRequestParamsData;
import com.trustly.api.domain.base.IResponseResultData;
Expand Down Expand Up @@ -694,6 +695,7 @@ private static <R extends IResponseResultData> void assertSuccessful(JsonRpcResp
public void handleNotification(
String jsonString,
NotificationOkHandler onOK,
NotificationOkStatusHandler onOkStatus,
NotificationFailHandler onFailed
) throws IOException, TrustlyNoNotificationListenerException, TrustlyValidationException, TrustlySignatureException {

Expand All @@ -710,13 +712,14 @@ public void handleNotification(
}
}

this.handleNotification(jsonString, mapper, onOK, onFailed);
this.handleNotification(jsonString, mapper, onOK, onOkStatus, onFailed);
}

private <D extends IFromTrustlyRequestData> void handleNotification(
String jsonString,
NotificationMeta<D> meta,
NotificationOkHandler onOK,
NotificationOkStatusHandler onOkStatus,
NotificationFailHandler onFailed
) throws IOException, TrustlyValidationException, TrustlySignatureException {

Expand All @@ -742,7 +745,7 @@ private <D extends IFromTrustlyRequestData> void handleNotification(
rpcRequest.getParams().getData(),
rpcRequest.getMethod(),
rpcRequest.getParams().getUuid(),
onOK, onFailed
onOK, onFailed, onOkStatus
);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public static void handleNotificationRequest(InputStream incoming, NotificationR
responseCount.incrementAndGet();
TrustlyApiClientExtensions.respond(client, responder, method, uuid, "OK", null, 200);
},
(method, uuid, status) -> {
responseCount.incrementAndGet();
TrustlyApiClientExtensions.respond(client, responder, method, uuid, status, null, 200);
},
(method, uuid, message) -> {
responseCount.incrementAndGet();
TrustlyApiClientExtensions.respond(client, responder, method, uuid, "FAILED", message, 500);
Expand Down