-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathpayment_method_nonce_gateway.js
36 lines (29 loc) · 1.19 KB
/
payment_method_nonce_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
'use strict';
let Gateway = require('./gateway').Gateway;
let PaymentMethodNonce = require('./payment_method_nonce').PaymentMethodNonce;
let wrapPrototype = require('@braintree/wrap-promise').wrapPrototype;
class PaymentMethodNonceGateway extends Gateway {
constructor(gateway) {
super();
this.gateway = gateway;
this.config = this.gateway.config;
}
responseHandler() {
let handler = this.createResponseHandler('payment_method_nonce', PaymentMethodNonce);
return function (payload) {
return handler(payload).then((response) => {
response.paymentMethodNonce = new PaymentMethodNonce(response.paymentMethodNonce);
return response;
});
};
}
create(paymentMethodToken) {
return this.gateway.http.post(`${this.config.baseMerchantPath()}/payment_methods/${paymentMethodToken}/nonces`, {}).then(this.responseHandler());
}
find(paymentMethodNonce) {
return this.gateway.http.get(`${this.config.baseMerchantPath()}/payment_method_nonces/${paymentMethodNonce}`).then((response) => {
return new PaymentMethodNonce(response.paymentMethodNonce);
});
}
}
module.exports = {PaymentMethodNonceGateway: wrapPrototype(PaymentMethodNonceGateway)};