WIP
This commit is contained in:
parent
11b5958c60
commit
e7960c217c
3 changed files with 21 additions and 4 deletions
|
|
@ -759,4 +759,6 @@ exports.fetchTx = function fetchTx (session, status) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchTx = function fetchTx (session, status) {
|
exports.requestDispense = function requestDispense (session, tx) {
|
||||||
|
return db.addDispenseRequest(session.fingerprint, tx)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -530,6 +530,22 @@ exports.fetchTx = function fetchTx (session, cb) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.addDispenseRequest = function addDispenseRequest (session, tx, cb) {
|
||||||
|
connect(function (cerr, client, done) {
|
||||||
|
if (cerr) return
|
||||||
|
|
||||||
|
const originalSession = {id: tx.sessionId, fingerprint: session.fingerprint}
|
||||||
|
async.waterfall([
|
||||||
|
async.apply(updateDispense, client, true),
|
||||||
|
async.apply(insertIncoming, client, originalSession, tx, 0, tx.fiat,
|
||||||
|
'dispense', 'pending')
|
||||||
|
], function (err) {
|
||||||
|
done()
|
||||||
|
if (err) logger.error(err)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function updateDispense (client, session, dispensed, cb) {
|
function updateDispense (client, session, dispensed, cb) {
|
||||||
var sql = 'UPDATE transactions SET dispense=$1 ' +
|
var sql = 'UPDATE transactions SET dispense=$1 ' +
|
||||||
'WHERE stage=$2 AND authority=$3 AND device_fingerprint=$4 AND session_id=$5'
|
'WHERE stage=$2 AND authority=$3 AND device_fingerprint=$4 AND session_id=$5'
|
||||||
|
|
@ -557,7 +573,6 @@ exports.addDispense = function addDispense (session, tx, cartridges) {
|
||||||
if (cerr) return
|
if (cerr) return
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(updateDispense, client, true),
|
|
||||||
async.apply(insertIncoming, client, session, tx, 0, tx.fiat,
|
async.apply(insertIncoming, client, session, tx, 0, tx.fiat,
|
||||||
'dispense', 'authorized'),
|
'dispense', 'authorized'),
|
||||||
async.apply(insertDispense, client, session, tx, cartridges)
|
async.apply(insertDispense, client, session, tx, cartridges)
|
||||||
|
|
|
||||||
|
|
@ -256,8 +256,8 @@ function waitForDispense (req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispense (req, res) {
|
function dispense (req, res) {
|
||||||
const originalSessionId = req.query['original-session-id']
|
const tx = req.body.tx
|
||||||
return plugins.addDispense(session(req).fingerprint, originalSessionId)
|
return plugins.requestDispense(session(req), tx)
|
||||||
.then(() => res.send(200))
|
.then(() => res.send(200))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue