Subversion Repositories SmartDukaan

Rev

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

Rev 23709 Rev 24033
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 java.text.SimpleDateFormat;
-
 
7
import java.util.ArrayList;
-
 
8
import java.util.Collections;
-
 
9
import java.util.Date;
-
 
10
import java.util.HashMap;
-
 
11
import java.util.List;
-
 
12
import java.util.Map;
-
 
13
 
-
 
14
import org.apache.commons.logging.Log;
-
 
15
import org.apache.commons.logging.LogFactory;
-
 
16
import org.apache.thrift.TException;
-
 
17
 
-
 
18
import com.opensymphony.xwork2.ValidationAwareSupport;
-
 
19
 
6
import in.shop2020.logistics.PickUpType;
20
import in.shop2020.logistics.PickUpType;
7
import in.shop2020.model.v1.catalog.CatalogServiceException;
21
import in.shop2020.model.v1.catalog.CatalogServiceException;
-
 
22
import in.shop2020.model.v1.catalog.HsItem;
8
import in.shop2020.model.v1.catalog.Item;
23
import in.shop2020.model.v1.catalog.Item;
9
import in.shop2020.model.v1.order.LineItem;
24
import in.shop2020.model.v1.order.LineItem;
10
import in.shop2020.model.v1.order.Order;
25
import in.shop2020.model.v1.order.Order;
11
import in.shop2020.model.v1.order.OrderSource;
26
import in.shop2020.model.v1.order.OrderSource;
12
import in.shop2020.model.v1.order.OrderType;
27
import in.shop2020.model.v1.order.OrderType;
Line 26... Line 41...
26
import in.shop2020.thrift.clients.PaymentClient;
41
import in.shop2020.thrift.clients.PaymentClient;
27
import in.shop2020.thrift.clients.TransactionClient;
42
import in.shop2020.thrift.clients.TransactionClient;
28
import in.shop2020.thrift.clients.UserClient;
43
import in.shop2020.thrift.clients.UserClient;
29
import in.shop2020.utils.ModelUtils;
44
import in.shop2020.utils.ModelUtils;
30
 
45
 
31
import java.text.SimpleDateFormat;
-
 
32
import java.util.ArrayList;
-
 
33
import java.util.Collections;
-
 
34
import java.util.Date;
-
 
35
import java.util.HashMap;
-
 
36
import java.util.List;
-
 
37
import java.util.Map;
-
 
38
 
-
 
39
import org.apache.commons.logging.Log;
-
 
40
import org.apache.commons.logging.LogFactory;
-
 
41
import org.apache.thrift.TException;
-
 
42
 
-
 
43
import com.opensymphony.xwork2.ValidationAwareSupport;
-
 
44
 
-
 
45
/**
46
/**
46
 * @author mandeep
47
 * @author mandeep
47
 * 
48
 * 
48
 */
49
 */
49
@SuppressWarnings("serial")
50
@SuppressWarnings("serial")
Line 72... Line 73...
72
	private int productCondition;
73
	private int productCondition;
73
	private Transaction transaction;
74
	private Transaction transaction;
74
	private Payment payment;
75
	private Payment payment;
75
	private long userWalletAmount;
76
	private long userWalletAmount;
76
	private int userId;
77
	private int userId;
77
	
-
 
78
 
78
 
79
	private Map<Transaction, Double> transactions;
79
	private Map<Transaction, Double> transactions;
80
	private List<LineItem> lineItems;
80
	private List<LineItem> lineItems;
81
	
81
 
82
	private Client transactionClient;
82
	private Client transactionClient;
83
	private in.shop2020.model.v1.user.UserContextService.Client userClient;
83
	private in.shop2020.model.v1.user.UserContextService.Client userClient;
84
	private in.shop2020.payments.PaymentService.Client paymentClient;
84
	private in.shop2020.payments.PaymentService.Client paymentClient;
85
	private in.shop2020.model.v1.catalog.CatalogService.Client catalogClient;
85
	private in.shop2020.model.v1.catalog.CatalogService.Client catalogClient;
86
	
-
 
87
 
86
 
88
	public String index() {
87
	public String index() {
89
		return "index";
88
		return "index";
90
	}
89
	}
91
	
90
 
