-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (58 loc) · 2.98 KB
/
index.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
const axios = require('axios');
const form = require('form-data');
const crypto = require('crypto');
const buffer = require('buffer');
function createPaymentLink(data, callback) {
if(!data.userName) throw new Error('userName is required');
if(!data.referer) throw new Error('referer is required');
if(!data.hash) throw new Error('hash is required Api Hash Anahtarı');
if(!data.password) throw new Error('password is required');
if(!data.shopCode) throw new Error('shopCode is required');
if(!data.productName) throw new Error('productName is required');
if(!data.productData) throw new Error('productData is required');
if(!data.productType) throw new Error('productType is required');
if(!data.productsTotalPrice) throw new Error('productsTotalPrice is required');
if(!data.orderPrice) throw new Error('orderPrice is required');
if(!data.currency) throw new Error('currency is required');
if(!data.orderId) throw new Error('orderId is required');
if(!data.locale) throw new Error('locale is required');
if(!data.conversationId) throw new Error('conversationId is required');
if(!data.buyerName) throw new Error('buyerName is required');
if(!data.buyerSurName) throw new Error('buyerSurName is required');
if(!data.buyerGsmNo) throw new Error('buyerGsmNo is required');
if(!data.buyerMail) throw new Error('buyerMail is required');
if(!data.buyerIp) throw new Error('buyerIp is required');
if(!data.buyerAdress) throw new Error('buyerAdress is required');
if(!data.BuyerCountry) throw new Error('BuyerCountry is required');
if(!data.BuyerCity) throw new Error('BuyerCity is required');
if(!data.buyerDistrict) throw new Error('buyerDistrict is required');
if(!data.callbackOkUrl) throw new Error('callbackOkUrl is required');
if(!data.callbackFailUrl) throw new Error('callbackFailUrl is required');
const userName = data.userName;
const password = data.password;
const shopCode = data.shopCode;
const string = data.orderId + data.currency + data.orderPrice + data.productsTotalPrice + data.productType + data.callbackOkUrl + data.callbackFailUrl;
const hash = data.hash;
const sha1Hash = crypto.createHash('sha1').update(userName + password + shopCode + string + hash).digest('hex');
const packedHash = buffer.Buffer.from(sha1Hash, 'hex');
const base64EncodedHash = packedHash.toString('base64');
data.hash = base64EncodedHash;
const formdata = new form();
for (const key in data) {
formdata.append(key, data[key]);
}
axios({
method: 'post',
url: 'https://apiv1.paymax.com.tr/api/create-payment-link',
data: formdata,
headers: {
'Content-Type': 'multipart/form-data',
'Referer': data.referer,
}
}).then((response) => {
callback(response.data);
}).catch((error) => {
callback(error);
});
}
module.exports = { createPaymentLink };