Exemplo n.º 1
0
  // goes to summary page
  public String subscribe() {

    try {

      preparePage();
      validateCustomer();

      SessionUtil.setCustomer(customer, getServletRequest());

      prepareZones();

      if (this.getPaymentMethod() == null
          || this.getPaymentMethod().getPaymentModuleName() == null) {
        super.addActionError("error.nopaymentmethod");
        return INPUT;
      }

      super.getServletRequest().setAttribute("SELECTEDPAYMENT", this.getPaymentMethod());

      MerchantStore store = SessionUtil.getMerchantStore(getServletRequest());

      // check if payment method is credit card type
      if (com.salesmanager.core.util.PaymentUtil.isPaymentModuleCreditCardType(
          this.getPaymentMethod().getPaymentModuleName())) {
        super.validateCreditCard(this.getPaymentMethod(), store.getMerchantId());
      } else {
        super.setCreditCard(null); // reset credit card information
      }

      if (getFieldErrors().size() > 0) {
        return INPUT;
      }

      SessionUtil.setPaymentMethod(this.getPaymentMethod(), getServletRequest());

    } catch (Exception e) {
      log.error(e);
      super.addActionError(getText("error.process.notransaction"));
      return "GLOBALERROR";
    }

    return SUCCESS;
  }
Exemplo n.º 2
0
  @RequestMapping(
      value = {"/password/reset.html"},
      method = RequestMethod.POST)
  public String resetPassword(HttpServletRequest request) throws Exception {

    String userName = request.getParameter("resetpasswordusername");
    CustomerService cservice =
        (CustomerService) ServiceFactory.getService(ServiceFactory.CustomerService);

    MerchantStore store = SessionUtil.getMerchantStore(request);
    Customer customer = cservice.findCustomerByUserName(userName, store.getMerchantId());

    if (customer != null) {
      cservice.resetCustomerPassword(customer);
    }

    super.setMessage("label.customer.passwordreset", request);

    return "redirect:/home.html";
  }
Exemplo n.º 3
0
  /**
   * This methhod is for subscription step 1
   *
   * @return
   */
  public String displaySubscriptionForm() {

    try {

      // check if the session is still active
      Order o = SessionUtil.getOrder(getServletRequest());
      if (o == null) {
        super.addActionError(getText("error.sessionexpired"));
        return "GLOBALERROR";
      }

      // This is for the progress bar
      getServletRequest().setAttribute("STEP", "1");
      prepareZones();

      /*
       * //STUB CUSTOMER
       * customer=ShoppingCartUtil.getCustomer(getServletRequest());
       * customer.setCustomerEmailAddress("*****@*****.**");
       * customer.setCustomerFirstname("Carlito");
       * customer.setCustomerLastname("Samsonos");
       * customer.setCustomerBillingStreetAddress("358 Du Languedoc");
       * customer.setCustomerBillingCity("Boucherville");
       * customer.setCustomerBillingState("Quebec");
       * customer.setCustomerBillingZoneId(76);
       * customer.setCustomerBillingCountryId(38);
       * customer.setCustomerBillingPostalCode("J4B8J9");
       * customer.setCustomerTelephone("4504497181");
       * ShoppingCartUtil.setCustomer(customer, getServletRequest());
       */

      preparePage();
      return SUCCESS;
    } catch (Exception e) {
      super.addActionError(getText("error.process.notransaction"));
      log.error(e);
      return "GLOBALERROR";
    }
  }
