-
Notifications
You must be signed in to change notification settings - Fork 41
/
PayOuts.js
110 lines (93 loc) · 3.45 KB
/
PayOuts.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @module PayOuts
* @desc [MangoPay PayOuts API Reference](https://docs.mangopay.com/endpoints/v2.01/payouts)
*/
var Service = require('../service');
var PayOut = require('../models/PayOut');
var PayOutPaymentDetailsBankWire = require('../models/PayOutPaymentDetailsBankWire');
var Refund = require('../models/Refund');
var PayOuts = Service.extend({
/**
* Create new pay-out
* @param {Object} payOut PayOut object
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
create: function(payOut, callback, options) {
options = this._api._getOptions(callback, options, {
data: payOut,
dataClass: PayOut
});
var paymentKey = this.getPaymentKey(payOut);
return this._api.method('payouts_' + paymentKey + '_create', callback, options);
},
/**
* Get payout
* @param {number} payOutId PayOut identifiers
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
get: function(payOutId, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
id: payOutId
},
dataClass: PayOut
});
return this._api.method('payouts_get', callback, options);
},
/**
* Get payout
* @param {number} payOutId PayOut identifiers
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
getBankwire: function(payOutId, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
id: payOutId
},
dataClass: PayOut
});
return this._api.method('payouts_bankwire_get', callback, options);
},
/**
* Gets list of Refunds of a PayOut
* @param {number} payOutId PayOut identifier
* @param {function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
getRefunds: function(payOutId, callback, options) {
if (options && !options.hasOwnProperty('parameters'))
Object.assign(options, {parameters: {...options}});
options = this._api._getOptions(callback, options, {
path: {
id: payOutId
},
dataClass: Refund
});
return this._api.method("refunds_get_for_payout", callback, options);
},
getPaymentKey: function(payOut) {
if (!payOut.MeanOfPaymentDetails && !payOut.PaymentType) {
this._api.errorHandler('Create Payout needs MeanOfPaymentDetails or PaymentType');
}
// Payment Type can be BANK_WIRE, etc.
if (payOut.PaymentType) {
return payOut.PaymentType.toLowerCase().replace('_', '');
}
if (payOut.MeanOfPaymentDetails instanceof PayOutPaymentDetailsBankWire) return 'bankwire';
},
checkEligibility: function(payOut, callback, options) {
options = this._api._getOptions(callback, options, {
data: payOut,
dataClass: PayOut
});
return this._api.method('payouts_check_eligibility', callback, options);
},
});
module.exports = PayOuts;