Subversion Repositories SmartDukaan

Rev

Rev 20278 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
419 rajveer 1
package in.shop2020.serving.controllers;
2
 
9338 manish.sha 3
import in.shop2020.model.v1.inventory.Warehouse;
8940 manish.sha 4
import in.shop2020.model.v1.order.Attribute;
11526 amit.gupta 5
import in.shop2020.model.v1.order.OrderSource;
12788 amit.gupta 6
import in.shop2020.model.v1.order.OrderType;
4325 mandeep.dh 7
import in.shop2020.model.v1.order.TransactionServiceException;
3063 chandransh 8
import in.shop2020.model.v1.user.Address;
8428 rajveer 9
import in.shop2020.model.v1.user.Cart;
12788 amit.gupta 10
import in.shop2020.model.v1.user.PrivateDealUser;
894 rajveer 11
import in.shop2020.model.v1.user.ShoppingCartException;
2817 vikas 12
import in.shop2020.serving.interceptors.TrackingInterceptor;
3063 chandransh 13
import in.shop2020.serving.services.CodPaymentService;
14
import in.shop2020.serving.services.CommonPaymentService;
7862 anupam.sin 15
import in.shop2020.serving.services.CouponPaymentService;
1905 chandransh 16
import in.shop2020.serving.services.EbsPaymentService;
3616 chandransh 17
import in.shop2020.serving.services.HdfcEmiPaymentService;
1318 rajveer 18
import in.shop2020.serving.services.HdfcPaymentService;
1905 chandransh 19
import in.shop2020.serving.services.IPaymentService;
6390 rajveer 20
import in.shop2020.serving.services.InnovitiPaymentService;
13372 amit.gupta 21
import in.shop2020.serving.services.PayuPaymentService;
6050 anupam.sin 22
import in.shop2020.serving.utils.DesEncrypter;
20278 aman.kumar 23
import in.shop2020.serving.utils.PaymentUtils;
13425 amit.gupta 24
import in.shop2020.serving.utils.Utils;
9338 manish.sha 25
import in.shop2020.thrift.clients.InventoryClient;
3126 rajveer 26
import in.shop2020.thrift.clients.TransactionClient;
27
import in.shop2020.thrift.clients.UserClient;
7954 manish.sha 28
import in.shop2020.utils.FedExShipAccountInfo;
517 rajveer 29
 
3394 vikas 30
import java.util.ArrayList;
7001 rajveer 31
import java.util.Arrays;
2419 vikas 32
import java.util.List;
33
 
12788 amit.gupta 34
import nl.captcha.Captcha;
35
 
832 rajveer 36
import org.apache.log4j.Logger;
822 vikas 37
import org.apache.struts2.convention.annotation.InterceptorRef;
38
import org.apache.struts2.convention.annotation.InterceptorRefs;
419 rajveer 39
import org.apache.struts2.convention.annotation.Result;
40
import org.apache.struts2.convention.annotation.Results;
517 rajveer 41
import org.apache.thrift.TException;
4325 mandeep.dh 42
import org.apache.thrift.transport.TTransportException;
7954 manish.sha 43
 
44
import com.ShipWebServiceClient;
8940 manish.sha 45
import com.fedex.ship.stub.AssociatedShipmentDetail;
7954 manish.sha 46
import com.fedex.ship.stub.CompletedPackageDetail;
47
import com.fedex.ship.stub.CompletedShipmentDetail;
8940 manish.sha 48
import com.fedex.ship.stub.OperationalInstruction;
49
import com.fedex.ship.stub.PackageOperationalDetail;
7954 manish.sha 50
import com.fedex.ship.stub.ProcessShipmentReply;
8940 manish.sha 51
import com.fedex.ship.stub.StringBarcode;
7954 manish.sha 52
import com.fedex.ship.stub.TrackingId;
53
 
2159 chandransh 54
@SuppressWarnings("serial")
822 vikas 55
@InterceptorRefs({
56
    @InterceptorRef("myDefault"),
57
    @InterceptorRef("login")
58
})
59
 
