-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
102 lines (92 loc) · 3 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const express = require('express')
const fetch = require('node-fetch');
const jsonxml = require('jsontoxml');
const soap = require('soap');
const bodyparser = require('body-parser')
const app = express()
const port = 3000
const key = 'kevinfan-Ebae-SBX-916e2f149-9ba29d82'
const secret = 'SBX-16e2f14953db-e3ee-44b4-a44f-6fa2'
let token = ''
app.use("/", express.static(__dirname));
function oauth(){
console.log("hello");
const url = "https://api.ebay.com/identity/v1/oauth2/token"
fetch(url, {
method: "POST",
headers: {
'Authorization': "Basic S2V2aW5GYW4tRWJhZS1QUkQtOTE2ZGU1NmRjLWExMjk5YmZmOlBSRC0xNmRlNTZkYzMzOGItYWIwNy00ZjAzLWI2OGEtM2UyNw==",
"Content-Type": "application/x-www-form-urlencoded",
},
body: "grant_type=client_credentials&scope=https%3A%2F%2Fapi.ebay.com%2Foauth%2Fapi_scope",
}).then((response) => {
return response.json()
}).then((data) => {
token = data['access_token']
}).catch(err => {
console.log(err)
})
}
app.get('/', function(req, res) {
res.sendFile(path.join(public, 'index.html'));
})
app.get('/auth', function(req, res){
data = oauth()
return data
})
app.post('/sell', function(req, res){
console.log(req.params, req.query, req.body.location)
template = `
<?xml version="1.0" encoding="utf-8"?>
<AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>` + token + `
</eBayAuthToken>
</RequesterCredentials>
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<Item>
<Title>` + name + `</Title>
<Description> at
`
+ location + ". come here and learn about " + info +
`
</Description>
<PrimaryCategory>
<CategoryID>377</CategoryID>
</PrimaryCategory>
<StartPrice>` + price + `</StartPrice>
<CategoryMappingAllowed>true</CategoryMappingAllowed>
<ConditionID></ConditionID>
<Country>US</Country>
<Currency>USD</Currency>
<DispatchTimeMax>3</DispatchTimeMax>
<ListingDuration>Days_7</ListingDuration>
<ListingType>Chinese</ListingType>
<PaymentMethods>PayPal</PaymentMethods>
<PayPalEmailAddress>[email protected]</PayPalEmailAddress>
<PictureDetails>
<PictureURL>https://mypicserver.com/myphoto.jpg</PictureURL>
</PictureDetails>
<PostalCode>95125</PostalCode>
<Quantity>1</Quantity>
<ReturnPolicy>
<ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<RefundOption>MoneyBack</RefundOption>
<ReturnsWithinOption>Days_30</ReturnsWithinOption>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
</ReturnPolicy>
<ShippingDetails>
<ShippingType>Flat</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>
<ShippingService>USPSMedia</ShippingService>
<ShippingServiceCost>2.50</ShippingServiceCost>
</ShippingServiceOptions>
</ShippingDetails>
<Site>US</Site>
</Item>
</AddItemRequest>
`
})
app.listen(port, () => console.log(port))