Beispiel #1
0
  public PaymentSimulationResult simulatePayment(final PaymentParameters params) {

    PaymentStatus status;
    AccountHistoryTransferVO transferVO = null;

    try {
      final PrepareParametersResult result = prepareParameters(params);
      status = result.getStatus();

      if (status == null) {
        final DoExternalPaymentDTO dto =
            paymentHelper.toExternalPaymentDTO(params, result.getFrom(), result.getTo());
        if (!validateTransferType(dto)) {
          webServiceHelper.trace(
              PaymentStatus.INVALID_PARAMETERS
                  + ". Reason: The service client doesn't have permission to the specified transfer type: "
                  + dto.getTransferType());
          status = PaymentStatus.INVALID_PARAMETERS;
        } else {
          // Simulate the payment
          final Transfer transfer = (Transfer) paymentService.simulatePayment(dto);
          transferVO = accountHelper.toVO(WebServiceContext.getMember(), transfer, null);
          status = paymentHelper.toStatus(transfer);
        }
      }
    } catch (final Exception e) {
      webServiceHelper.error(e);
      status = paymentHelper.toStatus(e);
    }

    if (!status.isSuccessful()) {
      webServiceHelper.error("Simulate payment status: " + status);
    }
    return new PaymentSimulationResult(status, transferVO);
  }
Beispiel #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);
  }
Beispiel #3
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));
  }