Exemplo n.º 1
0
  @Override
  protected void prepareForm(final ActionContext context) throws Exception {
    final HttpServletRequest request = context.getRequest();
    final EditCreditLimitForm form = context.getForm();
    final long id = form.getMemberId();
    if (id <= 0L) {
      throw new ValidationException();
    }
    final Member member = elementService.load(id, Element.Relationships.USER);
    final CreditLimitDTO creditLimit = accountService.getCreditLimits(member);

    // Transform positive to negative values to pass to the JSP
    Map<? extends AccountType, BigDecimal> limitPerType = creditLimit.getLimitPerType();
    final Map<AccountType, BigDecimal> newLimitPerType = new HashMap<AccountType, BigDecimal>();
    for (final AccountType accountType : limitPerType.keySet()) {
      BigDecimal limit = limitPerType.get(accountType);
      if (limit != null && limit.compareTo(new BigDecimal(0)) == 1) {
        limit = limit.negate();
      }
      newLimitPerType.put(accountType, limit);
    }
    limitPerType = newLimitPerType;
    creditLimit.setLimitPerType(limitPerType);

    request.setAttribute("member", member);
    request.setAttribute("limits", creditLimit.getEntries());
  }
Exemplo n.º 2
0
  private List<ChargebackResult> bulkReverse(
      final List<Transfer> transfers, final List<AccountDTO> accountsToLock) {
    final List<ChargebackResult> results = new LinkedList<ChargebackResult>();
    boolean failed = false;

    try {
      accountService.lockAccounts(true, accountsToLock);
    } catch (final Exception e) {
      WebServiceFaultsEnum.CURRENTLY_UNAVAILABLE.throwFault(e);
    }

    for (final Transfer transfer : transfers) {
      try {
        if (failed) {
          results.add(new ChargebackResult(ChargebackStatus.NOT_PERFORMED, null, null));
        } else {
          final ChargebackResult result = doChargeback(transfer);
          results.add(result);
          if (!result.getStatus().isSuccessful()) {
            failed = true;
          }
        }
      } catch (final Exception e) {
        failed = true;
        webServiceHelper.error(e);
        results.add(
            new ChargebackResult(ChargebackStatus.TRANSFER_CANNOT_BE_CHARGEDBACK, null, null));
      }
    }

    return results;
  }
Exemplo n.º 3
0
 @Override
 protected ActionForward handleSubmit(final ActionContext context) throws Exception {
   final EditCreditLimitForm form = context.getForm();
   final CreditLimitDTO creditLimit = getDataBinder().readFromString(form);
   accountService.setCreditLimit(getMember(form), creditLimit);
   context.sendMessage("creditLimit.modified");
   return ActionHelper.redirectWithParam(
       context.getRequest(), context.getSuccessForward(), "memberId", form.getMemberId());
 }
