@Override
  public void prepareModule() throws Exception {
    Context ctx =
        (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    ReferenceService rservice =
        (ReferenceService) ServiceFactory.getService(ServiceFactory.ReferenceService);

    Locale locale = getLocale();

    String country = locale.getCountry();
    if (locale.getVariant().equals("EUR")) {
      country = "X1";
    }

    Map packages = ShippingUtil.buildPackageMap(moduleid, locale);
    if (packages != null) {
      setPackageMap(packages);
    }

    // get merchant configs
    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);

    ConfigurationResponse config = mservice.getConfigurationByModule(moduleid, merchantid);
    this.setConfigurations(config);
  }
  @Override
  public void prepareModule() throws Exception {

    Context ctx =
        (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);

    String text =
        LabelUtil.getInstance().getText(super.getLocale(), "label.payment.methods.title.papal");
    this.setMessage(text);

    MerchantStore mstore = mservice.getMerchantStore(merchantid);

    if (mstore == null) {
      MessageUtil.addErrorMessage(
          super.getServletRequest(),
          LabelUtil.getInstance().getText("errors.profile.storenotcreated"));
    }

    ConfigurationResponse config = mservice.getConfigurationByModule(moduleid, merchantid);
    this.setConfigurations(config);
  }
  @Override
  public void deleteModule() throws Exception {
    Context ctx =
        (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    mservice.cleanConfigurationLikeKeyModule("SHP_RT_", moduleid, merchantid);
  }
  @Override
  public void saveModule() throws Exception {

    Context ctx =
        (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    // need validation
    boolean hasError = false;

    if (StringUtils.isBlank(this.getKeys().getProperties1())) {
      addFieldError("keys.properties1", getText("error.payment.paypal.userid.required"));
      hasError = true;
    }

    if (StringUtils.isBlank(this.getKeys().getProperties2())) {
      addFieldError("keys.properties2", getText("error.payment.paypal.password.required"));
      hasError = true;
    }

    if (StringUtils.isBlank(this.getKeys().getProperties3())) {
      addFieldError("keys.properties3", getText("error.payment.paypal.signature.required"));
      hasError = true;
    }

    String value2 = this.getKeys().getProperties5();
    this.getKeys().setProperties5("");

    String value1 = MerchantConfigurationUtil.getConfigurationValue(this.getKeys(), "|");

    ConfigurationResponse vo = this.getConfigurations();
    MerchantConfiguration conf = null;
    if (vo != null) {
      conf = (MerchantConfiguration) vo.getConfiguration(PaymentConstants.PAYMENT_PAYPALNAME);
    }
    if (conf != null) {
      conf.setConfigurationValue(value1);
      conf.setConfigurationValue1(value2);

    } else {

      conf = new MerchantConfiguration();
      conf.setMerchantId(merchantid);

      conf.setConfigurationModule(moduleid);
      conf.setConfigurationKey(
          PaymentConstants.MODULE_PAYMENT + PaymentConstants.PAYMENT_PAYPALNAME);
      conf.setConfigurationValue(value1); // userid | password | signature
      conf.setConfigurationValue1(value2); // environment
    }

    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    mservice.saveOrUpdateMerchantConfiguration(conf);
  }
  @Override
  public void deleteModule() throws Exception {
    ConfigurationResponse vo = this.getConfigurations();

    MerchantConfiguration conf =
        (MerchantConfiguration) vo.getConfiguration(PaymentConstants.PAYMENT_PAYPALNAME);

    if (conf != null) {
      MerchantService mservice =
          (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
      mservice.deleteMerchantConfiguration(conf);
    }
  }
  @Override
  public void saveModule() throws Exception {
    boolean fielderror = false;
    if (this.getKeys() == null || StringUtils.isBlank(this.getKeys().getKey1())) {
      addFieldError("keys.key1", getText("errors.required.fedexkey"));
      fielderror = true;
    }
    if (StringUtils.isBlank(this.getKeys().getUserid())) {
      addFieldError("keys.userid", getText("errors.required.userid"));
      fielderror = true;
    }
    if (StringUtils.isBlank(this.getKeys().getPassword())) {
      addFieldError("keys.password", getText("errors.required.fedexpassword"));
      fielderror = true;
    }
    if (StringUtils.isBlank(this.getKeys().getKey2())) {
      addFieldError("keys.key2", getText("errors.required.fedexmeter"));
      fielderror = true;
    }

    if (fielderror) {
      throw new ValidationException("Missing fields");
    }

    Context ctx =
        (Context) super.getServletRequest().getSession().getAttribute(ProfileConstants.context);
    Integer merchantid = ctx.getMerchantid();

    String submitedcredentials = ShippingUtil.buildShippingKeyLine(keys);

    String submitedproperties = ShippingUtil.buildShippingPropertiesLine(this.getProperties());

    String packageOption = getPackageSelection();

    List modulestosave =
        ShippingUtil.arrangeConfigurationsToSave(
            merchantid,
            configurations,
            moduleid,
            submitedcredentials,
            submitedproperties,
            packageOption,
            null,
            null);

    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    mservice.saveOrUpdateMerchantConfigurations(modulestosave);
  }
Ejemplo n.º 7
0
  @Transactional
  public boolean changeCustomerPassword(Customer customer, String oldPassword, String newPassword)
      throws Exception {
    String key = EncryptionUtil.generatekey(String.valueOf(SecurityConstants.idConstant));
    String encrypted = EncryptionUtil.encrypt(key, newPassword);

    String old = EncryptionUtil.encrypt(key, oldPassword);

    if (!customer.getCustomerPassword().equals(old)) {
      return false;
    }

    customer.setCustomerPassword(encrypted);

    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);

    // MerchantUserInformation minfo = mservice.getMerchantUserInfo(customer
    //		.getMerchantId());

    MerchantStore store = mservice.getMerchantStore(customer.getMerchantId());

    customerDao.saveOrUptade(customer);

    // send email
    String l = config.getString("core.system.defaultlanguage", "en");
    if (!StringUtils.isBlank(customer.getCustomerLang())) {
      l = customer.getCustomerLang();
    }

    LabelUtil lhelper = LabelUtil.getInstance();
    String subject = lhelper.getText(l, "label.profile.information");
    String info = lhelper.getText(l, "label.email.customer.portalinfo");
    String pass = lhelper.getText(l, "label.email.customer.passwordreset.text") + " " + newPassword;

    // @TODO replace suffix
    String url =
        "<a href=\""
            + config.getString("core.accountmanagement.portal.url")
            + "\">"
            + config.getProperty("core.accountmanagement.portal.url")
            + "</a>";
    String portalurl = lhelper.getText(l, "label.email.customer.portalurl") + " " + url;

    Map emailctx = new HashMap();
    emailctx.put("EMAIL_STORE_NAME", store.getStorename());
    emailctx.put("EMAIL_CUSTOMER_PASSWORD", pass);
    emailctx.put("EMAIL_CUSTOMER_PORTAL_INFO", info);
    emailctx.put("EMAIL_CUSTOMER_PORTAL_ENTRY", portalurl);
    emailctx.put("EMAIL_CONTACT_OWNER", store.getStoreemailaddress());

    CommonService cservice = new CommonService();

    cservice.sendHtmlEmail(
        customer.getCustomerEmailAddress(),
        subject,
        store,
        emailctx,
        "email_template_password_reset_customer.ftl",
        customer.getCustomerLang());

    return true;
  }
Ejemplo n.º 8
0
  /**
   * Reset a Customer password. Will also send an email the the customer with the new password
   *
   * @param customer
   * @throws Exception
   */
  @Transactional(rollbackFor = {Exception.class})
  public void resetCustomerPassword(Customer customer) throws Exception {

    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    MerchantStore store = mservice.getMerchantStore(customer.getMerchantId());
    // MerchantUserInformation minfo = mservice.getMerchantUserInfo(customer
    //		.getMerchantId());

    if (!customer.isCustomerAnonymous()) {

      // generate password
      PasswordGeneratorModule passwordGenerator =
          (PasswordGeneratorModule) SpringUtil.getBean("passwordgenerator");

      // encrypt
      String key = EncryptionUtil.generatekey(String.valueOf(SecurityConstants.idConstant));
      boolean found = true;

      String password = null;
      String encrypted = null;
      // validate if already exist
      while (found) {

        password = passwordGenerator.generatePassword();
        encrypted = EncryptionUtil.encrypt(key, password);
        Customer cfound =
            customerDao.findByUserNameAndPassword(customer.getCustomerNick(), encrypted);
        if (cfound == null) {
          found = false;
        }
      }

      // store in customer
      customer.setCustomerNick(customer.getCustomerEmailAddress());
      customer.setCustomerPassword(encrypted);
      customerDao.saveOrUptade(customer);

      // send email
      String l = config.getString("core.system.defaultlanguage", "en");
      if (!StringUtils.isBlank(customer.getCustomerLang())) {
        l = customer.getCustomerLang();
      }

      LabelUtil lhelper = LabelUtil.getInstance();
      String subject = lhelper.getText(l, "label.profile.information");
      String info = lhelper.getText(l, "label.email.customer.portalinfo");
      String pass = lhelper.getText(l, "label.email.customer.passwordreset.text") + " " + password;

      // @TODO replace suffix
      String url =
          "<a href=\""
              + config.getString("core.accountmanagement.portal.url")
              + "\">"
              + config.getString("core.accountmanagement.portal.url")
              + "</a>";
      String portalurl = lhelper.getText(l, "label.email.customer.portalurl") + " " + url;

      Map emailctx = new HashMap();
      emailctx.put("EMAIL_STORE_NAME", store.getStorename());
      emailctx.put("EMAIL_CUSTOMER_PASSWORD", pass);
      emailctx.put("EMAIL_CUSTOMER_PORTAL_INFO", info);
      emailctx.put("EMAIL_CONTACT_OWNER", store.getStoreemailaddress());

      CommonService cservice = new CommonService();
      cservice.sendHtmlEmail(
          customer.getCustomerEmailAddress(),
          subject,
          store,
          emailctx,
          "email_template_password_reset_customer.ftl",
          customer.getCustomerLang());
    }
  }
Ejemplo n.º 9
0
  @Transactional(rollbackFor = {Exception.class})
  public void saveOrUpdateCustomer(Customer customer, SystemUrlEntryType entryType, Locale locale)
      throws Exception {

    MerchantService mservice =
        (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);

    MerchantStore store = mservice.getMerchantStore(customer.getMerchantId());
    // MerchantUserInformation minfo = mservice.getMerchantUserInfo(customer
    //		.getMerchantId());

    if (entryType == null) {
      entryType = SystemUrlEntryType.WEB;
    }

    // check if email aleady exist

    boolean isNew = false;
    if (customer.getCustomerId() == 0) {
      isNew = true;
    }

    if (isNew && !customer.isCustomerAnonymous()) {

      // generate password
      PasswordGeneratorModule passwordGenerator =
          (PasswordGeneratorModule) SpringUtil.getBean("passwordgenerator");

      // encrypt
      String key = EncryptionUtil.generatekey(String.valueOf(SecurityConstants.idConstant));
      boolean found = true;

      String password = null;
      String encrypted = null;
      // validate if already exist
      while (found) {

        password = passwordGenerator.generatePassword();
        encrypted = EncryptionUtil.encrypt(key, password);
        Customer cfound =
            customerDao.findByUserNameAndPassword(customer.getCustomerNick(), encrypted);
        if (cfound == null) {
          found = false;
        }
      }

      // store in customer
      customer.setCustomerNick(customer.getCustomerEmailAddress());
      customer.setCustomerPassword(encrypted);

      // send email
      String l = config.getString("core.system.defaultlanguage", "en");
      if (!StringUtils.isBlank(customer.getCustomerLang())) {
        l = customer.getCustomerLang();
      }

      LabelUtil lhelper = LabelUtil.getInstance();
      String subject = lhelper.getText(l, "label.profile.information");
      List params = new ArrayList();
      params.add(store.getStorename());
      String greeting = lhelper.getText(locale, "label.email.customer.greeting", params);

      String username =
          lhelper.getText(l, "label.generic.customer.username") + " " + customer.getCustomerNick();
      String pass = lhelper.getText(l, "label.generic.customer.password") + " " + password;

      String info = "";
      String portalurl = "";

      if (entryType == SystemUrlEntryType.PORTAL) {
        info = lhelper.getText(l, "label.email.customer.portalinfo");
        String url =
            "<a href=\""
                + config.getProperty("core.accountmanagement.portal.url")
                + "/"
                + customer.getMerchantId()
                + "\">"
                + config.getProperty("core.accountmanagement.portal.url")
                + "/"
                + customer.getMerchantId()
                + "</a>";
        portalurl = lhelper.getText(l, "label.email.customer.portalurl") + " " + url;
      } else {
        info = lhelper.getText(l, "label.email.customer.webinfo");
        String url =
            "<a href=\""
                + ReferenceUtil.buildCatalogUri(store)
                + "/\">"
                + ReferenceUtil.buildCatalogUri(store)
                + "/landing.action?merchantId="
                + store.getMerchantId()
                + "</a>";
        portalurl = lhelper.getText(l, "label.email.customer.weburl") + " " + url;
      }

      Map emailctx = new HashMap();
      emailctx.put("EMAIL_STORE_NAME", store.getStorename());
      emailctx.put("EMAIL_CUSTOMER_FIRSTNAME", customer.getCustomerFirstname());
      emailctx.put("EMAIL_CUSTOMER_LAST", customer.getCustomerLastname());
      emailctx.put("EMAIL_CUSTOMER_USERNAME", username);
      emailctx.put("EMAIL_CUSTOMER_PASSWORD", pass);
      emailctx.put("EMAIL_GREETING", greeting);
      emailctx.put("EMAIL_CUSTOMER_PORTAL_INFO", info);
      emailctx.put("EMAIL_CUSTOMER_PORTAL_ENTRY", portalurl);
      emailctx.put("EMAIL_CONTACT_OWNER", store.getStoreemailaddress());

      CommonService cservice = new CommonService();
      cservice.sendHtmlEmail(
          customer.getCustomerEmailAddress(),
          subject,
          store,
          emailctx,
          "email_template_customer.ftl",
          customer.getCustomerLang());
    }

    customerDao.saveOrUptade(customer);

    // set CustomerInfo

    CustomerInfo customerInfo = new CustomerInfo();
    customerInfo.setCustomerInfoId(customer.getCustomerId());

    int login = customerInfo.getCustomerInfoNumberOfLogon();
    customerInfo.setCustomerInfoNumberOfLogon(login++);
    customerInfo.setCustomerInfoDateOfLastLogon(new Date());
    customerInfoDao.saveOrUpdate(customerInfo);
  }
Ejemplo n.º 10
0
  /**
   * Validates input parameters for a new subscription request
   *
   * @return
   */
  public boolean validateAddSubscription() {
    boolean success = true;
    if (value.getMerchantId() == 0) {
      addActionError(
          getText("error.validation.parameter.missing", new String[] {MERCHANT_ID_PARAM}));
      success = false;
    }
    if (value.getProductId() == 0) {
      addActionError(
          getText("error.validation.parameter.missing", new String[] {PRODUCT_ID_PARAM}));
      success = false;
    }

    if (success) {
      try {

        store = mservice.getMerchantStore(value.getMerchantId());
        Collection<MerchantUserInformation> minfo =
            mservice.getMerchantUserInfo(value.getMerchantId());

        if (store == null) {
          addActionError(
              getText(
                  "error.merchant.unavailable",
                  new String[] {String.valueOf(value.getMerchantId())}));
          return false;
        }

        // maybe this has to be done
        value.setCountryId(store.getCountry());

        // @TODO log to CommonService
        Product product = cservice.getProduct(value.getProductId());
        if (product == null || product.getMerchantId() != value.getMerchantId()) {
          LogMerchantUtil.log(
              value.getMerchantId(),
              getText(
                  "error.validation.merchant.product.ids",
                  new String[] {
                    String.valueOf(value.getProductId()), String.valueOf(value.getMerchantId())
                  }));
          addActionError(
              getText(
                  "error.validation.merchant.product.ids",
                  new String[] {
                    String.valueOf(value.getProductId()), String.valueOf(value.getMerchantId())
                  }));
          success = false;
        } else {
          if (product.getProductDateAvailable().after(new Date())) {
            LogMerchantUtil.log(
                value.getMerchantId(),
                getText(
                    "error.product.unavailable.purchase",
                    new String[] {String.valueOf(value.getProductId())}));
            addActionError(
                getText(
                    "error.product.unavailable.purchase",
                    new String[] {String.valueOf(value.getProductId())}));
            success = false;
          }
          if (product.getProductQuantity() == OUT_OF_STOCK_PRODUCT_QUANTITY) {
            LogMerchantUtil.log(
                value.getMerchantId(),
                getText(
                    "error.product.unavailable.purchase",
                    new String[] {String.valueOf(value.getProductId())}));
            addActionError(
                getText(
                    "error.product.unavailable.purchase",
                    new String[] {String.valueOf(value.getProductId())}));

            Configuration config = PropertiesUtil.getConfiguration();

            // MerchantProfile profile =
            // mservice.getMerchantProfile(value.getMerchantId());

            String l = config.getString("core.system.defaultlanguage", "en");

            if (minfo == null) {
              log.error("MerchantUserInformation is null for merchantId " + value.getMerchantId());
              addActionError(
                  getText(
                      "error.product.unavailable.purchase",
                      new String[] {String.valueOf(value.getProductId())}));
              // goto global error
              throw new Exception("Invalid MerchantId,Unable to find MerchantProfile");
            }

            MerchantUserInformation user = (MerchantUserInformation) ((List) minfo).get(0);

            if (!StringUtils.isBlank(user.getUserlang())) {
              l = user.getUserlang();
            }

            String description = "";

            Collection descriptionslist = product.getDescriptions();
            if (descriptionslist != null) {
              Iterator i = descriptionslist.iterator();
              while (i.hasNext()) {
                Object o = i.next();
                if (o instanceof ProductDescription) {
                  ProductDescription desc = (ProductDescription) o;
                  description = desc.getProductName();
                  if (desc.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(l)) {
                    description = desc.getProductName();
                    break;
                  }
                }
              }
            }

            List params = new ArrayList();
            params.add(description);
            params.add(product.getProductId());

            LabelUtil lhelper = LabelUtil.getInstance();
            String subject =
                lhelper.getText(super.getLocale(), "label.email.store.outofstock.subject");
            String productId =
                lhelper.getText(super.getLocale(), "label.email.store.outofstock.product", params);

            Map emailctx = new HashMap();
            emailctx.put("EMAIL_STORE_NAME", store.getStorename());
            emailctx.put("EMAIL_PRODUCT_TEXT", productId);

            CommonService cservice = new CommonService();
            cservice.sendHtmlEmail(
                store.getStoreemailaddress(),
                subject,
                store,
                emailctx,
                "email_template_outofstock.ftl",
                store.getDefaultLang());

            success = false;

          } else if (product.getProductQuantity() < LOW_STOCK_PRODUCT_QUANTITY) {

            Configuration config = PropertiesUtil.getConfiguration();

            // MerchantProfile profile =
            // mservice.getMerchantProfile(value.getMerchantId());

            String l = config.getString("core.system.defaultlanguage", "en");

            if (minfo == null) {
              log.error("MerchantUserInformationis null for merchantId " + value.getMerchantId());
              addActionError(
                  getText(
                      "error.product.unavailable.purchase",
                      new String[] {String.valueOf(value.getProductId())}));
              // goto global error
              throw new Exception("Invalid MerchantId,Unable to find MerchantProfile");
            }

            MerchantUserInformation user = (MerchantUserInformation) ((List) minfo).get(0);

            if (!StringUtils.isBlank(user.getUserlang())) {
              l = user.getUserlang();
            }

            String description = "";

            Collection descriptionslist = product.getDescriptions();
            if (descriptionslist != null) {
              Iterator i = descriptionslist.iterator();
              while (i.hasNext()) {
                Object o = i.next();
                if (o instanceof ProductDescription) {
                  ProductDescription desc = (ProductDescription) o;
                  description = desc.getProductName();
                  if (desc.getId().getLanguageId() == LanguageUtil.getLanguageNumberCode(l)) {
                    description = desc.getProductName();
                    break;
                  }
                }
              }
            }

            List params = new ArrayList();
            params.add(description);
            params.add(product.getProductId());

            LabelUtil lhelper = LabelUtil.getInstance();
            String subject = lhelper.getText(l, "label.email.store.lowinventory.subject");
            String productId =
                lhelper.getText(
                    super.getLocale(), "label.email.store.lowinventory.product", params);

            Map emailctx = new HashMap();
            emailctx.put("EMAIL_STORE_NAME", store.getStorename());
            emailctx.put("EMAIL_PRODUCT_TEXT", productId);

            CommonService cservice = new CommonService();
            cservice.sendHtmlEmail(
                store.getStoreemailaddress(),
                subject,
                store,
                emailctx,
                "email_template_lowstock.ftl",
                store.getDefaultLang());
          }
        }

      } catch (Exception e) {
        log.error("Exception occurred while getting product by Id", e);
        addActionError(getText("errors.technical"));
      }
    }

    return success;
  }