-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshopier.js
108 lines (93 loc) · 2.73 KB
/
shopier.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
103
104
105
106
107
108
const shopier = require('@api/shopier');
const conf = {
pat: 'SHOPIER_PAT_TOKEN',
username: 'SHOPIER_USERNAME',
key: 'SHOPIER_KEY'
};
shopier.auth(conf.pat);
shopier.postProducts({
type: 'digital',
priceData: {
currency: 'TRY', // USD, EUR, TRY
price: '1'
},
shippingPayer: 'sellerPays',
title: 'Add Balance',
media: [
{
type: 'image',
placement: 1,
url: 'https://cdn.iconscout.com/icon/free/png-256/free-add-money-icon-download-in-svg-png-gif-file-formats--to-wallet-e-pack-commerce-shopping-icons-1538068.png'
}
],
stockQuantity: 1,
description: 'Add balance to your account',
})
.then(({ data }) => console.log(data))
.catch(err => console.error(err));
shopier.deleteProductsId({id: '31850041'})
.then(({ data }) => console.log(data))
.catch(err => console.error(err));
const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const app = express();
app.use(require('multer')().none());
const username = conf.username;
const key = conf.key;
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/shopierWebhook', (req, res) => {
if (!(req.body.res && req.body.hash)) {
return res.status(400).send('missing parameter');
}
const calculatedHash = crypto
.createHmac('sha256', key)
.update(req.body.res + username)
.digest('hex');
if (calculatedHash !== req.body.hash) {
return res.status(401).end();
}
try {
const jsonResult = Buffer.from(req.body.res, 'base64').toString();
const data = JSON.parse(jsonResult);
console.log('Received data:', data);
const {
email,
orderid,
currency, // 0..TL, 1..USD, 2...EUR
price,
buyername,
buyersurname,
productcount,
productid,
productlist,
chartdetails,
customernote, // Müşteri notu
istest // 0..canlı, 1..test
} = data;
/*
Received data: {
email: 'fastuptime@gmail.com',
orderid: '313758163',
currency: 0,
price: '1',
buyername: 'Can',
buyersurname: 'Kaya',
productid: 31857020,
productcount: 1,
customernote: '',
productlist: '31857020',
chartdetails: [ { id: 31857020, quantity: 1 } ],
istest: 1
}
*/
res.send('success');
} catch (error) {
console.error('Error processing request:', error);
res.status(500).send('error');
}
});
const PORT = 80;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});