Exemplo n.º 4
0
  /** Complete overwrite * */
  public String comitOrder() {

    try {

      boolean paymentProcessed = false;

      // Get all entities

      Order order = SessionUtil.getOrder(getServletRequest());
      MerchantStore store = SessionUtil.getMerchantStore(getServletRequest());

      PaymentMethod payment = SessionUtil.getPaymentMethod(getServletRequest());

      order.setPaymentMethod(payment.getPaymentMethodName());
      order.setPaymentModuleCode(payment.getPaymentModuleName());

      Customer customer = SessionUtil.getCustomer(getServletRequest());

      if (super.getServletRequest().getSession().getAttribute("TRANSACTIONCOMITED") != null) {
        addActionError(
            getText(
                "error.transaction.duplicate",
                new String[] {String.valueOf(order.getOrderId()), store.getStoreemailaddress()}));
        return "GENERICERROR";
      }

      OrderService oservice = (OrderService) ServiceFactory.getService(ServiceFactory.OrderService);

      try {

        Map orderProducts = SessionUtil.getOrderProducts(getServletRequest());
        Set s = new HashSet();

        for (Object o : orderProducts.values()) {

          OrderProduct op = (OrderProduct) o;
          s.add(op);
        }

        order.setOrderProducts(s);

        String comments = null;
        if (this.getOrderHistory() != null) {
          comments = this.getOrderHistory().getComments();
        }

        // Order, PaymentMethod,
        ProcessorContext context = new ProcessorContext();

        Collection files = oservice.getOrderProductDownloads(order.getOrderId());
        if (files != null && files.size() > 0) {
          context.addObject("files", files);
        }

        context.addObject("Order", order);
        context.addObject("Customer", customer);
        context.addObject("MerchantStore", store);
        context.addObject("PaymentMethod", payment);
        context.addObject("Locale", super.getLocale());
        context.addObject("comments", comments);
        context.addObject("products", orderProducts.values());

        WorkflowProcessor wp = (WorkflowProcessor) SpringUtil.getBean("invoiceWorkflow");
        wp.doWorkflow(context);

        paymentProcessed = true;

        // set an indicator in HTTPSession to prevent duplicates
        super.getServletRequest().getSession().setAttribute("TRANSACTIONCOMITED", "true");

        if (!StringUtils.isBlank(comments)) {
          SessionUtil.setOrderStatusHistory(this.getOrderHistory(), getServletRequest());
        }

      } catch (Exception e) {
        if (e instanceof TransactionException) {
          super.addErrorMessage("error.payment.paymenterror");
          return "PAYMENTERROR";
        }

        if (e instanceof OrderException) {
          try {
            oservice.sendOrderProblemEmail(order.getMerchantId(), order, customer, store);
          } catch (Exception ee) {
            log.error(ee);
          }
        }

        addActionError(
            getText(
                "message.error.comitorder.error",
                new String[] {String.valueOf(order.getOrderId()), store.getStoreemailaddress()}));
        log.error(e);
        return "GENERICERROR";
      }

      return SUCCESS;

    } catch (Exception e) {
      log.error(e);
    }

    return SUCCESS;
  }
Exemplo n.º 5
0
  private void prepareZones() {

    if (value != null && value.getProductId() > 0) {
      setCountries(RefUtil.getCountries(value.getLang()));

      if (this.customer == null) {

        customer = SessionUtil.getCustomer(getServletRequest());

        if (customer == null) {

          customer = new Customer();
          customer.setCustomerBillingCountryId(value.getCountryId());
        }
      }

      customer.setLocale(getLocale());

      SessionUtil.setCustomer(customer, getServletRequest());

      Collection zones =
          RefUtil.getZonesByCountry(customer.getCustomerBillingCountryId(), value.getLang());

      if (zones != null && zones.size() > 0) {
        setZonesByCountry(zones);
      } else {
        setZone(customer.getBillingState());
      }

    } else {

      if (this.customer == null) {

        customer = SessionUtil.getCustomer(getServletRequest());
      }
      if (customer != null) {

        customer.setLocale(super.getLocale());

        setCountries(RefUtil.getCountries(super.getLocale().getLanguage()));

        Collection zones =
            RefUtil.getZonesByCountry(
                customer.getCustomerBillingCountryId(),
                LocaleUtil.getDefaultLocale().getLanguage());

        if (zones != null && zones.size() > 0) {
          setZonesByCountry(zones);
        } else {
          setZone(customer.getBillingState());
        }
      } else {

        setCountries(RefUtil.getCountries(LocaleUtil.getDefaultLocale().getLanguage()));

        Configuration conf = PropertiesUtil.getConfiguration();
        int defaultCountry = conf.getInt("core.system.defaultcountryid");
        customer = new Customer();
        customer.setCustomerBillingCountryId(defaultCountry);
        customer.setLocale(super.getLocale());

        Collection zones =
            RefUtil.getZonesByCountry(
                customer.getCustomerBillingCountryId(),
                LocaleUtil.getDefaultLocale().getLanguage());

        if (zones != null && zones.size() > 0) {
          setZonesByCountry(zones);
        } else {
          setZone(customer.getBillingState());
        }

        SessionUtil.setCustomer(customer, getServletRequest());
      }
    }
  }
