57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
module.exports = Self => {
|
|
Self.remoteMethodCtx('confirmTransaction', {
|
|
description: 'Confirm a web payment',
|
|
accessType: 'WRITE',
|
|
accepts: [{
|
|
arg: 'id',
|
|
type: 'number',
|
|
required: true,
|
|
description: 'Transaction id'
|
|
}],
|
|
returns: {
|
|
type: 'Object',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/confirmTransaction`,
|
|
verb: 'POST'
|
|
}
|
|
});
|
|
|
|
Self.confirmTransaction = async(ctx, id) => {
|
|
let userId = ctx.req.accessToken.userId;
|
|
let tx = await Self.beginTransaction({});
|
|
|
|
try {
|
|
let options = {transaction: tx};
|
|
|
|
let oldTpvTransaction = await Self.app.models.TpvTransaction.findById(id, null, options);
|
|
|
|
let confirm = await Self.rawSql('CALL hedera.tpvTransaction_confirmById(?)', [id], options);
|
|
|
|
let tpvTransaction = await Self.app.models.TpvTransaction.findById(id, null, options);
|
|
|
|
let oldInstance = {status: oldTpvTransaction.status};
|
|
let newInstance = {status: tpvTransaction.status};
|
|
|
|
let logRecord = {
|
|
originFk: tpvTransaction.clientFk,
|
|
userFk: userId,
|
|
action: 'update',
|
|
changedModel: 'TpvTransaction',
|
|
changedModelId: id,
|
|
oldInstance: oldInstance,
|
|
newInstance: newInstance
|
|
};
|
|
|
|
await Self.app.models.ClientLog.create(logRecord, options);
|
|
|
|
await tx.commit();
|
|
return confirm;
|
|
} catch (e) {
|
|
await tx.rollback();
|
|
throw e;
|
|
}
|
|
};
|
|
};
|