| Line 31... |
Line 31... |
| 31 |
import java.security.DigestInputStream;
|
31 |
import java.security.DigestInputStream;
|
| 32 |
import java.security.MessageDigest;
|
32 |
import java.security.MessageDigest;
|
| 33 |
import java.security.NoSuchAlgorithmException;
|
33 |
import java.security.NoSuchAlgorithmException;
|
| 34 |
import java.util.ArrayList;
|
34 |
import java.util.ArrayList;
|
| 35 |
import java.util.Arrays;
|
35 |
import java.util.Arrays;
|
| 36 |
import java.util.Calendar;
|
- |
|
| 37 |
import java.util.GregorianCalendar;
|
36 |
import java.util.GregorianCalendar;
|
| 38 |
import java.util.HashMap;
|
37 |
import java.util.HashMap;
|
| 39 |
import java.util.List;
|
38 |
import java.util.List;
|
| 40 |
import java.util.Map;
|
39 |
import java.util.Map;
|
| 41 |
import java.util.Random;
|
40 |
import java.util.Random;
|
| Line 90... |
Line 89... |
| 90 |
/**
|
89 |
/**
|
| 91 |
* This sample illustrates continuous order updates retrieval. It contains a
|
90 |
* This sample illustrates continuous order updates retrieval. It contains a
|
| 92 |
* order updates fetcher job that fetches updates every 15 minutes.
|
91 |
* order updates fetcher job that fetches updates every 15 minutes.
|
| 93 |
*/
|
92 |
*/
|
| 94 |
|
93 |
|
| 95 |
public class FetchOrderUpdatesJobandAcknowledge {
|
94 |
public class FetchOrderUpdatesJob {
|
| 96 |
|
95 |
|
| 97 |
/*
|
96 |
/*
|
| 98 |
* Add required parameters in OrdersConfig.java before trying out this
|
97 |
* Add required parameters in OrdersConfig.java before trying out this
|
| 99 |
* sample.
|
98 |
* sample.
|
| 100 |
*/
|
99 |
*/
|
| 101 |
public static final Log log = LogFactory.getLog(OrderFetcherSample.class);
|
- |
|
| 102 |
private volatile boolean keepRunning = true;
|
- |
|
| 103 |
|
100 |
|
| - |
|
101 |
public static final Log log = LogFactory.getLog(OrderFetcherSample.class);
|
| - |
|
102 |
//private volatile boolean keepRunning = true;
|
| - |
|
103 |
private boolean keepRunning = true;
|
| 104 |
/*************************************
|
104 |
/*************************************
|
| 105 |
* Throttling Limits in Milliseconds *
|
105 |
* Throttling Limits in Milliseconds *
|
| 106 |
*************************************/
|
106 |
*************************************/
|
| 107 |
// 1 call per 10 mins
|
107 |
// 1 call per 10 mins
|
| 108 |
static final long LIST_ORDERS_THROTTLE_LIMIT = 600000L;
|
108 |
static final long LIST_ORDERS_THROTTLE_LIMIT = 600000L;
|
| 109 |
// 1 call per 12 secs
|
109 |
// 1 call per 12 secs
|
| 110 |
static final long LIST_ORDER_ITEMS_THROTTLE_LIMIT = 12000L;
|
110 |
static final long LIST_ORDER_ITEMS_THROTTLE_LIMIT = 12000L;
|
| 111 |
|
111 |
|
| - |
|
112 |
final public static String AMAZON_ORDER_ACKNOWLEDGEMENT_XML = "/home/vikram/OrderAcknowledgeMent.xml";
|
| 112 |
|
113 |
|
| 113 |
public String AMAZON_ORDER_ACKNOWLEDGEMENT_XML;
|
- |
|
| 114 |
|
- |
|
| 115 |
static final int INTERVAL_IN_MINS = 1; // 15-minute update interval
|
114 |
static final int INTERVAL_IN_MINS = 30; // 1-minute update interval
|
| 116 |
|
115 |
|
| 117 |
//static final int INTERVAL_IN_MINS = 15; // 15-minute update interval
|
116 |
//static final int INTERVAL_IN_MINS = 15; // 15-minute update interval
|
| 118 |
|
117 |
|
| 119 |
protected MarketplaceWebServiceOrders service;
|
118 |
protected MarketplaceWebServiceOrders service;
|
| 120 |
protected String sellerId = null;
|
119 |
protected String sellerId = null;
|
| 121 |
protected MarketplaceIdList marketplaceIdList = null;
|
120 |
protected MarketplaceIdList marketplaceIdList = null;
|
| 122 |
private File file;
|
121 |
private File file;
|
| 123 |
|
122 |
|
| 124 |
public FetchOrderUpdatesJobandAcknowledge(
|
123 |
public FetchOrderUpdatesJob(
|
| 125 |
MarketplaceWebServiceOrders marketplaceWebServiceOrdersClient,
|
124 |
MarketplaceWebServiceOrders marketplaceWebServiceOrdersClient,
|
| 126 |
String sellerId, MarketplaceIdList marketplaceIdList) {
|
125 |
String sellerId, MarketplaceIdList marketplaceIdList) {
|
| 127 |
if (marketplaceWebServiceOrdersClient == null) {
|
126 |
if (marketplaceWebServiceOrdersClient == null) {
|
| 128 |
throw new IllegalArgumentException(
|
127 |
throw new IllegalArgumentException(
|
| 129 |
"MarketplaceWebServiceOrders object cannot be null.");
|
128 |
"MarketplaceWebServiceOrders object cannot be null.");
|
| Line 138... |
Line 137... |
| 138 |
OrdersConfig.accessKeyId,
|
137 |
OrdersConfig.accessKeyId,
|
| 139 |
OrdersConfig.secretAccessKey,
|
138 |
OrdersConfig.secretAccessKey,
|
| 140 |
OrdersConfig.applicationName,
|
139 |
OrdersConfig.applicationName,
|
| 141 |
OrdersConfig.applicationVersion,
|
140 |
OrdersConfig.applicationVersion,
|
| 142 |
OrdersConfig.config);
|
141 |
OrdersConfig.config);
|
| 143 |
final FetchOrderUpdatesJobandAcknowledge orderFetcher = new FetchOrderUpdatesJobandAcknowledge(
|
142 |
final FetchOrderUpdatesJob orderFetcher = new FetchOrderUpdatesJob(
|
| 144 |
client, OrdersConfig.sellerId,
|
143 |
client, OrdersConfig.sellerId,
|
| 145 |
OrdersConfig.marketplaceIdList);
|
144 |
OrdersConfig.marketplaceIdList);
|
| 146 |
|
145 |
|
| 147 |
/* Thread fetchOrderUpdatesJobThread = new Thread(new Runnable() {
|
146 |
/* Thread fetchOrderUpdatesJobThread = new Thread(new Runnable() {
|
| 148 |
public void run() {
|
147 |
public void run() {
|
| Line 201... |
Line 200... |
| 201 |
}
|
200 |
}
|
| 202 |
TransactionClient tcl=null;
|
201 |
TransactionClient tcl=null;
|
| 203 |
long time=0;
|
202 |
long time=0;
|
| 204 |
try {
|
203 |
try {
|
| 205 |
tcl = new TransactionClient();
|
204 |
tcl = new TransactionClient();
|
| 206 |
time = tcl.getClient().getSourceDetail(10).getLastUpdatedOn();
|
205 |
time = tcl.getClient().getSourceDetail(3).getLastUpdatedOn();
|
| 207 |
} catch (TException e) {
|
206 |
} catch (TException e) {
|
| 208 |
// TODO Auto-generated catch block
|
207 |
// TODO Auto-generated catch block
|
| 209 |
e.printStackTrace();
|
208 |
e.printStackTrace();
|
| 210 |
}
|
209 |
}
|
| 211 |
|
210 |
|
| Line 238... |
Line 237... |
| 238 |
* from the loop as the job is lagging far behind in getting new
|
237 |
* from the loop as the job is lagging far behind in getting new
|
| 239 |
* orders.
|
238 |
* orders.
|
| 240 |
*/
|
239 |
*/
|
| 241 |
//if (timeWaited > 24 * 4 * INTERVAL_IN_MINS * 60L * 1000L) {
|
240 |
//if (timeWaited > 24 * 4 * INTERVAL_IN_MINS * 60L * 1000L) {
|
| 242 |
if (timeWaited > 100000 * 60L * 1000L) {
|
241 |
if (timeWaited > 100000 * 60L * 1000L) {
|
| 243 |
//keepRunning = false;
|
242 |
keepRunning = false;
|
| 244 |
System.out.println("Setting keep running to false");
|
243 |
System.out.println("Setting keep running to false");
|
| 245 |
log
|
- |
|
| 246 |
.info("timeWaited is greater than 30 times the interval. This a too large a time interval for which to fetch orders.");
|
244 |
log.info("timeWaited is greater than 30 times the interval. This a too large a time interval for which to fetch orders.");
|
| 247 |
}
|
245 |
}
|
| 248 |
/*
|
246 |
/*
|
| 249 |
* If the time lapsed is greater than or equal to 15 mins, we will
|
247 |
* If the time lapsed is greater than or equal to 15 mins, we will
|
| 250 |
* try to fetchOrderUpdates giving it a startTime.
|
248 |
* try to fetchOrderUpdates giving it a startTime.
|
| 251 |
*/
|
249 |
*/
|
| 252 |
else if (timeWaited >= INTERVAL_IN_MINS * 60L * 1000L) {
|
250 |
else if (timeWaited >= INTERVAL_IN_MINS * 60L * 1000L) {
|
| 253 |
log.info("Time to fetch new order updates.");
|
251 |
log.info("Time to fetch new order updates.");
|
| 254 |
|
252 |
|
| 255 |
XMLGregorianCalendar endTime = fetchOrderUpdatesSince(startTime);
|
253 |
XMLGregorianCalendar endTime = fetchOrderUpdatesSince(startTime);
|
| 256 |
//System.out.println("End Time is : " + endTime.getDay() +"-"+ endTime.getMonth()+"-" + endTime.getHour()+":"+endTime.getMinute());
|
254 |
//System.out.println("End Time is : " + endTime.getDay() +"-"+ endTime.getMonth()+"-" + endTime.getHour()+":"+endTime.getMinute());
|
| - |
|
255 |
//createandsubmitOrderAcknowlegementFeed();
|
| 257 |
if (endTime != null) {
|
256 |
if (endTime != null) {
|
| 258 |
startTime = endTime;
|
257 |
startTime = endTime;
|
| - |
|
258 |
|
| 259 |
try {
|
259 |
try {
|
| 260 |
tcl = new TransactionClient();
|
- |
|
| 261 |
tcl.getClient().updateSourceDetailTimestamp(3,endTime.toGregorianCalendar().getTimeInMillis() - 7*24*60*60*1000);
|
260 |
tcl.getClient().updateSourceDetailTimestamp(3,endTime.toGregorianCalendar().getTimeInMillis());
|
| 262 |
} catch (TException e) {
|
261 |
} catch (TException e) {
|
| 263 |
// TODO Auto-generated catch block
|
262 |
// TODO Auto-generated catch block
|
| 264 |
e.printStackTrace();
|
263 |
e.printStackTrace();
|
| 265 |
}
|
264 |
}
|
| 266 |
} else {
|
265 |
} else {
|
| Line 309... |
Line 308... |
| 309 |
* it will terminate the job only after the call returns with valid results.
|
308 |
* it will terminate the job only after the call returns with valid results.
|
| 310 |
* If this method is called while the thread is sleeping, because a request
|
309 |
* If this method is called while the thread is sleeping, because a request
|
| 311 |
* was throttled, the job will terminate after it wakes up.
|
310 |
* was throttled, the job will terminate after it wakes up.
|
| 312 |
*/
|
311 |
*/
|
| 313 |
public void stopSynch() {
|
312 |
public void stopSynch() {
|
| 314 |
keepRunning = false;
|
313 |
//keepRunning = false;
|
| 315 |
}
|
314 |
}
|
| 316 |
|
315 |
|
| 317 |
/**
|
316 |
/**
|
| 318 |
* Gets all orders updated between the given startTime and the calculated
|
317 |
* Gets all orders updated between the given startTime and the calculated
|
| 319 |
* endTime. The endTime is calculated by the service as server's system
|
318 |
* endTime. The endTime is calculated by the service as server's system
|
| Line 373... |
Line 372... |
| 373 |
System.out.println("Request ID: " + ex.getRequestId());
|
372 |
System.out.println("Request ID: " + ex.getRequestId());
|
| 374 |
System.out.print("XML: " + ex.getXML());
|
373 |
System.out.print("XML: " + ex.getXML());
|
| 375 |
return null;
|
374 |
return null;
|
| 376 |
}
|
375 |
}
|
| 377 |
}
|
376 |
}
|
| - |
|
377 |
//This method will create Order Acknowledgement FEED
|
| - |
|
378 |
public void createandsubmitOrderAcknowlegementFeed() {
|
| - |
|
379 |
TransactionClient tcl=null;
|
| - |
|
380 |
List<AmazonOrdersToAcknowledge> amazonOrdersToAcknowledge=null;
|
| - |
|
381 |
try {
|
| - |
|
382 |
tcl = new TransactionClient();
|
| - |
|
383 |
amazonOrdersToAcknowledge = tcl.getClient().getAmazonOrdersToAcknowledge();
|
| - |
|
384 |
} catch (TTransportException e2) {
|
| - |
|
385 |
// TODO Auto-generated catch block
|
| - |
|
386 |
e2.printStackTrace();
|
| - |
|
387 |
} catch (TException e) {
|
| - |
|
388 |
// TODO Auto-generated catch block
|
| - |
|
389 |
e.printStackTrace();
|
| - |
|
390 |
}
|
| - |
|
391 |
if(amazonOrdersToAcknowledge!=null && amazonOrdersToAcknowledge.size() > 0){
|
| - |
|
392 |
file = new File(AMAZON_ORDER_ACKNOWLEDGEMENT_XML);
|
| - |
|
393 |
AmazonEnvelope amazonenvelope = new AmazonEnvelope();
|
| - |
|
394 |
Header header = new Header();
|
| - |
|
395 |
header.setDocumentVersion("1.0");
|
| - |
|
396 |
header.setMerchantIdentifier("AF6E3O0VE0X4D");
|
| - |
|
397 |
header.setOverrideReleaseId(null);
|
| - |
|
398 |
amazonenvelope.setHeader(header);
|
| - |
|
399 |
amazonenvelope.setMessageType("OrderAcknowledgement");
|
| - |
|
400 |
amazonenvelope.setMarketplaceName(null);
|
| - |
|
401 |
List<Message> messages = amazonenvelope.getMessage();
|
| - |
|
402 |
Map<String,Long> amazonOrdertxnMap = new HashMap<String,Long>();
|
| - |
|
403 |
Map<String,List<String>> amazonOrderIdOrderItemMap = new HashMap<String,List<String>>();
|
| - |
|
404 |
Map<String,Integer> amazonOrderItemSuccessMap = new HashMap<String,Integer>();
|
| - |
|
405 |
Map<String,Integer> amazonOrderItemFailureMap = new HashMap<String,Integer>();
|
| - |
|
406 |
for(AmazonOrdersToAcknowledge amazonOrderToAcknowledge:amazonOrdersToAcknowledge ){
|
| - |
|
407 |
if(!amazonOrdertxnMap.containsKey(amazonOrderToAcknowledge.getAmazonOrderId())){
|
| - |
|
408 |
amazonOrdertxnMap.put(amazonOrderToAcknowledge.getAmazonOrderId(),amazonOrderToAcknowledge.getTransaction_id());
|
| - |
|
409 |
}
|
| - |
|
410 |
if(!amazonOrderIdOrderItemMap.containsKey(amazonOrderToAcknowledge.getAmazonOrderId())){
|
| - |
|
411 |
List<String> orderItemsList = new ArrayList<String>();
|
| - |
|
412 |
orderItemsList.add(amazonOrderToAcknowledge.getAmazonOrderItemId());
|
| - |
|
413 |
amazonOrderIdOrderItemMap.put(amazonOrderToAcknowledge.getAmazonOrderId(),orderItemsList);
|
| - |
|
414 |
}
|
| - |
|
415 |
else{
|
| - |
|
416 |
if(!amazonOrderIdOrderItemMap.get(amazonOrderToAcknowledge.getAmazonOrderId()).contains(amazonOrderToAcknowledge.getAmazonOrderItemId()))
|
| - |
|
417 |
amazonOrderIdOrderItemMap.get(amazonOrderToAcknowledge.getAmazonOrderId()).add(amazonOrderToAcknowledge.getAmazonOrderItemId());
|
| - |
|
418 |
}
|
| - |
|
419 |
if(amazonOrderToAcknowledge.getStatus().equals("Order-Payment-Success")){
|
| - |
|
420 |
amazonOrderItemSuccessMap.put(amazonOrderToAcknowledge.getAmazonOrderId()+amazonOrderToAcknowledge.getAmazonOrderItemId(),amazonOrderToAcknowledge.getCount());
|
| - |
|
421 |
}
|
| - |
|
422 |
if(amazonOrderToAcknowledge.getStatus().equals("Order-Payment-Failure")){
|
| - |
|
423 |
amazonOrderItemFailureMap.put(amazonOrderToAcknowledge.getAmazonOrderId()+amazonOrderToAcknowledge.getAmazonOrderItemId(),amazonOrderToAcknowledge.getCount());
|
| - |
|
424 |
}
|
| - |
|
425 |
}
|
| - |
|
426 |
JAXBContext context;
|
| - |
|
427 |
Marshaller m=null;
|
| - |
|
428 |
try {
|
| - |
|
429 |
context = JAXBContext.newInstance(AmazonEnvelope.class);
|
| - |
|
430 |
m = context.createMarshaller();
|
| - |
|
431 |
} catch (JAXBException e1) {
|
| - |
|
432 |
// TODO Auto-generated catch block
|
| - |
|
433 |
e1.printStackTrace();
|
| - |
|
434 |
}
|
| - |
|
435 |
|
| - |
|
436 |
for (Map.Entry<String,List<String>> entry : amazonOrderIdOrderItemMap.entrySet()){
|
| - |
|
437 |
OrderAcknowledgement orderAcknowLedgement = new OrderAcknowledgement();
|
| - |
|
438 |
List<OrderAcknowledgement.Item> acknowledgementItems = orderAcknowLedgement.getItem();
|
| - |
|
439 |
String orderid = entry.getKey();
|
| - |
|
440 |
orderAcknowLedgement.setAmazonOrderID(orderid);
|
| - |
|
441 |
orderAcknowLedgement.setMerchantOrderID(amazonOrdertxnMap.get(orderid).toString());
|
| - |
|
442 |
orderAcknowLedgement.setStatusCode("Failure");
|
| - |
|
443 |
for(String orderItemId :entry.getValue()){
|
| - |
|
444 |
OrderAcknowledgement.Item orderAcknowledgementItem = new OrderAcknowledgement.Item();
|
| - |
|
445 |
if(amazonOrderItemSuccessMap.get(orderid+orderItemId)!=null && amazonOrderItemSuccessMap.get(orderid+orderItemId) > 0){
|
| - |
|
446 |
orderAcknowledgementItem.setAmazonOrderItemCode(orderItemId);
|
| - |
|
447 |
orderAcknowLedgement.setStatusCode("Success");
|
| - |
|
448 |
}
|
| - |
|
449 |
else{
|
| - |
|
450 |
orderAcknowledgementItem.setAmazonOrderItemCode(orderItemId);
|
| - |
|
451 |
orderAcknowledgementItem.setCancelReason("ShippingAddressUndeliverable");
|
| - |
|
452 |
}
|
| - |
|
453 |
acknowledgementItems.add(orderAcknowledgementItem);
|
| - |
|
454 |
|
| - |
|
455 |
}
|
| - |
|
456 |
AmazonEnvelope.Message message = new AmazonEnvelope.Message();
|
| - |
|
457 |
Random rand = new Random();
|
| - |
|
458 |
message.setMessageID(BigInteger.valueOf(Math.abs(rand.nextInt())));
|
| - |
|
459 |
message.setOrderAcknowledgement(orderAcknowLedgement);
|
| - |
|
460 |
messages.add(message);
|
| - |
|
461 |
}
|
| - |
|
462 |
|
| - |
|
463 |
System.out.println("Messages is " + messages);
|
| - |
|
464 |
try {
|
| - |
|
465 |
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
| - |
|
466 |
m.marshal(amazonenvelope, file);
|
| - |
|
467 |
m.marshal(amazonenvelope, System.out);
|
| - |
|
468 |
|
| - |
|
469 |
} catch (Exception e) {
|
| - |
|
470 |
// TODO Auto-generated catch block
|
| - |
|
471 |
e.printStackTrace();
|
| - |
|
472 |
|
| - |
|
473 |
}
|
| - |
|
474 |
if(submitAcknowledgementFeed()==0);
|
| - |
|
475 |
//if(true)
|
| - |
|
476 |
{
|
| - |
|
477 |
for (Map.Entry<String,Long> entry : amazonOrdertxnMap.entrySet()){
|
| - |
|
478 |
try {
|
| - |
|
479 |
tcl.getClient().changeAmazonOrderStatus(entry.getKey(),"Acknowledgement-Sent");
|
| - |
|
480 |
} catch (TException e) {
|
| - |
|
481 |
// TODO Auto-generated catch block
|
| - |
|
482 |
e.printStackTrace();
|
| - |
|
483 |
}
|
| - |
|
484 |
|
| - |
|
485 |
}
|
| - |
|
486 |
}
|
| - |
|
487 |
// GmailUtils gm = GmailUtils();
|
| - |
|
488 |
// gm.sendSSLMessage(arg0, arg1, arg2, arg3, arg4, arg5)
|
| - |
|
489 |
}
|
| - |
|
490 |
|
| - |
|
491 |
|
| - |
|
492 |
}
|
| 378 |
|
493 |
|
| 379 |
/*
|
494 |
/*
|
| 380 |
* listOrders call. If a request is throttled, this method calls the
|
495 |
* listOrders call. If a request is throttled, this method calls the
|
| 381 |
* throttling handler and sets the retry flag to true.
|
496 |
* throttling handler and sets the retry flag to true.
|
| 382 |
*/
|
497 |
*/
|
| Line 593... |
Line 708... |
| 593 |
return true;
|
708 |
return true;
|
| 594 |
}
|
709 |
}
|
| 595 |
else{
|
710 |
else{
|
| 596 |
return false;
|
711 |
return false;
|
| 597 |
}
|
712 |
}
|
| 598 |
|
713 |
|
| 599 |
} catch (TException e) {
|
714 |
} catch (TException e) {
|
| 600 |
e.printStackTrace();
|
715 |
e.printStackTrace();
|
| 601 |
}
|
716 |
}
|
| 602 |
return false;
|
717 |
return false;
|
| 603 |
}
|
718 |
}
|
| Line 672... |
Line 787... |
| 672 |
i++;
|
787 |
i++;
|
| 673 |
}
|
788 |
}
|
| 674 |
//if(order.getFulfillmentChannel().equals(FulfillmentChannelEnum.MFN) && (order.getOrderStatus().equals(OrderStatusEnum.UNSHIPPED) || order.getOrderStatus().equals(OrderStatusEnum.CANCELED))){
|
789 |
//if(order.getFulfillmentChannel().equals(FulfillmentChannelEnum.MFN) && (order.getOrderStatus().equals(OrderStatusEnum.UNSHIPPED) || order.getOrderStatus().equals(OrderStatusEnum.CANCELED))){
|
| 675 |
//if(order.getFulfillmentChannel().equals(FulfillmentChannelEnum.MFN) && (order.getOrderStatus().equals(OrderStatusEnum.UNSHIPPED) || order.getOrderStatus().equals(OrderStatusEnum.PARTIALLY_SHIPPED))){
|
790 |
//if(order.getFulfillmentChannel().equals(FulfillmentChannelEnum.MFN) && (order.getOrderStatus().equals(OrderStatusEnum.UNSHIPPED) || order.getOrderStatus().equals(OrderStatusEnum.PARTIALLY_SHIPPED))){
|
| 676 |
if(order.getFulfillmentChannel().equals(FulfillmentChannelEnum.MFN) && order.getOrderStatus().equals(OrderStatusEnum.UNSHIPPED) && order.getSellerOrderId()==null ){
|
791 |
if(order.getFulfillmentChannel().equals(FulfillmentChannelEnum.MFN) && order.getOrderStatus().equals(OrderStatusEnum.UNSHIPPED) && order.getSellerOrderId()==null ){
|
| 677 |
|
- |
|
| 678 |
String userEmail = order.getBuyerEmail();
|
792 |
String userEmail = order.getBuyerEmail();
|
| 679 |
User user = new User();
|
793 |
User user = new User();
|
| 680 |
user.setCommunicationEmail(userEmail);
|
794 |
user.setCommunicationEmail(userEmail);
|
| 681 |
user.setEmail(userEmail);
|
795 |
user.setEmail(userEmail);
|
| 682 |
user.setName(order.getBuyerName());
|
796 |
user.setName(order.getBuyerName());
|
| 683 |
user.setMobileNumber(order.getShippingAddress().getPhone());
|
797 |
user.setMobileNumber(order.getShippingAddress().getPhone());
|
| 684 |
user.setPassword("junglee");
|
798 |
user.setPassword("amazon");
|
| 685 |
user.setSourceId(10);
|
- |
|
| 686 |
try {
|
799 |
try {
|
| 687 |
UserClient ucl = new UserClient();
|
800 |
UserClient ucl = new UserClient();
|
| 688 |
user = ucl.getClient().createUser(user);
|
801 |
user = ucl.getClient().createUser(user);
|
| 689 |
} catch(Exception e) {
|
802 |
} catch(Exception e) {
|
| 690 |
//////////////log.error("Unable to get default source", e);
|
803 |
//////////////log.error("Unable to get default source", e);
|
| 691 |
}
|
804 |
}
|
| 692 |
|
805 |
|
| 693 |
long userId = user.getUserId();
|
806 |
long userId = user.getUserId();
|
| 694 |
AmazonOrder amazonOrder = new AmazonOrder();
|
807 |
AmazonOrder amazonOrder = new AmazonOrder();
|
| 695 |
long txnId = amazonOrder.persistTransaction(userId, user.getActiveCartId(), user.getEmail(), order, orderItems);
|
808 |
long txnId = amazonOrder.persistTransaction(userId, user.getActiveCartId(), user.getEmail(), order, orderItems);
|
| - |
|
809 |
|
| 696 |
TransactionClient tcl=null;
|
810 |
TransactionClient tcl=null;
|
| 697 |
InventoryClient icl = null;
|
811 |
InventoryClient icl = null;
|
| 698 |
PaymentClient pcl = null;
|
812 |
PaymentClient pcl = null;
|
| 699 |
Map<Long,Double> saholicItemMap = new HashMap<Long,Double>();
|
813 |
Map<Long,Double> saholicItemMap = new HashMap<Long,Double>();
|
| 700 |
if (txnId != -1){
|
814 |
if (txnId != -1){
|
| 701 |
List<in.shop2020.model.v1.order.AmazonOrder> amazonOrders = new ArrayList<in.shop2020.model.v1.order.AmazonOrder>();
|
815 |
List<in.shop2020.model.v1.order.AmazonOrder> amazonOrders = new ArrayList<in.shop2020.model.v1.order.AmazonOrder>();
|
| 702 |
try {
|
816 |
try {
|
| 703 |
|
817 |
|
| 704 |
tcl = new TransactionClient();
|
818 |
tcl = new TransactionClient();
|
| 705 |
icl = new InventoryClient();
|
819 |
icl = new InventoryClient();
|
| 706 |
pcl = new PaymentClient();;
|
820 |
pcl = new PaymentClient();;
|
| 707 |
System.out.println("temp id is" +userId);
|
821 |
System.out.println("temp id is" +userId);
|
| 708 |
List<in.shop2020.model.v1.order.Order> saholicOrders =tcl.getClient().getOrdersForTransaction(txnId,userId);
|
822 |
List<in.shop2020.model.v1.order.Order> saholicOrders =tcl.getClient().getOrdersForTransaction(txnId,userId);
|
| Line 722... |
Line 836... |
| 722 |
aOrder.setAmazonOrderItemCode(orderItemSkuMap.get(Long.toString(itemId)));
|
836 |
aOrder.setAmazonOrderItemCode(orderItemSkuMap.get(Long.toString(itemId)));
|
| 723 |
aOrder.setItem_id(itemId);
|
837 |
aOrder.setItem_id(itemId);
|
| 724 |
aOrder.setOrderId(saholicOrder.getId());
|
838 |
aOrder.setOrderId(saholicOrder.getId());
|
| 725 |
aOrder.setTransactionId(txnId);
|
839 |
aOrder.setTransactionId(txnId);
|
| 726 |
aOrder.setStatus("Order-Creation-Success");
|
840 |
aOrder.setStatus("Order-Creation-Success");
|
| 727 |
aOrder.setPurchaseDateOnAmazon(order.getPurchaseDate().toGregorianCalendar().getTimeInMillis());
|
- |
|
| 728 |
tcl.getClient().addAmazonOrder(aOrder);
|
841 |
tcl.getClient().addAmazonOrder(aOrder);
|
| 729 |
amazonOrders.add(aOrder);
|
842 |
amazonOrders.add(aOrder);
|
| 730 |
}
|
843 |
}
|
| 731 |
long merchantPaymentId = pcl.getClient().createPayment(userId, Double.parseDouble(order.getOrderTotal().getAmount()), 15, txnId, false);
|
844 |
long merchantPaymentId = pcl.getClient().createPayment(userId, Double.parseDouble(order.getOrderTotal().getAmount()), 15, txnId, false);
|
| 732 |
pcl.getClient().updatePaymentDetails(merchantPaymentId, "", "", "15", "", "", "", "", "", PaymentStatus.SUCCESS, "", null);
|
845 |
pcl.getClient().updatePaymentDetails(merchantPaymentId, "", "", "15", "", "", "", "", "", PaymentStatus.SUCCESS, "", null);
|
| Line 734... |
Line 847... |
| 734 |
if(success){
|
847 |
if(success){
|
| 735 |
for(in.shop2020.model.v1.order.AmazonOrder aorder:amazonOrders){
|
848 |
for(in.shop2020.model.v1.order.AmazonOrder aorder:amazonOrders){
|
| 736 |
AmazonInventorySnapshot amazonInventorySnapshot=icl.getClient().getAmazonInventoryForItem(aorder.getItem_id());
|
849 |
AmazonInventorySnapshot amazonInventorySnapshot=icl.getClient().getAmazonInventoryForItem(aorder.getItem_id());
|
| 737 |
long reserved = (amazonInventorySnapshot.getReserved()+1);
|
850 |
long reserved = (amazonInventorySnapshot.getReserved()+1);
|
| 738 |
amazonInventorySnapshot.setReserved(reserved);
|
851 |
amazonInventorySnapshot.setReserved(reserved);
|
| 739 |
icl.getClient().addOrUpdateAmazonInventoryForItem(amazonInventorySnapshot,0);
|
852 |
icl.getClient().addOrUpdateAmazonInventoryForItem((amazonInventorySnapshot),0);
|
| 740 |
tcl.getClient().updateAmazonOrderStatus(aorder.getOrderId(),"Order-Payment-Success");
|
853 |
tcl.getClient().updateAmazonOrderStatus(aorder.getOrderId(),"Order-Payment-Success");
|
| 741 |
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
- |
|
| 742 |
Calendar cal=GregorianCalendar.getInstance();
|
- |
|
| 743 |
String emailFromAddress = "build@shop2020.in";
|
- |
|
| 744 |
String emailSubjectTxt = "Order Created Payment Success "+sdf.format(cal.getTime())+" Amazon Order ID : "+aorder.getAmazonOrderCode();
|
- |
|
| 745 |
String sendTo[] = new String[]{ "anikendra.das@shop2020.in","sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in","khushal.bhatia@shop2020.in","rajveer.singh@saholic.com","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com"};
|
- |
|
| 746 |
String password = "cafe@nes";
|
- |
|
| 747 |
String text = "Order is now available for processing on Order Management Dashboard";
|
- |
|
| 748 |
GmailUtils mailer = new GmailUtils();
|
- |
|
| 749 |
try {
|
- |
|
| 750 |
System.out.println("Before Send mail order success");
|
- |
|
| 751 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
|
- |
|
| 752 |
}
|
- |
|
| 753 |
catch (Exception e) {
|
- |
|
| 754 |
e.printStackTrace();
|
- |
|
| 755 |
}
|
- |
|
| 756 |
|
- |
|
| 757 |
}
|
854 |
}
|
| 758 |
}
|
855 |
}
|
| 759 |
}
|
856 |
}
|
| 760 |
catch (TTransportException e) {
|
857 |
catch (TTransportException e) {
|
| - |
|
858 |
try{
|
| - |
|
859 |
tcl = new TransactionClient();
|
| - |
|
860 |
}
|
| 761 |
// TODO Auto-generated catch block
|
861 |
catch (TTransportException ex) {
|
| - |
|
862 |
|
| - |
|
863 |
}
|
| - |
|
864 |
|
| 762 |
for(in.shop2020.model.v1.order.AmazonOrder aorder:amazonOrders){
|
865 |
for(in.shop2020.model.v1.order.AmazonOrder aorder:amazonOrders){
|
| 763 |
try {
|
866 |
try {
|
| 764 |
|
- |
|
| 765 |
try {
|
- |
|
| 766 |
tcl = new TransactionClient();
|
- |
|
| 767 |
} catch (TException excep) {
|
- |
|
| 768 |
// TODO Auto-generated catch block
|
- |
|
| 769 |
e.printStackTrace();
|
- |
|
| 770 |
}
|
- |
|
| 771 |
tcl.getClient().updateAmazonOrderStatus(aorder.getOrderId(),"Order-Payment-Failure");
|
867 |
tcl.getClient().updateAmazonOrderStatus(aorder.getOrderId(),"Order-Payment-Failure");
|
| 772 |
in.shop2020.model.v1.order.Order saOrder= tcl.getClient().getOrder(aorder.getOrderId());
|
- |
|
| 773 |
String customer_details = saOrder.getCustomer_address1()+" "+saOrder.getCustomer_address2()+"\n"+saOrder.getCustomer_city()+"\n"+saOrder.getCustomer_state()+"\n"+saOrder.getCustomer_pincode();
|
- |
|
| 774 |
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
- |
|
| 775 |
Calendar cal=GregorianCalendar.getInstance();
|
- |
|
| 776 |
String emailFromAddress = "build@shop2020.in";
|
- |
|
| 777 |
String emailSubjectTxt = "Order Payment Failure Location not Serviciable "+sdf.format(cal.getTime())+" Amazon Order ID :"+aorder.getAmazonOrderCode();
|
- |
|
| 778 |
String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in","khushal.bhatia@shop2020.in","rajveer.singh@saholic.com","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com"};
|
- |
|
| 779 |
String password = "cafe@nes";
|
- |
|
| 780 |
String text = "Order payment failed because of non serviceable location"+"\n"+customer_details;
|
- |
|
| 781 |
GmailUtils mailer = new GmailUtils();
|
- |
|
| 782 |
try {
|
- |
|
| 783 |
System.out.println("Before Send mail order failure");
|
- |
|
| 784 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, text, emailFromAddress, password, new ArrayList<File>());
|
- |
|
| 785 |
}
|
- |
|
| 786 |
catch (Exception exc) {
|
- |
|
| 787 |
exc.printStackTrace();
|
- |
|
| 788 |
}
|
- |
|
| 789 |
|
- |
|
| 790 |
|
- |
|
| 791 |
} catch (TException e1) {
|
868 |
} catch (TException e1) {
|
| 792 |
// TODO Auto-generated catch block
|
869 |
// TODO Auto-generated catch block
|
| 793 |
e1.printStackTrace();
|
870 |
e1.printStackTrace();
|
| 794 |
}
|
871 |
}
|
| 795 |
catch (TransactionServiceException tex) {
|
- |
|
| 796 |
// TODO Auto-generated catch block
|
- |
|
| 797 |
tex.printStackTrace();
|
- |
|
| 798 |
}
|
- |
|
| 799 |
}
|
872 |
}
|
| 800 |
|
873 |
|
| 801 |
//e.printStackTrace();
|
874 |
//e.printStackTrace();
|
| 802 |
} catch (TException e) {
|
875 |
} catch (TException e) {
|
| 803 |
// TODO Auto-generated catch block
|
876 |
// TODO Auto-generated catch block
|
| 804 |
e.printStackTrace();
|
877 |
e.printStackTrace();
|
| 805 |
} catch (PaymentException e) {
|
878 |
} catch (PaymentException e) {
|