-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaypal.js
68 lines (63 loc) · 2.08 KB
/
paypal.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
const settings = require("../settings.json");
const fs = require('fs');
const indexjs = require("../index.js");
const fetch = require('node-fetch');
var validators = require('credit-card-validate');
const paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox', // Replace with 'live' for production
'client_id': settings.paypal.client_id,
'client_secret': settings.paypal.client_secret
});
module.exports.load = async function(app, db) {
app.get("/paypal", async(req, res) => {
if(!req.session.pterodactyl) return res.redirect("/paypal?error=invalidinfo")
let payment = {
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [{
"credit_card": {
"number": `${req.query.number}`,
"type": req.cardType,
"expire_month": +req.query.month,
"expire_year": +req.query.year,
"cvv2": req.query.vrf
}
}]
},
"transactions": [{
"amount": {
"total": req.query.amt * settings.paypal.amount,
"currency": "GBP"
},
"description": "Transaction: " + settings.paypal.coins * req.query.amt
}]
};
paypal.payment.create(payment, async function (error, payment) {
if (error) {
return res.redirect("/paypal?error=invalid")
} else {
const execute_payment_json = {
"payer_id": payment.payer.payer_info.payer_id,
"transactions": [{
"amount": {
"currency": "GBP",
"total": req.query.amt * settings.paypal.amount
}
}]
};
paypal.payment.execute(payment.id, execute_payment_json, async function (error, payment) {
if (error) {
console.log(error.response);
throw error;
} else {
let ccoins = await db.get(`coins-${req.session.userinfo.id}`)
ccoins += settings.paypal.coins * req.query.amt;
await db.set(`coins-${req.session.userinfo.id}`, coins)
}
});
}
});
});
};