Пример #1
0
  public void validateMerchant(Merchant merchant) throws Exception {
    StringBuilder errorList = new StringBuilder();

    if (merchant == null) {
      errorList.append("Please provide merchant details!");
    } else if (merchant.getPassword() == null) {
      errorList.append("Please provide merchant's password");
    } else if (merchant.getIdentifier() == null) {
      errorList.append("Please provide merchant's identifier");
    }

    if (errorList.length() > 0) {
      throw new Exception(errorList.toString());
    }
  }
Пример #2
0
  private void authenticateMerchant(MerchantOrder order) throws Exception {
    Merchant merchant = order.getMerchant();
    StringBuilder errorList = new StringBuilder();
    validateMerchant(merchant);

    Merchant dbMerchant = merchantService.getByIdentifier(merchant.getIdentifier());

    if (dbMerchant == null) {
      errorList.append("Merchant with provided identifier does not exist!");
    } else if (!merchant.getPassword().equals(dbMerchant.getPassword())) {
      errorList.append("Invalid password");
    }

    merchant.setId(dbMerchant.getId());

    if (errorList.length() > 0) {
      throw new Exception(errorList.toString());
    }
  }