-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateTransaction.js
More file actions
78 lines (62 loc) · 2.63 KB
/
validateTransaction.js
File metadata and controls
78 lines (62 loc) · 2.63 KB
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
69
70
71
72
73
74
75
76
77
78
var validator = require('validator');
var ValPaymentObj = require('./validatePayment');
function ValTransactionObj() {
this.validator = validator;
this.payload = {};
this.message = {};
this.payments = {};
this.isValid = true;
}
ValTransactionObj.prototype.valTransactionID = function() {
if (!this.validator.isAlphanumeric(this.payload.transactionID)) {
this.message.transactionID = 'Invalid transaction ID';
this.isValid = false; } };
ValTransactionObj.prototype.valInternalID = function() {
if (!this.validator.isAlphanumeric(this.payload.internalID)) {
this.message.internalID = 'Invalid internal ID';
this.isValid = false; } };
ValTransactionObj.prototype.valDate = function() {
if (!this.validator.isDate(this.payload.dateTime)) {
this.message.dateTime = 'Invalid Date/Time';
this.isValid = false; } };
ValTransactionObj.prototype.valTransPayments = function() {
var messages = [];
var valid = [];
this.payments.forEach(function (payment) {
var valPayment = new ValPaymentObj();
var eachPayment = valPayment.valPayment(payment);
if (Object.keys(eachPayment.message).length > 0) {
messages = eachPayment.message; }
valid.push(eachPayment.isValid); });
this.message.payments = messages;
if (valid.indexOf(false) > -1){ this.isValid = false; } };
ValTransactionObj.prototype.valTransaction = function(transaction) {
this.payload = transaction;
this.payments = transaction.transactionPayments;
this.valTransactionID();
this.valDate();
this.valInternalID();
this.valTransPayments();
//this.valTax();
//this.valMerchantID();
//this.valTerminalID();
//this.valCashierID();
return this;
};
module.exports = ValTransactionObj;
//ValTransactionObj.prototype.valMerchantID = function() {
// if (!this.validator.isAlphanumeric(this.payload.merchantID)) {
// this.message.merchantID = 'Invalid merchant ID';
// this.isValid = false; } };
//ValTransactionObj.prototype.valTerminalID = function() {
// if (!this.validator.isAlphanumeric(this.payload.terminalID)) {
// this.message.terminalID = 'Invalid terminal ID';
// this.isValid = false; } };
//ValTransactionObj.prototype.valCashierID = function() {
// if (!this.validator.isAlphanumeric(this.payload.cashierID)) {
// this.message.cashierID = 'Invalid cashier ID';
// this.isValid = false; } };
//ValTransactionObj.prototype.valTax = function() {
// if (!this.validator.isCurrency(this.payload.taxes)) {
// this.message.taxes = 'Invalid tax amount';
// this.isValid = false; } };