Subversion Repositories SmartDukaan

Rev

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

Rev 22451 Rev 22452
Line 17... Line 17...
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.user.Address;
19
import in.shop2020.model.v1.user.Address;
20
import in.shop2020.model.v1.user.ItemPriceQuantity;
20
import in.shop2020.model.v1.user.ItemPriceQuantity;
21
import in.shop2020.model.v1.user.User;
21
import in.shop2020.model.v1.user.User;
22
import in.shop2020.model.v1.user.UserContextException;
-
 
23
import in.shop2020.payments.Attribute;
22
import in.shop2020.payments.Attribute;
24
import in.shop2020.payments.Payment;
23
import in.shop2020.payments.Payment;
25
import in.shop2020.payments.PaymentException;
24
import in.shop2020.payments.PaymentException;
26
import in.shop2020.payments.PaymentStatus;
25
import in.shop2020.payments.PaymentStatus;
27
import in.shop2020.thrift.clients.CatalogClient;
26
import in.shop2020.thrift.clients.CatalogClient;
Line 78... Line 77...
78
	private int productCondition;
77
	private int productCondition;
79
	private Transaction transaction;
78
	private Transaction transaction;
80
	private Payment payment;
79
	private Payment payment;
81
	private long userWalletAmount;
80
	private long userWalletAmount;
82
	private int userId;
81
	private int userId;
-
 
82
	
83
 
83
 
84
	private Map<Transaction, Double> transactions;
84
	private Map<Transaction, Double> transactions;
85
	private List<LineItem> lineItems;
85
	private List<LineItem> lineItems;
-
 
86
	
-
 
87
	private Client transactionClient;
-
 
88
	private in.shop2020.model.v1.user.UserContextService.Client userClient;
-
 
89
	private in.shop2020.payments.PaymentService.Client paymentClient;
-
 
90
	private in.shop2020.model.v1.catalog.CatalogService.Client catalogClient;
-
 
91
	
-
 
92
	public BulkOrderController() {
-
 
93
		super();
-
 
94
		try {
-
 
95
			this.userClient = new UserClient().getClient();
-
 
96
			this.paymentClient = new PaymentClient().getClient();
-
 
97
			this.transactionClient = new TransactionClient().getClient();
-
 
98
			this.catalogClient = new CatalogClient().getClient();
-
 
99
		} catch (Exception e){
-
 
100
			log.error("Error occured while initialising client");
-
 
101
			e.printStackTrace();
-
 
102
		}
-
 
103
	}
86
 
104
 
87
	public String index() {
105
	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";
106
		return "index";
110
	}
107
	}
111
 
108
 
112
	public String editNew() throws Throwable {
109
	public String editNew() throws Throwable {
113
		in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
-
 
114
		User user = userClient.getUserByEmail(customerEmailId);
110
		User user = userClient.getUserByEmail(customerEmailId);
115
		Client transactionClient = new TransactionClient().getClient();
-
 
116
		this.userWalletAmount = transactionClient.getUserWallet(user.getUserId()).getAmount();
111
		this.userWalletAmount = this.transactionClient.getUserWallet(user.getUserId()).getAmount();
117
		return "editNew";
112
		return "editNew";
118
	}
113
	}
119
 
114
 