419 rajveer 60
@Results({
3101 chandransh 61
    @Result(name="shipping-redirect", type="redirectAction", params = {"actionName" , "shipping"}),
5716 anupam.sin 62
    @Result(name="proceed-to-pay-redirect", type="redirectAction", params = {"actionName" , "proceed-to-pay", "deliveryLocation", "${deliveryLocation}"}),
3063 chandransh 63
	@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}"),
6060 rajveer 64
	@Result(name="payu-pay-redirect", type="redirect", location="/payu-pay/${paymentId}"),
20112 aman.kumar 65
	@Result(name="hdfc-pay-redirect", type="redirect", location="/hdfc-pay/${paymentId}"),
6390 rajveer 66
	@Result(name="innoviti-pay-redirect", type="redirect", location="/innoviti-pay/${paymentId}"),
3063 chandransh 67
	@Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
419 rajveer 68
})
650 rajveer 69
public class OrderController extends BaseController {
419 rajveer 70
 
1905 chandransh 71
	public long getPaymentId() {
72
		return paymentId;
73
	}
419 rajveer 74
 
832 rajveer 75
	private static Logger log = Logger.getLogger(Class.class);
3063 chandransh 76
 
507 rajveer 77
	private String id;
712 rajveer 78
	private long txnId = 0;
650 rajveer 79
 
1905 chandransh 80
	private long paymentId;
81
 
1318 rajveer 82
	private String redirectURL;
5716 anupam.sin 83
	private String deliveryLocation = "";
681 rajveer 84
 
419 rajveer 85
	public OrderController(){
507 rajveer 86
		super();
419 rajveer 87
	}
88
 
507 rajveer 89
    // GET /order/ orderid
90
    public String show() {
91
    	log.info("id=" + id);
822 vikas 92
    	htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
4815 phani.kuma 93
    	htmlSnippets.put("ORDER_DETAILS", pageLoader.getOrderDetailsHtml(Long.parseLong(id), userinfo));
507 rajveer 94
    	return "show";
419 rajveer 95
    }
517 rajveer 96
 
572 chandransh 97
    // POST /order/
98
    public String create(){
20278 aman.kumar 99
 
100
 
786 rajveer 101
    	String addressIdString = this.request.getParameter("addressid");
18659 amit.gupta 102
    	if(addressIdString == null){
103
    		addActionError("Please specify shipping address to continue.");
104
    		return "proceed-to-pay-redirect";
105
    	}
106
    	long addressId;
107
    	try {
108
    		addressId = Long.parseLong(addressIdString);   
109
    	} catch(NumberFormatException nfe){
110
    		log.error("Unable to get address id", nfe);
111
    		addActionError("Invalid address. Please add an address to the cart.");
112
    		return "shipping-redirect";
113
    	}
12788 amit.gupta 114
    	OrderType orderType = OrderType.B2C;
115
    	String tin = null;
116
    	if(userinfo.isPrivateDealUser()){
117
    		try {
118
    			UserClient userServiceClient = new UserClient();
119
                in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
120
                PrivateDealUser user = userClient.getPrivateDealUser(userinfo.getUserId());
18659 amit.gupta 121
                Address billingAddress= userClient.getBillingAddressForUser(user.getUserId());
122
            	if(billingAddress != null){
123
            		Address shippingAddress = userClient.getAddressById(addressId);
124
            		if(billingAddress.getState().equals(shippingAddress.getState())){
125
            			orderType = OrderType.B2B;
126
            			tin = user.getTin().trim();
127
            		}
128
            	}
12788 amit.gupta 129
                if(user.getTin() != null && !user.getTin().equals("")) {
130
                	orderType = OrderType.B2B;
131
                	tin = user.getTin().trim();
132
                }
133
 
134
            } catch (Exception e) {
135
                log.error("Unable to talk to the user context service.", e);
136
                addActionError("We are experiencing some problems. Please try later.");
137
                return "proceed-to-pay-redirect";
138
            }
139
    	}
2159 chandransh 140
 
141
    	String paymentOption = request.getParameter("payment_option");
20278 aman.kumar 142
    	String paymentType="";
2159 chandransh 143
    	log.info("Payment Option Selected: " + paymentOption);
144
    	if(paymentOption == null || paymentOption.equals("")){
145
    		addActionError("Please select a payment method to continue.");
3101 chandransh 146
    		return "proceed-to-pay-redirect";
2159 chandransh 147
    	}
20278 aman.kumar 148
    	if(paymentOption.contains("~")){
149
    		paymentType = paymentOption.split("~")[0];
150
    		paymentOption = paymentOption.split("~")[1];
151
    	}
2159 chandransh 152
 
3101 chandransh 153
 
572 chandransh 154
    	long currentCartId = userinfo.getCartId();
5326 rajveer 155
    	long currentUserId = userinfo.getUserId();
3063 chandransh 156
 
157
    	if(paymentOption.equals(IPaymentService.COD)){
13521 amit.gupta 158
    	    if(!userinfo.isPrivateDealUser() && !verifyCaptcha()){
3063 chandransh 159
    	        addActionError("Invalid captcha");
4815 phani.kuma 160
    	        log.info("Invalid captcha error msg has been added");
3101 chandransh 161
    	        return "proceed-to-pay-redirect";    
3063 chandransh 162
    	    }
163
 
6353 rajveer 164
	        //Check that this address is eligible for COD shipping.
165
    	    UserClient userServiceClient = null;
166
            try {
167
                userServiceClient = new UserClient();
168
                in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
169
                Address address = userClient.getAddressById(addressId);
170
 
171
                if(!userClient.showCODOption(currentCartId, sourceId, address.getPin())){
172
                    addActionError("Cash on Delivery is currently not available for this pincode. Please choose a different payment option.");
173
                    return "proceed-to-pay-redirect";    
174
                }
175
            } catch (Exception e) {
176
                log.error("Unable to talk to the user context service.", e);
177
                addActionError("We are experiencing some problems. Please try later.");
178
                return "proceed-to-pay-redirect";
179
            }
3063 chandransh 180
    	}
181
 
7862 anupam.sin 182
    	if(paymentOption.equals(IPaymentService.COUPON)) {
13521 amit.gupta 183
    		if(!userinfo.isPrivateDealUser() && !verifyCaptcha()){
7862 anupam.sin 184
                addActionError("Invalid captcha");
185
                log.info("Invalid captcha error msg has been added");
186
                return "proceed-to-pay-redirect";    
187
            }
8428 rajveer 188
	    	UserClient userServiceClient = null;
189
            try {
190
                userServiceClient = new UserClient();
191
                in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
192
                Cart cart = userClient.getCart(currentCartId);
193
                if(!isCouponValid(cart)){
194
                    addActionError("Cart amount is not zero.");
195
                    log.info("Cart amount is not zero.");
196
                    return "proceed-to-pay-redirect";    
197
                }
198
            } catch (Exception e) {
199
                log.error("Unable to talk to the user context service.", e);
200
                addActionError("We are experiencing some problems. Please try later.");
201
                return "proceed-to-pay-redirect";
202
            }
7862 anupam.sin 203
    	}
204
 
3063 chandransh 205
    	try {
20278 aman.kumar 206
 
6390 rajveer 207
    		if(!createOrders(addressId, currentCartId, currentUserId, Long.parseLong(paymentOption))) {
1128 rajveer 208
    			addActionError("We are experiencing some problems. Please try later.");
3101 chandransh 209
    			return "proceed-to-pay-redirect";
894 rajveer 210
    		}
12788 amit.gupta 211
    		//If tin is available push it to order attribute table
212
    		if(tin != null){
213
    			TransactionClient transactionServiceClient = null;
214
 
215
    	        try {
216
    	            transactionServiceClient = new TransactionClient();
217
    	            Attribute attr1 = new Attribute();
218
    	            attr1.setName("tinNumber");
219
    	            attr1.setValue(tin);
220
    	            transactionServiceClient.getClient().setOrderAttributeForTransaction(txnId, attr1);
221
    	        } catch (Exception e1) {
222
    	        	log.warn("Unable to log orders through the datalogger", e1);
223
    	        }
224
    		}
3063 chandransh 225
    	} catch (Exception e) {
1128 rajveer 226
    		addActionError("We are experiencing some problems. Please try later.");
2296 chandransh 227
    		log.error("Exception in createOrders function. Something went wrong.", e);
3101 chandransh 228
    		return "proceed-to-pay-redirect";
693 rajveer 229
		}
2159 chandransh 230
 
20278 aman.kumar 231
    	int gatewayId = (int)findGatewayId(paymentType+paymentOption);
6390 rajveer 232
    	switch (gatewayId) {
6419 rajveer 233
    	case 4:
234
    		IPaymentService codPaymentService = new CodPaymentService();
20278 aman.kumar 235
    	    paymentId = codPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 4, paymentType);
6419 rajveer 236
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
237
                //Very unlikely. The only possible reason can be that the payment service is down.
238
                log.error("Unable to process the COD payment.");
239
                addActionError("We are experiencing some problems. Please try later.");
240
                return "proceed-to-pay-redirect";
241
            } else {
12788 amit.gupta 242
                CommonPaymentService.processCodTxn(txnId, orderType);
6419 rajveer 243
                return "cod-redirect";
244
            }
245
 
246
    	case 5:
20278 aman.kumar 247
    		IPaymentService payuPaymentService = new PayuPaymentService();
248
        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId, paymentType);
