Subversion Repositories SmartDukaan

Rev

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

Rev 7263 Rev 7268
Line 15... Line 15...
15
import in.shop2020.model.v1.order.SourceDetail;
15
import in.shop2020.model.v1.order.SourceDetail;
16
import in.shop2020.model.v1.order.Transaction;
16
import in.shop2020.model.v1.order.Transaction;
17
import in.shop2020.model.v1.order.TransactionStatus;
17
import in.shop2020.model.v1.order.TransactionStatus;
18
import in.shop2020.model.v1.user.User;
18
import in.shop2020.model.v1.user.User;
19
import in.shop2020.model.v1.user.UserContextException;
19
import in.shop2020.model.v1.user.UserContextException;
-
 
20
import in.shop2020.payments.PaymentStatus;
20
import in.shop2020.thrift.clients.CatalogClient;
21
import in.shop2020.thrift.clients.CatalogClient;
21
import in.shop2020.thrift.clients.HelperClient;
22
import in.shop2020.thrift.clients.HelperClient;
-
 
23
import in.shop2020.thrift.clients.PaymentClient;
22
import in.shop2020.thrift.clients.TransactionClient;
24
import in.shop2020.thrift.clients.TransactionClient;
23
import in.shop2020.thrift.clients.UserClient;
25
import in.shop2020.thrift.clients.UserClient;
24
import in.shop2020.utils.Mail;
26
import in.shop2020.utils.Mail;
25
 
27
 
26
import in.shop2020.serving.controllers.BaseController;
28
import in.shop2020.serving.controllers.BaseController;
Line 103... Line 105...
103
        }
105
        }
104
        
106
        
105
        orders.add(createOrder(tempUserId));
107
        orders.add(createOrder(tempUserId));
106
        txnObj.setOrders(orders);
108
        txnObj.setOrders(orders);
107
        TransactionClient tcl;
109
        TransactionClient tcl;
-
 
110
        long txnId = 0;
108
        try {
111
        try {
109
            tcl = new TransactionClient();
112
            tcl = new TransactionClient();
110
            long txnId = tcl.getClient().createTransaction(txnObj);
113
            txnId = tcl.getClient().createTransaction(txnObj);
111
        } catch (Exception e) {
114
        } catch (Exception e) {
112
            log.error("Unable to create transaction", e);
115
            log.error("Unable to create transaction", e);
113
            setErrorMsg("Unable to create order. Please try again.");
116
            setErrorMsg("Unable to create order. Please try again.");
114
            return "error-result";
117
            return "error-result";
115
        }
118
        }
-
 
119
        
-
 
120
        try {
-
 
121
        PaymentClient pcl = new PaymentClient();
-
 
122
        Long merchantPaymentId = pcl.getClient().createPayment(tempUserId, price, 10, txnId, true);
-
 
123
        //Update payment status as authorized
-
 
124
        pcl.getClient().updatePaymentDetails(merchantPaymentId, "", "", "0", "", "", "", "", "", PaymentStatus.SUCCESS, "", null);
-
 
125
        } catch(Exception e) {
-
 
126
            log.error("Unable to create payment for this order");
-
 
127
            setErrorMsg("Unable to create order. Please try again.");
-
 
128
            return "error-result";
-
 
129
        }
116
        return "create-order";
130
        return "create-order";
117
    }
131
    }
118
    
132
    
119
    public Order createOrder(long userId) {
133
    public Order createOrder(long userId) {
120
        LineItem lineObj = createLineItem();
134
        LineItem lineObj = createLineItem();
Line 142... Line 156...
142
        
156
        
143
        order.setTotal_amount(price);
157
        order.setTotal_amount(price);
144
        order.setStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
158
        order.setStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
145
        order.setStatusDescription("In process");
159
        order.setStatusDescription("In process");
146
        order.setCreated_timestamp(Calendar.getInstance().getTimeInMillis());
160
        order.setCreated_timestamp(Calendar.getInstance().getTimeInMillis());
-
 
161
        order.setTotal_weight(lineObj.getTotal_weight());
147
        
162
        
148
//        t_order.total_weight = t_line_item.total_weight
163
        List<LineItem> lines = new ArrayList<LineItem>();
-
 
164
        lines.add(lineObj);
149
//        t_order.lineitems = [t_line_item]
165
        order.setLineitems(lines);
150
        return order;
166
        return order;
151
    }
167
    }
