Subversion Repositories SmartDukaan

Rev

Rev 7143 | Rev 7176 | 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
        }
73
        response.setHeader("Content-disposition", "inline; filename=recharge-invoice-" + rechargeId + ".pdf");
74
 
75
        ServletOutputStream sos;
76
        try {
77
            sos = response.getOutputStream();
78
            sos.write(buffer.array());
79
            sos.flush();
80
        } catch (Exception e) {
81
            System.out.println("Unable to stream the invoice file");
82
        }
83
        return "index";
84
    }
7080 anupam.sin 85
 
7109 anupam.sin 86
 
7080 anupam.sin 87
    public long getRechargeId() {
88
        return rechargeId;
89
    }
90
 
91
 
92
    public void setRechargeId(long rechargeId) {
93
        this.rechargeId = rechargeId;
94
    }
95
 
96
    public RechargeTransaction getRecharge() {
97
        return recharge;
98
    }
99
 
100
    public void setRecharge(RechargeTransaction recharge) {
101
        this.recharge = recharge;
102
    }
7139 amit.gupta 103
 
104
    public long getPaymentAmount() {
105
		return paymentAmount;
106
	}
107
 
108
	public void setPaymentAmount(long paymentAmount) {
109
		this.paymentAmount = paymentAmount;
110
	}
7080 anupam.sin 111
}