Subversion Repositories SmartDukaan

Rev

Rev 12616 | Rev 12789 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12616 Rev 12788
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.datalogger.EventType;
-
 
4
import in.shop2020.model.v1.inventory.Warehouse;
3
import in.shop2020.model.v1.inventory.Warehouse;
5
import in.shop2020.model.v1.order.Attribute;
4
import in.shop2020.model.v1.order.Attribute;
6
import in.shop2020.model.v1.order.Order;
5
import in.shop2020.model.v1.order.Order;
7
import in.shop2020.model.v1.order.OrderSource;
6
import in.shop2020.model.v1.order.OrderSource;
-
 
7
import in.shop2020.model.v1.order.OrderType;
8
import in.shop2020.model.v1.order.TransactionServiceException;
8
import in.shop2020.model.v1.order.TransactionServiceException;
9
import in.shop2020.model.v1.user.Address;
9
import in.shop2020.model.v1.user.Address;
10
import in.shop2020.model.v1.user.Cart;
10
import in.shop2020.model.v1.user.Cart;
-
 
11
import in.shop2020.model.v1.user.PrivateDealUser;
11
import in.shop2020.model.v1.user.ShoppingCartException;
12
import in.shop2020.model.v1.user.ShoppingCartException;
-
 
13
import in.shop2020.model.v1.user.User;
12
import in.shop2020.serving.interceptors.TrackingInterceptor;
14
import in.shop2020.serving.interceptors.TrackingInterceptor;
13
import in.shop2020.serving.services.CodPaymentService;
15
import in.shop2020.serving.services.CodPaymentService;
14
import in.shop2020.serving.services.CommonPaymentService;
16
import in.shop2020.serving.services.CommonPaymentService;
15
import in.shop2020.serving.services.CouponPaymentService;
17
import in.shop2020.serving.services.CouponPaymentService;
16
import in.shop2020.serving.services.EbsPaymentService;
18
import in.shop2020.serving.services.EbsPaymentService;
17
import in.shop2020.serving.services.HdfcEmiPaymentService;
19
import in.shop2020.serving.services.HdfcEmiPaymentService;
18
import in.shop2020.serving.services.HdfcPaymentService;
20
import in.shop2020.serving.services.HdfcPaymentService;
19
import in.shop2020.serving.services.IPaymentService;
21
import in.shop2020.serving.services.IPaymentService;
20
import in.shop2020.serving.services.InnovitiPaymentService;
22
import in.shop2020.serving.services.InnovitiPaymentService;
21
//import in.shop2020.serving.services.PayuPaymentService;
-
 
22
import in.shop2020.serving.utils.DesEncrypter;
23
import in.shop2020.serving.utils.DesEncrypter;
23
import in.shop2020.serving.utils.Utils;
24
import in.shop2020.serving.utils.Utils;
24
import in.shop2020.thrift.clients.InventoryClient;
25
import in.shop2020.thrift.clients.InventoryClient;
25
import in.shop2020.thrift.clients.TransactionClient;
26
import in.shop2020.thrift.clients.TransactionClient;
26
import in.shop2020.thrift.clients.UserClient;
27
import in.shop2020.thrift.clients.UserClient;
27
import in.shop2020.utils.DataLogger;
-
 
28
import in.shop2020.utils.FedExShipAccountInfo;
28
import in.shop2020.utils.FedExShipAccountInfo;
29
 
29
 
30
import java.util.ArrayList;
30
import java.util.ArrayList;
31
import java.util.Arrays;
31
import java.util.Arrays;
32
import java.util.List;
32
import java.util.List;
33
 
33
 
-
 
34
import nl.captcha.Captcha;
-
 
35
 
