Skip to content

Commit

Permalink
feature/Make OBP Payments - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
constantine2nd committed Jun 27, 2024
1 parent 656c5c6 commit 5322701
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

Expand Down Expand Up @@ -87,6 +84,10 @@ public class OtherController {
@Value("${obp.base_url}/obp/v5.1.0/my/mtls/certificate/current")
private String mtlsClientCertificateInfo;


@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;

@Resource
private RestTemplate restTemplate;

Expand Down Expand Up @@ -261,6 +262,44 @@ public Object getTransactionsObp(@PathVariable String bankId, @PathVariable Stri
.replace("BANK_ID", bankId), HttpMethod.GET, entity, HashMap.class);
return exchange.getBody();
}

@GetMapping("/payment_obp/{bankId}/{accountId}/{viewId}/{couterpartyId}/{currency}/{amount}/{description}/{chargePolicy}/{futureDate}")
public Object makePaymentObp(@PathVariable String bankId,
@PathVariable String accountId,
@PathVariable String viewId,
@PathVariable String couterpartyId,
@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);

PostJsonCreateTransactionRequestCounterparty body = new PostJsonCreateTransactionRequestCounterparty(
couterpartyId,
currency,
amount,
description,
chargePolicy,
futureDate
);

HttpEntity<PostJsonCreateTransactionRequestCounterparty> request = new HttpEntity<>(body, headers);
ResponseEntity<HashMap> response = restTemplate.exchange(
makePaymentCouterpartyObp
.replace("ACCOUNT_ID", accountId)
.replace("VIEW_ID", viewId)
.replace("BANK_ID", bankId),
HttpMethod.POST,
request,
HashMap.class
);
return response.getBody();
}
@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,122 @@
package com.openbankproject.model;

import com.fasterxml.jackson.annotation.JsonProperty;

class CounterpartyId {
@JsonProperty("counterparty_id")
private String counterpartyId;

public String getCounterpartyId() {
return counterpartyId;
}

public void setCounterpartyId(String counterpartyId) {
this.counterpartyId = counterpartyId;
}
}


class Value {
@JsonProperty("currency")
private String currency;

@JsonProperty("amount")
private String amount;

public String getCurrency() {
return currency;
}

public void setCurrency(String currency) {
this.currency = currency;
}

public String getAmount() {
return amount;
}

public void setAmount(String amount) {
this.amount = amount;
}
}


public class PostJsonCreateTransactionRequestCounterparty {
@JsonProperty("to")
private CounterpartyId to;

@JsonProperty("value")
private Value value;

@JsonProperty("description")
private String description;

@JsonProperty("charge_policy")
private String chargePolicy;

@JsonProperty("future_date")
private String futureDate;

public PostJsonCreateTransactionRequestCounterparty(String couterpartyId,
String currency,
String amount,
String description,
String chargePolicy,
String futureDate) {
CounterpartyId to = new CounterpartyId();
to.setCounterpartyId(couterpartyId);
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 CounterpartyId getTo() {
return to;
}


public void setTo(CounterpartyId 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;
}
}
72 changes: 72 additions & 0 deletions src/main/resources/static/js/main-html-obp-consent-flow.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
function makePaymentOBP(button) {
let resultBox = $(button).siblings('.payments_obp').empty().append('<h3>Payment List:</h3>');
let bankId = $(button).attr('bank_id');
let accountId = $(button).attr('account_id');
const viewHtmlId = "views-" + accountId;
const selectedViewId = $('#' + viewHtmlId).find(":selected").text();
let counterpartyId = document.getElementById("creditor_counterparty_obp").value;
let amount = document.getElementById("obp_payment_amount_of_money").value;
let currency = document.getElementById("obp_payment_currency").value;
let description = document.getElementById("obp_payment_description").value;

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

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

// Success callback function
function onSuccess(response) {
console.log('Success:', response);
let zson = JSON.stringify(response, 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>');
}

// Sending the GET request
$.getJSON(url, onSuccess)
.fail(function(jqxhr, textStatus, error) {
console.log('Request Failed:', textStatus, error);
});
};
function clearMakePaymentOBP(button) {
let resultBox = $('#payment_details_obp_div');
resultBox.empty();
};
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 @@ -79,13 +131,15 @@ $(function () {
<button onclick="getAccountDetails(this)" id="get_account_detail_obp_${account['id']}" class="btn btn-success" account_id="${account['id']}" bank_id="${account['bank_id']}" >Get Account detail</button>
<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="makePaymentOBP(this)" id="make_payment_obp_${account['id']}" class="btn btn-info" account_id="${account['id']}" bank_id="${account['bank_id']}" >Make payment</button>
<div class="input-group">
<label for=${viewHtmlId}>Choose a view:</label>
<select class="form-control" id=${viewHtmlId}></select>
</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>
<div class="payments_obp" style="margin-left: 50px;"></div>
<hr>
</div>
`);
Expand All @@ -96,4 +150,22 @@ $(function () {
});
});
});
});

function labelEventHandler() {
var div = document.getElementById("make_payment_obp_div");
var label = document.getElementById("make_payment_obp_label");
if (div.style.display == "none"){
div.style.display = "block";
label.textContent = "Hide payment box"
} else {
div.style.display = "none";
label.textContent = "Show payment box"
}
}

window.addEventListener("load", (event) => {
console.log("Page fully loaded");
// The function to be executed
labelEventHandler();
});
23 changes: 23 additions & 0 deletions src/main/resources/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,29 @@ <h1>Hello</h1> <br>
<div id="revoke_consent_obp_div"></div>
<div id="mtls_client_cert_info_obp_div"></div>
<div id="consent_info_obp_div"></div>
<hr>
<label id="make_payment_obp_label" for="make_payment_obp_div" onclick="labelEventHandler()">Show payment box</label>
<div id="make_payment_obp_div" class="collapse">
<div class="form-group">
<label for="creditor_counterparty_obp">To Counterparty ID</label>
<input type="text" name="creditor_counterparty_obp" id="creditor_counterparty_obp" class="form-control" >
</div>
<div class="form-group">
<label for="obp_payment_description">Description</label>
<input type="text" name="obp_payment_description" id="obp_payment_description" class="form-control" >
</div>
<div class="form-group">
<label for="obp_payment_amount_of_money">Amount of money</label>
<input type="number" min="0" value="0" name="obp_payment_amount_of_money" id="obp_payment_amount_of_money" class="form-control">
</div>
<div class="form-group">
<label for="obp_payment_currency">Currency</label>
<input type="text" value="EUR" name="obp_payment_currency" id="obp_payment_currency" class="form-control" >
</div>
<br>
<div id="payment_details_obp_div"></div>
</div>
<hr>
<div>
<button class="btn btn-primary" id="get_accounts_obp">Get accounts via OBP APIs using Consent-ID</button>
<div id="account_list_obp">
Expand Down

0 comments on commit 5322701

Please sign in to comment.