示例#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;
  }