34
import org.apache.log4j.Logger;
36
import org.apache.log4j.Logger;
35
import org.apache.struts2.convention.annotation.InterceptorRef;
37
import org.apache.struts2.convention.annotation.InterceptorRef;
36
import org.apache.struts2.convention.annotation.InterceptorRefs;
38
import org.apache.struts2.convention.annotation.InterceptorRefs;
37
import org.apache.struts2.convention.annotation.Result;
39
import org.apache.struts2.convention.annotation.Result;
38
import org.apache.struts2.convention.annotation.Results;
40
import org.apache.struts2.convention.annotation.Results;
Line 47... Line 49...
47
import com.fedex.ship.stub.PackageOperationalDetail;
49
import com.fedex.ship.stub.PackageOperationalDetail;
48
import com.fedex.ship.stub.ProcessShipmentReply;
50
import com.fedex.ship.stub.ProcessShipmentReply;
49
import com.fedex.ship.stub.StringBarcode;
51
import com.fedex.ship.stub.StringBarcode;
50
import com.fedex.ship.stub.TrackingId;
52
import com.fedex.ship.stub.TrackingId;
51
 
53
 
52
import nl.captcha.Captcha;
-
 
53
 
-
 
54
@SuppressWarnings("serial")
54
@SuppressWarnings("serial")
55
@InterceptorRefs({
55
@InterceptorRefs({
56
    @InterceptorRef("myDefault"),
56
    @InterceptorRef("myDefault"),
57
    @InterceptorRef("login")
57
    @InterceptorRef("login")
58
})
58
})
Line 94... Line 94...
94
    }
94
    }
95
 
95
 
96
    // POST /order/
96
    // POST /order/
97
    public String create(){
97
    public String create(){
98
    	String addressIdString = this.request.getParameter("addressid");
98
    	String addressIdString = this.request.getParameter("addressid");
-
 
99
    	OrderType orderType = OrderType.B2C;
-
 
100
    	String tin = null;
-
 
101
    	if(userinfo.isPrivateDealUser()){
-
 
102
    		try {
-
 
103
    			UserClient userServiceClient = new UserClient();
-
 
104
                in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
-
 
105
                PrivateDealUser user = userClient.getPrivateDealUser(userinfo.getUserId());
-
 
106
                if(user.getTin() != null && !user.getTin().equals("")) {
-
 
107
                	orderType = OrderType.B2B;
-
 
108
                	tin = user.getTin().trim();
-
 
109
                }
-
 
110
                    
-
 
111
            } catch (Exception e) {
-
 
112
                log.error("Unable to talk to the user context service.", e);
-
 
113
                addActionError("We are experiencing some problems. Please try later.");
-
 
114
                return "proceed-to-pay-redirect";
-
 
115
            }
-
 
116
    	}
99
    	if(addressIdString == null){
117
    	if(addressIdString == null){
100
    		addActionError("Please specify shipping address to continue.");
118
    		addActionError("Please specify shipping address to continue.");
101
    		return "proceed-to-pay-redirect";
119
    		return "proceed-to-pay-redirect";
102
    	}
120
    	}
103
    	
121
    	
Line 172... Line 190...
172
    	try {
190
    	try {
173
    		if(!createOrders(addressId, currentCartId, currentUserId, Long.parseLong(paymentOption))) {
191
    		if(!createOrders(addressId, currentCartId, currentUserId, Long.parseLong(paymentOption))) {
174
    			addActionError("We are experiencing some problems. Please try later.");
192
    			addActionError("We are experiencing some problems. Please try later.");
175
    			return "proceed-to-pay-redirect";
193
    			return "proceed-to-pay-redirect";
176
    		}
194
    		}
-
 
195
    		//If tin is available push it to order attribute table
-
 
196
    		if(tin != null){
-
 
197
    			TransactionClient transactionServiceClient = null;
-
 
198
 
-
 
199
    	        try {
-
 
200
    	            transactionServiceClient = new TransactionClient();
-
 
201
    	            Attribute attr1 = new Attribute();
-
 
202
    	            attr1.setName("tinNumber");
-
 
203
    	            attr1.setValue(tin);
-
 
204
    	            transactionServiceClient.getClient().setOrderAttributeForTransaction(txnId, attr1);
-
 
205
    	        } catch (Exception e1) {
-
 
206
    	        	log.warn("Unable to log orders through the datalogger", e1);
-
 
207
    	        }
-
 
208
    		}
177
    	} catch (Exception e) {
209
    	} catch (Exception e) {
178
    		addActionError("We are experiencing some problems. Please try later.");
210
    		addActionError("We are experiencing some problems. Please try later.");
179
    		log.error("Exception in createOrders function. Something went wrong.", e);
211
    		log.error("Exception in createOrders function. Something went wrong.", e);
180
    		return "proceed-to-pay-redirect";
212
    		return "proceed-to-pay-redirect";
181
		}
213
		}
Line 189... Line 221...
189
                //Very unlikely. The only possible reason can be that the payment service is down.
221
                //Very unlikely. The only possible reason can be that the payment service is down.
190
                log.error("Unable to process the COD payment.");
222
                log.error("Unable to process the COD payment.");
191
                addActionError("We are experiencing some problems. Please try later.");
223
                addActionError("We are experiencing some problems. Please try later.");
192
                return "proceed-to-pay-redirect";
224
                return "proceed-to-pay-redirect";
193
            } else {
225
            } else {
194
                CommonPaymentService.processCodTxn(txnId);
226
                CommonPaymentService.processCodTxn(txnId, orderType);
195
                return "cod-redirect";
227
                return "cod-redirect";
196
            }
228
            }
