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
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ private <T extends IData> String createSignature(String method, String uuid, T d
}

@Override
public <D extends IRequestParamsData, P extends IRequestParams<D>> void verify(IRequest<P> request) throws TrustlySignatureException {
public <D extends IRequestParamsData, P extends IRequestParams<D>> void verify(IRequest<P> request, JsonNode dataNode) throws TrustlySignatureException {

String uuid = (request.getParams() == null) ? null : request.getParams().getUuid();
String signature = (request.getParams() == null) ? null : request.getParams().getSignature();
D data = (request.getParams() == null) ? null : request.getParams().getData();

this.verify(request.getMethod(), uuid, signature, data, null);
this.verify(request.getMethod(), uuid, signature, data, dataNode);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/trustly/api/client/JsonRpcSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface JsonRpcSigner {

<T extends IResponseResultData> JsonRpcResponse<T> sign(JsonRpcResponse<T> response);

<D extends IRequestParamsData, P extends IRequestParams<D>> void verify(IRequest<P> request) throws TrustlySignatureException;
<D extends IRequestParamsData, P extends IRequestParams<D>> void verify(IRequest<P> request, JsonNode dataNode) throws TrustlySignatureException;

<T extends IResponseResultData> void verify(JsonRpcResponse<T> response, JsonNode nodeResponse) throws TrustlySignatureException;
}
3 changes: 3 additions & 0 deletions src/main/java/com/trustly/api/client/NotificationArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public interface NotificationFailHandler {
@Valid
private final D data;

@Getter
private final String method;

@Getter
private final String uuid;

private final NotificationOkHandler onOK;
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/trustly/api/client/TrustlyApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,19 @@ private <D extends IFromTrustlyRequestData> void handleNotification(
NotificationFailHandler onFailed
) throws IOException, TrustlyValidationException, TrustlySignatureException {

// Get the JsonNode for the data field for verifying later
JsonNode jsonToken = this.objectMapper.readTree(jsonString);
JsonNode dataToken = null;
if (jsonToken.at("/params/data") != null) {
dataToken = jsonToken.at("/params/data");
}

JavaType javaRequestType = this.objectMapper.getTypeFactory().constructParametricType(NotificationRequest.class, meta.getDataClass());
NotificationRequest<D> rpcRequest = this.objectMapper.readValue(jsonString, javaRequestType);

// Verify the notification (RpcRequest from Trustly) signature.
try {
this.signer.verify(rpcRequest);
this.signer.verify(rpcRequest, dataToken);
} catch (TrustlySignatureException ex) {
throw new TrustlySignatureException(
"Could not validate signature of notification from Trustly. Is the public key for Trustly the correct one, for test or production?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,21 @@ public class AbstractAccountDataAttributes extends AbstractRequestParamsDataAttr
String unchangeableNationalIdentificationNumber;

/**
* @deprecated (see ReturnToAppURL)
* If you are using Trustly from within your native iOS app, this attribute should be sent so that we can redirect the users back to your
* app in case an external app is used for authentication (for example Mobile Bank ID in Sweden).
*/
@Deprecated
@JsonProperty("URLScheme")
String urlScheme;

/**
* When rendering the Trustly Checkout in a native app you are required to pass your application’s url as an attribute to the order
* initiation request. By doing so, Trustly can redirect users back to your app after using external identification apps such as
* Mobile BankID: Please visit this link for more info. It must not be included for transactions that are not originating from an app.
* NOTE! This value is only used for redirecting users back to the native app within the flows.
* See also SuccessURL and FailURL descriptions.
*/
@JsonProperty("ReturnToAppURL")
String returnToAppURL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public class CancelNotificationData extends AbstractFromTrustlyRequestData<Empty

@JsonProperty("timestamp")
String timestamp;

@JsonProperty("lastorderstep")
String lastOrderStep;

@JsonProperty("orderstatuses")
String orderStatuses;
}
2 changes: 1 addition & 1 deletion src/test/java/com/trustly/api/NoOpJsonRpcSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public <T extends IResponseResultData> JsonRpcResponse<T> sign(JsonRpcResponse<T
}

@Override
public <D extends IRequestParamsData, P extends IRequestParams<D>> void verify(IRequest<P> request) {
public <D extends IRequestParamsData, P extends IRequestParams<D>> void verify(IRequest<P> request, JsonNode dataNode) {

}

Expand Down