Subversion Repositories SmartDukaan

Rev

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