Esempio n. 1
0
 public static void doIntercept(HttpServletRequest request, HttpServletResponse response)
     throws IOException {
   String path = request.getRequestURI();
   if (redirect && !path.contains("/admin/") && !redirectUrl.contains(path)) {
     if (redirectUrl != null && redirectStart.isBeforeNow() && redirectEnd.isAfterNow()) {
       response.sendRedirect(redirectUrl);
     }
   }
 }
Esempio n. 2
0
  public boolean isOnCurrentPeriod() {
    boolean isOnCurrentPeriod = false;

    if (getCalendarEntry() != null) {
      DateTime beginPeriodDateTime = getCalendarEntry().getBeginPeriodFullDateTime();
      DateTime endPeriodDateTime = getCalendarEntry().getEndPeriodFullDateTime();
      isOnCurrentPeriod =
          (beginPeriodDateTime.isEqualNow() || beginPeriodDateTime.isBeforeNow())
              && endPeriodDateTime.isAfterNow();
    }

    return isOnCurrentPeriod;
  }
  private synchronized void scheduleRemoval() {

    if (scheduledExpiration != null && scheduledExpiration.isAfterNow()) {
      return;
    }

    DateTime newExpiration = scheduledExpiration;

    do {
      newExpiration = askChatter(DateTime.class, new RemoveAfter(newExpiration));
    } while (newExpiration != null && newExpiration.isBeforeNow());

    scheduledExpiration = newExpiration;

    if (scheduledExpiration != null) {
      autoremover.schedule(
          this,
          scheduledExpiration.getMillis() - System.currentTimeMillis(),
          TimeUnit.MILLISECONDS);
    }
  }
  /**
   * Does minimal Credit Card Validation (luhn check and expiration date is after today). Mimics the
   * Response of a real Payment Gateway.
   *
   * @param creditCardDTO
   * @return
   */
  protected PaymentResponseDTO commonCreditCardProcessing(
      PaymentRequestDTO requestDTO, PaymentTransactionType paymentTransactionType) {
    PaymentResponseDTO responseDTO =
        new PaymentResponseDTO(PaymentType.CREDIT_CARD, NullPaymentGatewayType.NULL_GATEWAY);
    responseDTO.valid(true).paymentTransactionType(paymentTransactionType);

    CreditCardDTO creditCardDTO = requestDTO.getCreditCard();
    String transactionAmount = requestDTO.getTransactionTotal();

    CreditCardValidator visaValidator = new CreditCardValidator(CreditCardValidator.VISA);
    CreditCardValidator amexValidator = new CreditCardValidator(CreditCardValidator.AMEX);
    CreditCardValidator mcValidator = new CreditCardValidator(CreditCardValidator.MASTERCARD);
    CreditCardValidator discoverValidator = new CreditCardValidator(CreditCardValidator.DISCOVER);

    if (StringUtils.isNotBlank(transactionAmount)
        && StringUtils.isNotBlank(creditCardDTO.getCreditCardNum())
        && (StringUtils.isNotBlank(creditCardDTO.getCreditCardExpDate())
            || (StringUtils.isNotBlank(creditCardDTO.getCreditCardExpMonth())
                && StringUtils.isNotBlank(creditCardDTO.getCreditCardExpYear())))) {

      boolean validCard = false;
      if (visaValidator.isValid(creditCardDTO.getCreditCardNum())) {
        validCard = true;
      } else if (amexValidator.isValid(creditCardDTO.getCreditCardNum())) {
        validCard = true;
      } else if (mcValidator.isValid(creditCardDTO.getCreditCardNum())) {
        validCard = true;
      } else if (discoverValidator.isValid(creditCardDTO.getCreditCardNum())) {
        validCard = true;
      }

      boolean validDateFormat = false;
      boolean validDate = false;
      String[] parsedDate = null;
      if (StringUtils.isNotBlank(creditCardDTO.getCreditCardExpDate())) {
        parsedDate = creditCardDTO.getCreditCardExpDate().split("/");
      } else {
        parsedDate = new String[2];
        parsedDate[0] = creditCardDTO.getCreditCardExpMonth();
        parsedDate[1] = creditCardDTO.getCreditCardExpYear();
      }

      if (parsedDate.length == 2) {
        String expMonth = parsedDate[0];
        String expYear = parsedDate[1];
        try {
          DateTime expirationDate =
              new DateTime(Integer.parseInt("20" + expYear), Integer.parseInt(expMonth), 1, 0, 0);
          expirationDate = expirationDate.dayOfMonth().withMaximumValue();
          validDate = expirationDate.isAfterNow();
          validDateFormat = true;
        } catch (Exception e) {
          // invalid date format
        }
      }

      if (!validDate || !validDateFormat) {
        responseDTO
            .amount(new Money(0))
            .rawResponse("cart.payment.expiration.invalid")
            .successful(false);
      } else if (!validCard) {
        responseDTO.amount(new Money(0)).rawResponse("cart.payment.card.invalid").successful(false);
      } else {
        responseDTO
            .amount(new Money(requestDTO.getTransactionTotal()))
            .rawResponse("Success!")
            .successful(true);
      }

    } else {
      responseDTO.amount(new Money(0)).rawResponse("cart.payment.invalid").successful(false);
    }

    return responseDTO;
  }