-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvalidate.js
48 lines (44 loc) · 1.12 KB
/
validate.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
const fetch = require('node-fetch');
const senders = [
"www.payfast.co.za",
"w1w.payfast.co.za",
"w2w.payfast.co.za",
"sandbox.payfast.co.za",
"https://www.payfast.co.za"
];
const FormParams = require('url').URLSearchParams;
exports.sender = async (referer) => {
if (senders.includes(referer)) {
return {
'valid': true
};
} else {
return {
'valid': false
};
};
};
exports.request = async (payload) => {
const form = new FormParams();
Object.keys(payload).sort().map(key => {
form.append(key, payload[key]);
});
const response = await fetch('https://www.payfast.co.za/eng/query/validate', {
'headers': {
'accept': '*/*',
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
},
'body': form,
'method': "POST"
});
const result = await response.text();
if (result == 'VALID') {
return await {
'valid': true
};
} else {
return await {
'valid': false
};
};
};