Subversion Repositories SmartDukaan

Rev

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

Rev 3859 Rev 4325
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import in.shop2020.datalogger.EventType;
3
import in.shop2020.datalogger.EventType;
4
import in.shop2020.model.v1.order.Order;
4
import in.shop2020.model.v1.order.Order;
-
 
5
import in.shop2020.model.v1.order.TransactionServiceException;
5
import in.shop2020.model.v1.user.Address;
6
import in.shop2020.model.v1.user.Address;
6
import in.shop2020.model.v1.user.ShoppingCartException;
7
import in.shop2020.model.v1.user.ShoppingCartException;
7
import in.shop2020.serving.interceptors.TrackingInterceptor;
8
import in.shop2020.serving.interceptors.TrackingInterceptor;
8
import in.shop2020.serving.services.CodPaymentService;
9
import in.shop2020.serving.services.CodPaymentService;
9
import in.shop2020.serving.services.CommonPaymentService;
10
import in.shop2020.serving.services.CommonPaymentService;
Line 28... Line 29...
28
import org.apache.struts2.convention.annotation.InterceptorRef;
29
import org.apache.struts2.convention.annotation.InterceptorRef;
29
import org.apache.struts2.convention.annotation.InterceptorRefs;
30
import org.apache.struts2.convention.annotation.InterceptorRefs;
30
import org.apache.struts2.convention.annotation.Result;
31
import org.apache.struts2.convention.annotation.Result;
31
import org.apache.struts2.convention.annotation.Results;
32
import org.apache.struts2.convention.annotation.Results;
32
import org.apache.thrift.TException;
33
import org.apache.thrift.TException;
-
 
34
import org.apache.thrift.transport.TTransportException;
33
 
35
 
34
@SuppressWarnings("serial")
36
@SuppressWarnings("serial")
35
@InterceptorRefs({
37
@InterceptorRefs({
36
    @InterceptorRef("myDefault"),
38
    @InterceptorRef("myDefault"),
37
    @InterceptorRef("login")
39
    @InterceptorRef("login")
Line 123... Line 125...
123
                return "proceed-to-pay-redirect";
125
                return "proceed-to-pay-redirect";
124
            }
126
            }
125
    	}
127
    	}
126
    	
128
    	
127
    	try {
129
    	try {
128
    		if(!createOrders(addressId, currentCartId)){
130
    		if(!createOrders(addressId, currentCartId)) {
129
    			addActionError("We are experiencing some problems. Please try later.");
131
    			addActionError("We are experiencing some problems. Please try later.");
130
    			return "proceed-to-pay-redirect";
132
    			return "proceed-to-pay-redirect";
131
    		}
133
    		}
132
    	} catch (Exception e) {
134
    	} catch (Exception e) {
133
    		addActionError("We are experiencing some problems. Please try later.");
135
    		addActionError("We are experiencing some problems. Please try later.");
134
    		log.error("Exception in createOrders function. Something went wrong.", e);
136
    		log.error("Exception in createOrders function. Something went wrong.", e);
135
    		return "proceed-to-pay-redirect";
137
    		return "proceed-to-pay-redirect";
136
		}
138
		}
137
    	
139
    	
138
    	if(paymentOption.equals(IPaymentService.COD)){
140
    	if(paymentOption.equals(IPaymentService.COD)) {
139
    	    IPaymentService codPaymentService = new CodPaymentService();
141
    	    IPaymentService codPaymentService = new CodPaymentService();
140
    	    paymentId = codPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption, sourceId);
142
    	    paymentId = codPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption, sourceId);
141
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
143
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
142
                //Very unlikely. The only possible reason can be that the payment service is down.
144
                //Very unlikely. The only possible reason can be that the payment service is down.
143
                log.error("Unable to process the COD payment.");
145
                log.error("Unable to process the COD payment.");
Line 298... Line 300...
298
			log.error("Thrift exception while creating orders from cart.", e);
300
			log.error("Thrift exception while creating orders from cart.", e);
299
			return false;
301
			return false;
300
		}
302
		}
301
		
303
		
302
		TransactionClient transactionServiceClient = null;
304
		TransactionClient transactionServiceClient = null;
-
 
305
 
303
        try {
306
        try {
304
            transactionServiceClient = new TransactionClient();
307
            transactionServiceClient = new TransactionClient();
305
            List<Order> orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
308
            List<Order> orders = transactionServiceClient.getClient().getOrdersForTransaction(txnId, userinfo.getUserId());
306
            for (Order order : orders) {
309
            for (Order order : orders) {
307
                List<Order> tmpOrders = new ArrayList<Order>();
310
                List<Order> tmpOrders = new ArrayList<Order>();
Line 314... Line 317...
314
        	log.warn("Unable to log orders through the datalogger", e1);
317
        	log.warn("Unable to log orders through the datalogger", e1);
315
        }
318
        }
316
		
319
		
317
		return true;
320
		return true;
318
	}
321
	}
-
 
322
 
-
 
323
	/**
-
 
324
	 * This method updates address of a given order.
-
 
325
	 *
-
 
326
	 * @return
-
 
327
	 */
-
 
328
	public String modifyAddress() {
-
 
329
        long orderId   = Long.parseLong(request.getParameter("orderId"));
-
 
330
        long addressId = Long.valueOf(request.getParameter("addressId"));
-
 
331
 
-
 
332
		try {
-
 
333
		    TransactionClient transactionServiceClient = new TransactionClient();
-
 
334
			in.shop2020.model.v1.order.TransactionService.Client transactionClient
-
 
335
			    = transactionServiceClient.getClient();			
-
 
336
			transactionClient.updateShipmentAddress(orderId, addressId);
-
 
337
		} catch (TTransportException e) {
-
 
338
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
-
 
339
		} catch (NumberFormatException e) {
-
 
340
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
-
 
341
		} catch (TransactionServiceException e) {
-
 
342
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
-
 
343
		} catch (TException e) {
-
 
344
		    log.error("Could not update address: " + addressId + " for orderId: " + orderId, e);
-
 
345
		}			
-
 
346
 
-
 
347
		return "index";
319
	
348
	}
-
 
349
 
320
	public String getRedirectURL(){
350
	public String getRedirectURL(){
321
		return this.redirectURL;
351
		return this.redirectURL;
322
	}
352
	}
323
}
353
}