Subversion Repositories SmartDukaan

Rev

Rev 7207 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7080 anupam.sin 1
package in.shop2020.recharge.controllers;
2
 
7207 anupam.sin 3
import in.shop2020.model.v1.order.HotspotStore;
7080 anupam.sin 4
import in.shop2020.model.v1.order.RechargeOrderStatus;
5
import in.shop2020.model.v1.order.RechargeTransaction;
7109 anupam.sin 6
import in.shop2020.model.v1.order.TransactionService;
7080 anupam.sin 7
import in.shop2020.thrift.clients.TransactionClient;
8
 
7151 amit.gupta 9
import java.nio.ByteBuffer;
7080 anupam.sin 10
 
7151 amit.gupta 11
import javax.servlet.ServletOutputStream;
12
 
13
 
7080 anupam.sin 14
public class RechargeResultController extends BaseController {
15
 
16
    private static final long serialVersionUID = 1L;
7109 anupam.sin 17
    private long rechargeId = 0l;
7139 amit.gupta 18
    private long paymentAmount;
19
	private RechargeTransaction recharge = null;
7080 anupam.sin 20
 
21
 
22
    public String index() {
23
        TransactionClient tcl;
24
        try {
7207 anupam.sin 25
            String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
26
            if(loginStatus == null || !loginStatus.equals("TRUE")){
27
                return "authfail";
28
            }
7080 anupam.sin 29
            tcl = new TransactionClient();
30
            recharge =  tcl.getClient().getRechargeTransaction(rechargeId);
7207 anupam.sin 31
            storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));
8263 anupam.sin 32
            try{
33
                HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");
34
                hotspotStores.put(storeId, hotSpotStore);
35
            } catch (Exception e) {
36
                log.error("Unable to get store", e);
7207 anupam.sin 37
            }
7080 anupam.sin 38
        } catch (Exception e) {
39
            log.error("Unable to get recharge txn for id : " + rechargeId, e);
40
            return ":";
41
        }
42
        return "index";
43
    }
44
 
45
    public String getResultMessage() {
7143 amit.gupta 46
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
7080 anupam.sin 47
            return "Recharge successful";
48
        }
49
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_FAILED
50
                 || recharge.getStatus() == RechargeOrderStatus.INIT) {
7178 anupam.sin 51
            return "Recharge Failed. Reason : " + recharge.getDescription();
7080 anupam.sin 52
        }
53
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_UNKNOWN) {
54
            return "Recharge Under Process";
55
        }
56
        else {
57
            return "There is some problem. Please try again later.";
7143 amit.gupta 58
        }
7080 anupam.sin 59
    }
60
 
61
    public boolean showPrintButton() {
7143 amit.gupta 62
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
7080 anupam.sin 63
            return true;
64
        } else {
65
            return false;
7143 amit.gupta 66
        }
7080 anupam.sin 67
    }
68
 
7109 anupam.sin 69
    public String downloadInvoice() {
70
        ByteBuffer buffer = null;
71
        try {
72
            if (rechargeId == 0) {
73
                log.error("Recharge Id 0");
74
                return "index";
75
            }
76
            TransactionClient transactionServiceClient = new TransactionClient();
77
            TransactionService.Client orderClient = transactionServiceClient.getClient();
78
            buffer = orderClient.retrieveHotspotRechargeInvoice(rechargeId);
79
            if(!buffer.hasArray()) {
80
                log.error("The invoice was not found for rechargeId : " + rechargeId);
81
            }
82
        } catch (Exception e) {
83
            System.out.println(e.getMessage());
84
        }
7176 anupam.sin 85
        response.setContentType("application/pdf");
7178 anupam.sin 86
        response.setHeader("Content-disposition", "attachment; filename=recharge-invoice-" + rechargeId + ".pdf");
7109 anupam.sin 87
 
88
        ServletOutputStream sos;
89
        try {
90
            sos = response.getOutputStream();
91
            sos.write(buffer.array());
92
            sos.flush();
93
        } catch (Exception e) {
94
            System.out.println("Unable to stream the invoice file");
95
        }
96
        return "index";
97
    }
7080 anupam.sin 98
 
7109 anupam.sin 99
 
7080 anupam.sin 100
    public long getRechargeId() {
101
        return rechargeId;
102
    }
103
 
104
 
105
    public void setRechargeId(long rechargeId) {
106
        this.rechargeId = rechargeId;
107
    }
108
 
109
    public RechargeTransaction getRecharge() {
110
        return recharge;
111
    }
112
 
113
    public void setRecharge(RechargeTransaction recharge) {
114
        this.recharge = recharge;
115
    }
7139 amit.gupta 116
 
117
    public long getPaymentAmount() {
118
		return paymentAmount;
119
	}
120
 
121
	public void setPaymentAmount(long paymentAmount) {
122
		this.paymentAmount = paymentAmount;
123
	}
7080 anupam.sin 124
}