Exemplo n.º 6
0
  /**
   * Invoked after addSubscriptionItem
   *
   * @throws Exception
   */
  public void addItem() throws Exception {

    boolean quantityUpdated = false;

    // get store country
    Map lcountries =
        RefCache.getAllcountriesmap(LanguageUtil.getLanguageNumberCode(value.getLang()));
    if (lcountries != null) {
      Country country = (Country) lcountries.get(store.getCountry());
      getServletRequest().getSession().setAttribute("COUNTRY", country);
    }

    // check if language is supported by the store
    if (lcountries != null) {
      Country country = (Country) lcountries.get(store.getCountry());
      getServletRequest().getSession().setAttribute("COUNTRY", country);
    }

    // store can not be null, if it is the case, generic error page
    if (store == null) {
      throw new Exception("Invalid Store!");
    }

    // check if order product already exist. If that orderproduct already
    // exist
    // and has no ptoperties, so just update the quantity
    if (value.getAttributeId() == null
        || (value.getAttributeId() != null && value.getAttributeId().size() == 0)) {
      Map savedProducts = SessionUtil.getOrderProducts(getServletRequest());
      if (savedProducts != null) {
        Iterator it = savedProducts.keySet().iterator();
        while (it.hasNext()) {
          String line = (String) it.next();
          OrderProduct op = (OrderProduct) savedProducts.get(line);
          if (op.getProductId() == value.getProductId()) {
            Set attrs = op.getOrderattributes();
            if (attrs.size() == 0) {
              int qty = op.getProductQuantity();
              qty = qty + value.getQty();
              op.setProductQuantity(qty);
              quantityUpdated = true;
              break;
            }
          }
        }
      }
    }

    // create an order with merchantId and all dates
    // will need to create a new order id when submited
    Order order = SessionUtil.getOrder(getServletRequest());
    if (order == null) {
      order = new Order();
    }

    order.setMerchantId(store.getMerchantId());
    order.setDatePurchased(new Date());
    SessionUtil.setOrder(order, getServletRequest());

    if (!StringUtils.isBlank(value.getReturnUrl())) {
      // Return to merchant site Url is set from store.
      value.setReturnUrl(store.getContinueshoppingurl());
    }
    SessionUtil.setMerchantStore(store, getServletRequest());

    if (!quantityUpdated) { // new submission

      // Prepare order
      OrderProduct orderProduct =
          com.salesmanager.core.util.CheckoutUtil.createOrderProduct(
              value.getProductId(), getLocale(), store.getCurrency());
      orderProduct.setProductQuantity(value.getQty());
      orderProduct.setProductId(value.getProductId());

      List<OrderProductAttribute> attributes = new ArrayList<OrderProductAttribute>();
      if (value.getAttributeId() != null && value.getAttributeId().size() > 0) {
        for (Long attrId : value.getAttributeId()) {
          if (attrId != null && attrId != 0) {
            ProductAttribute pAttr =
                cservice.getProductAttributeByOptionValueAndProduct(value.getProductId(), attrId);
            if (pAttr != null && pAttr.getProductId() == value.getProductId()) {
              OrderProductAttribute orderAttr = new OrderProductAttribute();
              orderAttr.setProductOptionValueId(pAttr.getOptionValueId());

              attributes.add(orderAttr);
            } else {
              LogMerchantUtil.log(
                  value.getMerchantId(),
                  getText(
                      "error.validation.product.attributes.ids",
                      new String[] {String.valueOf(attrId), String.valueOf(value.getProductId())}));
            }
          }
        }
      }

      if (!attributes.isEmpty()) {
        // ShoppingCartUtil.addAttributesFromRawObjects(attributes,
        // orderProduct, store.getCurrency(), getServletRequest());
        com.salesmanager.core.util.CheckoutUtil.addAttributesToProduct(
            attributes, orderProduct, store.getCurrency(), getLocale());
      }

      Set attributesSet = new HashSet(attributes);
      orderProduct.setOrderattributes(attributesSet);

      SessionUtil.addOrderProduct(orderProduct, getServletRequest());
    }

    // because this is a submission, cannot continue browsing, so that's it
    // for the OrderProduct
    Map orderProducts = SessionUtil.getOrderProducts(super.getServletRequest());
    // transform to a list
    List products = new ArrayList();

    if (orderProducts != null) {
      Iterator i = orderProducts.keySet().iterator();
      while (i.hasNext()) {
        String line = (String) i.next();
        OrderProduct op = (OrderProduct) orderProducts.get(line);
        products.add(op);
      }
      super.getServletRequest().getSession().setAttribute("ORDER_PRODUCT_LIST", products);
    }

    // for displaying the order summary, need to create an OrderSummary
    // entity
    OrderTotalSummary summary =
        oservice.calculateTotal(order, products, store.getCurrency(), super.getLocale());

    Map totals =
        OrderUtil.getOrderTotals(
            order.getOrderId(), summary, store.getCurrency(), super.getLocale());

    HttpSession session = getServletRequest().getSession();

    // transform totals to a list
    List totalsList = new ArrayList();
    if (totals != null) {
      Iterator totalsIterator = totals.keySet().iterator();
      while (totalsIterator.hasNext()) {
        String key = (String) totalsIterator.next();
        OrderTotal total = (OrderTotal) totals.get(key);
        totalsList.add(total);
      }
    }

    SessionUtil.setOrderTotals(totalsList, getServletRequest());

    value.setLangId(LanguageUtil.getLanguageNumberCode(value.getLang()));
    prepareZones();

    // set locale according to the language passed in parameters and store
    // information
    Locale locale = LocaleUtil.getLocaleFromStoreEntity(store, value.getLang());
    setLocale(locale);
  }
