salix/modules/client/back/methods/client/confirmTransaction.js

43 lines
1.1 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, options) => {
let tx;
const myOptions = {userId: ctx.req.accessToken.userId};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const confirm = await Self.rawSql('CALL hedera.tpvTransaction_confirmById(?)', [id], myOptions);
if (tx) await tx.commit();
return confirm;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};