152
        
168
        
153
    public LineItem createLineItem() {
169
    public LineItem createLineItem() {
154
        LineItem lineitem = new LineItem();
170
        LineItem lineitem = new LineItem();
Line 181... Line 197...
181
        
197
        
182
        if(item.getWarrantyPeriod() > 0) {
198
        if(item.getWarrantyPeriod() > 0) {
183
            //Computing Manufacturer Warranty expiry date
199
            //Computing Manufacturer Warranty expiry date
184
            Calendar cal = Calendar.getInstance();
200
            Calendar cal = Calendar.getInstance();
185
            cal.add(Calendar.MONTH, item.getWarrantyPeriod());
201
            cal.add(Calendar.MONTH, item.getWarrantyPeriod());
186
            cal.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, 23, 59, 59);
202
            cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
187
            lineitem.setWarrantry_expiry_timestamp(cal.getTimeInMillis());
203
            lineitem.setWarrantry_expiry_timestamp(cal.getTimeInMillis());
188
        }
204
        }
189
        
205
        
190
        return lineitem;
206
        return lineitem;
191
    }
207
    }
192
 
208
 
193
//        if item.warrantyPeriod:
-
 
194
//            #Computing Manufacturer Warranty expiry date
-
 
195
//            today = datetime.date.today()
-
 
196
//            expiry_year = today.year + int((today.month + item.warrantyPeriod) / 12)
-
 
197
//            expiry_month = (today.month + item.warrantyPeriod) % 12
-
 
198
//            
-
 
199
//            try:
-
 
200
//                expiry_date = datetime.datetime(expiry_year, expiry_month, today.day, 23, 59, 59, 999999)
-
 
201
//            except ValueError:
-
 
202
//                try:
-
 
203
//                    expiry_date = datetime.date(expiry_year, expiry_month, (today.day - 1), 23, 59, 59, 999999)
-
 
204
//                except ValueError:
-
 
205
//                    try:
-
 
206
//                        expiry_date = datetime.date(expiry_year, expiry_month, (today.day - 2), 23, 59, 59, 999999)
-
 
207
//                    except ValueError:
-
 
208
//                        expiry_date = datetime.date(expiry_year, expiry_month, (today.day - 3), 23, 59, 59, 999999)
-
 
209
//            
-
 
210
//            t_line_item.warrantry_expiry_timestamp = to_java_date(expiry_date)
-
 
211
//    
-
 
212
    private static String generateNewPassword() {
209
    private static String generateNewPassword() {
213
        char[] buf = new char[LENGTH];
210
        char[] buf = new char[LENGTH];
214
        for (int i = 0; i < buf.length; i++) {
211
        for (int i = 0; i < buf.length; i++) {
215
            buf[i] = chars.charAt(random.nextInt(chars.length()));
212
            buf[i] = chars.charAt(random.nextInt(chars.length()));
216
        }
213
        }
Line 342... Line 339...
342
    }
339
    }
343
 
340
 
344
    public void setPrice(double price) {
341
    public void setPrice(double price) {
345
        this.price = price;
342
        this.price = price;
346
    }
343
    }
347
    
-
 
348
    public static void main(String[] args) {
-
 
349
        Calendar cal = Calendar.getInstance();
-
 
350
        cal.add(Calendar.MONTH, 12);
-
 
351
        cal.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, 23, 59, 59);
-
 
352
        System.out.println(cal.getTimeInMillis());
-
 
353
    }
-
 
354
 
-
 
355
}
344
}