Subversion Repositories SmartDukaan

Rev

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