Example #1
0
 public void authorizeOrder(PaymentEngine paymentEngine, HttpServletRequest request)
     throws AuthorizationException, PaymentException, Exception {
   if (!isOpen(orderHeader)) {
     throw new PaymentException("Order is not open");
   }
   if (!shoppingCart.isCashPaymentOrder()) {
     paymentEngine.setCreditCardInfo(creditCardInfo);
     shoppingCart.getPaymentEngine().authorizePayment(orderHeader, request);
     PaymentTran paymentTran = new PaymentTran();
     paymentTran.setAuthCode(paymentEngine.getAuthCode());
     paymentTran.setPaymentReference1(paymentEngine.getPaymentReference1());
     paymentTran.setPaymentReference2(paymentEngine.getPaymentReference2());
     paymentTran.setPaymentReference3(paymentEngine.getPaymentReference3());
     paymentTran.setPaymentReference4(paymentEngine.getPaymentReference4());
     paymentTran.setPaymentReference5(paymentEngine.getPaymentReference5());
     paymentTran.setTranDatetime(new Date());
     orderHeader.setPaymentTran(paymentTran);
     orderHeader.setPaymentGatewayProvider(paymentEngine.getClass().getSimpleName());
   }
   orderHeader.setOrderStatus(calcStatus(orderHeader));
 }
