-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathsettlement_batch_summary_gateway.js
45 lines (36 loc) · 1.39 KB
/
settlement_batch_summary_gateway.js
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
'use strict';
let Gateway = require('./gateway').Gateway;
let Util = require('./util').Util;
let SettlementBatchSummary = require('./settlement_batch_summary').SettlementBatchSummary;
let wrapPrototype = require('@braintree/wrap-promise').wrapPrototype;
class SettlementBatchSummaryGateway extends Gateway {
constructor(gateway) {
super();
this.gateway = gateway;
this.config = this.gateway.config;
}
generate(criteria) {
return this.gateway.http.post(`${this.config.baseMerchantPath()}/settlement_batch_summary`, {
settlementBatchSummary: criteria
}).then(this.responseHandler(criteria));
}
responseHandler(criteria) {
let handler = this.createResponseHandler('settlementBatchSummary', SettlementBatchSummary);
return (payload) => {
return handler(payload).then((response) => {
return this.underscoreCustomField(criteria, response);
});
};
}
underscoreCustomField(criteria, response) {
if (response.success && 'groupByCustomField' in criteria) {
let camelCustomField = Util.toCamelCase(criteria.groupByCustomField);
for (let record of response.settlementBatchSummary.records) {
record[criteria.groupByCustomField] = record[camelCustomField];
record[camelCustomField] = null;
}
}
return response;
}
}
module.exports = {SettlementBatchSummaryGateway: wrapPrototype(SettlementBatchSummaryGateway)};