Subversion Repositories SmartDukaan

Rev

Rev 7151 | Rev 7178 | 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
 
3
import in.shop2020.model.v1.order.RechargeOrderStatus;
4
import in.shop2020.model.v1.order.RechargeTransaction;
7109 anupam.sin 5
import in.shop2020.model.v1.order.TransactionService;
7080 anupam.sin 6
import in.shop2020.thrift.clients.TransactionClient;
7
 
7151 amit.gupta 8
import java.nio.ByteBuffer;
7080 anupam.sin 9
 
7151 amit.gupta 10
import javax.servlet.ServletOutputStream;
11
 
12
 
7080 anupam.sin 13
public class RechargeResultController extends BaseController {
14
 
15
    private static final long serialVersionUID = 1L;
7109 anupam.sin 16
    private long rechargeId = 0l;
7139 amit.gupta 17
    private long paymentAmount;
18
	private RechargeTransaction recharge = null;
7080 anupam.sin 19
 
20
 
21
    public String index() {
22
        TransactionClient tcl;
23
        try {
24
            tcl = new TransactionClient();
25
            recharge =  tcl.getClient().getRechargeTransaction(rechargeId);
26
        } catch (Exception e) {
27
            log.error("Unable to get recharge txn for id : " + rechargeId, e);
28
            return ":";
29
        }
30
        return "index";
31
    }
32
 
33
    public String getResultMessage() {
7143 amit.gupta 34
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
7080 anupam.sin 35
            return "Recharge successful";
36
        }
37
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_FAILED
38
                 || recharge.getStatus() == RechargeOrderStatus.INIT) {
39
            return "Recharge Failed";
40
        }
41
        else if (recharge.getStatus() == RechargeOrderStatus.RECHARGE_UNKNOWN) {
42
            return "Recharge Under Process";
43
        }
44
        else {
45
            return "There is some problem. Please try again later.";
7143 amit.gupta 46
        }
7080 anupam.sin 47
    }
48
 
49
    public boolean showPrintButton() {
7143 amit.gupta 50
        if(recharge.getStatus() == RechargeOrderStatus.RECHARGE_SUCCESSFUL) {
7080 anupam.sin 51
            return true;
52
        } else {
53
            return false;
7143 amit.gupta 54
        }
7080 anupam.sin 55
    }
56
 
7109 anupam.sin 57
    public String downloadInvoice() {
58
        ByteBuffer buffer = null;
59
        try {
60
            if (rechargeId == 0) {
61
                log.error("Recharge Id 0");
62
                return "index";
63
            }
64
            TransactionClient transactionServiceClient = new TransactionClient();
65
            TransactionService.Client orderClient = transactionServiceClient.getClient();
66
            buffer = orderClient.retrieveHotspotRechargeInvoice(rechargeId);
67
            if(!buffer.hasArray()) {
68
                log.error("The invoice was not found for rechargeId : " + rechargeId);
69
            }
70
        } catch (Exception e) {
71
            System.out.println(e.getMessage());
72
        }
7176 anupam.sin 73
        response.setContentType("application/pdf");
7109 anupam.sin 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
    public RechargeTransaction getRecharge() {
98
        return recharge;
99
    }
100
 
101
    public void setRecharge(RechargeTransaction recharge) {
102
        this.recharge = recharge;
103
    }
7139 amit.gupta 104
 
105
    public long getPaymentAmount() {
106
		return paymentAmount;
107
	}
108
 
109
	public void setPaymentAmount(long paymentAmount) {
110
		this.paymentAmount = paymentAmount;
111
	}
7080 anupam.sin 112
}