Example #2
0
  public void saveOrder() throws Exception {
    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    String userId = user == null ? Constants.USERNAME_SYSTEM : user.getUserId();
    Date current = new Date();

    saveHeader();
    orderHeader.setOrderAbundantLoc("");

    Iterator<?> iterator = null;
    iterator = orderHeader.getOrderItemDetails().iterator();
    while (iterator.hasNext()) {
      OrderItemDetail orderItemDetail = (OrderItemDetail) iterator.next();
      if (!isDirty(orderItemDetail.getItemSkuCd())) {
        continue;
      }
      if (orderItemDetail.getItem() != null) {
        InventoryEngine engine = new InventoryEngine(orderItemDetail.getItem());
        engine.adjustBookedQty(orderItemDetail.getItemOrderQty());
      }
      if (orderItemDetail.getRecCreateDatetime() == null) {
        orderItemDetail.setRecCreateBy(userId);
        orderItemDetail.setRecCreateDatetime(current);
      }
      orderItemDetail.setRecUpdateBy(userId);
      orderItemDetail.setRecUpdateDatetime(current);
      if (orderItemDetail.getOrderItemDetailId() == null) {
        em.persist(orderItemDetail);
      }

      Iterator<?> attributes = orderItemDetail.getOrderAttributeDetails().iterator();
      while (attributes.hasNext()) {
        OrderAttributeDetail orderAttributeDetail = (OrderAttributeDetail) attributes.next();
        if (orderAttributeDetail.getRecCreateDatetime() == null) {
          orderAttributeDetail.setRecCreateBy(userId);
          orderAttributeDetail.setRecCreateDatetime(current);
        }
        orderAttributeDetail.setRecUpdateBy(userId);
        orderAttributeDetail.setRecUpdateDatetime(current);
        if (orderAttributeDetail.getOrderAttribDetailId() == null) {
          em.persist(orderAttributeDetail);
        }
      }

      Iterator<?> taxes = orderItemDetail.getOrderDetailTaxes().iterator();
      while (taxes.hasNext()) {
        OrderDetailTax orderDetailTax = (OrderDetailTax) taxes.next();
        if (orderDetailTax.getRecCreateDatetime() == null) {
          orderDetailTax.setRecCreateBy(userId);
          orderDetailTax.setRecCreateDatetime(current);
        }
        orderDetailTax.setRecUpdateBy(userId);
        orderDetailTax.setRecUpdateDatetime(current);
        if (orderDetailTax.getOrderDetailTaxId() == null) {
          em.persist(orderDetailTax);
        }
      }
    }

    iterator = orderHeader.getOrderOtherDetails().iterator();
    while (iterator.hasNext()) {
      OrderOtherDetail orderOtherDetail = (OrderOtherDetail) iterator.next();
      if (isDirty(orderOtherDetail.getCoupon())) {
        if (orderOtherDetail.getRecCreateDatetime() == null) {
          orderOtherDetail.setRecCreateBy(userId);
          orderOtherDetail.setRecCreateDatetime(current);
          orderOtherDetail.setOrderHeader(orderHeader);
        }
        orderOtherDetail.setRecUpdateBy(userId);
        orderOtherDetail.setRecUpdateDatetime(current);
        if (orderOtherDetail.getOrderOtherDetailId() == null) {
          em.persist(orderOtherDetail);
        }
      }
    }

    PaymentTran paymentTran = orderHeader.getPaymentTran();
    if (paymentTran != null) {
      if (paymentTran.getRecUpdateDatetime() == null) {
        paymentTran.setRecCreateBy(userId);
        paymentTran.setRecCreateDatetime(current);
        paymentTran.setRecUpdateBy(userId);
        paymentTran.setRecUpdateDatetime(current);
        if (paymentTran.getPaymentTranId() == null) {
          em.persist(paymentTran);
        }
      }
    }
    paymentTran = orderHeader.getVoidPaymentTran();
    if (paymentTran != null) {
      if (paymentTran.getRecUpdateDatetime() == null) {
        paymentTran.setRecCreateBy(userId);
        paymentTran.setRecCreateDatetime(current);
        paymentTran.setRecUpdateBy(userId);
        paymentTran.setRecUpdateDatetime(current);
        if (paymentTran.getPaymentTranId() == null) {
          em.persist(paymentTran);
        }
      }
    }

    if (orderHeader.getCustAddress() != null) {
      OrderAddress custAddress = orderHeader.getCustAddress();
      if (custAddress.getRecCreateBy() == null) {
        custAddress.setRecCreateBy(userId);
        custAddress.setRecCreateDatetime(current);
      }
      custAddress.setRecUpdateBy(userId);
      custAddress.setRecUpdateDatetime(current);
      if (orderHeader.getCustAddress().getOrderAddressId() == null) {
        em.persist(orderHeader.getCustAddress());
      }
    }
    if (orderHeader.getShippingAddress() != null) {
      OrderAddress shippingAddress = orderHeader.getShippingAddress();
      if (shippingAddress.getRecCreateBy() == null) {
        shippingAddress.setRecCreateBy(userId);
        shippingAddress.setRecCreateDatetime(current);
      }
      shippingAddress.setRecUpdateBy(userId);
      shippingAddress.setRecUpdateDatetime(current);
      if (orderHeader.getShippingAddress().getOrderAddressId() == null) {
        em.persist(orderHeader.getShippingAddress());
      }
    }
    if (orderHeader.getBillingAddress() != null) {
      OrderAddress billingAddress = orderHeader.getBillingAddress();
      if (billingAddress.getRecCreateBy() == null) {
        billingAddress.setRecCreateBy(userId);
        billingAddress.setRecCreateDatetime(current);
      }
      billingAddress.setRecUpdateBy(userId);
      billingAddress.setRecUpdateDatetime(current);
      if (orderHeader.getBillingAddress().getOrderAddressId() == null) {
        em.persist(orderHeader.getBillingAddress());
      }
    }

    Iterator<?> taxes = orderHeader.getOrderTaxes().iterator();
    while (taxes.hasNext()) {
      OrderDetailTax orderDetailTax = (OrderDetailTax) taxes.next();
      if (orderDetailTax.getRecCreateDatetime() == null) {
        orderDetailTax.setRecCreateBy(userId);
        orderDetailTax.setRecCreateDatetime(current);
      }
      orderDetailTax.setRecUpdateBy(userId);
      orderDetailTax.setRecUpdateDatetime(current);
      if (orderDetailTax.getOrderDetailTaxId() == null) {
        em.persist(orderDetailTax);
      }
    }
    //		orderHeader.setOrderStatus(calcStatus(orderHeader));

    this.clean();
    isNew = false;
  }