@@ -88,32 +88,48 @@ app.post('/transactions', async (req, res) => {
88
88
response . startingBalance = balance ; // could be named differently in this use case.
89
89
90
90
let allTransactions = [ ] ;
91
+ let bookedTransactions = [ ] ;
92
+ let pendingTransactions = [ ] ;
91
93
92
94
for ( let trans of account . transactions ) {
93
95
let newTrans = { } ;
94
96
95
- //newTrans.bankTransactionCode = don't have compared to GoCardless
96
- newTrans . booked = true ;
97
- newTrans . bookingDate = new Date ( trans . posted * 1000 )
97
+ let dateToUse = 0 ;
98
+
99
+ if ( trans . posted == 0 ) {
100
+ newTrans . booked = false ;
101
+ dateToUse = trans . transacted_at ;
102
+ } else {
103
+ newTrans . booked = true ;
104
+ dateToUse = trans . posted ;
105
+ }
106
+
107
+ newTrans . bookingDate = new Date ( dateToUse * 1000 )
98
108
. toISOString ( )
99
109
. split ( 'T' ) [ 0 ] ;
100
- newTrans . date = new Date ( trans . posted * 1000 ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
110
+
111
+ newTrans . date = new Date ( dateToUse * 1000 ) . toISOString ( ) . split ( 'T' ) [ 0 ] ;
101
112
newTrans . debtorName = trans . payee ;
102
113
//newTrans.debtorAccount = don't have compared to GoCardless
103
114
newTrans . remittanceInformationUnstructured = trans . description ;
104
115
newTrans . transactionAmount = { amount : trans . amount , currency : 'USD' } ;
105
116
newTrans . transactionId = trans . id ;
106
- newTrans . valueDate = new Date ( trans . posted * 1000 )
117
+ newTrans . valueDate = new Date ( dateToUse * 1000 )
107
118
. toISOString ( )
108
119
. split ( 'T' ) [ 0 ] ;
109
120
121
+ if ( newTrans . booked ) {
122
+ bookedTransactions . push ( newTrans ) ;
123
+ } else {
124
+ pendingTransactions . push ( newTrans ) ;
125
+ }
110
126
allTransactions . push ( newTrans ) ;
111
127
}
112
128
113
129
response . transactions = {
114
130
all : allTransactions ,
115
- booked : allTransactions ,
116
- pending : [ ] ,
131
+ booked : bookedTransactions ,
132
+ pending : pendingTransactions ,
117
133
} ;
118
134
119
135
res . send ( {
@@ -202,6 +218,9 @@ async function getAccounts(accessKey, startDate, endDate) {
202
218
if ( endDate ) {
203
219
params . push ( `end-date=${ normalizeDate ( endDate ) } ` ) ;
204
220
}
221
+
222
+ params . push ( `pending=1` ) ;
223
+
205
224
if ( params . length > 0 ) {
206
225
queryString += '?' + params . join ( '&' ) ;
207
226
}
0 commit comments