Rev 7178 | Rev 8263 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.recharge.controllers;import in.shop2020.model.v1.order.HotspotStore;import in.shop2020.model.v1.order.RechargeOrderStatus;import in.shop2020.model.v1.order.RechargeTransaction;import in.shop2020.model.v1.order.TransactionService;import in.shop2020.thrift.clients.TransactionClient;import java.nio.ByteBuffer;import javax.servlet.ServletOutputStream;public class RechargeResultController extends BaseController {private static final long serialVersionUID = 1L;private long rechargeId = 0l;private long paymentAmount;private RechargeTransaction recharge = null;public String index() {TransactionClient tcl;try {String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");if(loginStatus == null || !loginStatus.equals("TRUE")){return "authfail";}tcl = new TransactionClient();recharge = tcl.getClient().getRechargeTransaction(rechargeId);storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));if(!hotspotStores.containsKey(storeId)){try{HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");hotspotStores.put(storeId, hotSpotStore);} catch (Exception e) {log.error("Unable to get store", e);}}} catch (Exception e) {log.error("Unable to get recharge txn for id : " + rechargeId, e);return ":";}return "index";}public String getResultMessage() {if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {return "Recharge successful";}else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_FAILED|| recharge.getStatus() == RechargeOrderStatus.INIT) {return "Recharge Failed. Reason : " + recharge.getDescription();}else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_UNKNOWN) {return "Recharge Under Process";}else {return "There is some problem. Please try again later.";}}public boolean showPrintButton() {if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {return true;} else {return false;}}public String downloadInvoice() {ByteBuffer buffer = null;try {if (rechargeId == 0) {log.error("Recharge Id 0");return "index";}TransactionClient transactionServiceClient = new TransactionClient();TransactionService.Client orderClient = transactionServiceClient.getClient();buffer = orderClient.retrieveHotspotRechargeInvoice(rechargeId);if(!buffer.hasArray()) {log.error("The invoice was not found for rechargeId : " + rechargeId);}} catch (Exception e) {System.out.println(e.getMessage());}response.setContentType("application/pdf");response.setHeader("Content-disposition", "attachment; filename=recharge-invoice-" + rechargeId + ".pdf");ServletOutputStream sos;try {sos = response.getOutputStream();sos.write(buffer.array());sos.flush();} catch (Exception e) {System.out.println("Unable to stream the invoice file");}return "index";}public long getRechargeId() {return rechargeId;}public void setRechargeId(long rechargeId) {this.rechargeId = rechargeId;}public RechargeTransaction getRecharge() {return recharge;}public void setRecharge(RechargeTransaction recharge) {this.recharge = recharge;}public long getPaymentAmount() {return paymentAmount;}public void setPaymentAmount(long paymentAmount) {this.paymentAmount = paymentAmount;}}