197
 
229
 
198
    	case 5:
230
    	case 5:
199
    	case 10:
231
    	case 10:
Line 232... Line 264...
232
                //Very unlikely. The only possible reason can be that the payment service is down.
264
                //Very unlikely. The only possible reason can be that the payment service is down.
233
                log.error("Unable to process the Coupon payment.");
265
                log.error("Unable to process the Coupon payment.");
234
                addActionError("We are experiencing some problems. Please try later.");
266
                addActionError("We are experiencing some problems. Please try later.");
235
                return "proceed-to-pay-redirect";
267
                return "proceed-to-pay-redirect";
236
            } else {
268
            } else {
237
                CommonPaymentService.processCouponTxn(txnId);
269
                CommonPaymentService.processCodTxn(txnId, orderType);
238
                return "cod-redirect";
270
                return "cod-redirect";
239
            }
271
            }
240
		default:
272
		default:
241
			break;
273
			break;
242
		}
274
		}
Line 425... Line 457...
425
			return false;
457
			return false;
426
		}
458
		}
427
		
459
		
428
		TransactionClient transactionServiceClient = null;
460
		TransactionClient transactionServiceClient = null;
429
 
461
 
430
        try {
462
        /*try {
431
            transactionServiceClient = new TransactionClient();
463
            transactionServiceClient = new TransactionClient();
432
            List<Order> orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
464
            List<Order> orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
433
            for (Order order : orders) {
465
            for (Order order : orders) {
434
                List<Order> tmpOrders = new ArrayList<Order>();
466
                List<Order> tmpOrders = new ArrayList<Order>();
435
                tmpOrders.add(order);
467
                tmpOrders.add(order);
Line 437... Line 469...
437
//                DataLogger.logData(EventType.ORDER_CREATION, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), 
469
//                DataLogger.logData(EventType.ORDER_CREATION, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), 
438
//                        Long.toString(order.getId()), Long.toString(currentCartId), itemIdString);
470
//                        Long.toString(order.getId()), Long.toString(currentCartId), itemIdString);
439
            }
471
            }
440
        } catch (Exception e1) {
472
        } catch (Exception e1) {
441
        	log.warn("Unable to log orders through the datalogger", e1);
473
        	log.warn("Unable to log orders through the datalogger", e1);
442
        }
474
        }*/
443
		
475
		
444
		return true;
476
		return true;
445
	}
477
	}
446
 
478
 
447
	/**
479
	/**