| Line 5... |
Line 5... |
| 5 |
|
5 |
|
| 6 |
import in.shop2020.logistics.PickUpType;
|
6 |
import in.shop2020.logistics.PickUpType;
|
| 7 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
7 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| 8 |
import in.shop2020.model.v1.catalog.Item;
|
8 |
import in.shop2020.model.v1.catalog.Item;
|
| 9 |
import in.shop2020.model.v1.order.LineItem;
|
9 |
import in.shop2020.model.v1.order.LineItem;
|
| - |
|
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.OrderType;
|
12 |
import in.shop2020.model.v1.order.OrderType;
|
| 12 |
import in.shop2020.model.v1.order.ProductCondition;
|
13 |
import in.shop2020.model.v1.order.ProductCondition;
|
| 13 |
import in.shop2020.model.v1.order.Transaction;
|
14 |
import in.shop2020.model.v1.order.Transaction;
|
| 14 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
15 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
| 15 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
16 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 16 |
import in.shop2020.model.v1.order.TransactionStatus;
|
17 |
import in.shop2020.model.v1.order.TransactionStatus;
|
| 17 |
import in.shop2020.model.v1.user.ItemPriceQuantity;
|
18 |
import in.shop2020.model.v1.user.ItemPriceQuantity;
|
| - |
|
19 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
| 18 |
import in.shop2020.model.v1.user.User;
|
20 |
import in.shop2020.model.v1.user.User;
|
| 19 |
import in.shop2020.payments.Attribute;
|
21 |
import in.shop2020.payments.Attribute;
|
| 20 |
import in.shop2020.payments.Payment;
|
22 |
import in.shop2020.payments.Payment;
|
| 21 |
import in.shop2020.payments.PaymentException;
|
23 |
import in.shop2020.payments.PaymentException;
|
| 22 |
import in.shop2020.payments.PaymentStatus;
|
24 |
import in.shop2020.payments.PaymentStatus;
|
| Line 28... |
Line 30... |
| 28 |
|
30 |
|
| 29 |
import java.text.SimpleDateFormat;
|
31 |
import java.text.SimpleDateFormat;
|
| 30 |
import java.util.ArrayList;
|
32 |
import java.util.ArrayList;
|
| 31 |
import java.util.Collections;
|
33 |
import java.util.Collections;
|
| 32 |
import java.util.Date;
|
34 |
import java.util.Date;
|
| - |
|
35 |
import java.util.HashMap;
|
| 33 |
import java.util.List;
|
36 |
import java.util.List;
|
| 34 |
import java.util.Map;
|
37 |
import java.util.Map;
|
| 35 |
|
38 |
|
| 36 |
import org.apache.commons.logging.Log;
|
39 |
import org.apache.commons.logging.Log;
|
| 37 |
import org.apache.commons.logging.LogFactory;
|
40 |
import org.apache.commons.logging.LogFactory;
|
| Line 119... |
Line 122... |
| 119 |
public String create() throws Throwable {
|
122 |
public String create() throws Throwable {
|
| 120 |
this.userClient = new UserClient().getClient();
|
123 |
this.userClient = new UserClient().getClient();
|
| 121 |
this.paymentClient = new PaymentClient().getClient();
|
124 |
this.paymentClient = new PaymentClient().getClient();
|
| 122 |
this.transactionClient = new TransactionClient().getClient();
|
125 |
this.transactionClient = new TransactionClient().getClient();
|
| 123 |
this.catalogClient = new CatalogClient().getClient();
|
126 |
this.catalogClient = new CatalogClient().getClient();
|
| - |
|
127 |
|
| - |
|
128 |
|
| 124 |
log.info("Creating orders for " + lineItems);
|
129 |
log.info("Creating orders for " + lineItems);
|
| 125 |
boolean hasError = true;
|
130 |
boolean hasError = true;
|
| 126 |
|
131 |
|
| 127 |
try {
|
132 |
try {
|
| 128 |
User user = this.userClient.getUserByEmail(customerEmailId);
|
133 |
User user = this.userClient.getUserByEmail(customerEmailId);
|
| Line 168... |
Line 173... |
| 168 |
OrderSource.WEBSITE);
|
173 |
OrderSource.WEBSITE);
|
| 169 |
this.transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
|
174 |
this.transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
|
| 170 |
"Paid fully through wallet", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
|
175 |
"Paid fully through wallet", PickUpType.valueOf(pickUp).getValue(), OrderType.valueOf(orderType),
|
| 171 |
OrderSource.WEBSITE);
|
176 |
OrderSource.WEBSITE);
|
| 172 |
log.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
|
177 |
log.info("Successfully created transaction: " + transactionId + " for amount: " + amount);
|
| - |
|
178 |
this.transactionClient = new TransactionClient().getClient();
|
| 173 |
this.transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
|
179 |
this.transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
|
| - |
|
180 |
try {
|
| - |
|
181 |
this.transactionClient.enqueueTransactionInfoEmail(Long.parseLong(transactionId));
|
| - |
|
182 |
} catch (Exception e1) {
|
| - |
|
183 |
log.error("Unable to update status of transaction. Thrift Exception:", e1);
|
| - |
|
184 |
}
|
| - |
|
185 |
this.userClient = new UserClient().getClient();
|
| - |
|
186 |
this.resetCart(transaction);
|
| 174 |
hasError = false;
|
187 |
hasError = false;
|
| 175 |
}
|
188 |
}
|
| 176 |
}
|
189 |
}
|
| 177 |
} catch (Exception e) {
|
190 |
} catch (Exception e) {
|
| 178 |
addActionError("Error occerred - " + e.getMessage());
|
191 |
addActionError("Error occerred - " + e.getMessage());
|
| Line 183... |
Line 196... |
| 183 |
}
|
196 |
}
|
| 184 |
|
197 |
|
| 185 |
id = transactionId;
|
198 |
id = transactionId;
|
| 186 |
return show();
|
199 |
return show();
|
| 187 |
}
|
200 |
}
|
| - |
|
201 |
|
| - |
|
202 |
private long resetCart(Transaction transaction) {
|
| - |
|
203 |
long sum = 0;
|
| - |
|
204 |
Map<Long, Double> items = new HashMap<Long, Double>();
|
| - |
|
205 |
for (Order order : transaction.getOrders()) {
|
| - |
|
206 |
sum += order.getGvAmount();
|
| - |
|
207 |
for (LineItem lineitem : order.getLineitems()) {
|
| - |
|
208 |
Long itemId = lineitem.getItem_id();
|
| - |
|
209 |
Double quantity = items.get(itemId);
|
| - |
|
210 |
if (quantity == null) {
|
| - |
|
211 |
quantity = lineitem.getQuantity();
|
| - |
|
212 |
} else {
|
| - |
|
213 |
quantity = quantity + lineitem.getQuantity();
|
| - |
|
214 |
}
|
| - |
|
215 |
items.put(itemId, quantity);
|
| - |
|
216 |
}
|
| - |
|
217 |
}
|
| - |
|
218 |
|
| - |
|
219 |
log.debug("Items to reset in cart are: " + items);
|
| - |
|
220 |
|
| - |
|
221 |
try {
|
| - |
|
222 |
// TODO Optimize the function to send less data over the wire
|
| - |
|
223 |
this.userClient .resetCart(transaction.getShoppingCartid(), items);
|
| - |
|
224 |
} catch (TException e) {
|
| - |
|
225 |
log.error("Error while updating information in payment database.", e);
|
| - |
|
226 |
} catch (ShoppingCartException e) {
|
| - |
|
227 |
log.error("Error while reseting the cart in cart database.", e);
|
| - |
|
228 |
} catch (Exception e) {
|
| - |
|
229 |
log.error("Unexpected exception", e);
|
| - |
|
230 |
}
|
| - |
|
231 |
return sum;
|
| - |
|
232 |
}
|
| 188 |
|
233 |
|
| 189 |
public String getModelName() throws Throwable {
|
234 |
public String getModelName() throws Throwable {
|
| 190 |
this.catalogClient = new CatalogClient().getClient();
|
235 |
this.catalogClient = new CatalogClient().getClient();
|
| 191 |
output = "Invalid Item Id: " + itemId;
|
236 |
output = "Invalid Item Id: " + itemId;
|
| 192 |
|
237 |
|