249
        	 if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
250
                 //Very unlikely. The only possible reason can be that the payment service is down.
251
        		 log.error("Unable to process the payu payment.");
252
 				addActionError("We are experiencing some problems. Please try later.");
253
 				return "proceed-to-pay-redirect";
254
             } else {
255
            	 log.info("Successfully created payment for Innoviti to process. Redirecting to /payu-pay/" + paymentId);
256
 				return "payu-pay-redirect";
257
             }
7001 rajveer 258
    	case 14:
6390 rajveer 259
			IPaymentService hdfcEmiPaymentService = new HdfcEmiPaymentService();
20278 aman.kumar 260
            paymentId = hdfcEmiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId, paymentType);
6390 rajveer 261
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
262
                addActionError("We are experiencing some problems. Please try later.");
263
                log.error("Unable to process payment through HDFC EMI.");
264
                return "proceed-to-pay-redirect";
265
            } else {
266
                this.redirectURL = ((HdfcEmiPaymentService)hdfcEmiPaymentService).getRedirectUrl();
267
                log.info(this.redirectURL);
268
                return "success";
269
            }
6419 rajveer 270
 
271
    	case 13:
272
			IPaymentService innovitiPaymentService = new InnovitiPaymentService();
20278 aman.kumar 273
			paymentId = innovitiPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId, paymentType);
