-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathtesting_gateway.js
43 lines (34 loc) · 1.38 KB
/
testing_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
'use strict';
let Gateway = require('./gateway').Gateway;
let Environment = require('./environment').Environment;
let exceptions = require('./exceptions');
let wrapPrototype = require('@braintree/wrap-promise').wrapPrototype;
class TestingGateway extends Gateway {
constructor(gateway) {
super();
this.gateway = gateway;
this.config = this.gateway.config;
}
settle(transactionId) {
return this.settlementOperationWithEnvironmentCheck(transactionId, 'settle');
}
settlementPending(transactionId) {
return this.settlementOperationWithEnvironmentCheck(transactionId, 'settlement_pending');
}
settlementConfirm(transactionId) {
return this.settlementOperationWithEnvironmentCheck(transactionId, 'settlement_confirm');
}
settlementDecline(transactionId) {
return this.settlementOperationWithEnvironmentCheck(transactionId, 'settlement_decline');
}
settlementOperationWithEnvironmentCheck(transactionId, operation) {
if (this.config.environment === Environment.Production) {
return Promise.reject(exceptions.TestOperationPerformedInProductionError('Test operation performed in production'), null); // eslint-disable-line new-cap
}
return this.gateway.http.put(
`${this.config.baseMerchantPath()}/transactions/${transactionId}/${operation}`,
null
);
}
}
module.exports = {TestingGateway: wrapPrototype(TestingGateway)};