120
	public String show() {
115
	public String show() {
121
		try {
116
		try {
122
			transactionId = id;
117
			transactionId = id;
123
 
118
 
124
			Client transactionClient = new TransactionClient().getClient();
-
 
125
			transaction = transactionClient.getTransaction(Long.valueOf(transactionId));
119
			transaction = this.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);
120
			payment = this.paymentClient.getPaymentForTxnId(Long.valueOf(transactionId)).get(0);
129
 
121
 
130
		} catch (NumberFormatException e) {
122
		} catch (NumberFormatException e) {
131
			log.error("Could not lookup transaction Id: " + transactionId, e);
123
			log.error("Could not lookup transaction Id: " + transactionId, e);
132
		} catch (TransactionServiceException e) {
124
		} catch (TransactionServiceException e) {
133
			log.error("Could not lookup transaction Id: " + transactionId, e);
125
			log.error("Could not lookup transaction Id: " + transactionId, e);
Line 143... Line 135...
143
	public String create() {
135
	public String create() {
144
		log.info("Creating orders for " + lineItems);
136
		log.info("Creating orders for " + lineItems);
145
		boolean hasError = true;
137
		boolean hasError = true;
146
 
138
 
147
		try {
139
		try {
148
			in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient().getClient();
-
 
149
			User user = userClient.getUserByEmail(customerEmailId);
140
			User user = this.userClient.getUserByEmail(customerEmailId);
150
			Client transactionClient = new TransactionClient().getClient();
-
 
151
			List<ItemPriceQuantity> ipqList = new ArrayList<ItemPriceQuantity>();
141
			List<ItemPriceQuantity> ipqList = new ArrayList<ItemPriceQuantity>();
152
			double totalAmount = 0;
142
			double totalAmount = 0;
153
 
143
 
154
			if (user == null) {
144
			if (user == null) {
155
				addActionError("Could not find user by email: " + customerEmailId);
145
				addActionError("Could not find user by email: " + customerEmailId);
156
			} else {
146
			} else {
157
				double walletAmount = transactionClient.getUserWallet(user.getUserId()).getAmount();
147
				double walletAmount = this.transactionClient.getUserWallet(user.getUserId()).getAmount();
158
				for (LineItem li : lineItems) {
148
				for (LineItem li : lineItems) {
159
					ItemPriceQuantity ipq = new ItemPriceQuantity();
149
					ItemPriceQuantity ipq = new ItemPriceQuantity();
160
					ipq.setQty((long) li.getQuantity());
150
					ipq.setQty((long) li.getQuantity());
161
					ipq.setItemId(li.getItemId());
151
					ipq.setItemId(li.getItem_id());
-
 
152
					log.info("Item ID ----------- " + li.getItem_id());
162
					ipq.setPrice(li.getUnit_price());
153
					ipq.setPrice(li.getUnit_price());
163
					ipqList.add(ipq);
154
					ipqList.add(ipq);
164
					totalAmount = li.getUnit_price() * li.getQuantity();
155
					totalAmount = li.getUnit_price() * li.getQuantity();
165
				}
156
				}
166
				if (totalAmount > walletAmount) {
157
				if (totalAmount > walletAmount) {
167
					addActionError("Total Amount not be greater than wallet amount");
158
					addActionError("Total Amount not be greater than wallet amount");
168
				} else if (!userClient.addItemPricingToCart(user.getActiveCartId(), ipqList)) {
159
				} else if (!this.userClient.addItemPricingToCart(user.getActiveCartId(), ipqList)) {
169
					addActionError("Total Amount not be greater than wallet amount");
160
					addActionError("Total Amount not be greater than wallet amount");
170
				} else {
161
				} else {
171
					log.info("Setting wallet amount in cart");
162
					log.info("Setting wallet amount in cart");
172
					userClient.setWalletAmountInCart(user.getActiveCartId(), walletAmount);
163
					this.userClient.setWalletAmountInCart(user.getActiveCartId(), walletAmount);
173
					transactionId = String.valueOf(userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, user.getUserId(), 7890,
164
					transactionId = String.valueOf(this.userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, user.getUserId(), 7890,
174
							OrderSource.WEBSITE.getValue(), true));
165
							OrderSource.WEBSITE.getValue(), true));
175
					log.info("Creating wallet payment for transactionId - " + transactionId);
166
					log.info("Creating wallet payment for transactionId - " + transactionId);
176
					createPayment(user);
167
					createPayment(user);
177
 
168
 
178
					in.shop2020.model.v1.order.Attribute orderAttribute1 = new in.shop2020.model.v1.order.Attribute();
169
					in.shop2020.model.v1.order.Attribute orderAttribute1 = new in.shop2020.model.v1.order.Attribute();
179
					orderAttribute1.setName("poRefNumber");
170
					if (poRefNumber != null && !poRefNumber.equals("")) {
180
					orderAttribute1.setValue(poRefNumber);
171
						orderAttribute1.setName("poRefNumber");
181
 
-
 
182
					if (!poRefNumber.equals("") && !(poRefNumber == null)) {
172
						orderAttribute1.setValue(poRefNumber);
183
						transactionClient.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute1);
173
						this.transactionClient.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute1);
184
					}
174
					}
185
					transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED,
175
					this.transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED,
186
							"Payment received for the order", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
176
							"Payment received for the order", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
187
							OrderSource.WEBSITE);
177
							OrderSource.WEBSITE);
188
					transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
178
					this.transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
189
							"RTGS Payment accepted", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
179
							"RTGS Payment accepted", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
190
							OrderSource.WEBSITE);
180
							OrderSource.WEBSITE);
191
					log.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
181
					log.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
-
 
182
					this.transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
192
					hasError = false;
183
					hasError = false;
193
				}
184
				}
194
			}