6419 rajveer 274
			if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
275
				//Very unlikely. The only possible reason can be that the payment service is down.
20278 aman.kumar 276
				log.error("Unable to process the innoviti payment.");
6419 rajveer 277
				addActionError("We are experiencing some problems. Please try later.");
278
				return "proceed-to-pay-redirect";
279
			} else {
280
	            log.info("Successfully created payment for Innoviti to process. Redirecting to /innoviti-pay/" + paymentId);
281
				return "innoviti-pay-redirect";
282
			}
283
 
8428 rajveer 284
    	case 17:
7862 anupam.sin 285
            IPaymentService couponPaymentService = new CouponPaymentService();
20278 aman.kumar 286
            paymentId = couponPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 17, paymentType);
7862 anupam.sin 287
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
288
                //Very unlikely. The only possible reason can be that the payment service is down.
289
                log.error("Unable to process the Coupon payment.");
290
                addActionError("We are experiencing some problems. Please try later.");
291
                return "proceed-to-pay-redirect";
292
            } else {
13505 amit.gupta 293
                CommonPaymentService.processCouponTxn(txnId, orderType);
7862 anupam.sin 294
                return "cod-redirect";
295
            }
20278 aman.kumar 296
 
297
    	case 18:
298
    		IPaymentService ebsPaymentService = new EbsPaymentService();
