errors.add("selectedProduct", new LocalizableError("com.zesped.action.BuyCredits.noCreditsSpecified"));
}
}
public Resolution buy() {
Order order = new Order();
try {
connect();
AtrilSession oSes = getSession();
Dms oDms = oSes.getDms();
CustomerAccount cacc = new CustomerAccount(oDms, getSessionAttribute("customer_account_docid"));
order = cacc.createOrder(oSes);
order.put("user_id", getSessionAttribute("user_docid"));
order.put("credits_bought", selectedProduct.getCredits());
order.save(oSes);
Log.out.info("Created order "+order.getString("order_id")+" for customer "+getSessionAttribute("customer_acount"));
OrderLine line = order.addLine(oSes, selectedProduct);
Log.out.info("Added order line for product "+selectedProduct.getString("product_name"));
order.put("base_price", line.getString("base_price"));
order.put("taxes", line.getString("taxes"));
order.put("taxespct", line.getString("taxespct"));
order.put("total_price", line.getString("subtotal_price"));
order.put("currency", line.getString("currency"));
order.save(oSes);
DAO.log(oSes, order.getDocument(), Order.class, "CREATE ORDER", AtrilEvent.Level.INFO, order.getDocument().id()+";"+getSessionAttribute("customer_acount")+";"+selectedProduct.getString("product_name"));
cacc.restoreCredits(oSes, new BigDecimal(selectedProduct.getCredits().longValue()));
Log.out.info("Added "+selectedProduct.getCredits().toString()+" credits to customer "+getSessionAttribute("customer_acount"));
DAO.log(oSes, cacc.getDocument(), CustomerAccount.class, "UPDATE CREDITS", AtrilEvent.Level.INFO, cacc.getDocument().id()+";"+cacc.get("credits_left"));