Subversion Repositories SmartDukaan

Rev

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

Rev 7426 Rev 7427
Line 11... Line 11...
11
import org.apache.struts2.convention.annotation.Result;
11
import org.apache.struts2.convention.annotation.Result;
12
import org.apache.struts2.convention.annotation.Results;
12
import org.apache.struts2.convention.annotation.Results;
13
import org.apache.thrift.TException;
13
import org.apache.thrift.TException;
14
import org.apache.thrift.transport.TTransportException;
14
import org.apache.thrift.transport.TTransportException;
15
 
15
 
-
 
16
import in.shop2020.logistics.DeliveryType;
-
 
17
import in.shop2020.logistics.LogisticsInfo;
16
import in.shop2020.logistics.PickUpType;
18
import in.shop2020.logistics.PickUpType;
-
 
19
import in.shop2020.logistics.LogisticsService.Client;
17
import in.shop2020.model.v1.catalog.Item;
20
import in.shop2020.model.v1.catalog.Item;
-
 
21
import in.shop2020.model.v1.catalog.ItemShippingInfo;
18
import in.shop2020.model.v1.catalog.StorePricing;
22
import in.shop2020.model.v1.catalog.StorePricing;
19
import in.shop2020.model.v1.order.HotspotStore;
23
import in.shop2020.model.v1.order.HotspotStore;
20
import in.shop2020.model.v1.order.LineItem;
24
import in.shop2020.model.v1.order.LineItem;
21
import in.shop2020.model.v1.order.Order;
25
import in.shop2020.model.v1.order.Order;
22
import in.shop2020.model.v1.order.OrderSource;
26
import in.shop2020.model.v1.order.OrderSource;
Line 30... Line 34...
30
import in.shop2020.model.v1.user.User;
34
import in.shop2020.model.v1.user.User;
31
import in.shop2020.model.v1.user.UserContextException;
35
import in.shop2020.model.v1.user.UserContextException;
32
import in.shop2020.payments.PaymentStatus;
36
import in.shop2020.payments.PaymentStatus;
33
import in.shop2020.thrift.clients.CatalogClient;
37
import in.shop2020.thrift.clients.CatalogClient;
34
import in.shop2020.thrift.clients.HelperClient;
38
import in.shop2020.thrift.clients.HelperClient;
-
 
39
import in.shop2020.thrift.clients.LogisticsClient;
35
import in.shop2020.thrift.clients.PaymentClient;
40
import in.shop2020.thrift.clients.PaymentClient;
36
import in.shop2020.thrift.clients.TransactionClient;
41
import in.shop2020.thrift.clients.TransactionClient;
37
import in.shop2020.thrift.clients.UserClient;
42
import in.shop2020.thrift.clients.UserClient;
38
import in.shop2020.utils.Mail;
43
import in.shop2020.utils.Mail;
39
 
44
 
Line 101... Line 106...
101
    public String create(){
106
    public String create(){
102
        return index();
107
        return index();
103
    }
108
    }
104
    
109
    
105
    public String persistTransaction() {
110
    public String persistTransaction() {
-
 
111
        if(advanceAmount > price) {
-
 
112
            setErrorMsg("Advance amount was greater than Total Price.");
-
 
113
            return "error-result";
-
 
114
        }
-
 
115
        
-
 
116
        if(cashAmount + cardAmount != advanceAmount) {
-
 
117
            setErrorMsg("Sum of cash and card amounts was not equal to total Price.");
-
 
118
            return "error-result";
-
 
119
        }
-
 
120
        
-
 
121
        if(cardAmount > 0 && approvalCode.equals("")) {
-
 
122
            setErrorMsg("Approval code cannot be empty.");
-
 
123
            return "error-result";
-
 
124
        }
-
 
125
        
-
 
126
        validateAddress();
-
 
127
        
106
        Transaction txnObj = new Transaction();
128
        Transaction txnObj = new Transaction();
107
        StoreOrderDetail storeOrderDetail = new StoreOrderDetail();
129
        StoreOrderDetail storeOrderDetail = new StoreOrderDetail();
108
        
130
        
109
        if(email != null && !email.isEmpty()) {
131
        if(email != null && !email.isEmpty()) {
110
            userId = createUserAndSendMail(email);
132
            userId = createUserAndSendMail(email);
111
        } else {
133
        } else {
112
            try {
-
 
113
                TransactionClient tcl = new TransactionClient();
134
            log.error("Email is null, terminating the transaction");
114
                //Source Id for store website is 2 and our normal website is 1
-
 
115
                SourceDetail detail = tcl.getClient().getSourceDetail(2);
-
 
116
                
-
 
117
                userId = createUserAndSendMail(detail.getEmail());
135
            setErrorMsg("Invalid email Id. Please try again.");
118
            } catch(Exception e) {
136
            return "error-result";
119
                log.error("Unable to get default source", e);
-
 
120
            }
-
 
121
        }
137
        }
122
        
138
        
123
        if(userId == -1) {
139
        if(userId == -1 || userId == 0) {
124
            log.error("Unable to get a user, terminating the transaction");
140
            log.error("Unable to get a user, terminating the transaction");
125
            setErrorMsg("Unable to create a user for this order. Please try again.");
141
            setErrorMsg("Unable to create a user for this order. Please try again.");
126
            return "error-result";
142
            return "error-result";
127
        }
143
        }
128
        
144
        
Line 221... Line 237...
221
        }
237
        }
