Subversion Repositories SmartDukaan

Rev

Rev 8263 | 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;
13014 kshitij.so 4
import in.shop2020.model.v1.order.RechargeOrder;
7080 anupam.sin 5
import in.shop2020.model.v1.order.RechargeOrderStatus;
6
import in.shop2020.model.v1.order.RechargeTransaction;
7109 anupam.sin 7
import in.shop2020.model.v1.order.TransactionService;
7080 anupam.sin 8
import in.shop2020.thrift.clients.TransactionClient;
9
 
7151 amit.gupta 10
import java.nio.ByteBuffer;
13014 kshitij.so 11
import java.util.Arrays;
12
import java.util.List;
7080 anupam.sin 13
 
7151 amit.gupta 14
import javax.servlet.ServletOutputStream;
15
 
13014 kshitij.so 16
import org.apache.struts2.convention.annotation.Result;
17
import org.apache.struts2.convention.annotation.Results;
18
import org.apache.thrift.TException;
7151 amit.gupta 19
 
13014 kshitij.so 20
@Results({
21
    @Result(name = "recharge-status", location = "recharge-status.vm")
22
})
23
 
24
 
7080 anupam.sin 25
public class RechargeResultController extends BaseController {
26
 
27
    private static final long serialVersionUID = 1L;
7109 anupam.sin 28
    private long rechargeId = 0l;
7139 amit.gupta 29
    private long paymentAmount;
30
	private RechargeTransaction recharge = null;
13014 kshitij.so 31
	private static List<Long> asyncOperators = Arrays.asList(9l);
32
	private boolean rechargeModeSynchronous = false;
33
    private String isFinal;
34
    private String newStatus;
7080 anupam.sin 35
 
36
 
37
    public String index() {
38
        TransactionClient tcl;
39
        try {
7207 anupam.sin 40
            String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
41
            if(loginStatus == null || !loginStatus.equals("TRUE")){
42
                return "authfail";
43
            }
7080 anupam.sin 44
            tcl = new TransactionClient();
45
            recharge =  tcl.getClient().getRechargeTransaction(rechargeId);
7207 anupam.sin 46
            storeId = Long.parseLong((String) request.getSession().getAttribute("STORE_ID"));
13014 kshitij.so 47
            log.info("Store id****");
48
            log.info((String)request.getSession().getAttribute("STORE_ID"));
8263 anupam.sin 49
            try{
50
                HotspotStore hotSpotStore = (new TransactionClient()).getClient().getHotspotStore(storeId, "");
51
                hotspotStores.put(storeId, hotSpotStore);
52
            } catch (Exception e) {
53
                log.error("Unable to get store", e);
7207 anupam.sin 54
            }
7080 anupam.sin 55
        } catch (Exception e) {
56
            log.error("Unable to get recharge txn for id : " + rechargeId, e);
57
            return ":";
58
        }
59
        return "index";
60
    }
61
 
62
    public String getResultMessage() {
7143 amit.gupta 63
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
7080 anupam.sin 64
            return "Recharge successful";
65
        }
66
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_FAILED
67
                 || recharge.getStatus() == RechargeOrderStatus.INIT) {
7178 anupam.sin 68
            return "Recharge Failed. Reason : " + recharge.getDescription();
7080 anupam.sin 69
        }
70
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_UNKNOWN) {
71
            return "Recharge Under Process";
72
        }
13014 kshitij.so 73
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_IN_PROCESS){
74
            return "Please wait while we check recharge with operator.Donot close this window.";
75
        }
7080 anupam.sin 76
        else {
77
            return "There is some problem. Please try again later.";
7143 amit.gupta 78
        }
7080 anupam.sin 79
    }
13014 kshitij.so 80
 
81
    public String getRechargeStatus() throws NumberFormatException, TException{
82
        TransactionClient transactionServiceClient = null;
83
        transactionServiceClient = new TransactionClient();
84
        recharge = transactionServiceClient.getClient().getRcgTransactionStatus(rechargeId, Boolean.valueOf(isFinal));
85
        setNewStatus(recharge.getStatus().name());
86
        return "recharge-status";
87
    }
7080 anupam.sin 88
 
89
    public boolean showPrintButton() {
7143 amit.gupta 90
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
7080 anupam.sin 91
            return true;
92
        } else {
93
            return false;
7143 amit.gupta 94
        }
7080 anupam.sin 95
    }
96
 
7109 anupam.sin 97
    public String downloadInvoice() {
98
        ByteBuffer buffer = null;
99
        try {
100
            if (rechargeId == 0) {
101
                log.error("Recharge Id 0");
102
                return "index";
103
            }
104
            TransactionClient transactionServiceClient = new TransactionClient();
105
            TransactionService.Client orderClient = transactionServiceClient.getClient();
106
            buffer = orderClient.retrieveHotspotRechargeInvoice(rechargeId);
107
            if(!buffer.hasArray()) {
108
                log.error("The invoice was not found for rechargeId : " + rechargeId);
109
            }
110
        } catch (Exception e) {
111
            System.out.println(e.getMessage());
112
        }
7176 anupam.sin 113
        response.setContentType("application/pdf");
7178 anupam.sin 114
        response.setHeader("Content-disposition", "attachment; filename=recharge-invoice-" + rechargeId + ".pdf");
7109 anupam.sin 115
 
116
        ServletOutputStream sos;
117
        try {
118
            sos = response.getOutputStream();
119
            sos.write(buffer.array());
120
            sos.flush();
121
        } catch (Exception e) {
122
            System.out.println("Unable to stream the invoice file");
123
        }
124
        return "index";
125
    }
7080 anupam.sin 126
 
7109 anupam.sin 127
 
7080 anupam.sin 128
    public long getRechargeId() {
129
        return rechargeId;
130
    }
131
 
132
 
133
    public void setRechargeId(long rechargeId) {
134
        this.rechargeId = rechargeId;
135
    }
136
 
137
    public RechargeTransaction getRecharge() {
138
        return recharge;
139
    }
140
 
141
    public void setRecharge(RechargeTransaction recharge) {
142
        this.recharge = recharge;
143
    }
7139 amit.gupta 144
 
145
    public long getPaymentAmount() {
146
		return paymentAmount;
147
	}
148
 
149
	public void setPaymentAmount(long paymentAmount) {
150
		this.paymentAmount = paymentAmount;
151
	}
13014 kshitij.so 152
 
153
    public void setRechargeModeSynchronous(boolean rechargeModeSynchronous) {
154
        this.rechargeModeSynchronous = rechargeModeSynchronous;
155
    }
156
 
157
    public boolean isRechargeModeSynchronous() {
158
        return rechargeModeSynchronous;
159
    }
160
 
161
    public void setIsFinal(String isFinal) {
162
        this.isFinal = isFinal;
163
    }
164
 
165
    public String getIsFinal() {
166
        return isFinal;
167
    }
168
 
169
    public void setNewStatus(String newStatus) {
170
        log.info(newStatus);
171
        this.newStatus = newStatus;
172
    }
173
 
174
    public String getNewStatus() {
175
        return newStatus;
176
    }
7080 anupam.sin 177
}