-
Notifications
You must be signed in to change notification settings - Fork 38
/
PayIns.js
320 lines (281 loc) · 12.5 KB
/
PayIns.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/**
* @module PayIns
* @desc [MangoPay PayIns API Reference](https://docs.mangopay.com/endpoints/v2.01/payins)
*/
var _ = require('underscore');
var Service = require('../service');
var PayIn = require('../models/PayIn');
var PayInPaymentDetailsBankWire = require('../models/PayInPaymentDetailsBankWire');
var PayInPaymentDetailsCard = require('../models/PayInPaymentDetailsCard');
var PayInPaymentDetailsDirectDebitDirect = require('../models/PayInPaymentDetailsDirectDebitDirect');
var PayInPaymentDetailsDirectDebitWeb = require('../models/PayInPaymentDetailsDirectDebitWeb');
var PayInPaymentDetailsPreAuthorized = require('../models/PayInPaymentDetailsPreAuthorized');
var PayInPaymentDetailsPayPal = require('../models/PayInPaymentDetailsPayPal');
var PayInExecutionDetailsWeb = require('../models/PayInExecutionDetailsWeb');
var PayInExecutionDetailsDirect = require('../models/PayInExecutionDetailsDirect');
var PayInExecutionDetailsBankingAlias = require('../models/PayInExecutionDetailsBankingAlias');
var PayInPaymentDetailsApplePay = require('../models/PayInPaymentDetailsApplePay');
var PayInPaymentDetailsGooglePay = require('../models/PayInPaymentDetailsGooglePay');
var PayInPaymentDetailsMbway = require('../models/PayInPaymentDetailsMbway');
var PayInPaymentDetailsBancontact = require('../models/PayInPaymentDetailsBancontact');
var Refund = require('../models/Refund');
var PayInRecurringRegistration = require('../models/PayInRecurringRegistration');
var PayInPaymentDetailsPayconiq = require('../models/PayInPaymentDetailsPayconiq');
const RecurringPayIn = require('../models/RecurringPayIn');
const PayInPaymentDetailsMultibanco = require("../models/PayInPaymentDetailsMultibanco");
const PayInPaymentDetailsSatispay = require("../models/PayInPaymentDetailsSatispay");
const PayInPaymentDetailsBlik = require("../models/PayInPaymentDetailsBlik");
const PayInPaymentDetailsKlarna = require("../models/PayInPaymentDetailsKlarna");
const PayInPaymentDetailsIdeal = require("../models/PayInPaymentDetailsIdeal");
const PayInPaymentDetailsGiropay = require("../models/PayInPaymentDetailsGiropay");
const PaymentMethodMetadata = require('../models/PaymentMethodMetadata');
var PayIns = Service.extend({
/**
* Create new pay-in
* @param {Object} payIn PayIn object
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
create: function(payIn, callback, options) {
options = this._api._getOptions(callback, options, {
data: payIn,
dataClass: PayIn
});
var paymentKey = this.getPaymentKey(payIn);
var executionKey = this.getExecutionKey(payIn);
return this._api.method('payins_' + paymentKey + '-' + executionKey + '_create', callback, options);
},
/**
* Get recurring pay-in
* @param {number} payInId PayIn identifier
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
getRecurringPayin: function(payInId, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
id: payInId
},
dataClass: PayInRecurringRegistration
});
return this._api.method('payins_recurring_registration_get', callback, options);
},
/**
* Update recurring pay-in
* @param {number} payInId PayIn identifier
* @param {RecurringPayInPut} toUpdate Updater Object
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
updateRecurringPayin: function(payInId, toUpdate, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
id: payInId
},
data: toUpdate,
dataClass: PayInRecurringRegistration
});
return this._api.method('payins_recurring_registration_put', callback, options);
},
/**
* Create Payin Registration
* @param {Object} payIn PayInRecurringRegistration object
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
createRecurringPayment: function(recurringPayin, callback, options) {
options = this._api._getOptions(callback, options, {
data: recurringPayin,
dataClass: PayInRecurringRegistration
});
return this._api.method('payins_recurring_registration', callback, options);
},
/**
*
*/
createRecurringPayInRegistrationCIT: function(payIn, callback, options) {
options = this._api._getOptions(callback, options, {
data: payIn,
dataClass: RecurringPayIn
});
return this._api.method('payins_create_recurring_card_direct', callback, options);
},
/**
*
*/
createRecurringPayInRegistrationMIT: function(payIn, callback, options) {
options = this._api._getOptions(callback, options, {
data: payIn,
dataClass: RecurringPayIn
});
return this._api.method('payins_create_recurring_card_direct', callback, options);
},
/**
* Get pay-in
* @param {number} payInId PayIn identifier
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
get: function(payInId, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
id: payInId
},
dataClass: PayIn
});
return this._api.method('payins_get', callback, options);
},
/**
* Create refund for pay-in object
* @param {number} payInId PayIn identifier
* @param {Object} refund Refund data
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
createRefund: function(payInId, refund, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
id: payInId
},
dataClass: Refund,
data: refund
});
return this._api.method('payins_createrefunds', callback, options);
},
/**
* Gets list of Refunds for a PayIn
* @param {number} payInId PayIn identifier
* @param {function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
getRefunds: function(payInId, callback, options) {
if (options && !options.hasOwnProperty('parameters'))
Object.assign(options, {parameters: {...options}});
options = this._api._getOptions(callback, options, {
path: {
id: payInId
},
dataClass: Refund
});
return this._api.method('refunds_get_for_payin', callback, options);
},
/**
* Create new Card PreAuthorized Deposit PayIn
*/
createCardPreAuthorizedDepositPayIn: function(payIn, callback, options) {
options = this._api._getOptions(callback, options, {
data: payIn,
dataClass: PayIn
});
return this._api.method('payins_create_card_pre_authorized_deposit', callback, options);
},
/**
* Create new PayPal Web pay-in.
* To be used instead of the 'create' method for PayPal PayIns
* @param {Object} payIn PayIn object
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
createPayPal: function(payIn, callback, options) {
options = this._api._getOptions(callback, options, {
data: payIn,
dataClass: PayIn
});
return this._api.method('payins_paypal-web_create_v2', callback, options);
},
/**
* Create new GooglePay Direct pay-in.
* To be used instead of the 'create' method for GooglePay PayIns
* @param {Object} payIn PayIn object
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
createGooglePay: function(payIn, callback, options) {
options = this._api._getOptions(callback, options, {
data: payIn,
dataClass: PayIn
});
return this._api.method('payins_googlepay-direct_create_v2', callback, options);
},
/**
*
* @param metadata POST body which should contain the 'Type' and: 'Bin' (if the type is BIN) or 'Token' (if the type is GOOGLE_PAY)
* @param callback Callback function
* @param options Request options
* @returns PaymentMethodMetadata
*/
getPaymentMethodMetadata: function(metadata, callback, options) {
options = this._api._getOptions(callback, options, {
data: metadata,
dataClass: PaymentMethodMetadata
});
return this._api.method('payment_method_metadata_get', callback, options);
},
/**
* Add tracking information to a PayPal PayIn (add the tracking number and carrier for LineItems shipments.)
*
* Caution – Tracking information cannot be edited
*
* You can’t modify the TrackingNumber, Carrier, or NotifyBuyer once added.
*
* You can only send a unique tracking number once.
*
* @param {string} payInId The ID of the PayIn
* @param {Object} trackingInformation trackingInformation object
* @param {Function} callback Callback function
* @param {Object} options Request options
* @return {Object} Request promise
*/
addPayPalTrackingInformation: function(payInId, trackingInformation, callback, options) {
options = this._api._getOptions(callback, options, {
path: {
payInId: payInId
},
data: trackingInformation,
dataClass: PayIn
});
return this._api.method('add_tracking_info', callback, options);
},
getPaymentKey: function(payIn) {
if (payIn.PaymentType) {
return payIn.PaymentType.toLowerCase().replace('_', '');
}
if (payIn.PaymentDetails instanceof PayInPaymentDetailsBankWire) return 'bankwire';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsCard) return 'card';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsDirectDebitDirect) return 'directdebit';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsDirectDebitWeb) return 'directdebit';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsPreAuthorized) return 'preauthorized';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsPayPal) return 'paypal';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsApplePay) return 'applepay';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsGooglePay) return 'googlepay';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsPayconiq) return 'payconiq';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsMbway) return 'mbway';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsBancontact) return 'bcmc';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsMultibanco) return 'multibanco';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsSatispay) return 'satispay';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsBlik) return 'blik';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsKlarna) return 'klarna';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsIdeal) return 'ideal';
if (payIn.PaymentDetails instanceof PayInPaymentDetailsGiropay) return 'giropay';
throw new Error('PayIn needs a PaymentType');
},
getExecutionKey: function(payIn) {
if (payIn.ExecutionType) {
return payIn.ExecutionType.toLowerCase();
}
if (payIn.ExecutionDetails instanceof PayInExecutionDetailsWeb) return 'web';
if (payIn.ExecutionDetails instanceof PayInExecutionDetailsDirect) return 'direct';
if (payIn.ExecutionDetails instanceof PayInExecutionDetailsBankingAlias) return 'bankingalias';
throw new Error('PayIn needs a ExecutionType');
}
});
module.exports = PayIns;