Subversion Repositories SmartDukaan

Rev

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

Rev 12653 Rev 22451
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.support.controllers;
4
package in.shop2020.support.controllers;
5
 
5
 
-
 
6
import in.shop2020.logistics.PickUpType;
6
import in.shop2020.model.v1.catalog.CatalogServiceException;
7
import in.shop2020.model.v1.catalog.CatalogServiceException;
7
import in.shop2020.model.v1.catalog.Item;
8
import in.shop2020.model.v1.catalog.Item;
8
import in.shop2020.model.v1.order.LineItem;
9
import in.shop2020.model.v1.order.LineItem;
9
import in.shop2020.model.v1.order.Order;
10
import in.shop2020.model.v1.order.Order;
10
import in.shop2020.model.v1.order.OrderSource;
11
import in.shop2020.model.v1.order.OrderSource;
11
import in.shop2020.model.v1.order.OrderStatus;
12
import in.shop2020.model.v1.order.OrderStatus;
12
import in.shop2020.model.v1.order.OrderType;
13
import in.shop2020.model.v1.order.OrderType;
13
import in.shop2020.model.v1.order.ProductCondition;
14
import in.shop2020.model.v1.order.ProductCondition;
14
import in.shop2020.model.v1.order.TaxType;
-
 
15
import in.shop2020.model.v1.order.Transaction;
15
import in.shop2020.model.v1.order.Transaction;
16
import in.shop2020.model.v1.order.TransactionService.Client;
16
import in.shop2020.model.v1.order.TransactionService.Client;
17
import in.shop2020.model.v1.order.TransactionServiceException;
17
import in.shop2020.model.v1.order.TransactionServiceException;
18
import in.shop2020.model.v1.order.TransactionStatus;
18
import in.shop2020.model.v1.order.TransactionStatus;
19
//import in.shop2020.model.v1.order.Attribute;
-
 
20
import in.shop2020.logistics.PickUpType;
-
 
21
import in.shop2020.model.v1.user.Address;
19
import in.shop2020.model.v1.user.Address;
-
 
20
import in.shop2020.model.v1.user.ItemPriceQuantity;
22
import in.shop2020.model.v1.user.User;
21
import in.shop2020.model.v1.user.User;
23
import in.shop2020.model.v1.user.UserContextException;
22
import in.shop2020.model.v1.user.UserContextException;
24
import in.shop2020.payments.Attribute;
23
import in.shop2020.payments.Attribute;
25
import in.shop2020.payments.Payment;
24
import in.shop2020.payments.Payment;
26
import in.shop2020.payments.PaymentException;
25
import in.shop2020.payments.PaymentException;
Line 33... Line 32...
33
 
32
 
34
import java.text.SimpleDateFormat;
33
import java.text.SimpleDateFormat;
35
import java.util.ArrayList;
34
import java.util.ArrayList;
36
import java.util.Collections;
35
import java.util.Collections;
37
import java.util.Date;
36
import java.util.Date;
38
import java.util.HashMap;
-
 
39
import java.util.List;
37
import java.util.List;
40
import java.util.Map;
38
import java.util.Map;
41
 
39
 
42
import org.apache.commons.logging.Log;
40
import org.apache.commons.logging.Log;
43
import org.apache.commons.logging.LogFactory;
41
import org.apache.commons.logging.LogFactory;
44
import org.apache.thrift.TException;
42
import org.apache.thrift.TException;
45
import org.apache.thrift.transport.TTransportException;
-
 
46
 
43
 
47
import com.opensymphony.xwork2.ValidationAwareSupport;
44
import com.opensymphony.xwork2.ValidationAwareSupport;
48
 
45
 
49
/**
46
/**
50
 * @author mandeep
47
 * @author mandeep
51
 * 
48
 * 
52
 */
49
 */
