Implement payment checks in API

This commit is contained in:
Rene Vergara 2022-01-25 15:20:01 -06:00
parent d8380ec33f
commit 323ffcc50b

View file

@ -155,16 +155,16 @@ var blockInterval = setInterval( function() {
if (pay.test(memo) && txData.confirmations < 100) { if (pay.test(memo) && txData.confirmations < 100) {
var match2 = pay.exec(memo); var match2 = pay.exec(memo);
if (match2 != null) { if (match2 != null) {
var session = match[1]; var session = match2[1];
} }
if (txData.amount >= 0.001 && txData.amount < 0.005){ if (txData.amount >= 0.001 && txData.amount < 0.005){
exptime = blocktime + 3600; exptime = txData.blocktime + 3600;
} else if (txData.amount >= 0.005 && txData.amount < 0.025){ } else if (txData.amount >= 0.005 && txData.amount < 0.025){
exptime = blocktime + 24*3600; exptime = txData.blocktime + 24*3600;
} else if (txData.amount >= 0.025 && txData.amount < 0.1) { } else if (txData.amount >= 0.025 && txData.amount < 0.1) {
exptime = blocktime + 7*24*3600; exptime = txData.blocktime + 7*24*3600;
} else if (txData.mount >= 0.1) { } else if (txData.mount >= 0.1) {
exptime = blocktime + 4*7*24*3600; exptime = txData.blocktime + 4*7*24*3600;
} }
usermodel.findOne({session: session}).then(function(doc){ usermodel.findOne({session: session}).then(function(doc){
@ -182,9 +182,9 @@ var blockInterval = setInterval( function() {
payment.save(function(error) { payment.save(function(error) {
if (error) { if (error) {
console.log(error); console.log(error);
} } else {
console.log('Payment saved'); console.log('Payment saved');
}
}); });
} }
}); });
@ -201,6 +201,32 @@ var blockInterval = setInterval( function() {
}); });
}, 75000); }, 75000);
var payCheck = setInterval( function() {
ownermodel.find({}).then((documents) => {
if(documents.length > 0){
//console.log(documents);
async.each (documents, function(document, callback) {
paymentmodel.findOne({ address: document.address, expiration: {$gt: Date.now()}}).then(payment => {
if (payment != null){
document.paid = true;
document.save();
} else {
document.paid = false;
document.save();
}
});
}, function (err) {
if (err) {
console.log(err);
} else {
console.log("Owners checked for payment");
}
});
}
});
}, 60000);
app.use(cors()); app.use(cors());
app.options('*', cors()); app.options('*', cors());