use of org.iban4j.InvalidCheckDigitException in project axelor-open-suite by axelor.
the class BankDetailsController method validateIban.
public void validateIban(ActionRequest request, ActionResponse response) {
response.setAttr("invalidIbanText", "hidden", true);
if (request.getAction().endsWith("onnew")) {
return;
}
BankDetails bankDetails = request.getContext().asType(BankDetails.class);
Bank bank = bankDetails.getBank();
if (bankDetails.getIban() != null && bank != null && bank.getBankDetailsTypeSelect() == BankRepository.BANK_IDENTIFIER_TYPE_IBAN) {
try {
Beans.get(BankDetailsService.class).validateIban(bankDetails.getIban());
} catch (IbanFormatException | InvalidCheckDigitException | UnsupportedCountryException e) {
if (request.getAction().endsWith("onchange")) {
response.setFlash(I18n.get(IExceptionMessage.BANK_DETAILS_1));
}
response.setAttr("invalidIbanText", "hidden", false);
} finally {
bankDetails = Beans.get(BankDetailsServiceImpl.class).detailsIban(bankDetails);
if (bank.getCountry() != null && bank.getCountry().getAlpha2Code().equals("FR")) {
response.setValue("bankCode", bankDetails.getBankCode());
response.setValue("sortCode", bankDetails.getSortCode());
response.setValue("accountNbr", bankDetails.getAccountNbr());
response.setValue("bbanKey", bankDetails.getBbanKey());
}
}
}
}
use of org.iban4j.InvalidCheckDigitException in project axelor-open-suite by axelor.
the class PartnerController method checkIbanValidity.
public void checkIbanValidity(ActionRequest request, ActionResponse response) throws AxelorException {
List<BankDetails> bankDetailsList = request.getContext().asType(Partner.class).getBankDetailsList();
List<String> ibanInError = Lists.newArrayList();
if (bankDetailsList != null && !bankDetailsList.isEmpty()) {
for (BankDetails bankDetails : bankDetailsList) {
Bank bank = bankDetails.getBank();
if (bankDetails.getIban() != null && bank != null && bank.getBankDetailsTypeSelect() == BankRepository.BANK_IDENTIFIER_TYPE_IBAN) {
LOG.debug("checking iban code : {}", bankDetails.getIban());
try {
Beans.get(BankDetailsService.class).validateIban(bankDetails.getIban());
} catch (IbanFormatException | InvalidCheckDigitException | UnsupportedCountryException e) {
ibanInError.add(bankDetails.getIban());
}
}
}
}
if (!ibanInError.isEmpty()) {
Function<String, String> addLi = new Function<String, String>() {
@Override
public String apply(String s) {
return "<li>".concat(s).concat("</li>").toString();
}
};
response.setAlert(String.format(IExceptionMessage.BANK_DETAILS_2, "<ul>" + Joiner.on("").join(Iterables.transform(ibanInError, addLi)) + "<ul>"));
}
}
Aggregations