53
@SuppressWarnings("serial")
50
@SuppressWarnings("serial")
54
public class BulkOrderController extends ValidationAwareSupport {
51
public class BulkOrderController extends ValidationAwareSupport {
55
    private static final int RTGS_GATEWAY_ID = 6;
52
	private static final int RTGS_GATEWAY_ID = 6;
-
 
53
	private static final int WALLET_GATEWAY_ID = 8;
-
 
54
 
-
 
55
	private static Log log = LogFactory.getLog(BulkOrderController.class);
-
 
56
	private SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
 
57
 
-
 
58
	private static final String IFSC_CODE = "ifscCode";
-
 
59
	private static final String RTGS_BRANCH = "rtgsBranch";
-
 
60
	private static final String RTGS_BANK = "rtgsBank";
-
 
61
	private static final String RTGS_ID = "rtgsId";
-
 
62
	private static final String PAY_METHOD = "payMethod";
-
 
63
 
-
 
64
	private String id;
-
 
65
	private String transactionId;
-
 
66
	private String customerEmailId;
-
 
67
	private String rtgsId;
-
 
68
	private String rtgsBank;
-
 
69
	private String rtgsBranch;
-
 
70
	private String ifscCode;
-
 
71
	private String amount;
-
 
72
	private String itemId;
-
 
73
	private String output;
-
 
74
	private String pickUp;
-
 
75
	private String orderType;
-
 
76
	private String tinNumber;
-
 
77
	private String poRefNumber;
-
 
78
	private int productCondition;
-
 
79
	private Transaction transaction;
-
 
80
	private Payment payment;
-
 
81
	private long userWalletAmount;
-
 
82
	private int userId;
-
 
83
 
-
 
84
	private Map<Transaction, Double> transactions;
-
 
85
	private List<LineItem> lineItems;
-
 
86
 
-
 
87
	public String index() {
-
 
88
		// transactions = new HashMap<Transaction, Double>();
-
 
89
 
-
 
90
		/*
-
 
91
		 * try { Client transactionClient = new TransactionClient().getClient();
-
 
92
		 * in.shop2020.payments.PaymentService.Client paymentClient = new
-
 
93
		 * PaymentClient().getClient(); List<Payment> payments =
-
 
94
		 * paymentClient.getPayments(0, new Date().getTime(),
-
 
95
		 * PaymentStatus.SUCCESS, RTGS_GATEWAY_ID);
-
 
96
		 * 
-
 
97
		 * log.info("Loaded " + payments.size() + " payments"); for (Payment
-
 
98
		 * payment : payments) { Transaction txn =
-
 
99
		 * transactionClient.getTransaction(payment.getMerchantTxnId());
-
 
100
		 * log.info("Got " + txn); transactions.put(txn, payment.getAmount()); }
-
 
101
		 * } catch (TTransportException e) {
-
 
102
		 * log.error("Could not create transaction client", e); } catch
-
 
103
		 * (TransactionServiceException e) {
-
 
104
		 * log.error("Could not lookup transaction", e); } catch (TException e)
-
 
105
		 * { log.error("Could not find payment", e); } catch (PaymentException
-
 
106
		 * e) { log.error("Could not find payment", e); }
-
 
107
		 */
-
 
108
 
-
 
109
		return "index";
-
 
110
	}
-
 
111
 
-
 
112
	public String editNew() throws Throwable {
-
 
113
		in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
-
 
114
		User user = userClient.getUserByEmail(customerEmailId);
-
 
115
		Client transactionClient = new TransactionClient().getClient();
-
 
116
		this.userWalletAmount = transactionClient.getUserWallet(user.getUserId()).getAmount();
-
 
117
		return "editNew";
-
 
118
	}
-
 
119
 
-
 
120
	public String show() {
-
 
121
		try {
-
 
122
			transactionId = id;
-
 
123
 
-
 
124
			Client transactionClient = new TransactionClient().getClient();
-
 
125
			transaction = transactionClient.getTransaction(Long.valueOf(transactionId));
-
 
126
 
-
 
127
			in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
-
 
128
			payment = paymentClient.getPaymentForTxnId(Long.valueOf(transactionId)).get(0);
-
 
129
 
-
 
130
		} catch (NumberFormatException e) {
-
 
131
			log.error("Could not lookup transaction Id: " + transactionId, e);
-
 
132
		} catch (TransactionServiceException e) {
-
 
133
			log.error("Could not lookup transaction Id: " + transactionId, e);
-
 
134
		} catch (TException e) {
-
 
135
			log.error("Could not lookup transaction Id: " + transactionId, e);
-
 
136
		} catch (PaymentException e) {
-
 
137
			log.error("Could not lookup payment for transaction Id: " + transactionId, e);
-
 
138
		}
-
 
139
 
-
 
140
		return "show";
-
 
141
	}
-
 
142
 
-
 
143
	public String create() {
-
 
144
		log.info("Creating orders for " + lineItems);
-
 
145
		boolean hasError = true;
-
 
146
 
-
 
147
		try {
-
 
148
			in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
-
 
149
			User user = userClient.getUserByEmail(customerEmailId);
-
 
150
			Client transactionClient = new TransactionClient().getClient();
-
 
151
			List<ItemPriceQuantity> ipqList = new ArrayList<ItemPriceQuantity>();
-
 
152
			double totalAmount = 0;
-
 
153
 
-
 
154
			if (user == null) {
-
 
155
				addActionError("Could not find user by email: " + customerEmailId);
-
 
156
			} else {
-
 
157
				double walletAmount = transactionClient.getUserWallet(user.getUserId()).getAmount();
-
 
158
				for (LineItem li : lineItems) {
-
 
159
					ItemPriceQuantity ipq = new ItemPriceQuantity();
-
 
160
					ipq.setQty((long) li.getQuantity());
-
 
161
					ipq.setItemId(li.getItemId());
-
 
162
					ipq.setPrice(li.getUnit_price());
-
 
163
					ipqList.add(ipq);
-
 
164
					totalAmount = li.getUnit_price() * li.getQuantity();
-
 
165
				}
-
 
166
				if (totalAmount > walletAmount) {
-
 
167
					addActionError("Total Amount not be greater than wallet amount");
-
 
168
				} else if (!userClient.addItemPricingToCart(user.getActiveCartId(), ipqList)) {
-
 
169
					addActionError("Total Amount not be greater than wallet amount");
-
 
170
				} else {
-
 
171
					log.info("Setting wallet amount in cart");
-
 
172
					userClient.setWalletAmountInCart(user.getActiveCartId(), walletAmount);
-
 
173
					transactionId = String.valueOf(userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, user.getUserId(), 7890,
-
 
174
							OrderSource.WEBSITE.getValue(), true));
-
 
175
					log.info("Creating wallet payment for transactionId - " + transactionId);
-
 
176
					createPayment(user);
-
 
177
 
-
 
178
					in.shop2020.model.v1.order.Attribute orderAttribute1 = new in.shop2020.model.v1.order.Attribute();
-
 
179
					orderAttribute1.setName("poRefNumber");
-
 
180
					orderAttribute1.setValue(poRefNumber);
-
 
181
 
-
 
182
					if (!poRefNumber.equals("") && !(poRefNumber == null)) {
-
 
183
						transactionClient.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute1);
-
 
184
					}
-
 
185
					transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED,
-
 
186
							"Payment received for the order", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
-
 
187
							OrderSource.WEBSITE);
-
 
188
					transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
-
 
189
							"RTGS Payment accepted", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
-
 
190
							OrderSource.WEBSITE);
-
 
191
					log.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
-
 
192
					hasError = false;
-
 
193
				}
-
 
194
			}
