-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathmerchant_gateway.js
35 lines (29 loc) · 1.04 KB
/
merchant_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
'use strict';
let Gateway = require('./gateway').Gateway;
let Merchant = require('./merchant').Merchant;
let OAuthCredentials = require('./oauth_credentials').OAuthCredentials;
let wrapPrototype = require('@braintree/wrap-promise').wrapPrototype;
class MerchantGateway extends Gateway {
constructor(gateway) {
super();
this.gateway = gateway;
this.config = this.gateway.config;
}
create(attributes) {
return this.gateway.http.post('/merchants/create_via_api', {merchant: attributes}).then(this.responseHandler());
}
responseHandler() {
let handler = this.createResponseHandler(null, null);
return function (payload) {
return handler(payload).then((response) => {
if (response.success) {
response.merchant = new Merchant(response.response.merchant);
response.credentials = new OAuthCredentials(response.response.credentials);
delete response.response;
}
return response;
});
};
}
}
module.exports = {MerchantGateway: wrapPrototype(MerchantGateway)};