Skip to content

Commit

Permalink
feature/Add SEPA payment at OBP Flow
Browse files Browse the repository at this point in the history
  • Loading branch information
constantine2nd committed Jul 9, 2024
1 parent e347ee6 commit 41acea7
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public class OtherController {

@Value("${obp.base_url}/obp/v5.1.0/banks/BANK_ID/accounts/ACCOUNT_ID/VIEW_ID/transaction-request-types/COUNTERPARTY/transaction-requests")
private String makePaymentCouterpartyObp;

@Value("${obp.base_url}/obp/v5.1.0/banks/BANK_ID/accounts/ACCOUNT_ID/VIEW_ID/transaction-request-types/SEPA/transaction-requests")
private String makePaymentSepaObp;

@Resource
private RestTemplate restTemplate;
Expand Down Expand Up @@ -294,6 +297,52 @@ public ResponseEntity<Object> makePaymentObp(@PathVariable String bankId,
.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<HashMap> 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("/payment_obp_sepa/{bankId}/{accountId}/{viewId}/{iban}/{currency}/{amount}/{description}/{chargePolicy}/{futureDate}")
public ResponseEntity<Object> makePaymentSepaObp(@PathVariable String bankId,
@PathVariable String accountId,
@PathVariable String viewId,
@PathVariable String iban,
@PathVariable String currency,
@PathVariable String amount,
@PathVariable String description,
@PathVariable String chargePolicy,
@PathVariable String futureDate,
HttpSession session) {
String consentId = SessionData.getConsentId(session);
HttpHeaders headers = new HttpHeaders();
headers.add("Consent-Id", consentId);
HttpEntity<String> entity = new HttpEntity<>(headers);

PostJsonCreateTransactionRequestSepa body = new PostJsonCreateTransactionRequestSepa(
iban,
currency,
amount,
description,
chargePolicy,
futureDate
);

HttpEntity<PostJsonCreateTransactionRequestSepa> request = new HttpEntity<>(body, headers);
String url = makePaymentSepaObp
.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);
Expand All @@ -309,6 +358,7 @@ public ResponseEntity<Object> makePaymentObp(@PathVariable String bankId,
return new ResponseEntity<>(e.getResponseBodyAsString(), responseHeaders, e.getStatusCode());
}
}

@GetMapping("/revoke_consent_obp")
public Object revokeConsentObp(HttpSession session) {
String consentId = SessionData.getConsentId(session);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.openbankproject.model;

import com.fasterxml.jackson.annotation.JsonProperty;

class Iban {
@JsonProperty("iban")
private String iban;

public String getIban() {
return iban;
}

public void setIban(String iban) {
this.iban = iban;
}
}


public class PostJsonCreateTransactionRequestSepa {
@JsonProperty("to")
private Iban to;

@JsonProperty("value")
private Value value;

@JsonProperty("description")
private String description;

@JsonProperty("charge_policy")
private String chargePolicy;

@JsonProperty("future_date")
private String futureDate;

public PostJsonCreateTransactionRequestSepa(String iban,
String currency,
String amount,
String description,
String chargePolicy,
String futureDate) {
Iban to = new Iban();
to.setIban(iban);
this.to = to;

Value value = new Value();
value.setCurrency(currency);
value.setAmount(amount);
this.value = value;

this.description = description;
this.chargePolicy = chargePolicy;
this.futureDate = futureDate;


}

public Iban getTo() {
return to;
}


public void setTo(Iban to) {
this.to = to;
}

public Value getValue() {
return value;
}

public void setValue(Value value) {
this.value = value;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getChargePolicy() {
return chargePolicy;
}

public void setChargePolicy(String chargePolicy) {
this.chargePolicy = chargePolicy;
}

public String getFutureDate() {
return futureDate;
}

public void setFutureDate(String futureDate) {
this.futureDate = futureDate;
}
}
102 changes: 100 additions & 2 deletions src/main/resources/static/js/main-html-obp-consent-flow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function createTransactioRequestObp(button) {
function createTransactionRequestObp(button) {
let resultBox = $(button).siblings('.payments_obp').empty().append('<h3>Response:</h3>');
let bankId = $(button).attr('bank_id');
let accountId = $(button).attr('account_id');
Expand Down Expand Up @@ -68,6 +68,77 @@ function createTransactioRequestObp(button) {

};

function createTransactionRequestObpSepa(button) {
let resultBox = $(button).siblings('.payments_obp_sepa').empty().append('<h3>Response:</h3>');
let bankId = $(button).attr('bank_id');
let accountId = $(button).attr('account_id');
const viewHtmlId = "views-" + accountId;
const selectedViewId = $('#' + viewHtmlId).find(":selected").text();
let iban = document.getElementById("creditor_iban_obp_sepa_" + accountId).value;
let amount = document.getElementById("obp_payment_amount_of_money_sepa_" + accountId).value;
let currency = document.getElementById("obp_payment_currency_sepa_" + accountId).value;
let description = document.getElementById("obp_payment_description_sepa_" + accountId).value;

// The data to be sent to the server
var data = {
to: {
iban: iban
},
value: {
currency: currency,
amount: amount
},
description: description,
charge_policy: "SHARED",
future_date: "20200127"
};

// URL to which the request is sent
var url = '/payment_obp_sepa/' + bankId + '/' + accountId + "/" + selectedViewId + "/" +
data.to.iban + "/" +
data.value.currency + "/" + data.value.amount + "/" +
data.description + "/" +
data.charge_policy + "/" +
data.future_date;

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(`<div id=${iconId} style="cursor:pointer;" onclick="copyJsonResultToClipboard(this)" class="fa-solid fa-copy"></div><pre><div id=${resultBoxId}>${zson}</div></pre>`).append('<br>');
}
function setPathOfCall(path) {
document.getElementById("path-of-endpoint-sepa-" + accountId).textContent = path;
}

// Sending the GET request
$.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) {
let resultBox = $(button).siblings('.account_detail_obp').empty().append('<h3>Account Detail:</h3>');
let accountId = $(button).attr('account_id');
Expand Down Expand Up @@ -151,11 +222,13 @@ $(function () {
<button onclick="getBalances(this)" id="get_balances_obp_${account['id']}" class="btn btn-warning" account_id="${account['id']}" bank_id="${account['bank_id']}" >Get Balances</button>
<button onclick="getTransactions(this)" id="get_transactions_obp_${account['id']}" class="btn btn-info" account_id="${account['id']}" bank_id="${account['bank_id']}" >Get Transactions</button>
<button onclick="collapsibleElementEventHandler(make_payment_obp_div_${account['id']})" id="prepare_payment_obp_${account['id']}" class="btn btn-info" account_id="${account['id']}" bank_id="${account['bank_id']}" >Prepare / Hide payment</button>
<button onclick="collapsibleElementEventHandler(make_payment_obp_sepa_div_${account['id']})" id="prepare_payment_obp_sepa_${account['id']}" class="btn btn-info" account_id="${account['id']}" bank_id="${account['bank_id']}" >Prepare / Hide SEPA payment</button>
<div class="input-group">
<label for=${viewHtmlId}>Choose a view:</label>
<select class="form-control" id=${viewHtmlId}></select>
</div>
<!-- Counterparty Transaction Request -->
<div id="make_payment_obp_div_${account['id']}" class="collapse" style="display: none; margin-left: 50px;">
<hr>
<div class="form-group">
Expand All @@ -174,12 +247,37 @@ $(function () {
<label for="obp_payment_currency_${account['id']}">Currency</label>
<input type="text" value="EUR" name="obp_payment_currency_${account['id']}" id="obp_payment_currency_${account['id']}" class="form-control" >
</div>
<button onclick="createTransactioRequestObp(this)" id="make_payment_obp_${account['id']}" class="btn btn-info" account_id="${account['id']}" bank_id="${account['bank_id']}" result_box_id="${account['id']}">Create Transaction Request</button>
<button onclick="createTransactionRequestObp(this)" id="make_payment_obp_${account['id']}" class="btn btn-info" account_id="${account['id']}" bank_id="${account['bank_id']}" result_box_id="${account['id']}">Create Transaction Request</button>
<h6 id="path-of-endpoint-${account['id']}"></h6>
<div class="payments_obp" style="margin-left: 50px;"></div>
<hr>
</div>
<!-- SEPA Transaction Request -->
<div id="make_payment_obp_sepa_div_${account['id']}" class="collapse" style="display: none; margin-left: 50px;">
<hr>
<div class="form-group">
<label for="creditor_iban_obp_sepa_${account['id']}">To IBAN</label>
<input type="text" name="creditor_iban_obp_sepa_${account['id']}" id="creditor_iban_obp_sepa_${account['id']}" class="form-control" >
</div>
<div class="form-group">
<label for="obp_payment_description_sepa_${account['id']}">Description</label>
<input type="text" name="obp_payment_description_sepa_${account['id']}" id="obp_payment_description_sepa_${account['id']}" class="form-control" >
</div>
<div class="form-group">
<label for="obp_payment_amount_of_money_sepa_${account['id']}">Amount of money</label>
<input type="number" min="0" value="0" name="obp_payment_amount_of_money_sepa_${account['id']}" id="obp_payment_amount_of_money_sepa_${account['id']}" class="form-control">
</div>
<div class="form-group">
<label for="obp_payment_currency_sepa_${account['id']}">Currency</label>
<input type="text" value="EUR" name="obp_payment_currency_sepa_${account['id']}" id="obp_payment_currency_sepa_${account['id']}" class="form-control" >
</div>
<button onclick="createTransactionRequestObpSepa(this)" id="make_payment_obp_sepa_${account['id']}" class="btn btn-info" account_id="${account['id']}" bank_id="${account['bank_id']}" result_box_id="${account['id']}">Create Transaction Request</button>
<h6 id="path-of-endpoint-sepa-${account['id']}"></h6>
<div class="payments_obp_sepa" style="margin-left: 50px;"></div>
<hr>
</div>
<div class="account_detail_obp" style="margin-left: 50px;"></div>
<div class="balances_obp" style="margin-left: 50px;"></div>
<div class="transactions_obp" style="margin-left: 50px;"></div>
Expand Down

0 comments on commit 41acea7

Please sign in to comment.