| 12589 |
manish.sha |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
import java.io.BufferedReader;
|
| 12596 |
manish.sha |
4 |
import java.io.File;
|
| 12589 |
manish.sha |
5 |
import java.io.IOException;
|
|
|
6 |
import java.io.InputStreamReader;
|
|
|
7 |
import java.util.ArrayList;
|
| 12596 |
manish.sha |
8 |
import java.util.Calendar;
|
|
|
9 |
import java.util.GregorianCalendar;
|
| 12589 |
manish.sha |
10 |
import java.util.List;
|
|
|
11 |
|
|
|
12 |
import in.shop2020.model.v1.order.FlipkartOrder;
|
|
|
13 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
14 |
|
|
|
15 |
import in.shop2020.serving.model.Order;
|
|
|
16 |
import in.shop2020.serving.model.OrderItems;
|
|
|
17 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 12596 |
manish.sha |
18 |
import in.shop2020.utils.GmailUtils;
|
| 12589 |
manish.sha |
19 |
|
|
|
20 |
import org.apache.http.HttpResponse;
|
|
|
21 |
import org.apache.http.NameValuePair;
|
|
|
22 |
import org.apache.http.client.HttpClient;
|
|
|
23 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
24 |
import org.apache.http.client.methods.HttpGet;
|
|
|
25 |
import org.apache.http.client.methods.HttpPost;
|
|
|
26 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
27 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
28 |
import org.apache.thrift.TException;
|
|
|
29 |
import org.apache.thrift.transport.TTransportException;
|
|
|
30 |
import org.json.JSONArray;
|
|
|
31 |
import org.json.JSONException;
|
|
|
32 |
import org.json.JSONObject;
|
|
|
33 |
|
|
|
34 |
import com.google.gson.Gson;
|
|
|
35 |
|
|
|
36 |
public class FlipkartHoldOrdersReconciliation{
|
| 12596 |
manish.sha |
37 |
private static String sendTo[] = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
|
|
38 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
|
|
39 |
"yukti.jain@shop2020.in","manish.sharma@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","anikendra.das@shop2020.in"};
|
|
|
40 |
private static java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
|
|
41 |
private static Calendar cal=GregorianCalendar.getInstance();
|
|
|
42 |
private static String emailFromAddress = "build@shop2020.in";
|
|
|
43 |
private static String password = "cafe@nes";
|
|
|
44 |
private static GmailUtils mailer = new GmailUtils();
|
|
|
45 |
|
| 12589 |
manish.sha |
46 |
public static void main(String[] args) throws TException, TransactionServiceException, JSONException {
|
|
|
47 |
HttpClient client = new DefaultHttpClient();
|
|
|
48 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
|
|
49 |
BufferedReader rd= null;
|
|
|
50 |
try {
|
|
|
51 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
52 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
53 |
"flipkart"));
|
|
|
54 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
55 |
"flipkart-support@saholic.com"));
|
|
|
56 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
57 |
"076c27ee24d7596b06608a8ed2559f87"));
|
|
|
58 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
59 |
HttpResponse response = client.execute(post);
|
|
|
60 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
61 |
String line = "";
|
|
|
62 |
HttpGet get_new;
|
|
|
63 |
|
| 12596 |
manish.sha |
64 |
List<FlipkartOrder> pendingOrderList = new ArrayList<FlipkartOrder>();
|
|
|
65 |
List<FlipkartOrder> acceptedOrderList = new ArrayList<FlipkartOrder>();
|
|
|
66 |
List<FlipkartOrder> cancelledOrderList = new ArrayList<FlipkartOrder>();
|
|
|
67 |
List<FlipkartOrder> errorOrderList = new ArrayList<FlipkartOrder>();
|
|
|
68 |
|
| 12589 |
manish.sha |
69 |
while ((line = rd.readLine()) != null) {
|
|
|
70 |
System.out.println(line);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
//https://seller.flipkart.com/order_management/search_order_items?order_id=OD40827062297&sellerId=m2z93iskuj81qiid
|
|
|
74 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
75 |
in.shop2020.model.v1.order.TransactionService.Client tClient = transactionServiceClient.getClient();
|
|
|
76 |
List<FlipkartOrder> pendingFkOrdersList = tClient.getVerificationPendingOrdersFK();
|
|
|
77 |
StringBuffer sb = new StringBuffer();
|
| 12596 |
manish.sha |
78 |
StringBuffer resB = new StringBuffer();
|
| 12589 |
manish.sha |
79 |
for(FlipkartOrder fkOrder : pendingFkOrdersList){
|
|
|
80 |
get_new = new HttpGet("https://seller.flipkart.com/order_management/search_order_items?order_id="+fkOrder.getFlipkartOrderId()+"&sellerId=m2z93iskuj81qiid");
|
|
|
81 |
response = client.execute(get_new);
|
|
|
82 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
83 |
line = "";
|
|
|
84 |
line = rd.readLine();
|
|
|
85 |
JSONObject jsonDataObj = null;
|
|
|
86 |
JSONArray jsonObjArr = null;
|
|
|
87 |
if(line == null || line.isEmpty()){
|
|
|
88 |
sb.append("Flipkart Order Id -"+ fkOrder.getFlipkartOrderId()+" Response - "+line);
|
|
|
89 |
sb.append("\n");
|
|
|
90 |
continue;
|
|
|
91 |
} else if (!line.startsWith("{")){
|
|
|
92 |
sb.append("Flipkart Order Id -"+ fkOrder.getFlipkartOrderId()+" Response - "+line);
|
|
|
93 |
sb.append("\n");
|
|
|
94 |
continue;
|
|
|
95 |
}
|
|
|
96 |
else{
|
|
|
97 |
jsonDataObj = new JSONObject(line);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
if(jsonDataObj!=null){
|
|
|
101 |
jsonObjArr = new JSONArray(jsonDataObj.get("items").toString());
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
if(jsonObjArr!=null && jsonObjArr.length()>0){
|
|
|
105 |
JSONObject jsonObj = null;
|
|
|
106 |
jsonObj = jsonObjArr.getJSONObject(0);
|
|
|
107 |
if(jsonObj!=null){
|
|
|
108 |
System.out.println("jsonObj..... "+ jsonObj);
|
|
|
109 |
if(jsonObj.get("status")!=null){
|
|
|
110 |
String status = jsonObj.get("status").toString();
|
|
|
111 |
if("on_hold".equalsIgnoreCase(status)){
|
| 12596 |
manish.sha |
112 |
pendingOrderList.add(fkOrder);
|
| 12589 |
manish.sha |
113 |
}
|
|
|
114 |
if("approved".equalsIgnoreCase(status)){
|
|
|
115 |
if(tClient ==null || !tClient.isAlive()){
|
|
|
116 |
tClient = transactionServiceClient.getClient();
|
|
|
117 |
}
|
|
|
118 |
tClient.verifyOrder(fkOrder.getOrderId());
|
|
|
119 |
tClient.acceptOrder(fkOrder.getOrderId());
|
| 12596 |
manish.sha |
120 |
acceptedOrderList.add(fkOrder);
|
| 12589 |
manish.sha |
121 |
}
|
|
|
122 |
if("cancelled".equalsIgnoreCase(status)){
|
|
|
123 |
if(tClient ==null || !tClient.isAlive()){
|
|
|
124 |
tClient = transactionServiceClient.getClient();
|
|
|
125 |
}
|
|
|
126 |
tClient.refundOrder(fkOrder.getOrderId(), "flipkart", "As per Buyer's Request");
|
| 12596 |
manish.sha |
127 |
cancelledOrderList.add(fkOrder);
|
| 12589 |
manish.sha |
128 |
}
|
|
|
129 |
}else{
|
| 12596 |
manish.sha |
130 |
errorOrderList.add(fkOrder);
|
| 12589 |
manish.sha |
131 |
}
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
|
| 12596 |
manish.sha |
136 |
resB.append("Still Pending Orders:-\n");
|
|
|
137 |
for(FlipkartOrder order: pendingOrderList){
|
|
|
138 |
resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");
|
|
|
139 |
}
|
|
|
140 |
resB.append("Accepeted Orders:-\n");
|
|
|
141 |
for(FlipkartOrder order: acceptedOrderList){
|
|
|
142 |
resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");
|
|
|
143 |
}
|
|
|
144 |
resB.append("Cancelled Orders:-\n");
|
|
|
145 |
for(FlipkartOrder order: cancelledOrderList){
|
|
|
146 |
resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");
|
|
|
147 |
}
|
|
|
148 |
resB.append("Response not found Orders:-\n");
|
|
|
149 |
for(FlipkartOrder order: errorOrderList){
|
|
|
150 |
resB.append(order.getOrderId()+" "+ order.getFlipkartOrderId()+"\n");
|
|
|
151 |
}
|
|
|
152 |
String emailSubjectTxt = " Flipkart Hold Order Reconcilaition Process "+sdf.format(cal.getTime());
|
|
|
153 |
mailer.sendSSLMessage(sendTo, emailSubjectTxt, resB.toString(), emailFromAddress, password, new ArrayList<File>());
|
| 12589 |
manish.sha |
154 |
System.out.println(sb.toString());
|
| 12596 |
manish.sha |
155 |
} catch (Exception e) {
|
| 12589 |
manish.sha |
156 |
e.printStackTrace();
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
}
|