299
            paymentId = ebsPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 2, paymentType);
300
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
301
                addActionError("We are experiencing some problems. Please try later.");
302
                log.error("Unable to process payment through EBS.");
303
                return "proceed-to-pay-redirect";
304
            } else {
305
                log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
306
                return "ebs-pay-redirect";
307
            } 
6390 rajveer 308
		default:
309
			break;
310
		}
311
 
312
 
20278 aman.kumar 313
		/*if(paymentOption.equals(IPaymentService.HDFC_MASTERCARD_CREDIT) || paymentOption.equals(IPaymentService.HDFC_MASTERCARD_DEBIT) || 
6390 rajveer 314
		        paymentOption.equals(IPaymentService.HDFC_VISA) || paymentOption.equals(IPaymentService.HDFC_VISA_ELECTRON)) {
315
            // User has selected Visa or MasterCard
316
            IPaymentService hdfcPaymentService = new HdfcPaymentService();
317
            paymentId = hdfcPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, 1);
318
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
10968 amit.gupta 319
            	//TODO:Update order gatewayTxnStatus in case its not processed using txnId
6390 rajveer 320
                log.error("Unable to process payment through HDFC. Falling through to EBS.");
3616 chandransh 321
            } else {
6390 rajveer 322
                this.redirectURL = ((HdfcPaymentService)hdfcPaymentService).getRedirectUrl();
3616 chandransh 323
                log.info(this.redirectURL);
324
                return "success";
325
            }
20278 aman.kumar 326
        }*/
2199 chandransh 327
 
20278 aman.kumar 328
/*    	if (paymentOption.equals("91000")){
20112 aman.kumar 329
        	IPaymentService payuPaymentService = new HdfcPaymentService();
330
        	paymentId = payuPaymentService.createPayment(userinfo.getUserId(), txnId, paymentOption, gatewayId);
331
        	return "hdfc-pay-redirect";
20278 aman.kumar 332
        }*/
333
        return "payu-pay-redirect";
334
 
6390 rajveer 335
	}
336
 
8428 rajveer 337
    private boolean isCouponValid(Cart cart) {
338
    	String couponCode = cart.getCouponCode();
339
    	double totalAmountD;
340
        if(couponCode == null || "".equals(couponCode))
341
        	totalAmountD = cart.getTotalPrice();
342
        else
343
            totalAmountD = cart.getDiscountedPrice();
344
        if(totalAmountD == 0) {
345
            return true;
346
        }else{
347
        	return false;
348
        }
349
    }
350
 
6390 rajveer 351
    private long findGatewayId(String paymentOption){
352
    	long gatewayId = 0;
20278 aman.kumar 353
    	gatewayId = PaymentUtils.getGatewayId(paymentOption);
354
 
355
 
6390 rajveer 356
    	return gatewayId;
572 chandransh 357
    }
6390 rajveer 358
 
3063 chandransh 359
    /**
360
     * Verifies if the recaptcha response matches the recaptcha challenge.
361
     * 
362
     * @return True if the captcha was valid, false otherwise.
363
     */
364
    private boolean verifyCaptcha() {
4609 phani.kuma 365
        String cookieCaptchaAnswer = getCookie(Captcha.NAME, true, "saholic");
366
    	String captchaReceived = (String) request.getParameter("captcha_response_field");
367
 
368
    	if (captchaReceived.equalsIgnoreCase(cookieCaptchaAnswer)) {
369
			try {
12616 anikendra 370
//				DataLogger.logData(EventType.CAPTCHA_SUCCESS, getSessionId(), userinfo.getUserId(), userinfo.getEmail());
4609 phani.kuma 371
			} catch (Exception e1) {
372
	        	log.warn("Unable to log orders through the datalogger", e1);
373
	        }
374
			return true;
375
		} 
376
		else {
377
			try {
12616 anikendra 378
//				DataLogger.logData(EventType.CAPTCHA_FAILED, getSessionId(), userinfo.getUserId(), userinfo.getEmail());
4609 phani.kuma 379
			} catch (Exception e1) {
380
	        	log.warn("Unable to log orders through the datalogger", e1);
381
	        }
382
			return false;
383
		}
3063 chandransh 384
    }
572 chandransh 385
 
507 rajveer 386
	public String getId(){
387
		return id;
388
	}
419 rajveer 389
 
507 rajveer 390
	public void setId(String id){
391
		this.id = id;
392
	}
419 rajveer 393
 
507 rajveer 394
	public String getMyaccountHeaderSnippet(){
395
		return htmlSnippets.get("MYACCOUNT_HEADER");
396
	}
397
 
398
	public String getOrderDetailsSnippet(){
399
		return htmlSnippets.get("ORDER_DETAILS");
400
	}
401
 
712 rajveer 402
	public long getTxn(){
403
		return this.txnId;
517 rajveer 404
	}
894 rajveer 405
 
406
	/**
407
	 * 
408
	 * @param addressId
409
	 * @param currentCartId
410
	 * @return
411
	 */
6390 rajveer 412
	private boolean createOrders(long addressId, long currentCartId, long currentUserId, long emiSchemeId){
3126 rajveer 413
		UserClient userServiceClient = null;
894 rajveer 414
		try {
3126 rajveer 415
			userServiceClient = new UserClient();
894 rajveer 416
		} catch (Exception e) {
2296 chandransh 417
			log.error("Unable to talk to the user context service.", e);
894 rajveer 418
			return false;
419
		}
420
 
421
		in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
422
		try {
423
			userClient.addAddressToCart(currentCartId, addressId);
424
		} catch (ShoppingCartException e1) {
2296 chandransh 425
			log.error("Not able to set address in the cart.", e1);
894 rajveer 426
			return false;
427
		} catch (TException e1) {
2296 chandransh 428
			log.error("Thrift exception while setting address in cart.", e1);
894 rajveer 429
			return false;
430
		}
431
 
432
 
433
		try {
6736 amit.gupta 434
			String errorMsg = userClient.validateCart(currentCartId, sourceId).get(0); 
1466 ankur.sing 435
			if(!errorMsg.isEmpty()){
436
				addActionError(errorMsg);
894 rajveer 437
				return false;
438
			}
439
		} catch (ShoppingCartException e1) {
2296 chandransh 440
			log.error("Error while validating shopping cart.", e1);
894 rajveer 441
			return false;
442
		} catch (TException e) {
2296 chandransh 443
			log.error("Thrift exception while validating cart.", e);
894 rajveer 444
			return false;
445
		}
446
 
447
 
448
		try {
3859 vikas 449
		    String sessionSrc = getCookie(TrackingInterceptor.SESSION_SRC_COOKIE, true, TrackingInterceptor.ENCRIPTION_STRING);
450
		    String firstSrc = getCookie(TrackingInterceptor.SRC_COOKIE, true, TrackingInterceptor.ENCRIPTION_STRING);
2817 vikas 451
 
3859 vikas 452
		    long sessionTime = 0;
453
            try {
454
                sessionTime = Long.parseLong(getCookie(TrackingInterceptor.SESSION_SRC_TIME_COOKIE, false, null));
455
            } catch (Exception e) {
456
                log.warn("Unable to parse session src time cookie.", e);
2817 vikas 457
            }
3859 vikas 458
            long firstSrcTime = 0;
459
            try {
460
                firstSrcTime = Long.parseLong(getCookie(TrackingInterceptor.SRC_TIME_COOKIE, false, null));
461
            } catch (Exception e) {
462
                log.warn("Unable to parse session src time cookie.", e);
463
            }
22520 amit.gupta 464
            txnId = userClient.createOrders(currentCartId, sessionSrc, sessionTime, firstSrc, firstSrcTime, currentUserId, emiSchemeId, OrderSource.WEBSITE.getValue(), false);
894 rajveer 465
		} catch (ShoppingCartException e1) {
2296 chandransh 466
			log.error("Error while creating orders from cart.", e1);
894 rajveer 467
			return false;
468
		} catch (TException e) {
2296 chandransh 469
			log.error("Thrift exception while creating orders from cart.", e);
894 rajveer 470
			return false;
471
		}
472
 
3126 rajveer 473
		TransactionClient transactionServiceClient = null;
4325 mandeep.dh 474
 
12788 amit.gupta 475
        /*try {
3126 rajveer 476
            transactionServiceClient = new TransactionClient();
2183 vikas 477
            List<Order> orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
478
            for (Order order : orders) {
3394 vikas 479
                List<Order> tmpOrders = new ArrayList<Order>();
480
                tmpOrders.add(order);
481
                String itemIdString = Utils.getItemIdStringFromOrders(tmpOrders);
12616 anikendra 482
//                DataLogger.logData(EventType.ORDER_CREATION, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), 
483
//                        Long.toString(order.getId()), Long.toString(currentCartId), itemIdString);
2183 vikas 484
            }
485
        } catch (Exception e1) {
2296 chandransh 486
        	log.warn("Unable to log orders through the datalogger", e1);
12788 amit.gupta 487
        }*/
894 rajveer 488
 
489
		return true;
490
	}