Exemplo n.º 4
0
  public PaymentResult doPayment(final PaymentParameters params) {
    AccountHistoryTransferVO transferVO = null;
    PaymentStatus status;
    AccountStatus fromMemberStatus = null;
    AccountStatus toMemberStatus = null;
    try {
      final PrepareParametersResult result = prepareParameters(params);
      status = result.getStatus();

      if (status == null) {
        // Status null means no "pre-payment" errors (like validation, pin, channel...)
        // Perform the payment
        final DoExternalPaymentDTO dto =
            paymentHelper.toExternalPaymentDTO(params, result.getFrom(), result.getTo());

        // Validate the transfer type
        if (!validateTransferType(dto)) {
          status = PaymentStatus.INVALID_PARAMETERS;
          webServiceHelper.trace(
              status
                  + ". Reason: The service client doesn't have permission to the specified transfer type: "
                  + dto.getTransferType());
        } else {
          final Transfer transfer = (Transfer) paymentService.insertExternalPayment(dto);
          status = paymentHelper.toStatus(transfer);
          transferVO = accountHelper.toVO(WebServiceContext.getMember(), transfer, null);

          if (WebServiceContext.getClient()
                  .getPermissions()
                  .contains(ServiceOperation.ACCOUNT_DETAILS)
              && params.isReturnStatus()) {
            if (WebServiceContext.getMember() == null) {
              fromMemberStatus =
                  accountService.getStatus(
                      new GetTransactionsDTO(dto.getFrom(), dto.getTransferType().getFrom()));
              toMemberStatus =
                  accountService.getStatus(
                      new GetTransactionsDTO(dto.getTo(), dto.getTransferType().getTo()));
            } else if (WebServiceContext.getMember()
                .equals(paymentHelper.resolveFromMember(params))) {
              fromMemberStatus =
                  accountService.getStatus(
                      new GetTransactionsDTO(dto.getFrom(), dto.getTransferType().getFrom()));
            } else {
              toMemberStatus =
                  accountService.getStatus(
                      new GetTransactionsDTO(dto.getTo(), dto.getTransferType().getTo()));
            }
          }
        }
      }
    } catch (final Exception e) {
      webServiceHelper.error(e);
      status = paymentHelper.toStatus(e);
    }

    if (!status.isSuccessful()) {
      webServiceHelper.error("Payment status: " + status);
    }

    return new PaymentResult(
        status,
        transferVO,
        accountHelper.toVO(fromMemberStatus),
        accountHelper.toVO(toMemberStatus));
  }
Exemplo n.º 5
0
  public List<PaymentResult> doBulkPayment(final List<PaymentParameters> params) {
    final List<PaymentResult> results =
        new ArrayList<PaymentResult>(params == null ? 0 : params.size());
    if (params != null) {
      // We should lock at once all from accounts for all payments, but only if all accounts are
      // passed ok
      boolean hasError = false;
      final List<AccountDTO> allAccounts = new ArrayList<AccountDTO>();
      for (int i = 0; i < params.size(); i++) {
        final PaymentParameters param = params.get(i);
        final PrepareParametersResult result = prepareParameters(param);

        if (result.getStatus() == null) {
          try {
            final DoExternalPaymentDTO dto =
                paymentHelper.toExternalPaymentDTO(param, result.getFrom(), result.getTo());
            if (!validateTransferType(dto)) {
              results.add(new PaymentResult(PaymentStatus.INVALID_PARAMETERS, null));
              webServiceHelper.error(
                  "The specified transfer type is invalid: " + dto.getTransferType());
              hasError = true;
            } else {
              allAccounts.add(new AccountDTO(result.getFrom(), dto.getTransferType().getFrom()));
              results.add(new PaymentResult(PaymentStatus.NOT_PERFORMED, null));
            }
          } catch (final Exception e) {
            webServiceHelper.error(e);
            hasError = true;
            results.add(new PaymentResult(paymentHelper.toStatus(e), null));
          }
        } else {
          hasError = true;
          results.add(new PaymentResult(result.getStatus(), null));
          webServiceHelper.error(
              "Bulk payment validation status [" + i + "]: " + result.getStatus());
        }
      }
      if (!hasError) {
        // No validation error. Lock all accounts and perform each payment
        try {
          accountService.lockAccounts(true, allAccounts);
        } catch (final Exception e) {
          WebServiceFaultsEnum.CURRENTLY_UNAVAILABLE.throwFault(e);
        }
        for (int i = 0; i < params.size(); i++) {
          final PaymentParameters param = params.get(i);
          PaymentResult result;
          if (hasError) {
            result = new PaymentResult(PaymentStatus.NOT_PERFORMED, null);
          } else {
            result = doPayment(param);
            if (!result.getStatus().isSuccessful()) {
              hasError = true;
            }
          }
          results.set(i, result);
        }
      }
    }
    return results;
  }
