Subversion Repositories SmartDukaan

Rev

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

Rev 3063 Rev 3101
Line 36... Line 36...
36
    @InterceptorRef("myDefault"),
36
    @InterceptorRef("myDefault"),
37
    @InterceptorRef("login")
37
    @InterceptorRef("login")
38
})
38
})
39
 
39
 
40
@Results({
40
@Results({
41
    @Result(name="shipping-redirect", type="redirectAction", 
41
    @Result(name="shipping-redirect", type="redirectAction", params = {"actionName" , "shipping"}),
42
    		params = {"actionName" , "shipping"}),
42
    @Result(name="proceed-to-pay-redirect", type="redirectAction", params = {"actionName" , "proceed-to-pay"}),
43
	@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}"),
43
	@Result(name="ebs-pay-redirect", type="redirect", location="/ebs-pay/${paymentId}"),
44
	@Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
44
	@Result(name="cod-redirect", type="redirect", location="/pay-success?paymentId=${paymentId}")
45
})
45
})
46
public class OrderController extends BaseController {
46
public class OrderController extends BaseController {
47
	
47
	
Line 75... Line 75...
75
    // POST /order/
75
    // POST /order/
76
    public String create(){
76
    public String create(){
77
    	String addressIdString = this.request.getParameter("addressid");
77
    	String addressIdString = this.request.getParameter("addressid");
78
    	if(addressIdString == null){
78
    	if(addressIdString == null){
79
    		addActionError("Please specify shipping address to continue.");
79
    		addActionError("Please specify shipping address to continue.");
80
    		return "shipping-redirect";
80
    		return "proceed-to-pay-redirect";
81
    	}
81
    	}
82
    	
82
    	
83
    	String paymentOption = request.getParameter("payment_option");
83
    	String paymentOption = request.getParameter("payment_option");
84
    	log.info("Payment Option Selected: " + paymentOption);
84
    	log.info("Payment Option Selected: " + paymentOption);
85
    	if(paymentOption == null || paymentOption.equals("")){
85
    	if(paymentOption == null || paymentOption.equals("")){
86
    		addActionError("Please select a payment method to continue.");
86
    		addActionError("Please select a payment method to continue.");
87
    		return "shipping-redirect";
87
    		return "proceed-to-pay-redirect";
88
    	}
88
    	}
89
    	
89
    	
90
    	
90
    	
-
 
91
    	long addressId;
-
 
92
    	try {
91
    	long addressId = Long.parseLong(addressIdString);
93
    	    addressId = Long.parseLong(addressIdString);   
-
 
94
    	} catch(NumberFormatException nfe){
-
 
95
    	    log.error("Unable to get address id", nfe);
-
 
96
    	    addActionError("Invalid address. Please add an address to the cart.");
-
 
97
    	    return "shipping-redirect";
-
 
98
    	}
-
 
99
    	 
92
    	long currentCartId = userinfo.getCartId();
100
    	long currentCartId = userinfo.getCartId();
93
    	
101
    	
94
    	if(paymentOption.equals(IPaymentService.COD)){
102
    	if(paymentOption.equals(IPaymentService.COD)){
95
    	    if(!verifyCaptcha()){
103
    	    if(!verifyCaptcha()){
96
    	        addActionError("Invalid captcha");
104
    	        addActionError("Invalid captcha");
97
    	        return "shipping-redirect";    
105
    	        return "proceed-to-pay-redirect";    
98
    	    }
106
    	    }
99
    	    
107
    	    
100
    	    //Check that this address is eligible for COD shipping.
108
    	    //Check that this address is eligible for COD shipping.
101
    	    UserContextServiceClient userServiceClient = null;
109
    	    UserContextServiceClient userServiceClient = null;
102
            try {
110
            try {
Line 105... Line 113...
105
                Address address = userClient.getAddressById(addressId);
113
                Address address = userClient.getAddressById(addressId);
106
                
114
                
107
                LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
115
                LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
108
                if(!logisticsServiceClient.getClient().isCodAllowed(address.getPin())){
116
                if(!logisticsServiceClient.getClient().isCodAllowed(address.getPin())){
109
                    addActionError("Cash on Delivery is currently not available for this pincode. Please choose a different payment option.");
117
                    addActionError("Cash on Delivery is currently not available for this pincode. Please choose a different payment option.");
110
                    return "shipping-redirect";    
118
                    return "proceed-to-pay-redirect";    
111
                }
119
                }
112
            } catch (Exception e) {
120
            } catch (Exception e) {
113
                log.error("Unable to talk to the user context service.", e);
121
                log.error("Unable to talk to the user context service.", e);
114
                addActionError("We are experiencing some problems. Please try later.");
122
                addActionError("We are experiencing some problems. Please try later.");
115
                return "shipping-redirect";
123
                return "proceed-to-pay-redirect";
116
            }
124
            }
117
    	}
125
    	}
118
    	
126
    	
119
    	try {
127
    	try {
120
    		if(!createOrders(addressId, currentCartId)){
128
    		if(!createOrders(addressId, currentCartId)){
121
    			addActionError("We are experiencing some problems. Please try later.");
129
    			addActionError("We are experiencing some problems. Please try later.");
122
    			return "shipping-redirect";
130
    			return "proceed-to-pay-redirect";
123
    		}
131
    		}
124
    	} catch (Exception e) {
132
    	} catch (Exception e) {
125
    		addActionError("We are experiencing some problems. Please try later.");
133
    		addActionError("We are experiencing some problems. Please try later.");
126
    		log.error("Exception in createOrders function. Something went wrong.", e);
134
    		log.error("Exception in createOrders function. Something went wrong.", e);
127
    		return "shipping-redirect";
135
    		return "proceed-to-pay-redirect";
128
		}
136
		}
129
    	
137
    	
130
    	if(paymentOption.equals(IPaymentService.COD)){
138
    	if(paymentOption.equals(IPaymentService.COD)){
131
    	    IPaymentService codPaymentService = new CodPaymentService();
139
    	    IPaymentService codPaymentService = new CodPaymentService();
132
    	    paymentId = codPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption);
140
    	    paymentId = codPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption);
133
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
141
            if (paymentId == IPaymentService.PAYMENT_NOT_CREATED) {
134
                //Very unlikely. The only possible reason can be that the payment service is down.
142
                //Very unlikely. The only possible reason can be that the payment service is down.
135
                log.error("Unable to process the COD payment.");
143
                log.error("Unable to process the COD payment.");
136
                addActionError("We are experiencing some problems. Please try later.");
144
                addActionError("We are experiencing some problems. Please try later.");
137
                return "shipping-redirect";
145
                return "proceed-to-pay-redirect";
138
            } else {
146
            } else {
139
                CommonPaymentService.processCodTxn(txnId);
147
                CommonPaymentService.processCodTxn(txnId);
140
                return "cod-redirect";
148
                return "cod-redirect";
141
            }
149
            }
142
    	} else {
150
    	} else {
Line 162... Line 170...
162
            
170
            
163
            IPaymentService ebsPaymentService = new EbsPaymentService();
171
            IPaymentService ebsPaymentService = new EbsPaymentService();
164
            paymentId = ebsPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption);
172
            paymentId = ebsPaymentService.createPayment(userinfo.getCartId(), userinfo.getUserId(), txnId, paymentOption);
165
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
173
            if(paymentId == IPaymentService.PAYMENT_NOT_CREATED){
166
                addActionError("We are experiencing some problems. Please try later.");
174
                addActionError("We are experiencing some problems. Please try later.");
167
                return "shipping-redirect";
175
                return "proceed-to-pay-redirect";
168
            } else {
176
            } else {
169
                log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
177
                log.info("Successfully created payment for EBS to process. Redirecting to /ebs-pay/" + paymentId);
170
                return "ebs-pay-redirect";
178
                return "ebs-pay-redirect";
171
            }    	    
179
            }    	    
172
    	}
180
    	}