Skip to content

Commit

Permalink
Add method to create SessionRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
gcatanese committed Oct 28, 2024
1 parent dded256 commit 458ec60
Showing 1 changed file with 60 additions and 11 deletions.
71 changes: 60 additions & 11 deletions src/main/java/com/adyen/controller/DashboardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,7 @@ ResponseEntity<SessionResponse> getTransactions() {
}

// Perform session call to obtain a valid Session token
SessionRequest sessionRequest = new SessionRequest()
.allowOrigin(getApplicationProperty().getComponentsAllowOrigin())
.product("platform")
.policy(new SessionRequestPolicy()
.resources(List.of(new PolicyResource()
.accountHolderId(getUserIdOnSession())
.type("accountHolder")))
.roles(List.of("Transactions Overview Component: View")));

SessionRequest sessionRequest = getSessionRequest("Transactions Overview Component: View");
SessionResponse response = restClient.call(getApplicationProperty().getSessionAuthenticationApiUrl(), sessionRequest);

return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
Expand All @@ -147,12 +139,69 @@ ResponseEntity<List<TransactionItem>> getTransactionsCustomView() {
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}



return new ResponseEntity<>(
getConfigurationAPIService().getTransactions(getUserIdOnSession()), HttpStatus.ACCEPTED);
}

/**
* Displays the Account Holder Payouts using the Adyen Payouts component
*
* This demonstrates how to integrate the Adyen web component that fetches and
* displays the payouts
*
* @return
*/
@PostMapping("/getPayouts")
ResponseEntity<SessionResponse> getPayouts() {

if (getUserIdOnSession() == null) {
log.warn("User is not logged in");
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}

// Perform session call to obtain a valid Session token
SessionRequest sessionRequest = getSessionRequest("Payouts Overview Component: View");
SessionResponse response = restClient.call(getApplicationProperty().getSessionAuthenticationApiUrl(), sessionRequest);

return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
}

/**
* Displays the Account Holder Reports using the Adyen Reports component
*
* This demonstrates how to integrate the Adyen web component that fetches and
* displays the reports
*
* @return
*/
@PostMapping("/getReports")
ResponseEntity<SessionResponse> getReports() {

if (getUserIdOnSession() == null) {
log.warn("User is not logged in");
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}

// Perform session call to obtain a valid Session token
SessionRequest sessionRequest = getSessionRequest("Reports Overview Component: View");
SessionResponse response = restClient.call(getApplicationProperty().getSessionAuthenticationApiUrl(), sessionRequest);

return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
}

// define SessionRequest object
private SessionRequest getSessionRequest(String role) {
SessionRequest sessionRequest = new SessionRequest()
.allowOrigin(getApplicationProperty().getComponentsAllowOrigin())
.product("platform")
.policy(new SessionRequestPolicy()
.resources(List.of(new PolicyResource()
.accountHolderId(getUserIdOnSession())
.type("accountHolder")))
.roles(List.of(role)));
return sessionRequest;
}

public ConfigurationAPIService getConfigurationAPIService() {
return configurationAPIService;
}
Expand Down

0 comments on commit 458ec60

Please sign in to comment.