Subversion Repositories SmartDukaan

Rev

Rev 7080 | Rev 7139 | 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
 
7109 anupam.sin 3
import java.nio.ByteBuffer;
4
 
5
import javax.servlet.ServletOutputStream;
6
 
7080 anupam.sin 7
import in.shop2020.model.v1.order.DeviceNumberInfo;
8
import in.shop2020.model.v1.order.RechargeOrderStatus;
9
import in.shop2020.model.v1.order.RechargeTransaction;
10
import in.shop2020.model.v1.order.RechargeType;
7109 anupam.sin 11
import in.shop2020.model.v1.order.TransactionService;
7080 anupam.sin 12
import in.shop2020.thrift.clients.TransactionClient;
13
 
14
 
15
public class RechargeResultController extends BaseController {
16
 
17
    private static final long serialVersionUID = 1L;
7109 anupam.sin 18
    private long rechargeId = 0l;
7080 anupam.sin 19
    private RechargeTransaction recharge = null;
20
 
21
 
22
    public String index() {
23
        TransactionClient tcl;
24
        try {
25
            tcl = new TransactionClient();
26
            recharge =  tcl.getClient().getRechargeTransaction(rechargeId);
27
        } catch (Exception e) {
28
            log.error("Unable to get recharge txn for id : " + rechargeId, e);
29
            return ":";
30
        }
31
        return "index";
32
    }
33
 
34
    public String getResultMessage() {
35
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
36
            return "Recharge successful";
37
        }
38
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_FAILED
39
                 || recharge.getStatus() == RechargeOrderStatus.INIT) {
40
            return "Recharge Failed";
41
        }
42
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_UNKNOWN) {
43
            return "Recharge Under Process";
44
        }
45
        else {
46
            return "There is some problem. Please try again later.";
47
        }
48
    }
49
 
50
    public boolean showPrintButton() {
51
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
52
            return true;
53
        } else {
54
            return false;
55
        }
56
    }
57
 
7109 anupam.sin 58
    public String downloadInvoice() {
59
        ByteBuffer buffer = null;
60
        try {
61
            if (rechargeId == 0) {
62
                log.error("Recharge Id 0");
63
                return "index";
64
            }
65
            TransactionClient transactionServiceClient = new TransactionClient();
66
            TransactionService.Client orderClient = transactionServiceClient.getClient();
67
            buffer = orderClient.retrieveHotspotRechargeInvoice(rechargeId);
68
            if(!buffer.hasArray()) {
69
                log.error("The invoice was not found for rechargeId : " + rechargeId);
70
            }
71
        } catch (Exception e) {
72
            System.out.println(e.getMessage());
73
        }
74
        response.setHeader("Content-disposition", "inline; filename=recharge-invoice-" + rechargeId + ".pdf");
75
 
76
        ServletOutputStream sos;
77
        try {
78
            sos = response.getOutputStream();
79
            sos.write(buffer.array());
80
            sos.flush();
81
        } catch (Exception e) {
82
            System.out.println("Unable to stream the invoice file");
83
        }
84
        return "index";
85
    }
7080 anupam.sin 86
 
7109 anupam.sin 87
 
7080 anupam.sin 88
    public long getRechargeId() {
89
        return rechargeId;
90
    }
91
 
92
 
93
    public void setRechargeId(long rechargeId) {
94
        this.rechargeId = rechargeId;
95
    }
96
 
97
 
98
    public RechargeTransaction getRecharge() {
99
        return recharge;
100
    }
101
 
102
 
103
    public void setRecharge(RechargeTransaction recharge) {
104
        this.recharge = recharge;
105
    }
106
}