Subversion Repositories SmartDukaan

Rev

Rev 7178 | Rev 8263 | 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"));
32
            if(!hotspotStores.containsKey(storeId)){
33
                try{
34
                    HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");
35
                    hotspotStores.put(storeId, hotSpotStore);
36
                } catch (Exception e) {
37
                    log.error("Unable to get store", e);
38
                }
39
            }
7080 anupam.sin 40
        } catch (Exception e) {
41
            log.error("Unable to get recharge txn for id : " + rechargeId, e);
42
            return ":";
43
        }
44
        return "index";
45
    }
46
 
47
    public String getResultMessage() {
7143 amit.gupta 48
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
7080 anupam.sin 49
            return "Recharge successful";
50
        }
51
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_FAILED
52
                 || recharge.getStatus() == RechargeOrderStatus.INIT) {
7178 anupam.sin 53
            return "Recharge Failed. Reason : " + recharge.getDescription();
7080 anupam.sin 54
        }
55
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_UNKNOWN) {
56
            return "Recharge Under Process";
57
        }
58
        else {
59
            return "There is some problem. Please try again later.";
7143 amit.gupta 60
        }
7080 anupam.sin 61
    }
62
 
63
    public boolean showPrintButton() {
7143 amit.gupta 64
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
7080 anupam.sin 65
            return true;
66
        } else {
67
            return false;
7143 amit.gupta 68
        }
7080 anupam.sin 69
    }
70
 
7109 anupam.sin 71
    public String downloadInvoice() {
72
        ByteBuffer buffer = null;
73
        try {
74
            if (rechargeId == 0) {
75
                log.error("Recharge Id 0");
76
                return "index";
77
            }
78
            TransactionClient transactionServiceClient = new TransactionClient();
79
            TransactionService.Client orderClient = transactionServiceClient.getClient();
80
            buffer = orderClient.retrieveHotspotRechargeInvoice(rechargeId);
81
            if(!buffer.hasArray()) {
82
                log.error("The invoice was not found for rechargeId : " + rechargeId);
83
            }
84
        } catch (Exception e) {
85
            System.out.println(e.getMessage());
86
        }
7176 anupam.sin 87
        response.setContentType("application/pdf");
7178 anupam.sin 88
        response.setHeader("Content-disposition", "attachment; filename=recharge-invoice-" + rechargeId + ".pdf");
7109 anupam.sin 89
 
90
        ServletOutputStream sos;
91
        try {
92
            sos = response.getOutputStream();
93
            sos.write(buffer.array());
94
            sos.flush();
95
        } catch (Exception e) {
96
            System.out.println("Unable to stream the invoice file");
97
        }
98
        return "index";
99
    }
7080 anupam.sin 100
 
7109 anupam.sin 101
 
7080 anupam.sin 102
    public long getRechargeId() {
103
        return rechargeId;
104
    }
105
 
106
 
107
    public void setRechargeId(long rechargeId) {
108
        this.rechargeId = rechargeId;
109
    }
110
 
111
    public RechargeTransaction getRecharge() {
112
        return recharge;
113
    }
114
 
115
    public void setRecharge(RechargeTransaction recharge) {
116
        this.recharge = recharge;
117
    }
7139 amit.gupta 118
 
119
    public long getPaymentAmount() {
120
		return paymentAmount;
121
	}
122
 
123
	public void setPaymentAmount(long paymentAmount) {
124
		this.paymentAmount = paymentAmount;
125
	}
7080 anupam.sin 126
}