| Line 1... |
Line 1... |
| 1 |
package com.amazonservices.mws.orders.samples;
|
1 |
package com.amazonservices.mws.orders.samples;
|
| 2 |
|
2 |
|
| 3 |
import java.text.SimpleDateFormat;
|
- |
|
| 4 |
import java.util.ArrayList;
|
3 |
import java.util.ArrayList;
|
| 5 |
import java.util.Calendar;
|
4 |
import java.util.Calendar;
|
| 6 |
import java.util.Date;
|
- |
|
| 7 |
import java.util.List;
|
5 |
import java.util.List;
|
| 8 |
import java.util.Random;
|
- |
|
| 9 |
|
6 |
|
| 10 |
import org.apache.thrift.TException;
|
- |
|
| 11 |
import org.apache.thrift.transport.TTransportException;
|
- |
|
| 12 |
import in.shop2020.logistics.PickUpType;
|
- |
|
| 13 |
import in.shop2020.model.v1.catalog.Item;
|
7 |
import in.shop2020.model.v1.catalog.Item;
|
| 14 |
import in.shop2020.model.v1.order.LineItem;
|
8 |
import in.shop2020.model.v1.order.LineItem;
|
| 15 |
import in.shop2020.model.v1.order.Order;
|
9 |
import in.shop2020.model.v1.order.Order;
|
| 16 |
import in.shop2020.model.v1.order.OrderSource;
|
10 |
import in.shop2020.model.v1.order.OrderSource;
|
| 17 |
import in.shop2020.model.v1.order.OrderStatus;
|
11 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 18 |
import in.shop2020.model.v1.order.OrderType;
|
- |
|
| 19 |
import in.shop2020.model.v1.order.SourceDetail;
|
- |
|
| 20 |
import in.shop2020.model.v1.order.Transaction;
|
12 |
import in.shop2020.model.v1.order.Transaction;
|
| 21 |
import in.shop2020.model.v1.order.TransactionStatus;
|
13 |
import in.shop2020.model.v1.order.TransactionStatus;
|
| 22 |
import in.shop2020.model.v1.user.User;
|
14 |
import in.shop2020.model.v1.user.User;
|
| 23 |
import in.shop2020.model.v1.user.UserContextException;
|
- |
|
| 24 |
import in.shop2020.payments.PaymentStatus;
|
- |
|
| 25 |
import in.shop2020.serving.model.ShipmentUpdate;
|
- |
|
| 26 |
import in.shop2020.thrift.clients.CatalogClient;
|
15 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 27 |
import in.shop2020.thrift.clients.HelperClient;
|
- |
|
| 28 |
import in.shop2020.thrift.clients.PaymentClient;
|
- |
|
| 29 |
import in.shop2020.thrift.clients.TransactionClient;
|
16 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 30 |
import in.shop2020.thrift.clients.UserClient;
|
17 |
import in.shop2020.thrift.clients.UserClient;
|
| 31 |
|
18 |
|
| 32 |
public class AmazonOrder {
|
19 |
public class AmazonOrder {
|
| 33 |
|
20 |
|
| 34 |
/**
|
21 |
/**
|
| 35 |
*
|
22 |
*
|
| 36 |
*/
|
23 |
*/
|
| 37 |
private static final long serialVersionUID = 1L;
|
24 |
private static final long serialVersionUID = 1L;
|
| 38 |
private String tempUserEmail;
|
- |
|
| 39 |
private List<Order> orders = new ArrayList<Order>();
|
25 |
private List<Order> orders = new ArrayList<Order>();
|
| 40 |
|
26 |
|
| 41 |
public long persistTransaction(com.amazonservices.mws.orders.model.Order amazonitem,List<com.amazonservices.mws.orders.model.OrderItem> amazonItems) {
|
27 |
public long persistTransaction(com.amazonservices.mws.orders.model.Order amazonitem, List<com.amazonservices.mws.orders.model.OrderItem> amazonItems) {
|
| 42 |
|
28 |
|
| 43 |
/**
|
29 |
/**
|
| 44 |
* 0.Create user
|
30 |
* 0.Create user
|
| 45 |
* 1.Make a transaction object comprised of Order which in turn contains lineitem.
|
31 |
* 1.Make a transaction object comprised of Order which in turn contains lineitem.
|
| 46 |
* 2.Call create_transaction
|
32 |
* 2.Call create_transaction
|
| 47 |
* 3.retrieve that order
|
33 |
* 3.retrieve that order
|
| 48 |
*/
|
34 |
*/
|
| 49 |
|
35 |
|
| 50 |
Transaction txnObj = new Transaction();
|
36 |
Transaction txnObj = new Transaction();
|
| 51 |
|
37 |
|
| - |
|
38 |
String userEmail = amazonitem.getBuyerEmail();
|
| - |
|
39 |
|
| 52 |
long tempUserId = -1;
|
40 |
User user = new User();
|
| - |
|
41 |
user.setCommunicationEmail(userEmail);
|
| - |
|
42 |
user.setEmail(userEmail);
|
| - |
|
43 |
user.setName(amazonitem.getBuyerName());
|
| - |
|
44 |
user.setMobileNumber(amazonitem.getShippingAddress().getPhone());
|
| - |
|
45 |
user.setPassword("amazon");
|
| 53 |
|
46 |
|
| 54 |
try {
|
47 |
try {
|
| 55 |
TransactionClient tcl = new TransactionClient();
|
- |
|
| 56 |
//Source Id for store website is 2 and our normal website is 1
|
- |
|
| 57 |
SourceDetail detail = tcl.getClient().getSourceDetail(3);
|
- |
|
| 58 |
tempUserEmail=detail.getEmail();
|
- |
|
| 59 |
try {
|
- |
|
| 60 |
UserClient ucl = new UserClient();
|
48 |
UserClient ucl = new UserClient();
|
| 61 |
User user = ucl.getClient().getUserByEmail(tempUserEmail);
|
49 |
user = ucl.getClient().createUser(user);
|
| 62 |
tempUserId = user.getUserId();
|
- |
|
| 63 |
} catch (Exception e) {
|
- |
|
| 64 |
//////////////log.error("Unable to get user for id " + tempUserId, e);
|
- |
|
| 65 |
}
|
- |
|
| 66 |
} catch(Exception e) {
|
50 |
} catch(Exception e) {
|
| 67 |
//////////////log.error("Unable to get default source", e);
|
51 |
//////////////log.error("Unable to get default source", e);
|
| 68 |
}
|
52 |
}
|
| - |
|
53 |
|
| - |
|
54 |
long userId = user.getUserId();
|
| 69 |
txnObj.setShoppingCartid(0);
|
55 |
txnObj.setShoppingCartid(user.getActiveCartId());
|
| 70 |
txnObj.setCustomer_id(tempUserId);
|
56 |
txnObj.setCustomer_id(userId);
|
| 71 |
txnObj.setCreatedOn(Calendar.getInstance().getTimeInMillis());
|
57 |
txnObj.setCreatedOn(Calendar.getInstance().getTimeInMillis());
|
| 72 |
txnObj.setTransactionStatus(TransactionStatus.INIT);
|
58 |
txnObj.setTransactionStatus(TransactionStatus.INIT);
|
| 73 |
txnObj.setStatusDescription("New Amazon Order");
|
59 |
txnObj.setStatusDescription("New Amazon Order");
|
| 74 |
txnObj.setCoupon_code("");
|
60 |
txnObj.setCoupon_code("");
|
| 75 |
txnObj.setEmiSchemeId(0);
|
61 |
txnObj.setEmiSchemeId(0);
|
| 76 |
|
62 |
|
| 77 |
//if(createOrder(tempUserId) == null) {
|
- |
|
| 78 |
//////////////log.error("Unable to create transaction");
|
- |
|
| 79 |
//setErrorMsg("Unable to create order. Please try again.");
|
- |
|
| 80 |
// return "error-result";
|
- |
|
| 81 |
//}
|
- |
|
| 82 |
for(com.amazonservices.mws.orders.model.OrderItem amazonItemlist: amazonItems){
|
63 |
for(com.amazonservices.mws.orders.model.OrderItem amazonItemlist: amazonItems){
|
| 83 |
int netQuantity = amazonItemlist.getQuantityOrdered() - amazonItemlist.getQuantityShipped();
|
64 |
int netQuantity = amazonItemlist.getQuantityOrdered() - amazonItemlist.getQuantityShipped();
|
| 84 |
for (int i=0;i<netQuantity;i++){
|
65 |
for (int i=0;i<netQuantity;i++){
|
| 85 |
orders.add(createOrder(tempUserEmail,tempUserId,amazonItemlist,amazonitem));
|
66 |
orders.add(createOrder(userEmail, userId, amazonItemlist, amazonitem));
|
| 86 |
}
|
67 |
}
|
| 87 |
}
|
68 |
}
|
| 88 |
|
69 |
|
| 89 |
txnObj.setOrders(orders);
|
70 |
txnObj.setOrders(orders);
|
| 90 |
TransactionClient tcl;
|
71 |
TransactionClient tcl;
|
| Line 100... |
Line 81... |
| 100 |
System.out.println("Could not Create Transaction ......");
|
81 |
System.out.println("Could not Create Transaction ......");
|
| 101 |
return -1;
|
82 |
return -1;
|
| 102 |
}
|
83 |
}
|
| 103 |
}
|
84 |
}
|
| 104 |
|
85 |
|
| 105 |
public Order createOrder(String tempUserEmail,long userId,com.amazonservices.mws.orders.model.OrderItem aitem1,com.amazonservices.mws.orders.model.Order aitem) {
|
86 |
public Order createOrder(String userEmail,long userId,com.amazonservices.mws.orders.model.OrderItem aitem1,com.amazonservices.mws.orders.model.Order aitem) {
|
| 106 |
LineItem lineObj = createLineItem(aitem1);
|
87 |
LineItem lineObj = createLineItem(aitem1);
|
| 107 |
if (lineObj == null) {
|
88 |
if (lineObj == null) {
|
| 108 |
return null;
|
89 |
return null;
|
| 109 |
}
|
90 |
}
|
| 110 |
Order order = new Order();
|
91 |
Order order = new Order();
|
| 111 |
|
92 |
|
| 112 |
order.setCustomer_id(userId);
|
93 |
order.setCustomer_id(userId);
|
| 113 |
order.setCustomer_email(tempUserEmail);
|
94 |
order.setCustomer_email(userEmail);
|
| 114 |
order.setCustomer_name(aitem.getBuyerName());
|
95 |
order.setCustomer_name(aitem.getBuyerName());
|
| 115 |
order.setCustomer_address1(aitem.getShippingAddress().getAddressLine1());
|
96 |
order.setCustomer_address1(aitem.getShippingAddress().getAddressLine1());
|
| 116 |
if(aitem.getShippingAddress().getAddressLine3()!=null){
|
97 |
if(aitem.getShippingAddress().getAddressLine3()!=null){
|
| 117 |
order.setCustomer_address2(aitem.getShippingAddress().getAddressLine2() +" " +aitem.getShippingAddress().getAddressLine3());
|
98 |
order.setCustomer_address2(aitem.getShippingAddress().getAddressLine2() +" " +aitem.getShippingAddress().getAddressLine3());
|
| 118 |
}
|
99 |
}
|
| Line 128... |
Line 109... |
| 128 |
order.setStatus(OrderStatus.PAYMENT_PENDING);
|
109 |
order.setStatus(OrderStatus.PAYMENT_PENDING);
|
| 129 |
order.setStatusDescription("Initiated");
|
110 |
order.setStatusDescription("Initiated");
|
| 130 |
order.setCreated_timestamp(Calendar.getInstance().getTimeInMillis());
|
111 |
order.setCreated_timestamp(Calendar.getInstance().getTimeInMillis());
|
| 131 |
order.setTotal_weight(lineObj.getTotal_weight());
|
112 |
order.setTotal_weight(lineObj.getTotal_weight());
|
| 132 |
|
113 |
|
| 133 |
order.setSource(3);
|
114 |
order.setSource(OrderSource.AMAZON.getValue());
|
| 134 |
order.setAdvanceAmount(0.0);
|
115 |
order.setAdvanceAmount(0.0);
|
| 135 |
|
116 |
|
| 136 |
List<LineItem> lines = new ArrayList<LineItem>();
|
117 |
List<LineItem> lines = new ArrayList<LineItem>();
|
| 137 |
lines.add(lineObj);
|
118 |
lines.add(lineObj);
|
| 138 |
order.setLineitems(lines);
|
119 |
order.setLineitems(lines);
|