185
			}
195
		} catch (Exception e) {
186
		} catch (Exception e) {
196
			addActionError("Error occerred" + e.getMessage());
187
			addActionError("Error occerred - " + e.getMessage());
197
			e.printStackTrace();
188
			e.printStackTrace();
198
		}
189
		}
199
		if (hasError) {
190
		if (hasError) {
200
			return "error";
191
			return "error";
201
		}
192
		}
Line 206... Line 197...
206
 
197
 
207
	public String getModelName() {
198
	public String getModelName() {
208
		output = "Invalid Item Id: " + itemId;
199
		output = "Invalid Item Id: " + itemId;
209
 
200
 
210
		try {
201
		try {
211
			in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
-
 
-
 
202
			
212
			Item item = client.getItem(Long.parseLong(itemId));
203
			Item item = this.catalogClient.getItem(Long.parseLong(itemId));
213
			if (item != null && item.getId() != 0) {
204
			if (item != null && item.getId() != 0) {
214
				output = ModelUtils.extractProductNameFromItem(item);
205
				output = ModelUtils.extractProductNameFromItem(item);
215
			}
206
			}
216
		} catch (NumberFormatException e) {
207
		} catch (NumberFormatException e) {
217
			log.error("Could not parse itemId: " + itemId, e);
208
			log.error("Could not parse itemId: " + itemId, e);
Line 234... Line 225...
234
		 * paymentAttributes.add(new Attribute(RTGS_BANK, rtgsBank));
225
		 * paymentAttributes.add(new Attribute(RTGS_BANK, rtgsBank));
235
		 * paymentAttributes.add(new Attribute(RTGS_BRANCH, rtgsBranch));
226
		 * paymentAttributes.add(new Attribute(RTGS_BRANCH, rtgsBranch));
236
		 * paymentAttributes.add(new Attribute(IFSC_CODE, ifscCode));
227
		 * paymentAttributes.add(new Attribute(IFSC_CODE, ifscCode));
237
		 */
228
		 */
238
 
229
 
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),
230
		long paymentId = this.paymentClient.createPayment(user.getUserId(), Double.valueOf(amount), WALLET_GATEWAY_ID, Long.valueOf(transactionId),
241
				false);
231
				false);
242
		client.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null,
232
		this.paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null,
243
				paymentAttributes);
233
				paymentAttributes);
244
	}
234
	}
245
 
235
 
246
	/*
236
	/*
247
	 * private long createTransaction(User user) throws
237
	 * private long createTransaction(User user) throws
Line 295... Line 285...
295
 
285
 
296
		return orders;
286
		return orders;
297
	}
287
	}
298
 
288
 
299
	private LineItem enrichLineItem(LineItem lineItem) throws CatalogServiceException, TException {
289
	private LineItem enrichLineItem(LineItem lineItem) throws CatalogServiceException, TException {
300
		in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
-
 
301
 
290
 
302
		Item item = client.getItem(lineItem.getItem_id());
291
		Item item = this.catalogClient.getItem(lineItem.getItem_id());
303
 
292
 
304
		lineItem.setProductGroup(item.getProductGroup());
293
		lineItem.setProductGroup(item.getProductGroup());
305
		lineItem.setBrand(item.getBrand());
294
		lineItem.setBrand(item.getBrand());
306
		lineItem.setModel_number(item.getModelNumber());
295
		lineItem.setModel_number(item.getModelNumber());
307
		lineItem.setModel_name(item.getModelName());
296
		lineItem.setModel_name(item.getModelName());