-
 
195
		} catch (Exception e) {
-
 
196
			addActionError("Error occerred" + e.getMessage());
-
 
197
			e.printStackTrace();
-
 
198
		}
-
 
199
		if (hasError) {
-
 
200
			return "error";
-
 
201
		}
-
 
202
 
-
 
203
		id = transactionId;
-
 
204
		return show();
-
 
205
	}
-
 
206
 
-
 
207
	public String getModelName() {
-
 
208
		output = "Invalid Item Id: " + itemId;
-
 
209
 
-
 
210
		try {
-
 
211
			in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
-
 
212
			Item item = client.getItem(Long.parseLong(itemId));
-
 
213
			if (item != null && item.getId() != 0) {
-
 
214
				output = ModelUtils.extractProductNameFromItem(item);
-
 
215
			}
-
 
216
		} catch (NumberFormatException e) {
-
 
217
			log.error("Could not parse itemId: " + itemId, e);
-
 
218
		} catch (CatalogServiceException e) {
-
 
219
			log.error("Could not lookup itemId: " + itemId, e);
-
 
220
		} catch (TException e) {
-
 
221
			log.error("Could not find itemId: " + itemId, e);
-
 
222
		}
-
 
223
 
-
 
224
		return "output";
-
 
225
	}
-
 
226
	/**
-
 
227
	 As it is always going to be wallet
-
 
228
	 **/
-
 
229
	private void createPayment(User user) throws NumberFormatException, PaymentException, TException {
-
 
230
		List<Attribute> paymentAttributes = new ArrayList<Attribute>();
-
 
231
		paymentAttributes.add(new Attribute(PAY_METHOD, "7890"));
-
 
232
		/*
-
 
233
		 * paymentAttributes.add(new Attribute(RTGS_ID, rtgsId));
-
 
234
		 * paymentAttributes.add(new Attribute(RTGS_BANK, rtgsBank));
-
 
235
		 * paymentAttributes.add(new Attribute(RTGS_BRANCH, rtgsBranch));
-
 
236
		 * paymentAttributes.add(new Attribute(IFSC_CODE, ifscCode));
-
 
237
		 */
-
 
238
 
-
 
239
		in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
-
 
240
		long paymentId = client.createPayment(user.getUserId(), Double.valueOf(amount), WALLET_GATEWAY_ID, Long.valueOf(transactionId),
-
 
241
				false);
-
 
242
		client.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null,
-
 
243
				paymentAttributes);
-
 
244
	}
-
 
245
 
-
 
246
	/*
-
 
247
	 * private long createTransaction(User user) throws
-
 
248
	 * TransactionServiceException, TException, CatalogServiceException {
-
 
249
	 * Transaction txn = new Transaction();
-
 
250
	 * txn.setShoppingCartid(user.getActiveCartId());
-
 
251
	 * txn.setCustomer_id(user.getUserId()); txn.setCreatedOn(new
-
 
252
	 * Date().getTime()); txn.setTransactionStatus(TransactionStatus.INIT);
-
 
253
	 * txn.setStatusDescription("New Order"); txn.setOrders(createOrders(user));
-
 
254
	 * Client transaction_client = new TransactionClient().getClient(); return
-
 
255
	 * transaction_client.createTransaction(txn); }
-
 
256
	 */
-
 
257
 
-
 
258
	private List<Order> createOrders(User user) throws CatalogServiceException, TException {
-
 
259
		List<Order> orders = new ArrayList<Order>();
-
 
260
 
-
 
261
		// Extracting default address
-
 
262
		Address defaultAddress = null;
-
 
263
		for (Address address : user.getAddresses()) {
-
 
264
			if (address.getId() == user.getDefaultAddressId()) {
-
 
265
				defaultAddress = address;
-
 
266
				break;
-
 
267
			}
-
 
268
		}
-
 
269
 
-
 
270
		for (LineItem lineItem : lineItems) {
-
 
271
			enrichLineItem(lineItem);
-
 
272
 
-
 
273
			Order t_order = new Order();
-
 
274
			t_order.setCustomer_id(user.getUserId());
-
 
275
			t_order.setCustomer_email(user.getEmail());
-
 
276
			t_order.setCustomer_name(defaultAddress.getName());
-
 
277
			t_order.setCustomer_pincode(defaultAddress.getPin());
-
 
278
			t_order.setCustomer_address1(defaultAddress.getLine1());
-
 
279
			t_order.setCustomer_address2(defaultAddress.getLine2());
-
 
280
			t_order.setCustomer_city(defaultAddress.getCity());
-
 
281
			t_order.setCustomer_state(defaultAddress.getState());
-
 
282
			t_order.setCustomer_mobilenumber(defaultAddress.getPhone());
-
 
283
			t_order.setTotal_amount(lineItem.getTotal_price());
-
 
284
			t_order.setTotal_weight(lineItem.getTotal_weight());
-
 
285
			t_order.setLineitems(Collections.singletonList(lineItem));
-
 
286
			t_order.setStatus(OrderStatus.PAYMENT_PENDING);
-
 
287
			t_order.setStatusDescription("Payment Pending");
-
 
288
			t_order.setCreated_timestamp(new Date().getTime());
-
 
289
			t_order.setSource(1);// Source : Website
-
 
290
			t_order.setProductCondition(ProductCondition.findByValue(productCondition));
-
 
291
			// t_order.setProductCondition(ProductCondition.findByValue(productCondition.intValue()));
-
 
292
 
-
 
293
			orders.add(t_order);
-
 
294
		}
-
 
295
 
-
 
296
		return orders;
-
 
297
	}
