Esempio n. 1
0
 /** Checks the given member's pin */
 private void checkCredentials(Member member, final Channel channel, final String credentials) {
   if (member == null) {
     return;
   }
   final ServiceClient client = WebServiceContext.getClient();
   final Member restrictedMember = client.getMember();
   if (restrictedMember == null) {
     // Non-restricted clients use the flag credentials required
     if (!client.isCredentialsRequired()) {
       // No credentials should be checked
       throw new InvalidCredentialsException();
     }
   } else {
     // Restricted clients don't need check if is the same member
     if (restrictedMember.equals(member)) {
       throw new InvalidCredentialsException();
     }
   }
   if (StringUtils.isEmpty(credentials)) {
     throw new InvalidCredentialsException();
   }
   member = fetchService.fetch(member, Element.Relationships.USER);
   accessService.checkCredentials(
       channel,
       member.getMemberUser(),
       credentials,
       WebServiceContext.getRequest().getRemoteAddr(),
       WebServiceContext.getMember());
 }
Esempio n. 2
0
  /** Prepares the parameters for a payment. The resulting status is null when no problem found */
  private PrepareParametersResult prepareParameters(final PaymentParameters params) {

    final Member restricted = WebServiceContext.getMember();
    final boolean fromSystem = params.isFromSystem();
    final boolean toSystem = params.isToSystem();
    PaymentStatus status = null;
    Member fromMember = null;
    Member toMember = null;
    // Load the from member
    if (!fromSystem) {
      try {
        fromMember = paymentHelper.resolveFromMember(params);
      } catch (final EntityNotFoundException e) {
        webServiceHelper.error(e);
        status = PaymentStatus.FROM_NOT_FOUND;
      }
    }
    // Load the to member
    if (!toSystem) {
      try {
        toMember = paymentHelper.resolveToMember(params);
      } catch (final EntityNotFoundException e) {
        webServiceHelper.error(e);
        status = PaymentStatus.TO_NOT_FOUND;
      }
    }

    if (status == null) {
      if (restricted == null) {
        // Ensure has the do payment permission
        if (!WebServiceContext.hasPermission(ServiceOperation.DO_PAYMENT)) {
          throw new PermissionDeniedException(
              "The service client doesn't have the following permission: "
                  + ServiceOperation.DO_PAYMENT);
        }
        // Check the channel immediately, as needed by SMS controller
        if (fromMember != null
            && !accessService.isChannelEnabledForMember(channelHelper.restricted(), fromMember)) {
          status = PaymentStatus.INVALID_CHANNEL;
        }
      } else {
        // Enforce the restricted to member parameters
        if (fromSystem) {
          // Restricted to member can't perform payment from system
          status = PaymentStatus.FROM_NOT_FOUND;
        } else {
          if (fromMember == null) {
            fromMember = restricted;
          } else if (toMember == null && !toSystem) {
            toMember = restricted;
          }
        }
        if (status == null) {
          // Check make / receive payment permissions
          if (fromMember.equals(restricted)) {
            if (!WebServiceContext.hasPermission(ServiceOperation.DO_PAYMENT)) {
              throw new PermissionDeniedException(
                  "The service client doesn't have the following permission: "
                      + ServiceOperation.DO_PAYMENT);
            }
          } else {
            if (!WebServiceContext.hasPermission(ServiceOperation.RECEIVE_PAYMENT)) {
              throw new PermissionDeniedException(
                  "The service client doesn't have the following permission: "
                      + ServiceOperation.RECEIVE_PAYMENT);
            }
          }
          // Ensure that either from or to member is the restricted one
          if (!fromMember.equals(restricted) && !toMember.equals(restricted)) {
            status = PaymentStatus.INVALID_PARAMETERS;
            webServiceHelper.trace(
                status
                    + ". Reason: Neither the origin nor the destination members are equal to the restricted: "
                    + restricted);
          }
        }
        if (status == null) {
          // Enforce the permissions
          if (restricted.equals(fromMember)
              && !WebServiceContext.hasPermission(ServiceOperation.DO_PAYMENT)) {
            throw new PermissionDeniedException(
                "The service client doesn't have the following permission: "
                    + ServiceOperation.DO_PAYMENT);
          } else if (restricted.equals(toMember)
              && !WebServiceContext.hasPermission(ServiceOperation.RECEIVE_PAYMENT)) {
            throw new PermissionDeniedException(
                "The service client doesn't have the following permission: "
                    + ServiceOperation.RECEIVE_PAYMENT);
          }
        }
      }
    }

    // Ensure both from and to member are present
    if (status == null) {
      if (fromMember == null && !fromSystem) {
        status = PaymentStatus.FROM_NOT_FOUND;
      } else if (toMember == null && !toSystem) {
        status = PaymentStatus.TO_NOT_FOUND;
      }
    }

    if (status == null) {
      // Check the channel
      if (fromMember != null
          && !accessService.isChannelEnabledForMember(channelHelper.restricted(), fromMember)) {
        status = PaymentStatus.INVALID_CHANNEL;
      }
    }
    if (status == null) {
      // Check the credentials
      boolean checkCredentials;
      if (restricted != null) {
        checkCredentials = !fromMember.equals(restricted);
      } else {
        checkCredentials = !fromSystem && WebServiceContext.getClient().isCredentialsRequired();
      }
      if (checkCredentials) {
        try {
          checkCredentials(fromMember, WebServiceContext.getChannel(), params.getCredentials());
        } catch (final InvalidCredentialsException e) {
          status = PaymentStatus.INVALID_CREDENTIALS;
        } catch (final BlockedCredentialsException e) {
          status = PaymentStatus.BLOCKED_CREDENTIALS;
        }
      }
    }

    // No error
    final AccountOwner fromOwner = fromSystem ? SystemAccountOwner.instance() : fromMember;
    final AccountOwner toOwner = toSystem ? SystemAccountOwner.instance() : toMember;
    return new PrepareParametersResult(status, fromOwner, toOwner);
  }
Esempio n. 3
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));
  }