4325 mandeep.dh 491
 
492
	/**
493
	 * This method updates address of a given order.
494
	 *
495
	 * @return
496
	 */
497
	public String modifyAddress() {
498
        long orderId   = Long.parseLong(request.getParameter("orderId"));
499
        long addressId = Long.valueOf(request.getParameter("addressId"));
500
 
501
		try {
502
		    TransactionClient transactionServiceClient = new TransactionClient();
503
			in.shop2020.model.v1.order.TransactionService.Client transactionClient
504
			    = transactionServiceClient.getClient();			
505
			transactionClient.updateShipmentAddress(orderId, addressId);
7954 manish.sha 506
			in.shop2020.model.v1.order.Order t_order = transactionClient.getOrder(orderId);
9338 manish.sha 507
			Warehouse warehouse = null;
508
			try{
509
	    		InventoryClient isc = new InventoryClient();
510
	    		warehouse = isc.getClient().getWarehouse(t_order.getWarehouse_id());
511
			} catch(Exception e) {
512
			    log.error("Unable to get warehouse for id : " + t_order.getWarehouse_id(), e);
513
			    //TODO throw e;
514
			}
19545 manish.sha 515
			if(t_order.getLogistics_provider_id()==7L || t_order.getLogistics_provider_id()==46L){
19433 manish.sha 516
				FedExShipAccountInfo fedexAccountInfo = FedExShipAccountInfo.getFedExInfo();
517
				List<in.shop2020.model.v1.order.Order> orders = new ArrayList<in.shop2020.model.v1.order.Order>();
518
				orders.add(t_order);
519
				ProcessShipmentReply  processShipmentReply = ShipWebServiceClient.getShipmentCreationReply(orders,fedexAccountInfo.getClientDetail(),fedexAccountInfo.getWad(),fedexAccountInfo.getEndPointAddress(), t_order.getLogistics_provider_id());
7954 manish.sha 520
				CompletedShipmentDetail completedShipmentDetails = processShipmentReply.getCompletedShipmentDetail();
521
				CompletedPackageDetail completedPackageDetails =  completedShipmentDetails.getCompletedPackageDetails(0);
522
				TrackingId  trackId= completedPackageDetails.getTrackingIds(0);
523
				t_order = transactionClient.updateOrderAWB(t_order.getId(), trackId.getTrackingNumber());
8940 manish.sha 524
				//Start:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
525
				CompletedPackageDetail[] cpd= completedShipmentDetails.getCompletedPackageDetails();
526
				AssociatedShipmentDetail[] asdetails = completedShipmentDetails.getAssociatedShipments();
527
				List<Attribute> attrList = new ArrayList<Attribute>();
528
				if(t_order.isCod()){
529
					if(asdetails!=null){
530
						for(AssociatedShipmentDetail as : asdetails){
531
							if(as.getType().getValue().equalsIgnoreCase("COD_RETURN")){
532
								PackageOperationalDetail pod = as.getPackageOperationalDetail();
533
								StringBarcode[] barcodes = pod.getBarcodes().getStringBarcodes();
534
								for(StringBarcode bc : barcodes){
535
									Attribute attr3 = new Attribute();
536
									attr3.setName("FedEx_COD_Return_BarCode");
537
									attr3.setValue(bc.getValue());
538
									attrList.add(attr3);
539
								}
540
 
541
								String codReturnTrackingNo= as.getTrackingId().getTrackingNumber();
542
								Attribute attr4 = new Attribute();
543
								attr4.setName("FedEx_COD_Return_Tracking_No");
544
								attr4.setValue(codReturnTrackingNo);
545
								attrList.add(attr4);
546
							}
547
						}
548
					}
549
				}
550
				for(CompletedPackageDetail cd : cpd){
551
					PackageOperationalDetail pod = cd.getOperationalDetail();
552
					StringBarcode[] barcodes = pod.getBarcodes().getStringBarcodes();
553
					for(StringBarcode bc : barcodes){
554
						Attribute attr1 = new Attribute();
555
						attr1.setName("FedEx_Package_BarCode");
556
						attr1.setValue(bc.getValue());
557
						attrList.add(attr1);
558
					}
559
					OperationalInstruction[] ois = pod.getOperationalInstructions();
560
					Attribute attr2 = new Attribute();
561
					for(OperationalInstruction oi : ois){
562
						if(oi.getNumber().intValue()==5){
563
							attr2.setName("FedEx_Location_Code");
564
							attr2.setValue(oi.getContent());
565
							attrList.add(attr2);
566
						}
567
					}						
568
				}
569
				transactionClient.setOrderAttributes(t_order.getId(), attrList);
570
				//End:-Added By Manish Sharma for FedEx Integration - Shipment Creation on 21-Aug-2013
571
 
7954 manish.sha 572
			}
4325 mandeep.dh 573
		} catch (TTransportException e) {
574
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
575
		} catch (NumberFormatException e) {
576
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
577
		} catch (TransactionServiceException e) {
578
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
579
		} catch (TException e) {
580
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
581
		}			
582
 
583
		return "index";
584
	}
585
 
1318 rajveer 586
	public String getRedirectURL(){
587
		return this.redirectURL;
588
	}
5716 anupam.sin 589
 
590
    public String getDeliveryLocation() {
591
        return deliveryLocation;
592
    }
593
 
594
    public void setDeliveryLocation(String deliveryLocation) {
595
        this.deliveryLocation = deliveryLocation;
596
    }
6050 anupam.sin 597
 
598
    public static void main(String[] args) {
599
        DesEncrypter d = new DesEncrypter("shop2020");
600
        System.out.println(d.decrypt("pmkcWEzhf4IFRLyHce89Cg"));
7001 rajveer 601
    	long[] HDFC_EMI_GATEWAY_IDS = {5,10,11,12};
602
    	List<Long> stooges = Arrays.asList(5L,10L,11L,12L);
603
    	List<Long> lista = new ArrayList<Long>();
604
    	lista.add(5L);
605
    	lista.add(10L);
606
    	lista.add(11L);
607
    	lista.add(12L);
608
    	long gatewayId = 10;
609
    	if(stooges.contains(gatewayId)){
610
    		System.out.println("true");
611
    	}else{
612
    		System.out.println("false");
613
    	}
6050 anupam.sin 614
    }
419 rajveer 615
}