Subversion Repositories SmartDukaan

Rev

Rev 693 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 693 Rev 712
Line 16... Line 16...
16
import org.apache.thrift.TException;
16
import org.apache.thrift.TException;
17
 
17
 
18
@Results({
18
@Results({
19
    @Result(name="redirect", type="redirectAction", 
19
    @Result(name="redirect", type="redirectAction", 
20
    		params = {"actionName" , "login"}),
20
    		params = {"actionName" , "login"}),
-
 
21
	@Result(name="payredirect", type="redirectAction", 
21
	@Result(name="payredirect", location="${url}", type="redirect", params = {"paymentid" , "${payment-id}"}),
22
			params = {"actionName" , "${url}", "paymentid", "${pid}", "txnid", "${txn}", "amount", "${amount}"}),
22
    @Result(name="shipping-redirect", type="redirectAction", 
23
    @Result(name="shipping-redirect", type="redirectAction", 
23
    		params = {"actionName" , "shipping"})
24
    		params = {"actionName" , "shipping"}),
-
 
25
    @Result(name="failure", type="redirectAction", 
-
 
26
    		params = {"actionName" , "shipping"})    		
24
		
27
		
25
})
28
})
26
public class OrderController extends BaseController {
29
public class OrderController extends BaseController {
27
	
30
	
28
	private static final long serialVersionUID = 1L;
31
	private static final long serialVersionUID = 1L;
29
	
32
	
30
	private static Log log = LogFactory.getLog(OrderController.class);
33
	private static Log log = LogFactory.getLog(OrderController.class);
31
	private String id;
34
	private String id;
32
	
-
 
33
	private String message;
35
	private long txnId = 0;
34
	
36
	
35
	//FIXME right now only one PG. Once we will have more, need to fix it.
37
	//FIXME right now only one PG. Once we will have more, need to fix it.
36
	private String paymentUrl="hdfc-pay";
38
	private String paymentUrl="hdfc-pay";
37
	private int gatewayId=1;
39
	private int gatewayId=1;
38
	
40
	
39
	private long paymentId;
41
	private long paymentId;
40
	
42
	
-
 
43
	private double amount;
-
 
44
	
41
	public OrderController(){
45
	public OrderController(){
42
		super();
46
		super();
43
	}
47
	}
44
	
48
	
45
    // GET /order/ orderid
49
    // GET /order/ orderid
Line 60... Line 64...
60
    		setRedirectUrl();
64
    		setRedirectUrl();
61
    		return "redirect";
65
    		return "redirect";
62
    	}
66
    	}
63
    	long addressId = Long.parseLong(this.request.getParameter("addressid"));
67
    	long addressId = Long.parseLong(this.request.getParameter("addressid"));
64
    	long currentCartId = userinfo.getCartId();
68
    	long currentCartId = userinfo.getCartId();
65
    	double amount;
69
    	
66
		try{
70
		try{
67
			amount = Double.parseDouble(request.getParameter("amount"));
71
			amount = Double.parseDouble(request.getParameter("amount"));
68
		}catch(Exception e){
72
		}catch(Exception e){
69
			amount = Utils.getPaymentAmount(userinfo.getCartId());
73
			amount = Utils.getPaymentAmount(userinfo.getCartId());
70
		}
74
		}
71
 
75
 
72
		
-
 
73
    	List<Order> orders = null;
-
 
74
		try {
76
		try {
75
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
77
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
76
			in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
78
			in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
77
			
79
			
78
			userClient.addAddressToCart(currentCartId, addressId);
80
			userClient.addAddressToCart(currentCartId, addressId);
-
 
81
			//TODO validate only item quantity change. Other validations should not be done. 
79
			if(!userClient.validateCart(currentCartId)){
82
			if(!userClient.validateCart(currentCartId)){
-
 
83
				addActionError("Some items are added in your cart.");
80
				return "shipping-redirect";
84
				return "shipping-redirect";
81
			}
85
			}
82
			Long txnId = userClient.createOrders(currentCartId);
86
			txnId = userClient.createOrders(currentCartId);
83
			
87
			
84
			PaymentServiceClient paymentServiceClient = new PaymentServiceClient();
88
			PaymentServiceClient paymentServiceClient = new PaymentServiceClient();
85
			Client paymentClient = paymentServiceClient.getClient();
89
			Client paymentClient = paymentServiceClient.getClient();
86
			
90
			
87
			this.paymentId = paymentClient.createPayment(userinfo.getUserId(), amount, gatewayId, txnId);
91
			this.paymentId = paymentClient.createPayment(userinfo.getUserId(), amount, gatewayId, txnId);
88
			return "payredirect";
92
			return "payredirect";
89
			
93
			
90
			/*
94
			/*
91
			TransactionServiceClient tsc = new TransactionServiceClient();
-
 
92
			orders = tsc.getClient().getOrdersForTransaction(txnId);
-
 
93
			
-
 
94
			long newCartId = userClient.getUserById(userinfo.getUserId()).getActiveCartId();
-
 
95
			userinfo.setCartId(newCartId);
-
 
96
			userinfo.setTotalItems(0);
-
 
97
			
-
 
98
			011-46010946
95
			011-46010946
99
			*/
96
			*/
100
		} catch (TException e) {
97
		} catch (TException e) {
101
			e.printStackTrace();
98
			e.printStackTrace();
102
		} catch (Exception e) {
99
		} catch (Exception e) {
103
			e.printStackTrace();
100
			e.printStackTrace();
104
		}
101
		}
105
    	
102
    	
106
		this.message = "Your order numbers are as below:";
-
 
107
		
-
 
108
		for(Order order: orders){
-
 
109
			this.message = this.message  + "<br> <a href=\"./order/" + order.getId() + "\">" + order.getId() + "</a>";
-
 
110
		}
-
 
111
		
-
 
112
		return "success";
103
		return "failure";
113
    }
104
    }
114
    
105
    
115
	public String getId(){
106
	public String getId(){
116
		return id;
107
		return id;
117
	}
108
	}
Line 130... Line 121...
130
	
121
	
131
	public String getUrl(){
122
	public String getUrl(){
132
		return this.paymentUrl;
123
		return this.paymentUrl;
133
	}
124
	}
134
	
125
	
135
	public long getPaymentId(){
126
	public long getPid(){
136
		return this.paymentId;
127
		return this.paymentId;
137
	}
128
	}
138
	
129
	
139
	public String getMessage(){
130
	public long getTxn(){
140
		return this.message;
131
		return this.txnId;
141
	}
132
	}
-
 
133
	
-
 
134
	public double getAmount(){
-
 
135
		return this.amount;
-
 
136
	}
-
 
137
	
142
 
138
 
143
}
139
}