Exemplo n.º 6
0
  public PaymentResult confirmPayment(final ConfirmPaymentParameters params) {
    Exception errorException = null;
    AccountStatus fromMemberStatus = null;
    AccountStatus toMemberStatus = null;
    Member fromMember = null;
    Member toMember = null;

    // It's nonsense to use this if restricted to a member
    if (WebServiceContext.getMember() != null) {
      throw new PermissionDeniedException();
    }
    final Channel channel = WebServiceContext.getChannel();
    final String channelName = channel == null ? null : channel.getInternalName();

    PaymentStatus status = null;
    AccountHistoryTransferVO transferVO = null;

    // Get the ticket
    PaymentRequestTicket ticket = null;
    try {
      // Check that the ticket is valid
      final Ticket t = ticketService.load(params.getTicket());
      fromMember = t.getFrom();
      toMember = t.getTo();

      if (!(t instanceof PaymentRequestTicket) || t.getStatus() != Ticket.Status.PENDING) {
        throw new Exception(
            "Invalid ticket and/or status: "
                + t.getClass().getName()
                + ", status: "
                + t.getStatus());
      }
      // Check that the channel is the expected one
      ticket = (PaymentRequestTicket) t;
      if (!ticket.getToChannel().getInternalName().equals(channelName)) {
        throw new Exception(
            "The ticket's destination channel is not the expected one (expected="
                + channelName
                + "): "
                + ticket.getToChannel().getInternalName());
      }
    } catch (final Exception e) {
      errorException = e;
      status = PaymentStatus.INVALID_PARAMETERS;
    }

    // Validate the Channel and credentials
    Member member = null;
    if (status == null) {
      member = ticket.getFrom();
      if (!accessService.isChannelEnabledForMember(channelName, member)) {
        status = PaymentStatus.INVALID_CHANNEL;
      }
      if (status == null && WebServiceContext.getClient().isCredentialsRequired()) {
        try {
          checkCredentials(member, channel, params.getCredentials());
        } catch (final InvalidCredentialsException e) {
          status = PaymentStatus.INVALID_CREDENTIALS;
        } catch (final BlockedCredentialsException e) {
          status = PaymentStatus.BLOCKED_CREDENTIALS;
        }
      }
    }
    // Confirm the payment
    if (status == null) {
      try {
        final Transfer transfer = (Transfer) paymentService.confirmPayment(ticket.getTicket());
        transferVO = accountHelper.toVO(member, transfer, null);
        status = paymentHelper.toStatus(transfer);

        if (WebServiceContext.getClient()
            .getPermissions()
            .contains(ServiceOperation.ACCOUNT_DETAILS)) {
          if (WebServiceContext.getMember() == null) {
            fromMemberStatus =
                accountService.getStatus(
                    new GetTransactionsDTO(fromMember, transfer.getFrom().getType()));
            toMemberStatus =
                accountService.getStatus(
                    new GetTransactionsDTO(toMember, transfer.getTo().getType()));
          } else if (WebServiceContext.getMember().equals(fromMember)) {
            fromMemberStatus =
                accountService.getStatus(
                    new GetTransactionsDTO(fromMember, transfer.getFrom().getType()));
          } else {
            toMemberStatus =
                accountService.getStatus(
                    new GetTransactionsDTO(toMember, transfer.getTo().getType()));
          }
        }
      } catch (final Exception e) {
        errorException = e;
        status = paymentHelper.toStatus(e);
      }
    }

    if (!status.isSuccessful()) {
      webServiceHelper.error(
          errorException != null
              ? errorException
              : new Exception("Confirm payment status: " + status));
    }
    // Build the result
    return new PaymentResult(
        status,
        transferVO,
        accountHelper.toVO(fromMemberStatus),
        accountHelper.toVO(toMemberStatus));
  }
Exemplo n.º 7
0
 @Override
 protected void validateForm(final ActionContext context) {
   final EditCreditLimitForm form = context.getForm();
   final CreditLimitDTO creditLimit = getDataBinder().readFromString(form);
   accountService.validate(getMember(form), creditLimit);
 }