}
protected void finalizeOrder(ShoppingCartActionForm form, Site site, ShoppingCart shoppingCart, HttpServletRequest request, ActionMessages messages) throws Exception {
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
ContentBean contentBean = getContentBean(request);
PaymentEngine paymentEngine = (PaymentEngine) shoppingCart.getPaymentEngine();
createEmptySecureTemplateInfo(request);
OrderEngine orderEngine = null;
try {
SiteDomainParamBean siteDomainParamBean = SiteDomainDAO.getSiteDomainParamBean(contentBean.getContentSessionBean().getSiteDomain().getSiteDomainLanguage(),
contentBean.getContentSessionBean().getSiteDomain().getSiteDomainLanguage());
orderEngine = new OrderEngine(shoppingCart, null);
if (shoppingCart.isCashPaymentOrder()) {
orderEngine.processOrder();
orderEngine.saveOrder();
}
else {
String value = siteDomainParamBean.getPaymentProcessType();
boolean authorizeOnly = false;
if (value == null || value.equals(Constants.PAYMENT_PROCESS_TYPE_AUTHORIZE_ONLY)) {
authorizeOnly = true;
}
if (authorizeOnly) {
orderEngine.authorizeOrder(shoppingCart.getPaymentEngine(), request);
orderEngine.processOrder();
orderEngine.saveOrder();
}
else {
OrderHeader orderHeader = orderEngine.getOrderHeader();
InvoiceEngine invoiceEngine = new InvoiceEngine(orderHeader, null);
invoiceEngine.invoiceAll();
invoiceEngine.setCreditCardInfo(orderEngine.getCreditCardInfo());
invoiceEngine.payOrder(shoppingCart.getPaymentEngine(), request);
orderEngine.processOrder();
orderEngine.saveOrder();
invoiceEngine.saveOrder();
}
}
em.flush();
shoppingCart.setOrderNum(orderEngine.getOrderHeader().getOrderNum());
// em.getTransaction().commit();
}
catch (AuthorizationException e) {
throw e;
}
catch (PaymentException e) {
logger.error(e);
paymentEngine.abort();
shoppingCart.cancelTransaction();
throw e;
}
try {