-
 
298
 
-
 
299
	private LineItem enrichLineItem(LineItem lineItem) throws CatalogServiceException, TException {
-
 
300
		in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
56
 
301
 
57
    private static Log log = LogFactory.getLog(BulkOrderController.class);
302
		Item item = client.getItem(lineItem.getItem_id());
58
    private SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
 
59
 
303
 
60
    private static final String IFSC_CODE   = "ifscCode";
304
		lineItem.setProductGroup(item.getProductGroup());
61
    private static final String RTGS_BRANCH = "rtgsBranch";
305
		lineItem.setBrand(item.getBrand());
62
    private static final String RTGS_BANK   = "rtgsBank";
306
		lineItem.setModel_number(item.getModelNumber());
63
    private static final String RTGS_ID     = "rtgsId";
307
		lineItem.setModel_name(item.getModelName());
64
    private static final String PAY_METHOD  = "payMethod";
308
		lineItem.setExtra_info(item.getFeatureDescription());
65
 
309
		lineItem.setItem_id(item.getId());
66
    private String id;
310
		lineItem.setUnit_weight(item.getWeight());
67
    private String transactionId;
311
		lineItem.setTotal_weight(item.getWeight() * lineItem.getQuantity());
68
    private String customerEmailId;
312
		lineItem.setDealText(item.getBestDealText());
69
    private String rtgsId;
313
		lineItem.setTotal_price(lineItem.getUnit_price() * lineItem.getQuantity());
70
    private String rtgsBank;
314
 
71
    private String rtgsBranch;
315
		if (item.getColor() == null || "NA".equals(item.getColor())) {
72
    private String ifscCode;
316
			lineItem.setColor("");
73
    private String amount;
317
		} else {
74
    private String itemId;
318
			lineItem.setColor(item.getColor());
75
    private String output;
319
		}
76
    private String pickUp;
320
 
77
    private String orderType;
321
		return lineItem;
78
    private String tinNumber;
322
	}
79
    private String poRefNumber;
323
 
80
    private int productCondition;
324
	private boolean validate() {
81
    private int taxType;
325
		return false;
82
    private Transaction transaction;
326
	}
83
    private Payment payment;
327
 
84
 
328
	public String convertDate(long date) {
85
    private Map<Transaction, Double> transactions;
329
		return SDF.format(new Date(date));
86
    private List<LineItem> lineItems;
330
	}
87
 
331
 
88
    public String index() {
332
	public String extractProductName(LineItem lineItem) {
89
        transactions = new HashMap<Transaction, Double>();
333
		if (lineItem == null) {
90
 
334
			return "N/A";
91
        try {
335
		}
92
            Client transactionClient = new TransactionClient().getClient();
336
 
93
            in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
337
		return ModelUtils.extractProductNameFromLineItem(lineItem);
94
            List<Payment> payments = paymentClient.getPayments(0, new Date().getTime(), PaymentStatus.SUCCESS, RTGS_GATEWAY_ID);
338
	}
95
 
339
 
96
            log.info("Loaded " + payments.size() + " payments");
340
	// Getters and Setters
97
            for (Payment payment : payments) {
341
	public String getCustomerEmailId() {
98
                Transaction txn = transactionClient.getTransaction(payment.getMerchantTxnId());
342
		return customerEmailId;
99
                log.info("Got " + txn);
343
	}
100
                transactions.put(txn, payment.getAmount());
344
 
101
            }
345
	public void setCustomerEmailId(String customerEmailId) {
102
        } catch (TTransportException e) {
346
		this.customerEmailId = customerEmailId;
103
            log.error("Could not create transaction client", e);
347
	}
104
        } catch (TransactionServiceException e) {
348
 
105
            log.error("Could not lookup transaction", e);
349
	public String getRtgsId() {
106
        } catch (TException e) {
350
		return rtgsId;
107
            log.error("Could not find payment", e);
351
	}
108
        } catch (PaymentException e) {
352
 
109
            log.error("Could not find payment", e);
353
	public void setRtgsId(String rtgsId) {
110
        }
354
		this.rtgsId = rtgsId;
111
 
355
	}
112
        return "index";
356
 
113
    }
357
	public String getRtgsBank() {
114
 
358
		return rtgsBank;
115
    public String editNew() {
359
	}
116
        return "editNew";
360
 
117
    }
