@Override protected void prepareForm(final ActionContext context) throws Exception { final Transfer transfer = resolveTransfer(context); // Check for transaction password final HttpServletRequest request = context.getRequest(); final boolean requestTransactionPassword = shouldValidateTransactionPassword(context, transfer); if (requestTransactionPassword) { context.validateTransactionPassword(); } request.setAttribute("requestTransactionPassword", requestTransactionPassword); request.setAttribute( "wouldRequireAuthorization", paymentService.wouldRequireAuthorization(transfer)); // Transfer number and number of transfers final int transferNumber = getTransferNumber(transfer); final int numberOfTransfers = getNumberOfTransfer(transfer); request.setAttribute("transferNumber", transferNumber); request.setAttribute("numberOfTransfers", numberOfTransfers); // Fetch related data final AccountOwner from = transfer.getFromOwner(); final AccountOwner to = transfer.getToOwner(); final TransferType transferType = transferTypeService.load( transfer.getType().getId(), RelationshipHelper.nested( TransferType.Relationships.FROM, AccountType.Relationships.CURRENCY), TransferType.Relationships.TO); final BigDecimal amount = transfer.getAmount(); if (from instanceof Member) { request.setAttribute("fromMember", from); } if (to instanceof Member) { request.setAttribute("toMember", to); } transfer.setType(transferType); request.setAttribute("unitsPattern", transferType.getFrom().getCurrency().getPattern()); // Store the transaction fees final TransactionFeePreviewDTO preview = transactionFeeService.preview(from, to, transferType, amount); request.setAttribute("finalAmount", preview.getFinalAmount()); request.setAttribute("fees", preview.getFees()); request.setAttribute("transfer", transfer); }
private <V> ChargebackResult reverse(final V transferId, final TransferLoader<V> loader) { Exception errorException = null; ChargebackStatus status = null; Transfer transfer = null; try { transfer = loader.load(transferId); // Ensure the member is the one who received the payment final Member member = WebServiceContext.getMember(); if (member != null && !transfer.getToOwner().equals(member)) { throw new EntityNotFoundException(); } else { final Collection<TransferType> possibleTypes = fetchService .fetch( WebServiceContext.getClient(), ServiceClient.Relationships.CHARGEBACK_PAYMENT_TYPES) .getChargebackPaymentTypes(); if (!possibleTypes.contains(transfer.getType())) { throw new EntityNotFoundException(); } } } catch (final EntityNotFoundException e) { errorException = e; status = ChargebackStatus.TRANSFER_NOT_FOUND; } if (status == null) { try { return doChargeback(transfer); } catch (final Exception e) { webServiceHelper.error(e); return new ChargebackResult(ChargebackStatus.TRANSFER_CANNOT_BE_CHARGEDBACK, null, null); } } else { if (!status.isSuccessful()) { webServiceHelper.error( errorException != null ? errorException : new Exception("Chargeback status: " + status)); } return new ChargebackResult(status, null, null); } }
public TransferType getTransferType() { return transfer == null ? null : transfer.getType(); }
private boolean shouldValidateTransactionPassword( final ActionContext context, final Transfer transfer) { final TransferType transferType = transferTypeService.load(transfer.getType().getId(), TransferType.Relationships.FROM); return context.isTransactionPasswordEnabled(transferType.getFrom()); }