222
        
238
        
223
        return "order-success-redirect";
239
        return "order-success-redirect";
224
    }
240
    }
225
    
241
    
-
 
242
    String validateAddress() {
-
 
243
        if(name.equals("") || line1.equals("") || city.equals("") || state.equals("") || pincode.equals("") || phone.equals("")) {
-
 
244
            setErrorMsg("Address was invalid");
-
 
245
            return "error-result";
-
 
246
        }
-
 
247
        return "";
-
 
248
    }
-
 
249
    
226
    public Order createOrder(long userId) {
250
    public Order createOrder(long userId) {
227
        LineItem lineObj = createLineItem();
251
        LineItem lineObj = createLineItem();
228
        if (lineObj == null) {
252
        if (lineObj == null) {
229
            return null;
253
            return null;
230
        }
254
        }
Line 246... Line 270...
246
        order.setCustomer_state(state);
270
        order.setCustomer_state(state);
247
        order.setCustomer_pincode(pincode);
271
        order.setCustomer_pincode(pincode);
248
        order.setCustomer_mobilenumber(phone);
272
        order.setCustomer_mobilenumber(phone);
249
        
273
        
250
        order.setTotal_amount(price);
274
        order.setTotal_amount(price);
251
        order.setStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
275
        order.setStatus(OrderStatus.PAYMENT_PENDING);
252
        order.setStatusDescription("In process");
276
        order.setStatusDescription("Order Incomplete");
253
        order.setCreated_timestamp(Calendar.getInstance().getTimeInMillis());
277
        order.setCreated_timestamp(Calendar.getInstance().getTimeInMillis());
254
        order.setTotal_weight(lineObj.getTotal_weight());
278
        order.setTotal_weight(lineObj.getTotal_weight());
255
        
279
        
256
        order.setSource(2);
280
        order.setSource(2);
257
        order.setStoreId(Long.parseLong((String) request.getSession().getAttribute("STORE_ID")));
281
        order.setStoreId(Long.parseLong((String) request.getSession().getAttribute("STORE_ID")));
Line 271... Line 295...
271
        try {
295
        try {
272
            CatalogClient ccl = new CatalogClient();
296
            CatalogClient ccl = new CatalogClient();
273
            item = ccl.getClient().getItem(product_id);
297
            item = ccl.getClient().getItem(product_id);
274
            sp = ccl.getClient().getStorePricing(product_id);
298
            sp = ccl.getClient().getStorePricing(product_id);
275
            lineitem.setDealText(sp.getBestDealText());
299
            lineitem.setDealText(sp.getBestDealText());
-
 
300
            
-
 
301
            ItemShippingInfo info = ccl.getClient().isActive(product_id);
-
 
302
            boolean isActive = info.isIsActive();
-
 
303
            boolean activeOnStore = ccl.getClient().getItem(product_id).isActiveOnStore();
-
 
304
            
-
 
305
            if(!isActive || !activeOnStore) {
-
 
306
                setErrorMsg("Unable to create order. Please try again.");
-
 
307
                return null;
-
 
308
            }
-
 
309
            
-
 
310
            if(price < sp.getAbsoluteMinPrice()) {
-
 
311
                setErrorMsg("You cannot sell below Rs." + sp.getAbsoluteMinPrice());
-
 
312
                return null;
-
 
313
            }
276
        } catch (Exception e) {
314
        } catch (Exception e) {
277
            log.error("Unable to get the item from catalog service, ItemId : " + product_id, e);
315
            log.error("Unable to get the item from catalog service, ItemId : " + product_id, e);
278
            setErrorMsg("Unable to create order. Please try again.");
316
            setErrorMsg("Unable to create order. Please try again.");
279
            return null;
317
            return null;
280
        }
318
        }