92
	public String editNew() throws Throwable {
91
	public String editNew() throws Throwable {
93
		this.userClient = new UserClient().getClient();
92
		this.userClient = new UserClient().getClient();
94
		this.transactionClient = new TransactionClient().getClient();
93
		this.transactionClient = new TransactionClient().getClient();
95
		User user = userClient.getUserByEmail(customerEmailId);
94
		User user = userClient.getUserByEmail(customerEmailId);
96
		this.userWalletAmount = this.transactionClient.getUserWallet(user.getUserId()).getAmount();
95
		this.userWalletAmount = this.transactionClient.getUserWallet(user.getUserId()).getAmount();
Line 122... Line 121...
122
	public String create() throws Throwable {
121
	public String create() throws Throwable {
123
		this.userClient = new UserClient().getClient();
122
		this.userClient = new UserClient().getClient();
124
		this.paymentClient = new PaymentClient().getClient();
123
		this.paymentClient = new PaymentClient().getClient();
125
		this.transactionClient = new TransactionClient().getClient();
124
		this.transactionClient = new TransactionClient().getClient();
126
		this.catalogClient = new CatalogClient().getClient();
125
		this.catalogClient = new CatalogClient().getClient();
127
		
-
 
128
		
126
 
129
		log.info("Creating orders for " + lineItems);
127
		log.info("Creating orders for " + lineItems);
130
		boolean hasError = true;
128
		boolean hasError = true;
131
 
129
 
132
		try {
130
		try {
133
			User user = this.userClient.getUserByEmail(customerEmailId);
131
			User user = this.userClient.getUserByEmail(customerEmailId);
Line 155... Line 153...
155
					addActionError("Please make sure default address is set");
153
					addActionError("Please make sure default address is set");
156
				} else {
154
				} else {
157
					log.info("Setting wallet amount in cart");
155
					log.info("Setting wallet amount in cart");
158
					this.userClient.addAddressToCart(user.getActiveCartId(), user.getDefaultAddressId());
156
					this.userClient.addAddressToCart(user.getActiveCartId(), user.getDefaultAddressId());
159
					this.userClient.setWalletAmountInCart(user.getActiveCartId(), totalAmount);
157
					this.userClient.setWalletAmountInCart(user.getActiveCartId(), totalAmount);
160
					transactionId = String.valueOf(this.userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, user.getUserId(), 7890,
158
					transactionId = String.valueOf(this.userClient.createOrders(user.getActiveCartId(), "", 0, "", 0,
161
							OrderSource.WEBSITE.getValue(), true));
159
							user.getUserId(), 7890, OrderSource.WEBSITE.getValue(), true));
162
					log.info("Creating wallet payment for transactionId - " + transactionId);
160
					log.info("Creating wallet payment for transactionId - " + transactionId);
163
					createPayment(user);
161
					createPayment(user);
164
 
162
 
165
					in.shop2020.model.v1.order.Attribute orderAttribute1 = new in.shop2020.model.v1.order.Attribute();
163
					in.shop2020.model.v1.order.Attribute orderAttribute1 = new in.shop2020.model.v1.order.Attribute();
166
					if (poRefNumber != null && !poRefNumber.equals("")) {
164
					if (poRefNumber != null && !poRefNumber.equals("")) {
167
						orderAttribute1.setName("poRefNumber");
165
						orderAttribute1.setName("poRefNumber");
168
						orderAttribute1.setValue(poRefNumber);
166
						orderAttribute1.setValue(poRefNumber);
169
						this.transactionClient.setOrderAttributeForTransaction(Long.parseLong(transactionId), orderAttribute1);
167
						this.transactionClient.setOrderAttributeForTransaction(Long.parseLong(transactionId),
-
 
168
								orderAttribute1);
170
					}
169
					}
171
					this.transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.AUTHORIZED,
170
					this.transactionClient.changeTransactionStatus(Long.valueOf(transactionId),
172
							"Payment received for the order", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
171
							TransactionStatus.AUTHORIZED, "Payment received for the order",
173
							OrderSource.WEBSITE);
172
							PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType), OrderSource.WEBSITE);
174
					this.transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
173
					this.transactionClient.changeTransactionStatus(Long.valueOf(transactionId),
175
							"Paid fully through wallet", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
174
							TransactionStatus.IN_PROCESS, "Paid fully through wallet",
176
							OrderSource.WEBSITE);
175
							PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType), OrderSource.WEBSITE);
177
					log.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
176
					log.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
178
					this.transactionClient = new TransactionClient().getClient();
177
					this.transactionClient = new TransactionClient().getClient();
-
 
178
					this.transactionClient
179
					this.transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
179
							.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
180
					try {
180
					try {
181
						this.transactionClient.enqueueTransactionInfoEmail(Long.parseLong(transactionId));
181
						this.transactionClient.enqueueTransactionInfoEmail(Long.parseLong(transactionId));
182
					} catch (Exception e1) {
182
					} catch (Exception e1) {
183
						log.error("Unable to update status of transaction. Thrift Exception:", e1);
183
						log.error("Unable to update status of transaction. Thrift Exception:", e1);
184
					}
184
					}
Line 197... Line 197...
197
		}
