Example #1
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;
  }
Example #2
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());
      }
    }
  }