2 |
- |
1 |
<!DOCTYPE html>
|
|
|
2 |
<html lang="en">
|
|
|
3 |
|
|
|
4 |
<head>
|
|
|
5 |
<title>eBay Listing Promotion</title>
|
|
|
6 |
<meta charset="UTF-8">
|
|
|
7 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
8 |
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
|
|
|
9 |
<link rel="icon" href="favicon.ico" type="image/x-icon">
|
|
|
10 |
|
30 |
- |
11 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
|
|
|
12 |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
|
|
|
13 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
|
14 |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
|
|
|
15 |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
|
|
|
16 |
<script src="js/XMLWriter.js"></script>
|
|
|
17 |
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
|
|
|
18 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script>
|
|
|
19 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.23/moment-timezone-with-data-2012-2022.min.js"></script>
|
2 |
- |
20 |
<link rel="stylesheet" href="css/style.css">
|
|
|
21 |
<script src="js/muna-tools.js"></script>
|
|
|
22 |
</head>
|
|
|
23 |
|
|
|
24 |
<body onload="return initConfig();">
|
30 |
- |
25 |
<div>
|
|
|
26 |
<div>
|
|
|
27 |
<div class="container-fluid bg-secondary">
|
|
|
28 |
<div class="clearfix">
|
|
|
29 |
<img class="img-fluid float-right" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" />
|
|
|
30 |
<h1 id="connected">eBay Listing Promotion
|
|
|
31 |
<input id="login" type="button" class="btn bg-success mb-2 w3-hide" onclick="eBayLogin();" value="Login" /></h1>
|
|
|
32 |
</div>
|
2 |
- |
33 |
</div>
|
|
|
34 |
|
30 |
- |
35 |
<div class="border col">
|
2 |
- |
36 |
<div>
|
30 |
- |
37 |
<form id="searchForm" class="container-fluid bg-light" onsubmit="return getListingsForPromote();">
|
|
|
38 |
<input id="promoteButton" type="button" class="btn btn-danger" onclick="getListingsForPromote();" value="Promote" />
|
2 |
- |
39 |
</form>
|
|
|
40 |
</div>
|
30 |
- |
41 |
<div class="modal" id="progressBarDiv">
|
|
|
42 |
<div class="modal-dialog">
|
|
|
43 |
<div class="modal-content">
|
|
|
44 |
<div class="modal-header">
|
|
|
45 |
<h4 id="progressBarHeader"></h4>
|
|
|
46 |
</div>
|
|
|
47 |
<div class="modal-body">
|
|
|
48 |
<div class="progress">
|
|
|
49 |
<div id="progressBar" class="progress-bar" style="width:0%">0%</div>
|
|
|
50 |
</div>
|
|
|
51 |
</div>
|
|
|
52 |
</div>
|
2 |
- |
53 |
</div>
|
|
|
54 |
</div>
|
30 |
- |
55 |
<div id="results" class="border bg-info w3-hide"></div>
|
|
|
56 |
<div id="logging"></div>
|
2 |
- |
57 |
</div>
|
|
|
58 |
</div>
|
|
|
59 |
|
30 |
- |
60 |
<footer class="container-fluid text-center border border-bottom-0 border-left-0 border-right-0">
|
17 |
- |
61 |
<div w3-include-html="php/footer.php"></div>
|
2 |
- |
62 |
</footer>
|
|
|
63 |
|
|
|
64 |
</div>
|
|
|
65 |
|
|
|
66 |
<script>
|
|
|
67 |
|
|
|
68 |
// Config
|
|
|
69 |
var configCampaignId = '10477406018';
|
6 |
- |
70 |
var accessToken = '';
|
|
|
71 |
var refreshToken = '';
|
2 |
- |
72 |
|
|
|
73 |
var pagesToProcess = 0;
|
10 |
- |
74 |
var maxPagesToProcess = 0;
|
2 |
- |
75 |
var pagesProcessed = 0;
|
|
|
76 |
var html = [];
|
|
|
77 |
|
|
|
78 |
// Initialize Configuration Variables
|
|
|
79 |
function initConfig() {
|
|
|
80 |
eBayAuthToken = readCookie();
|
|
|
81 |
if (eBayAuthToken.length > 0) {
|
|
|
82 |
connected();
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
if (eBayAuthTokenFlag === false) {
|
|
|
86 |
var x = document.getElementById("login");
|
|
|
87 |
if (x.className.indexOf("w3-show") == -1) {
|
|
|
88 |
x.className += " w3-show";
|
|
|
89 |
}
|
|
|
90 |
}
|
6 |
- |
91 |
|
3 |
- |
92 |
getOAuthToken();
|
2 |
- |
93 |
}
|
|
|
94 |
|
|
|
95 |
function requireNewLogin() {
|
|
|
96 |
// dummy
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
function connected() {
|
|
|
100 |
var x;
|
|
|
101 |
|
|
|
102 |
eBayAuthTokenFlag = true;
|
|
|
103 |
document.getElementById("connected").innerHTML += " (Connected)";
|
|
|
104 |
|
|
|
105 |
x = document.getElementById("promoteButton");
|
30 |
- |
106 |
x.className = x.className.replace(" btn-danger", " btn-dark");
|
2 |
- |
107 |
|
|
|
108 |
x = document.getElementById("login");
|
|
|
109 |
x.className = x.className.replace(" w3-show", "");
|
|
|
110 |
|
|
|
111 |
x = document.getElementById("results");
|
|
|
112 |
x.innerHTML = "";
|
|
|
113 |
x.className = x.className.replace(" w3-show", "");
|
|
|
114 |
x.className = x.className.replace("process-errors", "");
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
function getListingsForPromote() {
|
|
|
118 |
var x;
|
|
|
119 |
|
|
|
120 |
if (eBayAuthTokenFlag === false) {
|
|
|
121 |
return;
|
|
|
122 |
}
|
|
|
123 |
|
6 |
- |
124 |
// if (accessToken.length < 1) {
|
|
|
125 |
// getOAuthToken();
|
|
|
126 |
// } else if (refreshToken.length > 0) {
|
|
|
127 |
// refreshApplicationToken(refreshToken);
|
|
|
128 |
// }
|
|
|
129 |
|
|
|
130 |
if (accessToken.length < 1) {
|
2 |
- |
131 |
return;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
document.getElementById("logging").innerHTML = '';
|
|
|
135 |
|
|
|
136 |
x = document.getElementById("results");
|
|
|
137 |
if (x.className.indexOf("w3-show") == -1) {
|
|
|
138 |
x.className += " w3-show";
|
|
|
139 |
}
|
|
|
140 |
x.innerHTML = '<p><strong>Retrieving Listings...</strong></p>';
|
|
|
141 |
x.className = x.className.replace("process-errors", "");
|
|
|
142 |
|
|
|
143 |
pagesToProcess = 1;
|
10 |
- |
144 |
maxPagesToProcess = 0;
|
2 |
- |
145 |
pagesProcessed = 0;
|
|
|
146 |
initProgressBar("Retrieving Listings...");
|
|
|
147 |
eBaySearch(1);
|
|
|
148 |
|
|
|
149 |
function checkpagesToProcess() {
|
|
|
150 |
if (pagesToProcess > 0) {
|
|
|
151 |
window.setTimeout(checkpagesToProcess, 300); // wait 100 milliseconds
|
|
|
152 |
} else {
|
|
|
153 |
endProgressBar();
|
|
|
154 |
processCurrentAds();
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
checkpagesToProcess();
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
function processCurrentAds() {
|
|
|
162 |
adsToRead = 1;
|
|
|
163 |
getCurrentAds(1);
|
|
|
164 |
|
|
|
165 |
function checkAdsToRead() {
|
|
|
166 |
if (adsToRead > 0) {
|
|
|
167 |
window.setTimeout(checkAdsToRead, 100); // wait 100 milliseconds
|
|
|
168 |
} else {
|
|
|
169 |
updateAds();
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
checkAdsToRead();
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
function updateAds() {
|
|
|
177 |
var i = 1;
|
|
|
178 |
var pt = document.getElementById("promoteTable");
|
|
|
179 |
var x;
|
|
|
180 |
var updateList = [];
|
|
|
181 |
var addList = [];
|
|
|
182 |
var entry;
|
|
|
183 |
var maxAds = 500;
|
|
|
184 |
|
|
|
185 |
adsToUpdate = 0;
|
|
|
186 |
|
|
|
187 |
for (i = 1; i < pt.rows.length; i++) {
|
|
|
188 |
if (pt.rows[i].cells[1].innerHTML != pt.rows[i].cells[3].innerHTML) {
|
|
|
189 |
entry = '{"bidPercentage":"' + pt.rows[i].cells[1].innerHTML + '","listingId" : "' + pt.rows[i].cells[0].innerHTML + '"}';
|
|
|
190 |
if (pt.rows[i].cells[2].innerHTML.length > 0) {
|
|
|
191 |
if (updateList.indexOf(entry) == -1) {
|
|
|
192 |
updateList.push(entry);
|
|
|
193 |
}
|
|
|
194 |
} else {
|
|
|
195 |
if (addList.indexOf(entry) == -1) {
|
|
|
196 |
addList.push(entry);
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
for (i = 0; (i * maxAds) < updateList.length; i++) {
|
|
|
203 |
++adsToUpdate;
|
|
|
204 |
updateAd(1, updateList.slice(i * maxAds, (i + 1) * maxAds));
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
for (i = 0; (i * maxAds) < addList.length; i++) {
|
|
|
208 |
++adsToUpdate;
|
|
|
209 |
updateAd(0, addList.slice(i * maxAds, (i + 1) * maxAds));
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
function checkAdsToUpdate() {
|
|
|
213 |
if (adsToUpdate > 0) {
|
|
|
214 |
window.setTimeout(checkAdsToUpdate, 100); // wait 100 milliseconds
|
|
|
215 |
} else {
|
|
|
216 |
x = document.getElementById("results");
|
|
|
217 |
x.innerHTML += '<p><strong>Report Finished!</strong></p>';
|
|
|
218 |
if (!x.className.includes("process-errors")) {
|
|
|
219 |
setTimeout(function() {
|
|
|
220 |
x.className = x.className.replace(" w3-show", "");
|
|
|
221 |
}, 3000);
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
checkAdsToUpdate();
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
function getCurrentAds(pageNumber) {
|
|
|
230 |
var i;
|
|
|
231 |
var response;
|
|
|
232 |
var limit = 500;
|
|
|
233 |
url = configeBayAdCampaign;
|
|
|
234 |
url += configCampaignId;
|
|
|
235 |
url += '/ad?';
|
|
|
236 |
url += 'offset=';
|
|
|
237 |
url += (pageNumber - 1) * limit;
|
|
|
238 |
url += '&limit=';
|
|
|
239 |
url += limit;
|
|
|
240 |
|
|
|
241 |
var xhttp = new XMLHttpRequest();
|
|
|
242 |
|
|
|
243 |
xhttp.onreadystatechange = function() {
|
|
|
244 |
if (this.readyState == 4) {
|
|
|
245 |
if (this.status == 200) {
|
|
|
246 |
response = JSON.parse(this.responseText);
|
|
|
247 |
|
|
|
248 |
for (i = 0; i < response.ads.length; i++) {
|
|
|
249 |
itemId = response.ads[i].listingId;
|
|
|
250 |
if (document.getElementById('AdId' + itemId) !== null) {
|
|
|
251 |
document.getElementById('AdId' + itemId).innerHTML = response.ads[i].adId;
|
|
|
252 |
document.getElementById('CurrentRate' + itemId).innerHTML = response.ads[i].bidPercentage;
|
|
|
253 |
}
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
if (Number(response.total) > (pageNumber * limit)) {
|
|
|
257 |
++adsToRead;
|
|
|
258 |
document.getElementById("results").innerHTML += '<p><strong>Retrieving Ads (' + pageNumber + '/' + Number((response.total / limit) + 1).toFixed(0) + ')</strong></p>';
|
|
|
259 |
getCurrentAds(pageNumber + 1);
|
|
|
260 |
}
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
--adsToRead;
|
|
|
264 |
}
|
|
|
265 |
};
|
|
|
266 |
|
|
|
267 |
xhttp.open("GET", configProxyUrl, true);
|
|
|
268 |
xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
|
6 |
- |
269 |
xhttp.setRequestHeader('X-Authorization', 'Bearer ' + accessToken);
|
2 |
- |
270 |
xhttp.send();
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
function updateAd(flag, list) {
|
|
|
274 |
var xhttp;
|
|
|
275 |
var json;
|
6 |
- |
276 |
var i, j;
|
2 |
- |
277 |
var obj;
|
6 |
- |
278 |
var errors;
|
2 |
- |
279 |
|
|
|
280 |
if (list.length === 0) {
|
|
|
281 |
return;
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
json = '{"requests":[' + list.join(',') + ']}';
|
|
|
285 |
|
|
|
286 |
if (flag) {
|
|
|
287 |
url = configeBayAdCampaign;
|
|
|
288 |
url += configCampaignId;
|
|
|
289 |
url += '/bulk_update_ads_bid_by_listing_id';
|
|
|
290 |
|
|
|
291 |
xhttp = new XMLHttpRequest();
|
|
|
292 |
|
|
|
293 |
xhttp.onreadystatechange = function() {
|
|
|
294 |
if (this.readyState == 4) {
|
|
|
295 |
obj = JSON.parse(this.responseText);
|
|
|
296 |
if (this.status == 200 || this.status == 207) {
|
|
|
297 |
for (i = 0; i < obj.responses.length; i++) {
|
|
|
298 |
if (Number(obj.responses[i].statusCode) == 200) {
|
|
|
299 |
document.getElementById('AdId' + obj.responses[i].listingId).innerHTML = obj.responses[i].adId;
|
|
|
300 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).innerHTML = 'Updated';
|
|
|
301 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).style.color = 'green';
|
|
|
302 |
} else {
|
|
|
303 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).innerHTML = 'Update Failed (';
|
6 |
- |
304 |
errors = getJsonArray(obj.responses[i].errors);
|
|
|
305 |
if (errors[0] !== undefined) {
|
|
|
306 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).innerHTML += errors[0].message;
|
2 |
- |
307 |
} else if (obj.responses[i].statusCode !== undefined) {
|
6 |
- |
308 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).innerHTML += " " + obj.responses[i].statusCode;
|
2 |
- |
309 |
}
|
|
|
310 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).innerHTML += ')';
|
|
|
311 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).style.color = 'red';
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
} else {
|
|
|
315 |
var x = document.getElementById("results");
|
|
|
316 |
x.className += " process-errors";
|
30 |
- |
317 |
x.innerHTML += '<p class="text-danger">Bulk Update Ads: <strong>' + this.status + '</strong></p>';
|
2 |
- |
318 |
}
|
|
|
319 |
|
|
|
320 |
--adsToRead;
|
|
|
321 |
}
|
|
|
322 |
};
|
|
|
323 |
|
|
|
324 |
xhttp.open("POST", configProxyUrl, true);
|
|
|
325 |
xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
|
6 |
- |
326 |
xhttp.setRequestHeader('X-Authorization', 'Bearer ' + accessToken);
|
2 |
- |
327 |
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
328 |
xhttp.send(json);
|
|
|
329 |
|
|
|
330 |
} else {
|
|
|
331 |
url = configeBayAdCampaign;
|
|
|
332 |
url += configCampaignId;
|
|
|
333 |
url += '/bulk_create_ads_by_listing_id';
|
|
|
334 |
|
|
|
335 |
xhttp = new XMLHttpRequest();
|
|
|
336 |
|
|
|
337 |
xhttp.onreadystatechange = function() {
|
|
|
338 |
if (this.readyState == 4) {
|
|
|
339 |
obj = JSON.parse(this.responseText);
|
|
|
340 |
if (this.status == 200 || this.status == 207) {
|
|
|
341 |
for (i = 0; i < obj.responses.length; i++) {
|
|
|
342 |
if (Number(obj.responses[i].statusCode) == 201) {
|
|
|
343 |
document.getElementById('AdId' + obj.responses[i].listingId).innerHTML = obj.responses[i].adId;
|
|
|
344 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).innerHTML = 'Added';
|
|
|
345 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).style.color = 'green';
|
|
|
346 |
} else {
|
6 |
- |
347 |
errors = getJsonArray(obj.responses[i].errors);
|
|
|
348 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).innerHTML = 'Add Failed (' + getJsonValue(errors[0].message) + ')';
|
2 |
- |
349 |
document.getElementById('UpdateStatus' + obj.responses[i].listingId).style.color = 'red';
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
} else {
|
|
|
353 |
var x = document.getElementById("results");
|
|
|
354 |
x.className += " process-errors";
|
30 |
- |
355 |
x.innerHTML += '<p class="text-danger">Bulk Create Ads: <strong>' + this.status + '</strong></p>';
|
2 |
- |
356 |
}
|
|
|
357 |
|
|
|
358 |
--adsToRead;
|
|
|
359 |
}
|
|
|
360 |
};
|
|
|
361 |
|
|
|
362 |
xhttp.open("POST", configProxyUrl, true);
|
|
|
363 |
xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
|
6 |
- |
364 |
xhttp.setRequestHeader('X-Authorization', 'Bearer ' + accessToken);
|
2 |
- |
365 |
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
366 |
xhttp.send(json);
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
--adsToUpdate;
|
|
|
370 |
}
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
// Build an HTML table to display search results
|
|
|
374 |
function eBaySearch(pageNo) {
|
|
|
375 |
var i;
|
|
|
376 |
var xml;
|
|
|
377 |
|
|
|
378 |
if (eBayAuthTokenFlag === false) {
|
|
|
379 |
return;
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
var xw = new XMLWriter('UTF-8', '1.0');
|
|
|
383 |
var xhr = new XMLHttpRequest();
|
|
|
384 |
|
|
|
385 |
if (!createAddXMLSearch(xw, xhr, 'GetSellerList', pageNo)) {
|
|
|
386 |
return;
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
xml = xw.flush();
|
|
|
390 |
xw.close();
|
|
|
391 |
|
|
|
392 |
xhr.onload = function() {
|
10 |
- |
393 |
var jsonObj = XMLparse(xhr.responseXML, false);
|
|
|
394 |
var obj = jsonObj.GetSellerListResponse;
|
2 |
- |
395 |
var returnCode = obj.Ack;
|
19 |
- |
396 |
var str;
|
2 |
- |
397 |
|
|
|
398 |
var x = document.getElementById("results");
|
|
|
399 |
|
|
|
400 |
if (returnCode == 'Success') {
|
|
|
401 |
createTable(obj.ItemArray, pageNo, Number(obj.PaginationResult.TotalNumberOfPages));
|
|
|
402 |
|
|
|
403 |
if (Number(obj.PaginationResult.TotalNumberOfPages) > pageNo) {
|
|
|
404 |
maxPagesToProcess = Number(obj.PaginationResult.TotalNumberOfPages);
|
|
|
405 |
++pagesToProcess;
|
|
|
406 |
eBaySearch(pageNo + 1);
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
updateProgressBar(maxPagesToProcess, pagesProcessed);
|
|
|
410 |
} else {
|
|
|
411 |
x.className += " process-errors";
|
30 |
- |
412 |
str = '<p class="text-danger"><strong>' + returnCode + ':</strong></p>';
|
6 |
- |
413 |
var errors = getJsonArray(obj.Errors);
|
19 |
- |
414 |
str += "<p>";
|
6 |
- |
415 |
for (i = 0; i < errors.length; i++) {
|
19 |
- |
416 |
str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
|
2 |
- |
417 |
}
|
19 |
- |
418 |
str += "</p>";
|
|
|
419 |
|
|
|
420 |
x.innerHTML += str;
|
2 |
- |
421 |
}
|
|
|
422 |
|
|
|
423 |
--pagesToProcess;
|
|
|
424 |
++pagesProcessed;
|
|
|
425 |
|
|
|
426 |
document.getElementById("logging").innerHTML = html.join('');
|
|
|
427 |
updateProgressBar(maxPagesToProcess, pagesProcessed);
|
|
|
428 |
};
|
|
|
429 |
|
|
|
430 |
xhr.send(xml);
|
|
|
431 |
}
|
|
|
432 |
|
|
|
433 |
function createAddXMLSearch(xw, xhr, callname, pageNo) {
|
|
|
434 |
var startDate = moment(moment().subtract(31, "days").format('YYYY-MM-DD') + " 00:00:00", "YYYY-MM-DD HH:mm:ss").tz("UTC").toISOString();
|
|
|
435 |
var todayDate = moment(moment().format('YYYY-MM-DD') + " 23:59:59", "YYYY-MM-DD HH:mm:ss").tz("UTC").toISOString();
|
|
|
436 |
var endDate = moment(moment().add(31, "days").format('YYYY-MM-DD') + " 00:00:00", "YYYY-MM-DD HH:mm:ss").tz("UTC").toISOString();
|
|
|
437 |
|
|
|
438 |
xw.writeStartDocument();
|
|
|
439 |
xw.writeStartElement(callname + "Request");
|
|
|
440 |
xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');
|
|
|
441 |
|
|
|
442 |
xw.writeStartElement('RequesterCredentials');
|
|
|
443 |
xw.writeElementString('eBayAuthToken', eBayAuthToken);
|
|
|
444 |
xw.writeEndElement(); /* RequesterCredentials */
|
|
|
445 |
|
10 |
- |
446 |
xw.writeElementString('DetailLevel', 'ItemReturnDescription');
|
2 |
- |
447 |
xw.writeElementString('StartTimeFrom', startDate);
|
|
|
448 |
xw.writeElementString('StartTimeTo', todayDate);
|
|
|
449 |
xw.writeElementString('EndTimeFrom', todayDate);
|
|
|
450 |
xw.writeElementString('EndTimeTo', endDate);
|
|
|
451 |
xw.writeElementString('OutputSelector', 'ItemArray.Item.ItemID');
|
|
|
452 |
xw.writeElementString('OutputSelector', 'ItemArray.Item.ListingType');
|
|
|
453 |
xw.writeElementString('OutputSelector', 'PaginationResult');
|
|
|
454 |
xw.writeElementString('OutputSelector', 'ItemArray.Item.SellingStatus.ConvertedCurrentPrice');
|
|
|
455 |
xw.writeStartElement('Pagination');
|
|
|
456 |
xw.writeElementString('EntriesPerPage', '200');
|
|
|
457 |
xw.writeElementString('PageNumber', '' + pageNo);
|
|
|
458 |
xw.writeEndElement(); /* Pagination*/
|
|
|
459 |
|
|
|
460 |
xw.writeElementString('ErrorLanguage', 'en_US');
|
|
|
461 |
xw.writeElementString('Version', configeBayTradingVersion);
|
|
|
462 |
xw.writeElementString('WarningLevel', configWarningLevel);
|
|
|
463 |
|
|
|
464 |
xw.writeEndElement(); /* xmlrequest */
|
|
|
465 |
xw.writeEndDocument();
|
|
|
466 |
|
|
|
467 |
xhr.open('POST', configProxyUrl, true);
|
|
|
468 |
xhr.setRequestHeader('Content-Type', 'text/xml');
|
|
|
469 |
xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
|
|
|
470 |
xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
|
|
|
471 |
xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
|
|
|
472 |
xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
|
|
|
473 |
xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
|
|
|
474 |
xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
|
|
|
475 |
xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);
|
|
|
476 |
|
|
|
477 |
return true;
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
function createTable(obj, pageNumber, totalPages) {
|
|
|
481 |
var currentPrice;
|
|
|
482 |
var adRate;
|
|
|
483 |
|
|
|
484 |
if (pageNumber == 1) {
|
|
|
485 |
document.getElementById("logging").innerHTML = '';
|
|
|
486 |
html = [];
|
|
|
487 |
|
30 |
- |
488 |
html.push('<div class="border table-responsive">');
|
2 |
- |
489 |
html.push('<h3>Listing Promotions</h3>');
|
30 |
- |
490 |
html.push('<table id="promoteTable" class="table table-hover table-striped table-bordered small">');
|
|
|
491 |
html.push('<thead class="thead-dark">');
|
2 |
- |
492 |
html.push('<tr>');
|
|
|
493 |
|
|
|
494 |
html.push(tableHeader('Item ID'));
|
|
|
495 |
html.push(tableHeader('New Ad Rate'));
|
|
|
496 |
html.push(tableHeader('Ad Id'));
|
|
|
497 |
html.push(tableHeader('Current Ad Rate'));
|
|
|
498 |
html.push(tableHeader('Create/Update Status'));
|
|
|
499 |
|
|
|
500 |
html.push('</tr>');
|
|
|
501 |
html.push('</thead>');
|
|
|
502 |
html.push('<tbody>');
|
|
|
503 |
}
|
|
|
504 |
|
10 |
- |
505 |
for (var entry = 0; entry < obj.Item.length; entry++) {
|
|
|
506 |
var item = obj.Item[entry];
|
2 |
- |
507 |
|
10 |
- |
508 |
if (item.ListingType == 'Chinese') {
|
2 |
- |
509 |
continue;
|
|
|
510 |
}
|
|
|
511 |
|
10 |
- |
512 |
currentPrice = Number(item.SellingStatus.ConvertedCurrentPrice.text).toFixed(2);
|
2 |
- |
513 |
|
|
|
514 |
// minimum ad rate is 1.00%
|
34 |
- |
515 |
/*
|
2 |
- |
516 |
if (currentPrice > 99.99) {
|
|
|
517 |
adRate = 2.0;
|
|
|
518 |
} else if (currentPrice > 49.99) {
|
|
|
519 |
adRate = 2.7;
|
|
|
520 |
} else if (currentPrice > 29.99) {
|
|
|
521 |
adRate = 3.0;
|
|
|
522 |
} else if (currentPrice > 19.99) {
|
|
|
523 |
adRate = 3.2;
|
|
|
524 |
} else if (currentPrice > 14.99) {
|
|
|
525 |
adRate = 3.5;
|
|
|
526 |
} else if (currentPrice > 9.99) {
|
|
|
527 |
adRate = 3.7;
|
|
|
528 |
} else if (currentPrice > 4.99) {
|
|
|
529 |
adRate = 4.0;
|
|
|
530 |
} else if (currentPrice > 3.99) {
|
|
|
531 |
adRate = 4.2;
|
|
|
532 |
} else {
|
|
|
533 |
continue;
|
|
|
534 |
}
|
34 |
- |
535 |
*/
|
2 |
- |
536 |
|
156 |
- |
537 |
adRate = 2.8;
|
34 |
- |
538 |
|
2 |
- |
539 |
html.push('<tr>');
|
|
|
540 |
|
10 |
- |
541 |
html.push(tableCell(item.ItemID));
|
2 |
- |
542 |
html.push(tableCell(Number(adRate).toFixed(1)));
|
10 |
- |
543 |
html.push(tableCellLabel('AdId' + item.ItemID));
|
|
|
544 |
html.push(tableCellLabel('CurrentRate' + item.ItemID));
|
|
|
545 |
html.push(tableCellLabel('UpdateStatus' + item.ItemID));
|
2 |
- |
546 |
|
|
|
547 |
html.push('</tr>');
|
|
|
548 |
}
|
|
|
549 |
|
|
|
550 |
if (pageNumber == totalPages) {
|
|
|
551 |
html.push('</tbody>');
|
|
|
552 |
html.push('</table>');
|
|
|
553 |
html.push('</div>');
|
|
|
554 |
}
|
|
|
555 |
}
|
|
|
556 |
|
3 |
- |
557 |
function getOAuthToken() {
|
|
|
558 |
var code = "";
|
|
|
559 |
|
|
|
560 |
var win = window.open(configeBayLoginUrl, "eBay OAUTH", "");
|
|
|
561 |
|
|
|
562 |
var pollTimer = window.setInterval(function() {
|
|
|
563 |
if (win.closed !== false) {
|
|
|
564 |
window.clearInterval(pollTimer);
|
|
|
565 |
getApplicationToken(code);
|
|
|
566 |
} else {
|
|
|
567 |
if (code === null || code.length === 0) {
|
|
|
568 |
try {
|
|
|
569 |
code = getUrlParameter(win, 'code');
|
|
|
570 |
} catch(err) {
|
|
|
571 |
// empty
|
6 |
- |
572 |
}
|
3 |
- |
573 |
}
|
|
|
574 |
}
|
|
|
575 |
}, 200);
|
6 |
- |
576 |
|
3 |
- |
577 |
}
|
|
|
578 |
|
|
|
579 |
function getApplicationToken(code) {
|
|
|
580 |
var param;
|
6 |
- |
581 |
|
3 |
- |
582 |
param = 'grant_type=authorization_code';
|
|
|
583 |
param += '&code=' + code;
|
|
|
584 |
param += '&redirect_uri=' + configRuName;
|
6 |
- |
585 |
|
3 |
- |
586 |
var xhttp = new XMLHttpRequest();
|
|
|
587 |
|
|
|
588 |
xhttp.onreadystatechange = function() {
|
|
|
589 |
if (this.readyState == 4) {
|
|
|
590 |
if (this.status == 200) {
|
|
|
591 |
response = JSON.parse(this.responseText);
|
|
|
592 |
|
6 |
- |
593 |
accessToken = getJsonValue(response.access_token);
|
|
|
594 |
refreshToken = getJsonValue(response.refresh_token);
|
3 |
- |
595 |
}
|
|
|
596 |
}
|
|
|
597 |
};
|
|
|
598 |
|
|
|
599 |
xhttp.open("POST", configProxyUrl, true);
|
|
|
600 |
xhttp.setRequestHeader("X-Proxy-Url", configOauthTokenUrl);
|
87 |
- |
601 |
xhttp.setRequestHeader('X-Authorization', 'Basic XxXAuthorization');
|
4 |
- |
602 |
xhttp.setRequestHeader('X-DECODE-PARAMS', '1');
|
6 |
- |
603 |
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
604 |
xhttp.send(param);
|
|
|
605 |
}
|
3 |
- |
606 |
|
6 |
- |
607 |
function refreshApplicationToken(code) {
|
|
|
608 |
var param;
|
|
|
609 |
|
|
|
610 |
param = 'grant_type=refresh_token';
|
|
|
611 |
param += '&refresh_token=' + code;
|
|
|
612 |
param += '&scope=https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope%2Fsell.marketing';
|
|
|
613 |
|
|
|
614 |
var xhttp = new XMLHttpRequest();
|
|
|
615 |
|
|
|
616 |
xhttp.onreadystatechange = function() {
|
|
|
617 |
if (this.readyState == 4) {
|
|
|
618 |
if (this.status == 200) {
|
|
|
619 |
response = JSON.parse(this.responseText);
|
|
|
620 |
|
|
|
621 |
accessToken = getJsonValue(response.access_token);
|
|
|
622 |
refreshToken = getJsonValue(response.refresh_token);
|
|
|
623 |
}
|
|
|
624 |
}
|
|
|
625 |
};
|
|
|
626 |
|
|
|
627 |
xhttp.open("POST", configProxyUrl, true);
|
|
|
628 |
xhttp.setRequestHeader("X-Proxy-Url", configOauthTokenUrl);
|
87 |
- |
629 |
xhttp.setRequestHeader('X-Authorization', 'Basic XxXAuthorization');
|
6 |
- |
630 |
xhttp.setRequestHeader('X-DECODE-PARAMS', '1');
|
3 |
- |
631 |
xhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
632 |
xhttp.send(param);
|
|
|
633 |
}
|
2 |
- |
634 |
</script>
|
17 |
- |
635 |
<script>includeHTML();</script>
|
2 |
- |
636 |
|
|
|
637 |
</body>
|
|
|
638 |
</html>
|