361
	public void setRtgsBank(String rtgsBank) {
118
 
362
		this.rtgsBank = rtgsBank;
119
    public String show() {
363
	}
120
        try {
364
 
121
            transactionId = id;
365
	public String getRtgsBranch() {
122
 
366
		return rtgsBranch;
123
            Client transactionClient = new TransactionClient().getClient();
367
	}
124
            transaction = transactionClient.getTransaction(Long.valueOf(transactionId));
368
 
125
 
369
	public void setRtgsBranch(String rtgsBranch) {
126
            in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
370
		this.rtgsBranch = rtgsBranch;
127
            payment = paymentClient.getPaymentForTxnId(Long.valueOf(transactionId)).get(0);
371
	}
128
 
372
 
129
            for (Attribute attribute : payment.getAttributes()) {
373
	public String getIfscCode() {
130
                if (RTGS_ID.equals(attribute.getName())) {
374
		return ifscCode;
131
                    rtgsId = attribute.getValue();
375
	}
132
                }
376
 
133
                else if (RTGS_BANK.equals(attribute.getName())) {
377
	public void setIfscCode(String ifscCode) {
134
                    rtgsBank = attribute.getValue();
378
		this.ifscCode = ifscCode;
135
                }
379
	}
136
                else if (RTGS_BRANCH.equals(attribute.getName())) {
380
 
137
                    rtgsBranch = attribute.getValue();
381
	public String getAmount() {
138
                }
382
		return amount;
139
                else if (IFSC_CODE.equals(attribute.getName())) {
383
	}
140
                    ifscCode = attribute.getValue();
384
 
141
                }
385
	public void setAmount(String amount) {
142
            }
386
		this.amount = amount;
143
        } catch (NumberFormatException e) {
387
	}
144
            log.error("Could not lookup transaction Id: " + transactionId, e);
388
 
145
        } catch (TransactionServiceException e) {
389
	public List<LineItem> getLineItems() {
146
            log.error("Could not lookup transaction Id: " + transactionId, e);
390
		return lineItems;
147
        } catch (TException e) {
391
	}
148
            log.error("Could not lookup transaction Id: " + transactionId, e);
392
 
149
        } catch (PaymentException e) {
393
	public void setLineItems(List<LineItem> lineItems) {
150
            log.error("Could not lookup payment for transaction Id: " + transactionId, e);
394
		this.lineItems = lineItems;
151
        }
395
	}
152
 
396
 
153
        return "show";
397
	public Map<Transaction, Double> getTransactions() {
154
    }
398
		return transactions;
155
 
399
	}
156
    public String create() {
400
 
157
        log.info("Creating orders for " + lineItems);
401
	public void setTransactions(Map<Transaction, Double> transactions) {
158
 
402
		this.transactions = transactions;
159
        boolean hasError = false;
403
	}
160
 
404
 
161
        try {
405
	public String getTransactionId() {
162
            hasError = validate();
406
		return transactionId;
163
 
407
	}
164
            in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
408
 
165
            User user = userClient.getUserByEmail(customerEmailId);
409
	public void setTransactionId(String transactionId) {
166
 
410
		this.transactionId = transactionId;
167
            if (user == null) {
411
	}
168
                addActionError("Could not find user by email: " + customerEmailId);
412
 
169
                hasError = true;
413
	public Transaction getTransaction() {
170
            }
414
		return transaction;
171
            else {
415
	}
172
                /*
416
 
173
            	boolean selfPickupFlag = false;
417
	public void setTransaction(Transaction transaction) {
174
            	if(selfPickup.equals("on")){
418
		this.transaction = transaction;
175
            		selfPickupFlag = true;
419
	}
176
            	}
420
 
177
            	*/
421
	public Payment getPayment() {
178
                transactionId = String.valueOf(createTransaction(user));
422
		return payment;
179
                createPayment(user);
423
	}
180
                
424
 
181
                in.shop2020.model.v1.order.Attribute orderAttribute = new in.shop2020.model.v1.order.Attribute();
425
	public void setPayment(Payment payment) {
182
                orderAttribute.setName("tinNumber");
426
		this.payment = payment;
183
                orderAttribute.setValue(tinNumber);
427
	}
184
                
428
 
185
                in.shop2020.model.v1.order.Attribute orderAttribute1 = new in.shop2020.model.v1.order.Attribute();
429
	public String getId() {
186
                orderAttribute1.setName("poRefNumber");
430
		return id;
187
                orderAttribute1.setValue(poRefNumber);
431
	}
188
 
432
 
189
                Client transactionClient = new TransactionClient().getClient();
433
	public void setId(String id) {
190
                if(!tinNumber.equals("") && !(tinNumber == null)) {
434
		this.id = id;
191
                    transactionClient.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute);
435
	}
192
                }
436
 
193
                if(!poRefNumber.equals("") && !(poRefNumber == null)) {
437
	public String getItemId() {
194
                    transactionClient.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute1);
438
		return itemId;
195
                }
439
	}
196
                transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED, "Payment received for the order", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType), OrderSource.WEBSITE);
440
 
197
                transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS, "RTGS Payment accepted", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType), OrderSource.WEBSITE);
441
	public void setItemId(String itemId) {
198
                log.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
442
		this.itemId = itemId;
199
            }
443
	}
200
        } catch (UserContextException e) {
444
 
201
            addActionError("Error while finding customer: " + customerEmailId);
445
	public String getOutput() {
202
            log.error("Could not fetch user for email Id: " + customerEmailId, e);
446
		return output;
203
        } catch (TException e) {
447
	}
204
            addActionError("Error while finding customer: " + customerEmailId);
448
 
205
            log.error("Could not fetch user for email Id: " + customerEmailId, e);
449
	public void setOutput(String output) {
206
        } catch (TransactionServiceException e) {
450
		this.output = output;
207
            addActionError("Error creating transaction");
451
	}
208
            log.error("Could not create transction Id", e);
452
 
209
        } catch (CatalogServiceException e) {
453
	public String getPickUp() {
210
            addActionError("Error updating inventory");
454
		return pickUp;
211
            log.error("Error in CatalogService", e);
455
	}
212
        } catch (NumberFormatException e) {
456
 
213
            addActionError("Error parsing transaction Id: " + transactionId);
457
	public void setPickUp(String pickUp) {
214
            log.error("Error parsing transaction Id: " + transactionId, e);
458
		this.pickUp = pickUp;
215
        } catch (PaymentException e) {
459
	}
216
            addActionError("Error creating payment");
460
 
217
            log.error("Could not create payment", e);
461
	public String getOrderType() {
218
        }
462
		return orderType;
219
 
463
	}