197
		}
198
 
198
 
199
		id = transactionId;
199
		id = transactionId;
200
		return show();
200
		return show();
201
	}
201
	}
202
	
202
 
203
	private long resetCart(Transaction transaction) {
203
	private long resetCart(Transaction transaction) {
204
		long sum = 0;
204
		long sum = 0;
205
		Map<Long, Double> items = new HashMap<Long, Double>();
205
		Map<Long, Double> items = new HashMap<Long, Double>();
206
		for (Order order : transaction.getOrders()) {
206
		for (Order order : transaction.getOrders()) {
207
			sum += order.getGvAmount();
207
			sum += order.getGvAmount();
Line 235... Line 235...
235
	public String getModelName() throws Throwable {
235
	public String getModelName() throws Throwable {
236
		this.catalogClient = new CatalogClient().getClient();
236
		this.catalogClient = new CatalogClient().getClient();
237
		output = "Invalid Item Id: " + itemId;
237
		output = "Invalid Item Id: " + itemId;
238
 
238
 
239
		try {
239
		try {
240
			
240
 
241
			Item item = this.catalogClient.getItem(Long.parseLong(itemId));
241
			Item item = this.catalogClient.getItem(Long.parseLong(itemId));
242
			if (item != null && item.getId() != 0) {
242
			if (item != null && item.getId() != 0) {
243
				output = ModelUtils.extractProductNameFromItem(item);
243
				output = ModelUtils.extractProductNameFromItem(item);
244
			}
244
			}
245
		} catch (NumberFormatException e) {
245
		} catch (NumberFormatException e) {
Line 250... Line 250...
250
			log.error("Could not find itemId: " + itemId, e);
250
			log.error("Could not find itemId: " + itemId, e);
251
		}
251
		}
252
 
252
 
253
		return "output";
253
		return "output";
254
	}
254
	}
-
 
255
 
-
 
256
	public String getPartnerPrice() throws Throwable {
-
 
257
		this.catalogClient = new CatalogClient().getClient();
-
 
258
		output = "Invalid Item Id: " + itemId;
-
 
259
		HsItem item = this.catalogClient.getHsItem(itemId);
-
 
260
		if (item != null && item.getItemId() != 0) {
-
 
261
			output = String.valueOf(item.getListingPrice());
-
 
262
		}
-
 
263
 
-
 
264
		return "output";
-
 
265
	}
-
 
266
 
255
	/**
267
	/**
256
	 As it is always going to be wallet
268
	 * As it is always going to be wallet
257
	 **/
269
	 **/
258
	private void createPayment(User user) throws NumberFormatException, PaymentException, TException {
270
	private void createPayment(User user) throws NumberFormatException, PaymentException, TException {
259
		List<Attribute> paymentAttributes = new ArrayList<Attribute>();
271
		List<Attribute> paymentAttributes = new ArrayList<Attribute>();
260
		paymentAttributes.add(new Attribute(PAY_METHOD, "7890"));
272
		paymentAttributes.add(new Attribute(PAY_METHOD, "7890"));
261
		long paymentId = this.paymentClient.createPayment(user.getUserId(), Double.valueOf(amount), WALLET_GATEWAY_ID, Long.valueOf(transactionId),
273
		long paymentId = this.paymentClient.createPayment(user.getUserId(), Double.valueOf(amount), WALLET_GATEWAY_ID,
262
				false);
274
				Long.valueOf(transactionId), false);
263
		this.paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null,
275
		this.paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null,
264
				paymentAttributes);
276
				PaymentStatus.SUCCESS, null, paymentAttributes);
265
	}
277
	}
266
 
278
 
267
	public String convertDate(long date) {
279
	public String convertDate(long date) {
268
		return SDF.format(new Date(date));
280
		return SDF.format(new Date(date));
269
	}
281
	}