Subversion Repositories SmartDukaan

Rev

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