220
        if (hasError) {
464
 
221
            return "error";
465
	public void setOrderType(String orderType) {
222
        }
466
		this.orderType = orderType;
223
 
467
	}
224
        id = transactionId;
468
 
225
        return show();
469
	public String getTinNumber() {
226
    }
470
		return tinNumber;
227
 
471
	}
228
    public String getModelName() {
472
 
229
        output = "Invalid Item Id: " + itemId;
473
	public void setTinNumber(String tinNumber) {
230
 
474
		this.tinNumber = tinNumber;
231
        try {
475
	}
232
            in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
-
 
233
            Item item = client.getItem(Long.parseLong(itemId));
-
 
234
            if (item != null && item.getId() != 0) {
-
 
235
                output = ModelUtils.extractProductNameFromItem(item);
-
 
236
            }
-
 
237
        } catch (NumberFormatException e) {
-
 
238
            log.error("Could not parse itemId: " + itemId, e);
-
 
239
        } catch (CatalogServiceException e) {
-
 
240
            log.error("Could not lookup itemId: " + itemId, e);
-
 
241
        } catch (TException e) {
-
 
242
            log.error("Could not find itemId: " + itemId, e);
-
 
243
        }
-
 
244
 
-
 
245
        return "output";
-
 
246
    }
-
 
247
 
-
 
248
    private void createPayment(User user) throws NumberFormatException, PaymentException, TException {
-
 
249
        List<Attribute> paymentAttributes = new ArrayList<Attribute>();
-
 
250
        paymentAttributes.add(new Attribute(PAY_METHOD, "4000"));
-
 
251
        paymentAttributes.add(new Attribute(RTGS_ID, rtgsId));
-
 
252
        paymentAttributes.add(new Attribute(RTGS_BANK, rtgsBank));
-
 
253
        paymentAttributes.add(new Attribute(RTGS_BRANCH, rtgsBranch));
-
 
254
        paymentAttributes.add(new Attribute(IFSC_CODE, ifscCode));
-
 
255
 
-
 
256
        in.shop2020.payments.PaymentService.Client client = new PaymentClient().getClient();
-
 
257
        long paymentId = client.createPayment(user.getUserId(), Double.valueOf(amount), RTGS_GATEWAY_ID, Long.valueOf(transactionId), false);
-
 
258
        client.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null, paymentAttributes);
-
 
259
    }
-
 
260
 
-
 
261
    private long createTransaction(User user) throws TransactionServiceException, TException, CatalogServiceException {
-
 
262
        Transaction txn = new Transaction();
-
 
263
        txn.setShoppingCartid(user.getActiveCartId());
-
 
264
        txn.setCustomer_id(user.getUserId());
-
 
265
        txn.setCreatedOn(new Date().getTime());
-
 
266
        txn.setTransactionStatus(TransactionStatus.INIT);
-
 
267
        txn.setStatusDescription("New Order");
-
 
268
        txn.setOrders(createOrders(user));
-
 
269
        Client transaction_client = new TransactionClient().getClient();
-
 
270
        return transaction_client.createTransaction(txn);
-
 
271
    }
-
 
272
 
-
 
273
    private List<Order> createOrders(User user) throws CatalogServiceException, TException {
-
 
274
        List<Order> orders = new ArrayList<Order>();
-
 
275
 
-
 
276
        // Extracting default address
-
 
277
        Address defaultAddress = null;
-
 
278
        for (Address address : user.getAddresses()) {
-
 
279
            if (address.getId() == user.getDefaultAddressId()) {
-
 
280
                defaultAddress = address;
-
 
281
                break;
-
 
282
            }
-
 
283
        }
-
 
284
 
-
 
285
        for (LineItem lineItem : lineItems) {
-
 
286
            enrichLineItem(lineItem);
-
 
287
 
-
 
288
            Order t_order = new Order();
-
 
289
            t_order.setCustomer_id(user.getUserId());
-
 
290
            t_order.setCustomer_email(user.getEmail());
-
 
291
            t_order.setCustomer_name(defaultAddress.getName());
-
 
292
            t_order.setCustomer_pincode(defaultAddress.getPin());
-
 
293
            t_order.setCustomer_address1(defaultAddress.getLine1());
-
 
294
            t_order.setCustomer_address2(defaultAddress.getLine2());
-
 
295
            t_order.setCustomer_city(defaultAddress.getCity());
-
 
296
            t_order.setCustomer_state(defaultAddress.getState());
-
 
297
            t_order.setCustomer_mobilenumber(defaultAddress.getPhone());
-
 
298
            t_order.setTotal_amount(lineItem.getTotal_price());            
-
 
299
            t_order.setTotal_weight(lineItem.getTotal_weight());
-
 
300
            t_order.setLineitems(Collections.singletonList(lineItem));            
-
 
301
            t_order.setStatus(OrderStatus.PAYMENT_PENDING);
-
 
302
            t_order.setStatusDescription("Payment Pending");
-
 
303
            t_order.setCreated_timestamp(new Date().getTime());
-
 
304
            t_order.setSource(1);//Source : Website
-
 
305
            t_order.setProductCondition(ProductCondition.findByValue(productCondition));
-
 
306
            t_order.setTaxType(TaxType.findByValue(taxType));
-
 
307
            //t_order.setProductCondition(ProductCondition.findByValue(productCondition.intValue()));
-
 
308
 
-
 
309
            orders.add(t_order);
-
 
310
        }
-
 
311
 
-
 
312
        return orders;
-
 
313
    }