Exemplo n.º 7
0
  public String execute(HttpServletRequest request) throws Exception {

    Customer customer = null;

    if (!validateCustomerLogon(request)) {

      LabelUtil l = LabelUtil.getInstance();
      Locale locale = LocaleUtil.getLocale(request);
      l.setLocale(locale);
      MessageUtil.addErrorMessage(request, l.getText(locale, "login.invalid"));
      return "redirect:/home.html";
    }
    try {

      CustomerLogonModule logon =
          (CustomerLogonModule) com.salesmanager.core.util.SpringUtil.getBean("customerLogon");

      // get merchantId
      int merchantId = 1;
      HttpSession session = request.getSession();
      MerchantStore store = (MerchantStore) session.getAttribute("STORE");
      if (store != null) {
        merchantId = store.getMerchantId();
      }

      customer = logon.logon(request, merchantId);

      if (customer == null) {

        MessageUtil.addErrorMessage(request, super.getText(request, "login.invalid"));
        return "redirect:/home.html";
      }

      Locale locale = LocaleUtil.getLocale(request);
      customer.setLocale(locale);

      // get CustomerInfo
      CustomerService cservice =
          (CustomerService) ServiceFactory.getService(ServiceFactory.CustomerService);
      CustomerInfo customerInfo = cservice.findCustomerInfoById(customer.getCustomerId());

      if (customerInfo == null) {
        customerInfo = new CustomerInfo();
        customerInfo.setCustomerInfoId(customer.getCustomerId());
      }

      Integer login = customerInfo.getCustomerInfoNumberOfLogon();
      login = login + 1;
      customerInfo.setCustomerInfoNumberOfLogon(login);
      cservice.saveOrUpdateCustomerInfo(customerInfo);

      SessionUtil.setCustomer(customer, request);
      request.setAttribute("CUSTOMER", customer);

      return "redirect:/profile/profile.html";

    } catch (ServiceException e) {

      MessageUtil.addErrorMessage(request, super.getText(request, "login.invalid"));
      return "redirect:/home.html";

    } catch (Exception ex) {
      log.error(ex);
      throw ex;
    }
  }