From b6ee37a371b1f3cfdfe1157f58add9fdbcef13e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Thu, 4 Jul 2024 14:47:26 +0200 Subject: [PATCH] feature/Add path of the call on create transaction request button press --- .../auth/controller/OtherController.java | 31 +++++++++----- .../static/js/main-html-obp-consent-flow.js | 42 ++++++++++++++----- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/openbankproject/hydra/auth/controller/OtherController.java b/src/main/java/com/openbankproject/hydra/auth/controller/OtherController.java index 192f684..bf9c2e5 100644 --- a/src/main/java/com/openbankproject/hydra/auth/controller/OtherController.java +++ b/src/main/java/com/openbankproject/hydra/auth/controller/OtherController.java @@ -264,7 +264,7 @@ public Object getTransactionsObp(@PathVariable String bankId, @PathVariable Stri } @GetMapping("/payment_obp/{bankId}/{accountId}/{viewId}/{couterpartyId}/{currency}/{amount}/{description}/{chargePolicy}/{futureDate}") - public Object makePaymentObp(@PathVariable String bankId, + public ResponseEntity makePaymentObp(@PathVariable String bankId, @PathVariable String accountId, @PathVariable String viewId, @PathVariable String couterpartyId, @@ -289,16 +289,25 @@ public Object makePaymentObp(@PathVariable String bankId, ); HttpEntity request = new HttpEntity<>(body, headers); - ResponseEntity response = restTemplate.exchange( - makePaymentCouterpartyObp - .replace("ACCOUNT_ID", accountId) - .replace("VIEW_ID", viewId) - .replace("BANK_ID", bankId), - HttpMethod.POST, - request, - HashMap.class - ); - return response.getBody(); + String url = makePaymentCouterpartyObp + .replace("ACCOUNT_ID", accountId) + .replace("VIEW_ID", viewId) + .replace("BANK_ID", bankId); + + // Create response headers + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.add("Path-Of-Call", HttpMethod.POST + ": " + url); + try { + ResponseEntity response = restTemplate.exchange( + url, + HttpMethod.POST, + request, + HashMap.class + ); + return new ResponseEntity<>(response.getBody(), responseHeaders, response.getStatusCode()); + } catch (HttpClientErrorException e) { + return new ResponseEntity<>(e.getResponseBodyAsString(), responseHeaders, e.getStatusCode()); + } } @GetMapping("/revoke_consent_obp") public Object revokeConsentObp(HttpSession session) { diff --git a/src/main/resources/static/js/main-html-obp-consent-flow.js b/src/main/resources/static/js/main-html-obp-consent-flow.js index 4249736..fe7fb24 100644 --- a/src/main/resources/static/js/main-html-obp-consent-flow.js +++ b/src/main/resources/static/js/main-html-obp-consent-flow.js @@ -1,5 +1,5 @@ function makePaymentOBP(button) { - let resultBox = $(button).siblings('.payments_obp').empty().append('

Payment:

'); + let resultBox = $(button).siblings('.payments_obp').empty().append('

Response:

'); let bankId = $(button).attr('bank_id'); let accountId = $(button).attr('account_id'); const viewHtmlId = "views-" + accountId; @@ -29,22 +29,43 @@ function makePaymentOBP(button) { data.value.currency + "/" + data.value.amount + "/" + data.description + "/" + data.charge_policy + "/" + - data.future_date; + data.future_date; - // Success callback function - function onSuccess(response) { - console.log('Success:', response); - let zson = JSON.stringify(response, null, 2); + function setResult(dataToSend) { + let zson = JSON.stringify(dataToSend, null, 2); let iconId = "result_copy_icon_" + accountId + button.id; let resultBoxId = "result_box_" + accountId + button.id; resultBox.append(`
${zson}
`).append('
'); } + function setPathOfCall(path) { + document.getElementById("path-of-endpoint-" + accountId).textContent = path; + } // Sending the GET request - $.getJSON(url, onSuccess) - .fail(function(jqxhr, textStatus, error) { - console.log('Request Failed:', textStatus, error); - }); + $.ajax({ + url: url, + method: 'GET', + dataType: 'json', + success: function(receivedData, textStatus, jqXHR) { + // Handle the response data here + console.log(receivedData); + setResult(receivedData); + // Access response headers + const customHeader = jqXHR.getResponseHeader('Path-Of-Call'); + setPathOfCall(customHeader); + console.log('Path-Of-Call:', customHeader); + }, + error: function(jqXHR, textStatus, errorThrown) { + console.log('Request Failed:', textStatus, errorThrown); + setResult(jqXHR.responseJSON); + + // Access response headers + const customHeader = jqXHR.getResponseHeader('Path-Of-Call'); + setPathOfCall(customHeader); + console.log('Path-Of-Call:', customHeader); + } + }); + }; function getAccountDetails(button) { @@ -154,6 +175,7 @@ $(function () { +