-
 
314
 
-
 
315
    private LineItem enrichLineItem(LineItem lineItem)
-
 
316
            throws CatalogServiceException, TException {
-
 
317
        in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
-
 
318
 
-
 
319
        Item item = client.getItem(lineItem.getItem_id());
-
 
320
 
-
 
321
        lineItem.setProductGroup(item.getProductGroup());
-
 
322
        lineItem.setBrand(item.getBrand());
-
 
323
        lineItem.setModel_number(item.getModelNumber());
-
 
324
        lineItem.setModel_name(item.getModelName());
-
 
325
        lineItem.setExtra_info(item.getFeatureDescription());
-
 
326
        lineItem.setItem_id(item.getId());
-
 
327
        lineItem.setUnit_weight(item.getWeight());
-
 
328
        lineItem.setTotal_weight(item.getWeight() * lineItem.getQuantity());
-
 
329
        lineItem.setDealText(item.getBestDealText());
-
 
330
        lineItem.setTotal_price(lineItem.getUnit_price() * lineItem.getQuantity());
-
 
331
 
-
 
332
        if (item.getColor() == null || "NA".equals(item.getColor())) {
-
 
333
            lineItem.setColor("");
-
 
334
        } else {
-
 
335
            lineItem.setColor(item.getColor());
-
 
336
        }
-
 
337
 
-
 
338
        return lineItem;
-
 
339
    }
-
 
340
 
-
 
341
    private boolean validate() {
-
 
342
        return false;
-
 
343
    }
-
 
344
 
-
 
345
    public String convertDate(long date) {
-
 
346
        return SDF.format(new Date(date));
-
 
347
    }
-
 
348
 
-
 
349
    public String extractProductName(LineItem lineItem) {
-
 
350
        if (lineItem == null) {
-
 
351
            return "N/A";
-
 
352
        }
-
 
353
 
-
 
354
        return ModelUtils.extractProductNameFromLineItem(lineItem);
-
 
355
    }
-
 
356
 
-
 
357
    // Getters and Setters
-
 
358
    public String getCustomerEmailId() {
-
 
359
        return customerEmailId;
-
 
360
    }
-
 
361
 
-
 
362
    public void setCustomerEmailId(String customerEmailId) {
-
 
363
        this.customerEmailId = customerEmailId;
-
 
364
    }
-
 
365
 
-
 
366
    public String getRtgsId() {
-
 
367
        return rtgsId;
-
 
368
    }
-
 
369
 
-
 
370
    public void setRtgsId(String rtgsId) {
-
 
371
        this.rtgsId = rtgsId;
-
 
372
    }
-
 
373
 
-
 
374
    public String getRtgsBank() {
-
 
375
        return rtgsBank;
-
 
376
    }
-
 
377
 
-
 
378
    public void setRtgsBank(String rtgsBank) {
-
 
379
        this.rtgsBank = rtgsBank;
-
 
380
    }
-
 
381
 
-
 
382
    public String getRtgsBranch() {
-
 
383
        return rtgsBranch;
-
 
384
    }
-
 
385
 
-
 
386
    public void setRtgsBranch(String rtgsBranch) {
-
 
387
        this.rtgsBranch = rtgsBranch;
-
 
388
    }
-
 
389
 
-
 
390
    public String getIfscCode() {
-
 
391
        return ifscCode;
-
 
392
    }
-
 
393
 
-
 
394
    public void setIfscCode(String ifscCode) {
-
 
395
        this.ifscCode = ifscCode;
-
 
396
    }
-
 
397
 
-
 
398
    public String getAmount() {
-
 
399
        return amount;
-
 
400
    }
-
 
401
 
-
 
402
    public void setAmount(String amount) {
-
 
403
        this.amount = amount;
-
 
404
    }
-
 
405
 
-
 
406
    public List<LineItem> getLineItems() {
-
 
407
        return lineItems;
-
 
408
    }
-
 
409
 
-
 
410
    public void setLineItems(List<LineItem> lineItems) {
-
 
411
        this.lineItems = lineItems;
-
 
412
    }
-
 
413
 
-
 
414
    public Map<Transaction, Double> getTransactions() {
-
 
415
        return transactions;
-
 
416
    }
-
 
417
 
-
 
418
    public void setTransactions(Map<Transaction, Double> transactions) {
-
 
419
        this.transactions = transactions;
-
 
420
    }
-
 
421
 
-
 
422
    public String getTransactionId() {
-
 
423
        return transactionId;
-
 
424
    }
-
 
425
 
-
 
426
    public void setTransactionId(String transactionId) {
-
 
427
        this.transactionId = transactionId;
-
 
428
    }
-
 
429
 
-
 
430
    public Transaction getTransaction() {
-
 
431
        return transaction;
-
 
432
    }
-
 
433
 
-
 
