Subversion Repositories SmartDukaan

Rev

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

Rev 689 Rev 693
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.model.v1.order.Order;
3
import in.shop2020.model.v1.order.Order;
-
 
4
import in.shop2020.payments.PaymentService.Client;
4
import in.shop2020.serving.controllers.BaseController;
5
import in.shop2020.serving.controllers.BaseController;
-
 
6
import in.shop2020.serving.utils.Utils;
5
import in.shop2020.thrift.clients.TransactionServiceClient;
7
import in.shop2020.thrift.clients.PaymentServiceClient;
6
import in.shop2020.thrift.clients.UserContextServiceClient;
8
import in.shop2020.thrift.clients.UserContextServiceClient;
7
 
9
 
8
import java.util.*;
10
import java.util.*;
9
 
11
 
10
import org.apache.juli.logging.Log;
12
import org.apache.juli.logging.Log;
Line 14... Line 16...
14
import org.apache.thrift.TException;
16
import org.apache.thrift.TException;
15
 
17
 
16
@Results({
18
@Results({
17
    @Result(name="redirect", type="redirectAction", 
19
    @Result(name="redirect", type="redirectAction", 
18
    		params = {"actionName" , "login"}),
20
    		params = {"actionName" , "login"}),
19
	@Result(name="payredirect", location="${url}", type="redirect")
21
	@Result(name="payredirect", location="${url}", type="redirect", params = {"paymentid" , "${payment-id}"}),
-
 
22
    @Result(name="shipping-redirect", type="redirectAction", 
-
 
23
    		params = {"actionName" , "shipping"})
20
		
24
		
21
})
25
})
22
public class OrderController extends BaseController {
26
public class OrderController extends BaseController {
23
	
27
	
24
	private static final long serialVersionUID = 1L;
28
	private static final long serialVersionUID = 1L;
Line 26... Line 30...
26
	private static Log log = LogFactory.getLog(OrderController.class);
30
	private static Log log = LogFactory.getLog(OrderController.class);
27
	private String id;
31
	private String id;
28
	
32
	
29
	private String message;
33
	private String message;
30
	
34
	
-
 
35
	//FIXME right now only one PG. Once we will have more, need to fix it.
31
	private String paymentUrl="hdfc-pay";
36
	private String paymentUrl="hdfc-pay";
-
 
37
	private int gatewayId=1;
-
 
38
	
-
 
39
	private long paymentId;
32
	
40
	
33
	public OrderController(){
41
	public OrderController(){
34
		super();
42
		super();
35
	}
43
	}
36
	
44
	
Line 52... Line 60...
52
    		setRedirectUrl();
60
    		setRedirectUrl();
53
    		return "redirect";
61
    		return "redirect";
54
    	}
62
    	}
55
    	long addressId = Long.parseLong(this.request.getParameter("addressid"));
63
    	long addressId = Long.parseLong(this.request.getParameter("addressid"));
56
    	long currentCartId = userinfo.getCartId();
64
    	long currentCartId = userinfo.getCartId();
-
 
65
    	double amount;
-
 
66
		try{
-
 
67
			amount = Double.parseDouble(request.getParameter("amount"));
-
 
68
		}catch(Exception e){
-
 
69
			amount = Utils.getPaymentAmount(userinfo.getCartId());
-
 
70
		}
-
 
71
 
-
 
72
		
57
    	List<Order> orders = null;
73
    	List<Order> orders = null;
58
		try {
74
		try {
59
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
75
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
60
			in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
76
			in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
61
			
77
			
62
			userClient.addAddressToCart(currentCartId, addressId);
78
			userClient.addAddressToCart(currentCartId, addressId);
-
 
79
			if(!userClient.validateCart(currentCartId)){
-
 
80
				return "shipping-redirect";
-
 
81
			}
63
			Long txn_id = userClient.createOrders(currentCartId);
82
			Long txnId = userClient.createOrders(currentCartId);
-
 
83
			
-
 
84
			PaymentServiceClient paymentServiceClient = new PaymentServiceClient();
-
 
85
			Client paymentClient = paymentServiceClient.getClient();
64
			
86
			
-
 
87
			this.paymentId = paymentClient.createPayment(userinfo.getUserId(), amount, gatewayId, txnId);
-
 
88
			return "payredirect";
-
 
89
			
-
 
90
			/*
65
			TransactionServiceClient tsc = new TransactionServiceClient();
91
			TransactionServiceClient tsc = new TransactionServiceClient();
66
			orders = tsc.getClient().getOrdersForTransaction(txn_id);
92
			orders = tsc.getClient().getOrdersForTransaction(txnId);
67
			
93
			
68
			long newCartId = userClient.getUserById(userinfo.getUserId()).getActiveCartId();
94
			long newCartId = userClient.getUserById(userinfo.getUserId()).getActiveCartId();
69
			userinfo.setCartId(newCartId);
95
			userinfo.setCartId(newCartId);
70
			userinfo.setTotalItems(0);
96
			userinfo.setTotalItems(0);
-
 
97
			
-
 
98
			011-46010946
-
 
99
			*/
71
		} catch (TException e) {
100
		} catch (TException e) {
72
			e.printStackTrace();
101
			e.printStackTrace();
73
		} catch (Exception e) {
102
		} catch (Exception e) {
74
			e.printStackTrace();
103
			e.printStackTrace();
75
		}
104
		}
Line 101... Line 130...
101
	
130
	
102
	public String getUrl(){
131
	public String getUrl(){
103
		return this.paymentUrl;
132
		return this.paymentUrl;
104
	}
133
	}
105
	
134
	
-
 
135
	public long getPaymentId(){
-
 
136
		return this.paymentId;
-
 
137
	}
-
 
138
	
106
	public String getMessage(){
139
	public String getMessage(){
107
		return this.message;
140
		return this.message;
108
	}
141
	}
109
 
142
 
110
}
143
}