@FXML private void perfromTransfer() { BigDecimal transferAmount = new BigDecimal(0); String dealer = ""; try { String amount = amountTextField.getText(); transferAmount = new BigDecimal(amount); dealer = recipientTextField.getText(); if (amount.equals("")) throw new IllegalArgumentException("Must supply a transfer amount"); if (!InputConstraints.validateMsisdn(dealer)) throw new IllegalArgumentException("Dealer Id not in correct msisdn format"); boolean sendSms = sendSmsBox.isSelected(); FundTransferRequest fundTransferRequest = new FundTransferRequest(); fundTransferRequest.setAmount(Integer.parseInt(amount)); fundTransferRequest.setRecipientMsisdn(dealer); fundTransferRequest.setSendSms(sendSms); FundTransferResponse transferResponse = mainApp.getSmartloadInterface().performFundsTransfer(fundTransferRequest); SubmissionStatus submissionStatus = DataAccess.loadSubmissionStatus(transferResponse.getResponseCode().name()); String status = transferResponse.getError() == null ? transferResponse.getResponseCode().name() : transferResponse.getError().getMessage(); saveTransaction(submissionStatus, status, transferAmount, dealer); if (transferResponse.getResponseCode().equals(ResponseCode.SUCCESS)) { NumberFormat currency = NumberFormat.getCurrencyInstance(); String message = "Successful Transfer of " + currency.format(transferAmount) + " New balance " + currency.format(transferResponse.getCurrentDealerBalance()); log.info(message + " new Dealer balance " + transferResponse.getNewDealerBalance()); DialogFactory.createDialogInformation(DESCRIPTION, "Transfer successful", message); recipientTextField.setText(""); amountTextField.setText(""); } else { DialogFactory.createDialogError( "Transfer error", "Error performing transfer", transferResponse.getError().getMessage()); } mainApp.refresh(); } catch (Exception e) { DialogFactory.createDialogException("Transfer error", "Error performing transfer", e); SubmissionStatus submissionStatus = DataAccess.loadSubmissionStatus(ResponseCode.SYS_ERROR.name()); saveTransaction(submissionStatus, e.getMessage(), transferAmount, dealer); } }
/** * Initializes the controller class. This method is automatically called after the fxml file has * been loaded. */ @FXML private void initialize() { InputConstraints.numbersOnly(amountTextField, 6); InputConstraints.numbersOnly(recipientTextField, 11); lastTransaction.setText("-"); }