434
    public void setTransaction(Transaction transaction) {
-
 
435
        this.transaction = transaction;
-
 
436
    }
-
 
437
 
-
 
438
    public Payment getPayment() {
-
 
439
        return payment;
-
 
440
    }
-
 
441
 
-
 
442
    public void setPayment(Payment payment) {
-
 
443
        this.payment = payment;
-
 
444
    }
-
 
445
 
-
 
446
    public String getId() {
-
 
447
        return id;
-
 
448
    }
-
 
449
 
-
 
450
    public void setId(String id) {
-
 
451
        this.id = id;
-
 
452
    }
-
 
453
 
-
 
454
    public String getItemId() {
-
 
455
        return itemId;
-
 
456
    }
-
 
457
 
-
 
458
    public void setItemId(String itemId) {
-
 
459
        this.itemId = itemId;
-
 
460
    }
-
 
461
 
-
 
462
    public String getOutput() {
-
 
463
        return output;
-
 
464
    }
-
 
465
 
-
 
466
    public void setOutput(String output) {
-
 
467
        this.output = output;
-
 
468
    }
-
 
469
 
-
 
470
    public String getPickUp() {
-
 
471
        return pickUp;
-
 
472
    }
-
 
473
 
-
 
474
    public void setPickUp(String pickUp) {
-
 
475
        this.pickUp = pickUp;
-
 
476
    }
-
 
477
 
-
 
478
    public String getOrderType() {
-
 
479
        return orderType;
-
 
480
    }
-
 
481
 
-
 
482
    public void setOrderType(String orderType) {
-
 
483
        this.orderType = orderType;
-
 
484
    }
-
 
485
 
-
 
486
    public String getTinNumber() {
-
 
487
        return tinNumber;
-
 
488
    }
-
 
489
 
-
 
490
    public void setTinNumber(String tinNumber) {
-
 
491
        this.tinNumber = tinNumber;
-
 
492
    }
-
 
493
 
476
 
494
	public int getProductCondition() {
477
	public int getProductCondition() {
495
		return productCondition;
478
		return productCondition;
496
	}
479
	}
497
 
480
 
498
	public void setProductCondition(int productCondition) {
481
	public void setProductCondition(int productCondition) {
499
		this.productCondition = productCondition;
482
		this.productCondition = productCondition;
500
	}
483
	}
501
 
484
 
502
	public int getTaxType() {
-
 
503
		return taxType;
-
 
504
	}
-
 
505
 
-
 
506
	public void setTaxType(int taxType) {
-
 
507
		this.taxType = taxType;
-
 
508
	}
-
 
509
	
-
 
510
	public String getPoRefNumber() {
485
	public String getPoRefNumber() {
511
		return poRefNumber;
486
		return poRefNumber;
512
	}
487
	}
513
 
488
 
514
	public void setPoRefNumber(String poRefNumber) {
489
	public void setPoRefNumber(String poRefNumber) {
Line 522... Line 497...
522
		blc.setRtgsBank("rtgsBank");
497
		blc.setRtgsBank("rtgsBank");
523
		blc.setRtgsBranch("rtgsBranch");
498
		blc.setRtgsBranch("rtgsBranch");
524
		blc.setIfscCode("ifscCode");
499
		blc.setIfscCode("ifscCode");
525
		blc.setAmount("3400");
500
		blc.setAmount("3400");
526
		blc.setItemId("10661");
501
		blc.setItemId("10661");
527
		//blc.setOutput();
502
		// blc.setOutput();
528
		blc.setPickUp("COURIER");
503
		blc.setPickUp("COURIER");
529
		blc.setOrderType("B2Cbulk");
504
		blc.setOrderType("B2Cbulk");
530
		//blc.setTinNumber();
505
		// blc.setTinNumber();
531
		blc.setProductCondition(0);
506
		blc.setProductCondition(ProductCondition.GOOD.getValue());
532
		blc.setTaxType(0);
-
 
533
		
507
 
534
		
-
 
535
		blc.index();
508
		blc.index();
536
		/*
509
		/*
537
		 * = "ifscCode";
-
 
538
    private static final String RTGS_BRANCH = "rtgsBranch";
510
		 * = "ifscCode"; private static final String RTGS_BRANCH = "rtgsBranch";
539
    private static final String RTGS_BANK   = "rtgsBank";
511
		 * private static final String RTGS_BANK = "rtgsBank"; private static
540
    private static final String RTGS_ID     = "rtgsId";
-
 
541
		 * private String customerEmailId;
512
		 * final String RTGS_ID = "rtgsId"; private String customerEmailId;
542
	    private String rtgsId;
-
 
543
	    private String rtgsBank;
513
		 * private String rtgsId; private String rtgsBank; private String
544
	    private String rtgsBranch;
-
 
545
	    private String ifscCode;
514
		 * rtgsBranch; private String ifscCode; private String amount; private
546
	    private String amount;
-
 
547
	    private String itemId;
-
 
548
	    private String output;
-
 
549
	    private String pickUp;
-
 
550
	    private String orderType;
515
		 * String itemId; private String output; private String pickUp; private
551
	    private String tinNumber;
516
		 * String orderType; private String tinNumber; private int
552
	    private int productCondition;
517
		 * productCondition; private int taxType;
553
	    private int taxType;*/
518
		 */
554
		//blc.set
519
		// blc.set
555
	}
520
	}
-
 
521
 
-
 
522
	public double getWalletAmount() {
-
 
523
		return this.userWalletAmount;
556
    
524
	}
-
 
525
 
557
}
526
}