mangopay4-python-sdk 4.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mangopay/utils.py ADDED
@@ -0,0 +1,1885 @@
1
+ # see: http://hustoknow.blogspot.com/2011/01/m2crypto-and-facebook-python-sdk.html
2
+ from __future__ import unicode_literals
3
+
4
+ import copy
5
+ import datetime
6
+ import decimal
7
+ import inspect
8
+ import sys
9
+ from calendar import timegm
10
+ from functools import wraps
11
+
12
+ import pytz
13
+ import six
14
+
15
+ from .compat import python_2_unicode_compatible
16
+ from .exceptions import CurrencyMismatch
17
+
18
+ if six.PY3:
19
+ from urllib import request
20
+
21
+ orig = request.URLopener.open_https
22
+ request.URLopener.open_https = orig # uncomment this line back and forth
23
+ elif six.PY2:
24
+ import urllib
25
+
26
+ orig = urllib.URLopener.open_https
27
+ urllib.URLopener.open_https = orig
28
+
29
+
30
+ class AliasProperty(object):
31
+ def __init__(self, name):
32
+ self.name = name
33
+
34
+ def __get__(self, instance, owner):
35
+ return getattr(instance, self.name)
36
+
37
+ def __set__(self, instance, value):
38
+ return setattr(instance, self.name, value)
39
+
40
+
41
+ def add_camelcase_aliases(cls):
42
+ for name in cls().__dict__.keys():
43
+ if name[0] == '_':
44
+ continue
45
+ setattr(cls, name.title().replace('_', ''), AliasProperty(name))
46
+ return cls
47
+
48
+
49
+ @add_camelcase_aliases
50
+ @python_2_unicode_compatible
51
+ class Money(object):
52
+ __hash__ = None
53
+
54
+ def __init__(self, amount="0", currency=None):
55
+ try:
56
+ if amount is not None:
57
+ self.amount = decimal.Decimal(amount)
58
+ else:
59
+ self.amount = None
60
+ except decimal.InvalidOperation:
61
+ raise ValueError("amount value could not be converted to "
62
+ "Decimal(): '{}'".format(amount))
63
+ self.currency = currency
64
+
65
+ def __repr__(self):
66
+ return "{} {}".format(self.currency, self.amount)
67
+
68
+ def __str__(self):
69
+ return force_text("{} {:,.2f}".format(self.currency, self.amount))
70
+
71
+ def __lt__(self, other):
72
+ if isinstance(other, Money):
73
+ if other.currency != self.currency:
74
+ raise CurrencyMismatch(self.currency, other.currency, '<')
75
+ other = other.amount
76
+ return self.amount < other
77
+
78
+ def __le__(self, other):
79
+ if isinstance(other, Money):
80
+ if other.currency != self.currency:
81
+ raise CurrencyMismatch(self.currency, other.currency, '<=')
82
+ other = other.amount
83
+ return self.amount <= other
84
+
85
+ def __eq__(self, other):
86
+ if isinstance(other, Money):
87
+ return ((self.amount == other.amount) and
88
+ (self.currency == other.currency))
89
+ return False
90
+
91
+ def __ne__(self, other):
92
+ return not self == other
93
+
94
+ def __gt__(self, other):
95
+ if isinstance(other, Money):
96
+ if other.currency != self.currency:
97
+ raise CurrencyMismatch(self.currency, other.currency, '>')
98
+ other = other.amount
99
+ return self.amount > other
100
+
101
+ def __ge__(self, other):
102
+ if isinstance(other, Money):
103
+ if other.currency != self.currency:
104
+ raise CurrencyMismatch(self.currency, other.currency, '>=')
105
+ other = other.amount
106
+ return self.amount >= other
107
+
108
+ def __bool__(self):
109
+ return bool(self.amount)
110
+
111
+ def __add__(self, other):
112
+ if isinstance(other, Money):
113
+ if other.currency != self.currency:
114
+ raise CurrencyMismatch(self.currency, other.currency, '+')
115
+ other = other.amount
116
+ amount = self.amount + other
117
+ return self.__class__(amount, self.currency)
118
+
119
+ def __radd__(self, other):
120
+ return self.__add__(other)
121
+
122
+ def __sub__(self, other):
123
+ if isinstance(other, Money):
124
+ if other.currency != self.currency:
125
+ raise CurrencyMismatch(self.currency, other.currency, '-')
126
+ other = other.amount
127
+ amount = self.amount - other
128
+ return self.__class__(amount, self.currency)
129
+
130
+ def __rsub__(self, other):
131
+ return (-self).__add__(other)
132
+
133
+ def __mul__(self, other):
134
+ if isinstance(other, Money):
135
+ raise TypeError("multiplication is unsupported between "
136
+ "two money objects")
137
+ amount = self.amount * other
138
+ return self.__class__(amount, self.currency)
139
+
140
+ def __rmul__(self, other):
141
+ return self.__mul__(other)
142
+
143
+ def __truediv__(self, other):
144
+ if isinstance(other, Money):
145
+ if other.currency != self.currency:
146
+ raise CurrencyMismatch(self.currency, other.currency, '/')
147
+
148
+ if other.amount == 0:
149
+ raise ZeroDivisionError()
150
+
151
+ return self.amount / other.amount
152
+
153
+ if other == 0:
154
+ raise ZeroDivisionError()
155
+
156
+ amount = self.amount / other
157
+
158
+ return self.__class__(amount, self.currency)
159
+
160
+ def __floordiv__(self, other):
161
+ if isinstance(other, Money):
162
+ if other.currency != self.currency:
163
+ raise CurrencyMismatch(self.currency, other.currency, '//')
164
+
165
+ if other.amount == 0:
166
+ raise ZeroDivisionError()
167
+ return self.amount // other.amount
168
+
169
+ if other == 0:
170
+ raise ZeroDivisionError()
171
+
172
+ amount = self.amount // other
173
+ return self.__class__(amount, self.currency)
174
+
175
+ def __mod__(self, other):
176
+ if isinstance(other, Money):
177
+ raise TypeError("modulo is unsupported between two '{}' "
178
+ "objects".format(self.__class__.__name__))
179
+ if other == 0:
180
+ raise ZeroDivisionError()
181
+
182
+ amount = self.amount % other
183
+ return self.__class__(amount, self.currency)
184
+
185
+ def __divmod__(self, other):
186
+ if isinstance(other, Money):
187
+ if other.currency != self.currency:
188
+ raise CurrencyMismatch(self.currency, other.currency, 'divmod')
189
+
190
+ if other.amount == 0:
191
+ raise ZeroDivisionError()
192
+
193
+ return divmod(self.amount, other.amount)
194
+
195
+ if other == 0:
196
+ raise ZeroDivisionError()
197
+
198
+ whole, remainder = divmod(self.amount, other)
199
+
200
+ return (self.__class__(whole, self.currency),
201
+ self.__class__(remainder, self.currency))
202
+
203
+ def __pow__(self, other):
204
+ if isinstance(other, Money):
205
+ raise TypeError("power operator is unsupported between two '{}' "
206
+ "objects".format(self.__class__.__name__))
207
+ amount = self.amount ** other
208
+ return self.__class__(amount, self.currency)
209
+
210
+ def __neg__(self):
211
+ return self.__class__(-self.amount, self.currency)
212
+
213
+ def __pos__(self):
214
+ return self.__class__(+self.amount, self.currency)
215
+
216
+ def __abs__(self):
217
+ return self.__class__(abs(self.amount), self.currency)
218
+
219
+ def __int__(self):
220
+ return int(self.amount)
221
+
222
+ def __float__(self):
223
+ return float(self.amount)
224
+
225
+ def __round__(self, ndigits=0):
226
+ return self.__class__(round(self.amount, ndigits), self.currency)
227
+
228
+
229
+ @add_camelcase_aliases
230
+ class PlatformCategorization(object):
231
+ def __init__(self, business_type=None, sector=None):
232
+ self.business_type = business_type
233
+ self.sector = sector
234
+
235
+ def __str__(self):
236
+ return 'PlatformCategorization: %s %s' % (self.business_type, self.sector)
237
+
238
+
239
+ @add_camelcase_aliases
240
+ class Billing(object):
241
+ def __init__(self, first_name=None, last_name=None, address=None):
242
+ self.first_name = first_name
243
+ self.last_name = last_name
244
+ self.address = address
245
+
246
+ def __str__(self):
247
+ return 'Billing: %s' % \
248
+ (self.first_name, self.last_name, self.address)
249
+
250
+
251
+ @add_camelcase_aliases
252
+ class FallbackReason(object):
253
+ def __init__(self, code=None, message=None):
254
+ self.code = code
255
+ self.message = message
256
+
257
+ def __str__(self):
258
+ return 'FallbackReason: %s' % \
259
+ (self.code, self.message)
260
+
261
+
262
+ @add_camelcase_aliases
263
+ class PaymentRef(object):
264
+ def __init__(self, reason_type=None, reference_id=None):
265
+ self.reason_type = reason_type
266
+ self.reference_id = reference_id
267
+
268
+ def __str__(self):
269
+ return 'PaymentRef: %s' % \
270
+ (self.reason_type, self.reference_id)
271
+
272
+
273
+ @add_camelcase_aliases
274
+ class InstantPayout(object):
275
+ def __init__(self, is_reachable=None, unreachable_reason=None):
276
+ self.is_reachable = is_reachable
277
+ self.unreachable_reason = unreachable_reason
278
+
279
+ def __str__(self):
280
+ return 'InstantPayout: %s' % \
281
+ (self.code, self.message)
282
+
283
+
284
+ @add_camelcase_aliases
285
+ class SecurityInfo(object):
286
+ def __init__(self, avs_result=None):
287
+ self.avs_result = avs_result
288
+
289
+ def __str__(self):
290
+ return 'AVS Result: %s' % self.avs_result
291
+
292
+
293
+ @add_camelcase_aliases
294
+ class DebitedBankAccount(object):
295
+ def __init__(self, owner_name=None, account_number=None, iban=None,
296
+ bic=None, type=None, country=None):
297
+ self.owner_name = owner_name
298
+ self.account_number = account_number
299
+ self.iban = iban
300
+ self.bic = bic
301
+ self.type = type
302
+ self.country = country
303
+
304
+ def __str__(self):
305
+ return 'DebitedBankAccount: %s' % \
306
+ (self.owner_name, self.account_number, self.iban, self.bic, self.type, self.country)
307
+
308
+ def __eq__(self, other):
309
+ if isinstance(other, DebitedBankAccount):
310
+ stat = (self.owner_name == other.owner_name and
311
+ self.account_number == other.account_number and
312
+ self.iban == other.iban and
313
+ self.bic == other.bic and
314
+ self.type == other.type and
315
+ self.country == other.country)
316
+
317
+ return stat
318
+ return False
319
+
320
+
321
+ @add_camelcase_aliases
322
+ class Address(object):
323
+ def __init__(self, address_line_1=None, address_line_2=None, city=None, region=None,
324
+ postal_code=None, country=None):
325
+ self.address_line_1 = address_line_1
326
+ self.address_line_2 = address_line_2
327
+ self.city = city
328
+ self.region = region
329
+ self.postal_code = postal_code
330
+ self.country = country
331
+
332
+ def __str__(self):
333
+ return 'Address: %s, %s , %s, %s, %s , %s' % \
334
+ (self.address_line_1, self.address_line_2, self.postal_code, self.city, self.region, self.country)
335
+
336
+ def __eq__(self, other):
337
+ if isinstance(other, Address):
338
+ stat = ((self.address_line_1 == other.address_line_1) and
339
+ (self.address_line_2 == other.address_line_2) and
340
+ (self.postal_code == other.postal_code) and
341
+ (self.city == other.city) and
342
+ (self.region == other.region) and
343
+ (self.country == other.country))
344
+ return stat
345
+ return False
346
+
347
+ def to_api_json(self):
348
+ return {
349
+ "AddressLine1": self.address_line_1,
350
+ "AddressLine2": self.address_line_2,
351
+ "PostalCode": self.postal_code,
352
+ "City": self.city,
353
+ "Region": self.region,
354
+ "Country": self.country,
355
+ }
356
+
357
+
358
+ @add_camelcase_aliases
359
+ class ShippingAddress(object):
360
+ def __init__(self, recipient_name=None, address=None):
361
+ self.recipient_name = recipient_name
362
+ self.address = address
363
+
364
+ def __str__(self):
365
+ return 'Recipient name: %s, %s' % (self.recipient_name, self.address)
366
+
367
+ def __eq__(self, other):
368
+ if isinstance(other, ShippingAddress):
369
+ return self.recipient_name == other.recipient_name and self.address == other.address
370
+ return False
371
+
372
+
373
+ @add_camelcase_aliases
374
+ class ApplepayPaymentData(object):
375
+ def __init__(self, transaction_id=None, network=None, token_data=None):
376
+ self.transaction_id = transaction_id
377
+ self.network = network
378
+ self.token_data = token_data
379
+
380
+ def __eq__(self, other):
381
+ if isinstance(other, ApplepayPaymentData):
382
+ return self.transaction_id == other.transaction_id and self.network == other.network and self.token_data == other.token_data
383
+ return False
384
+
385
+
386
+ @add_camelcase_aliases
387
+ class GooglepayPaymentData(object):
388
+ def __init__(self, transaction_id=None, network=None, token_data=None):
389
+ self.transaction_id = transaction_id
390
+ self.network = network
391
+ self.token_data = token_data
392
+
393
+ def __eq__(self, other):
394
+ if isinstance(other, GooglepayPaymentData):
395
+ return self.transaction_id == other.transaction_id and self.network == other.network and self.token_data == other.token_data
396
+ return False
397
+
398
+
399
+ @add_camelcase_aliases
400
+ class ReportTransactionsFilters(object):
401
+ def __init__(self, before_date=None, after_date=None, transaction_type=None, status=None, nature=None,
402
+ min_debited_funds_amount=None, min_debited_funds_currency=None, max_debited_funds_amount=None,
403
+ max_debited_funds_currency=None, author_id=None, wallet_id=None, result_code=None,
404
+ min_fees_amount=None, min_fees_currency=None, max_fees_amount=None, max_fees_currency=None):
405
+ self.before_date = before_date
406
+ self.after_date = after_date
407
+ self.transaction_type = transaction_type
408
+ self.status = status
409
+ self.nature = nature
410
+ self.min_debited_funds_amount = min_debited_funds_amount
411
+ self.min_debited_funds_currency = min_debited_funds_currency
412
+ self.max_debited_funds_amount = max_debited_funds_amount
413
+ self.max_debited_funds_currency = max_debited_funds_currency
414
+ self.author_id = author_id
415
+ self.wallet_id = wallet_id
416
+ self.result_code = result_code
417
+ self.min_fees_amount = min_fees_amount
418
+ self.min_fees_currency = min_fees_currency
419
+ self.max_fees_amount = max_fees_amount
420
+ self.max_fees_currency = max_fees_currency
421
+
422
+ def __eq__(self, other):
423
+ if isinstance(other, ReportTransactionsFilters):
424
+ stat = ((self.before_date == other.before_date) and
425
+ (self.after_date == other.after_date) and
426
+ (self.transaction_type == other.transaction_type) and
427
+ (self.status == other.status) and
428
+ (self.nature == other.nature) and
429
+ (self.min_debited_funds_amount == other.min_debited_funds_amount) and
430
+ (self.min_debited_funds_currency == other.min_debited_funds_currency) and
431
+ (self.max_debited_funds_amount == other.max_debited_funds_amount) and
432
+ (self.max_debited_funds_currency == other.max_debited_funds_currency) and
433
+ (self.author_id == other.author_id) and
434
+ (self.wallet_id == other.wallet_id) and
435
+ (self.result_code == other.result_code) and
436
+ (self.min_fees_amount == other.min_fees_amount) and
437
+ (self.min_fees_currency == other.min_fees_currency) and
438
+ (self.max_fees_amount == other.max_fees_amount) and
439
+ (self.max_fees_currency == other.max_fees_currency)
440
+ )
441
+ return stat
442
+ return False
443
+
444
+
445
+ @add_camelcase_aliases
446
+ class ReportWalletsFilters(object):
447
+ def __init__(self, before_date=None, after_date=None, owner_id=None, currency=None,
448
+ min_balance_amount=None, min_balance_currency=None, max_balance_amount=None,
449
+ max_balance_currency=None):
450
+ self.before_date = before_date
451
+ self.after_date = after_date
452
+ self.owner_id = owner_id
453
+ self.currency = currency
454
+ self.min_balance_amount = min_balance_amount
455
+ self.min_balance_currency = min_balance_currency
456
+ self.max_balance_amount = max_balance_amount
457
+ self.max_balance_currency = max_balance_currency
458
+
459
+ def __eq__(self, other):
460
+ if isinstance(other, ReportWalletsFilters):
461
+ stat = ((self.before_date == other.before_date) and
462
+ (self.after_date == other.after_date) and
463
+ (self.owner_id == other.owner_id) and
464
+ (self.currency == other.currency) and
465
+ (self.min_balance_amount == other.min_balance_amount) and
466
+ (self.min_balance_currency == other.min_balance_currency) and
467
+ (self.max_balance_amount == other.max_balance_amount) and
468
+ (self.max_balance_currency == other.max_balance_currency)
469
+ )
470
+ return stat
471
+ return False
472
+
473
+
474
+ class Reason(object):
475
+ def __init__(self, type=None, message=None):
476
+ self.type = type
477
+ self.message = message
478
+
479
+ def __str__(self):
480
+ return 'Reason: %s Message: %s' % (self.type, self.message)
481
+
482
+ def __eq__(self, other):
483
+ if isinstance(other, Reason):
484
+ return ((self.type == other.type) and
485
+ (self.message == other.message))
486
+ return False
487
+
488
+
489
+ @add_camelcase_aliases
490
+ class Birthplace(object):
491
+ def __init__(self, city=None, country=None):
492
+ self.city = city
493
+ self.country = country
494
+
495
+ def __str__(self):
496
+ return 'Birthplace: %s, %s' % (self.city, self.country)
497
+
498
+ def __eq__(self, other):
499
+ if isinstance(other, Birthplace):
500
+ stat = ((self.city == other.city) and
501
+ (self.country == other.country))
502
+ return stat
503
+ return False
504
+
505
+ def to_api_json(self):
506
+ return {
507
+ "City": self.city,
508
+ "Country": self.country,
509
+ }
510
+
511
+
512
+ @add_camelcase_aliases
513
+ class BrowserInfo(object):
514
+ def __init__(self, accept_header=None, java_enabled=None, javascript_enabled=None,
515
+ language=None, color_depth=None, screen_height=None, screen_width=None,
516
+ timezone_offset=None, user_agent=None):
517
+ self.user_agent = user_agent
518
+ self.timezone_offset = timezone_offset
519
+ self.screen_width = screen_width
520
+ self.screen_height = screen_height
521
+ self.color_depth = color_depth
522
+ self.language = language
523
+ self.accept_header = accept_header
524
+ self.java_enabled = java_enabled
525
+ self.javascript_enabled = javascript_enabled
526
+
527
+ def __str__(self):
528
+ return 'BrowserInfo: %s %s %s %s %s %s %s %s %s' % (self.java_enabled, self.accept_header, self.language,
529
+ self.color_depth, self.screen_height, self.screen_width,
530
+ self.timezone_offset, self.user_agent,
531
+ self.javascript_enabled)
532
+
533
+ def __eq__(self, other):
534
+ if isinstance(other, BrowserInfo):
535
+ stat = ((self.user_agent == other.user_agent) and
536
+ (self.timezone_offset == other.timezone_offset) and
537
+ (self.screen_width == other.screen_width) and
538
+ (self.screen_height == other.screen_height) and
539
+ (self.color_depth == other.color_depth) and
540
+ (self.language == other.language) and
541
+ (self.accept_header == other.accept_header) and
542
+ (self.java_enabled == other.java_enabled) and
543
+ (self.javascript_enabled == other.javascript_enabled))
544
+ return stat
545
+ return False
546
+
547
+ def to_api_json(self):
548
+ return {
549
+ "AcceptHeader": self.accept_header,
550
+ "JavaEnabled": self.java_enabled,
551
+ "JavascriptEnabled": self.javascript_enabled,
552
+ "Language": self.language,
553
+ "ColorDepth": self.color_depth,
554
+ "ScreenHeight": self.screen_height,
555
+ "ScreenWidth": self.screen_width,
556
+ "TimeZoneOffset": self.timezone_offset,
557
+ "UserAgent": self.user_agent
558
+ }
559
+
560
+
561
+ @add_camelcase_aliases
562
+ class Shipping(object):
563
+ def __init__(self, first_name=None, last_name=None, address=None):
564
+ self.first_name = first_name
565
+ self.last_name = last_name
566
+ self.address = address
567
+
568
+ def __str__(self):
569
+ return 'Shipping: %s' % \
570
+ (self.first_name, self.last_name, self.address)
571
+
572
+
573
+ @add_camelcase_aliases
574
+ class AccountFundingSender(object):
575
+ def __init__(self, first_name=None, last_name=None, address=None, email=None, birthday=None,
576
+ nationality=None, occupation=None, birth_country=None):
577
+ self.first_name = first_name
578
+ self.last_name = last_name
579
+ self.address = address
580
+ self.email = email
581
+ self.birthday = birthday
582
+ self.nationality = nationality
583
+ self.occupation = occupation
584
+ self.birth_country = birth_country
585
+
586
+ def __str__(self):
587
+ return 'AccountFundingSender: %s %s' % (self.first_name, self.last_name)
588
+
589
+ def to_api_json(self):
590
+ return {
591
+ 'FirstName': self.first_name,
592
+ 'LastName': self.last_name,
593
+ 'Address': self.address,
594
+ 'Email': self.email,
595
+ 'Birthday': self.birthday,
596
+ 'Nationality': self.nationality,
597
+ 'Occupation': self.occupation,
598
+ 'BirthCountry': self.birth_country
599
+ }
600
+
601
+
602
+ @add_camelcase_aliases
603
+ class AccountFunding(object):
604
+ def __init__(self, sender=None, purpose=None, type=None):
605
+ self.sender = sender
606
+ self.purpose = purpose
607
+ self.type = type
608
+
609
+ def __str__(self):
610
+ return 'AccountFunding: %s, %s' % (self.purpose, self.type)
611
+
612
+ def to_api_json(self):
613
+ return {
614
+ 'Sender': self.sender,
615
+ 'Purpose': self.purpose,
616
+ 'Type': self.type
617
+ }
618
+
619
+
620
+ @add_camelcase_aliases
621
+ class CurrentState(object):
622
+ def __init__(self, payins_linked=None, cumulated_debited_amount=None, cumulated_debited_fees=None,
623
+ last_payin_id=None):
624
+ self.payins_linked = payins_linked
625
+ self.cumulated_debited_amount = cumulated_debited_amount
626
+ self.cumulated_debited_fees = cumulated_debited_fees
627
+ self.last_payin_id = last_payin_id
628
+
629
+ def __str__(self):
630
+ return 'CurrentState: %s' % \
631
+ (self.cumulated_debited_amount, self.cumulated_debited_fees, self.last_payin_id, self.payins_linked)
632
+
633
+
634
+ @add_camelcase_aliases
635
+ class ScopeBlocked(object):
636
+ def __init__(self, inflows=None, outflows=None):
637
+ self.inflows = inflows
638
+ self.outflows = outflows
639
+
640
+ def __str__(self):
641
+ return 'ScopeBlocked: %s, %s' % (self.inflows, self.outflows)
642
+
643
+ def __eq__(self, other):
644
+ if isinstance(other, ScopeBlocked):
645
+ stat = ((self.inflows == other.inflows) and
646
+ (self.outflows == other.outflows))
647
+ return stat
648
+ return False
649
+
650
+ def to_api_json(self):
651
+ return {
652
+ "Inflows": self.inflows,
653
+ "Outflows": self.outflows,
654
+ }
655
+
656
+
657
+ @add_camelcase_aliases
658
+ class KycInformation(object):
659
+ def __init__(self, last_kyc_date=None, kyc_renewal_deadline=None):
660
+ self.last_kyc_date = last_kyc_date
661
+ self.kyc_renewal_deadline = kyc_renewal_deadline
662
+
663
+ def __str__(self):
664
+ return 'KycInformation: %s, %s' % (self.last_kyc_date, self.kyc_renewal_deadline)
665
+
666
+ def __eq__(self, other):
667
+ if isinstance(other, KycInformation):
668
+ stat = ((self.last_kyc_date == other.last_kyc_date) and
669
+ (self.kyc_renewal_deadline == other.kyc_renewal_deadline))
670
+ return stat
671
+ return False
672
+
673
+ def to_api_json(self):
674
+ return {
675
+ "LastKycDate": self.last_kyc_date,
676
+ "KycRenewalDeadline": self.kyc_renewal_deadline,
677
+ }
678
+
679
+
680
+ # This code belongs to https://github.com/carljm/django-model-utils
681
+ class Choices(object):
682
+ """
683
+ A class to encapsulate handy functionality for lists of choices
684
+ for a Django model field.
685
+ Each argument to ``Choices`` is a choice, represented as either a
686
+ string, a two-tuple, or a three-tuple.
687
+ If a single string is provided, that string is used as the
688
+ database representation of the choice as well as the
689
+ human-readable presentation.
690
+ If a two-tuple is provided, the first item is used as the database
691
+ representation and the second the human-readable presentation.
692
+ If a triple is provided, the first item is the database
693
+ representation, the second a valid Python identifier that can be
694
+ used as a readable label in code, and the third the human-readable
695
+ presentation. This is most useful when the database representation
696
+ must sacrifice readability for some reason: to achieve a specific
697
+ ordering, to use an integer rather than a character field, etc.
698
+ Regardless of what representation of each choice is originally
699
+ given, when iterated over or indexed into, a ``Choices`` object
700
+ behaves as the standard Django choices list of two-tuples.
701
+ If the triple form is used, the Python identifier names can be
702
+ accessed as attributes on the ``Choices`` object, returning the
703
+ database representation. (If the single or two-tuple forms are
704
+ used and the database representation happens to be a valid Python
705
+ identifier, the database representation itself is available as an
706
+ attribute on the ``Choices`` object, returning itself.)
707
+ Option groups can also be used with ``Choices``; in that case each
708
+ argument is a tuple consisting of the option group name and a list
709
+ of options, where each option in the list is either a string, a
710
+ two-tuple, or a triple as outlined above.
711
+ """
712
+
713
+ def __init__(self, *choices):
714
+ # list of choices expanded to triples - can include optgroups
715
+ self._triples = []
716
+ # list of choices as (db, human-readable) - can include optgroups
717
+ self._doubles = []
718
+ # dictionary mapping db representation to human-readable
719
+ self._display_map = {}
720
+ # dictionary mapping Python identifier to db representation
721
+ self._identifier_map = {}
722
+ # set of db representations
723
+ self._db_values = set()
724
+
725
+ self._process(choices)
726
+
727
+ def _store(self, triple, triple_collector, double_collector):
728
+ self._identifier_map[triple[1]] = triple[0]
729
+ self._display_map[triple[0]] = triple[2]
730
+ self._db_values.add(triple[0])
731
+ triple_collector.append(triple)
732
+ double_collector.append((triple[0], triple[2]))
733
+
734
+ def _process(self, choices, triple_collector=None, double_collector=None):
735
+ if triple_collector is None:
736
+ triple_collector = self._triples
737
+ if double_collector is None:
738
+ double_collector = self._doubles
739
+
740
+ store = lambda c: self._store(c, triple_collector, double_collector)
741
+
742
+ for choice in choices:
743
+ if isinstance(choice, (list, tuple)):
744
+ if len(choice) == 3:
745
+ store(choice)
746
+ elif len(choice) == 2:
747
+ if isinstance(choice[1], (list, tuple)):
748
+ # option group
749
+ group_name = choice[0]
750
+ subchoices = choice[1]
751
+ tc = []
752
+ triple_collector.append((group_name, tc))
753
+ dc = []
754
+ double_collector.append((group_name, dc))
755
+ self._process(subchoices, tc, dc)
756
+ else:
757
+ store((choice[0], choice[0], choice[1]))
758
+ else:
759
+ raise ValueError(
760
+ "Choices can't take a list of length %s, only 2 or 3"
761
+ % len(choice))
762
+ else:
763
+ store((choice, choice, choice))
764
+
765
+ def __len__(self):
766
+ return len(self._doubles)
767
+
768
+ def __iter__(self):
769
+ return iter(self._doubles)
770
+
771
+ def __getattr__(self, attname):
772
+ try:
773
+ return self._identifier_map[attname]
774
+ except KeyError:
775
+ raise AttributeError(attname)
776
+
777
+ def __getitem__(self, key):
778
+ return self._display_map[key]
779
+
780
+ def __add__(self, other):
781
+ if isinstance(other, self.__class__):
782
+ other = other._triples
783
+ else:
784
+ other = list(other)
785
+ return Choices(*(self._triples + other))
786
+
787
+ def __radd__(self, other):
788
+ # radd is never called for matching types, so we don't check here
789
+ other = list(other)
790
+ return Choices(*(other + self._triples))
791
+
792
+ def __eq__(self, other):
793
+ if isinstance(other, self.__class__):
794
+ return self._triples == other._triples
795
+ return False
796
+
797
+ def __repr__(self):
798
+ return '%s(%s)' % (
799
+ self.__class__.__name__,
800
+ ', '.join(("%s" % repr(i) for i in self._triples)))
801
+
802
+ def __contains__(self, item):
803
+ return item in self._db_values
804
+
805
+ def __deepcopy__(self, memo):
806
+ return self.__class__(*copy.deepcopy(self._triples, memo))
807
+
808
+
809
+ def timestamp_from_datetime(dt):
810
+ """
811
+ Compute timestamp from a datetime object that could be timezone aware
812
+ or unaware.
813
+ """
814
+ try:
815
+ utc_dt = dt.astimezone(pytz.utc)
816
+ except ValueError:
817
+ utc_dt = dt.replace(tzinfo=pytz.utc)
818
+ return timegm(utc_dt.timetuple())
819
+
820
+
821
+ def timestamp_from_date(date):
822
+ epoch = datetime.date(1970, 1, 1)
823
+ diff = date - epoch
824
+ return diff.days * 24 * 3600 + diff.seconds
825
+
826
+
827
+ if six.PY3:
828
+ memoryview = memoryview
829
+ else:
830
+ memoryview = buffer # noqa
831
+
832
+
833
+ def is_protected_type(obj):
834
+ """Determine if the object instance is of a protected type.
835
+
836
+ Objects of protected types are preserved as-is when passed to
837
+ force_text(strings_only=True).
838
+ """
839
+ return isinstance(obj, six.integer_types + (type(None), float, decimal.Decimal,
840
+ datetime.datetime, datetime.date, datetime.time))
841
+
842
+
843
+ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
844
+ """
845
+ Similar to smart_text, except that lazy instances are resolved to
846
+ strings, rather than kept as lazy objects.
847
+
848
+ If strings_only is True, don't convert (some) non-string-like objects.
849
+ """
850
+ # Handle the common case first, saves 30-40% when s is an instance of
851
+ # six.text_type. This function gets called often in that setting.
852
+ if isinstance(s, six.text_type):
853
+ return s
854
+ if strings_only and is_protected_type(s):
855
+ return s
856
+ try:
857
+ if not isinstance(s, six.string_types):
858
+ if hasattr(s, '__unicode__'):
859
+ s = s.__unicode__()
860
+ else:
861
+ if six.PY3:
862
+ if isinstance(s, bytes):
863
+ s = six.text_type(s, encoding, errors)
864
+ else:
865
+ s = six.text_type(s)
866
+ else:
867
+ s = six.text_type(bytes(s), encoding, errors)
868
+ else:
869
+ # Note: We use .decode() here, instead of six.text_type(s, encoding,
870
+ # errors), so that if s is a SafeBytes, it ends up being a
871
+ # SafeText at the end.
872
+ s = s.decode(encoding, errors)
873
+ except UnicodeDecodeError:
874
+ # If we get to here, the caller has passed in an Exception
875
+ # subclass populated with non-ASCII bytestring data without a
876
+ # working unicode method. Try to handle this without raising a
877
+ # further exception by individually forcing the exception args
878
+ # to unicode.
879
+ s = ' '.join([force_text(arg, encoding, strings_only,
880
+ errors) for arg in s])
881
+ return s
882
+
883
+
884
+ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
885
+ """
886
+ Similar to smart_bytes, except that lazy instances are resolved to
887
+ strings, rather than kept as lazy objects.
888
+
889
+ If strings_only is True, don't convert (some) non-string-like objects.
890
+ """
891
+ if isinstance(s, memoryview):
892
+ s = bytes(s)
893
+ if isinstance(s, bytes):
894
+ if encoding == 'utf-8':
895
+ return s
896
+ else:
897
+ return s.decode('utf-8', errors).encode(encoding, errors)
898
+ if strings_only and (s is None or isinstance(s, int)):
899
+ return s
900
+ if not isinstance(s, six.string_types):
901
+ try:
902
+ if six.PY3:
903
+ return six.text_type(s).encode(encoding)
904
+ else:
905
+ return bytes(s)
906
+ except UnicodeEncodeError:
907
+ if isinstance(s, Exception):
908
+ # An Exception subclass containing non-ASCII data that doesn't
909
+ # know how to print itself properly. We shouldn't raise a
910
+ # further exception.
911
+ return b' '.join([force_bytes(arg, encoding, strings_only,
912
+ errors) for arg in s])
913
+ return six.text_type(s).encode(encoding, errors)
914
+ else:
915
+ return s.encode(encoding, errors)
916
+
917
+
918
+ if six.PY3:
919
+ force_str = force_text
920
+ else:
921
+ force_str = force_bytes
922
+
923
+
924
+ def memoize(func, cache, num_args):
925
+ """
926
+ Wrap a function so that results for any argument tuple are stored in
927
+ 'cache'. Note that the args to the function must be usable as dictionary
928
+ keys.
929
+ Only the first num_args are considered when creating the key.
930
+ """
931
+
932
+ @wraps(func)
933
+ def wrapper(*args):
934
+ mem_args = args[:num_args]
935
+ if mem_args in cache:
936
+ return cache[mem_args]
937
+ result = func(*args)
938
+ cache[mem_args] = result
939
+ return result
940
+
941
+ return wrapper
942
+
943
+
944
+ def reraise_as(new_exception_or_type):
945
+ """
946
+ Obtained from https://github.com/dcramer/reraise/blob/master/src/reraise.py
947
+ >>> try:
948
+ >>> do_something_crazy()
949
+ >>> except Exception:
950
+ >>> reraise_as(UnhandledException)
951
+ """
952
+ __traceback_hide__ = True # NOQA
953
+
954
+ e_type, e_value, e_traceback = sys.exc_info()
955
+
956
+ if inspect.isclass(new_exception_or_type):
957
+ new_type = new_exception_or_type
958
+ new_exception = new_exception_or_type()
959
+ else:
960
+ new_type = type(new_exception_or_type)
961
+ new_exception = new_exception_or_type
962
+
963
+ new_exception.__cause__ = e_value
964
+
965
+ try:
966
+ six.reraise(new_type, new_exception, e_traceback)
967
+ finally:
968
+ del e_traceback
969
+
970
+
971
+ def truncatechars(value, length=255):
972
+ if isinstance(value, dict):
973
+ for k, v in value.items():
974
+ value[k] = truncatechars(v)
975
+ elif isinstance(value, six.string_types):
976
+ return (value[:length] + '...') if len(value) > length else value
977
+
978
+ return value
979
+
980
+
981
+ class CountryAuthorizationData(object):
982
+ def __init__(self, block_user_creation=None, block_bank_account_creation=None, block_payout=None):
983
+ self.block_user_creation = block_user_creation
984
+ self.block_bank_account_creation = block_bank_account_creation
985
+ self.block_payout = block_payout
986
+
987
+ def __str__(self):
988
+ return 'CountryAuthorizationData: %s, %s , %s' % \
989
+ (self.block_user_creation, self.block_bank_account_creation, self.block_payout)
990
+
991
+ def __eq__(self, other):
992
+ if isinstance(other, CountryAuthorizationData):
993
+ stat = ((self.block_user_creation == other.block_user_creation) and
994
+ (self.block_bank_account_creation == other.block_bank_account_creation) and
995
+ (self.block_payout == other.block_payout))
996
+ return stat
997
+ return False
998
+
999
+ def to_api_json(self):
1000
+ return {
1001
+ "BlockUserCreation": self.block_user_creation,
1002
+ "BlockBankAccountCreation": self.block_bank_account_creation,
1003
+ "BlockPayout": self.block_payout
1004
+ }
1005
+
1006
+
1007
+ class PayinsLinked(object):
1008
+ def __init__(self, payin_capture_id=None, payin_complement_id=None):
1009
+ self.payin_capture_id = payin_capture_id
1010
+ self.payin_complement_id = payin_complement_id
1011
+
1012
+ def __str__(self):
1013
+ return 'PayinsLinked: %s, %s' % \
1014
+ (self.payin_capture_id, self.payin_complement_id)
1015
+
1016
+ def to_api_json(self):
1017
+ return {
1018
+ "PayinCaptureId": self.payin_capture_id,
1019
+ "PayinComplementId": self.payin_complement_id
1020
+ }
1021
+
1022
+
1023
+ class LineItem(object):
1024
+ def __init__(self, name=None, quantity=None, unit_amount=None, tax_amount=None, description=None, category=None,
1025
+ sku=None, discount=None):
1026
+ self.name = name
1027
+ self.quantity = quantity
1028
+ self.unit_amount = unit_amount
1029
+ self.tax_amount = tax_amount
1030
+ self.description = description
1031
+ self.category = category
1032
+ self.sku = sku
1033
+ self.discount = discount
1034
+
1035
+ def __str__(self):
1036
+ return 'LineItem: %s %s %s %s %s %s %s %s' % \
1037
+ (self.name, self.quantity, self.unit_amount, self.tax_amount, self.description, self.category, self.sku, self.discount)
1038
+
1039
+ def to_api_json(self):
1040
+ return {
1041
+ "Name": self.name,
1042
+ "Quantity": self.quantity,
1043
+ "UnitAmount": self.unit_amount,
1044
+ "TaxAmount": self.tax_amount,
1045
+ "Description": self.description,
1046
+ "Category": self.category,
1047
+ "Sku": self.sku,
1048
+ "Discount": self.discount
1049
+ }
1050
+
1051
+
1052
+ @add_camelcase_aliases
1053
+ class ConversionRate(object):
1054
+ def __init__(self, client_rate=None, market_rate=None):
1055
+ self.client_rate = client_rate
1056
+ self.market_rate = market_rate
1057
+
1058
+ def __str__(self):
1059
+ return 'Conversion rate: %s %s' % \
1060
+ (self.client_rate, self.market_rate)
1061
+
1062
+ def to_api_json(self):
1063
+ return {
1064
+ "ClientRate": self.client_rate,
1065
+ "MarketRate": self.market_rate
1066
+ }
1067
+
1068
+
1069
+ @add_camelcase_aliases
1070
+ class CardInfo(object):
1071
+ def __init__(self,
1072
+ bin=None,
1073
+ issuing_bank=None,
1074
+ issuer_country_code=None,
1075
+ type=None,
1076
+ brand=None,
1077
+ sub_type=None):
1078
+ self.bin = bin
1079
+ self.issuing_bank = issuing_bank
1080
+ self.issuer_country_code = issuer_country_code
1081
+ self.type = type
1082
+ self.brand = brand
1083
+ self.sub_type = sub_type
1084
+
1085
+ def __str__(self):
1086
+ return 'Card info: %s %s %s %s %s %s' % \
1087
+ (self.bin, self.issuing_bank, self.issuer_country_code, self.type, self.brand, self.sub_type)
1088
+
1089
+ def to_api_json(self):
1090
+ return {
1091
+ "BIN": self.bin,
1092
+ "IssuingBank": self.issuing_bank,
1093
+ "IssuerCountryCode": self.issuer_country_code,
1094
+ "Type": self.type,
1095
+ "Brand": self.brand,
1096
+ "SubType": self.sub_type
1097
+ }
1098
+
1099
+
1100
+ class PayPalTrackingInformation(object):
1101
+ def __init__(self, tracking_number=None, carrier=None, notify_buyer=None):
1102
+ self.tracking_number = tracking_number
1103
+ self.carrier = carrier
1104
+ self.notify_buyer = notify_buyer
1105
+
1106
+ def __str__(self):
1107
+ return 'PayPalTrackingInformation: %s %s %s' % \
1108
+ (self.tracking_number, self.carrier, self.notify_buyer)
1109
+
1110
+ def to_api_json(self):
1111
+ return {
1112
+ "TrackingNumber": self.tracking_number,
1113
+ "Carrier": self.carrier,
1114
+ "NotifyBuyer": self.notify_buyer
1115
+ }
1116
+
1117
+
1118
+ class LocalAccountDetails(object):
1119
+ def __init__(self, address=None, account=None, bank_name=None):
1120
+ self.address = address
1121
+ self.account = account
1122
+ self.bank_name = bank_name
1123
+
1124
+ def __str__(self):
1125
+ return 'LocalAccountDetails: %s %s %s' % \
1126
+ (self.address, self.account, self.bank_name)
1127
+
1128
+ def to_api_json(self):
1129
+ return {
1130
+ "Address": self.address,
1131
+ "Account": self.account,
1132
+ "BankName": self.bank_name
1133
+ }
1134
+
1135
+
1136
+ class InternationalAccountDetails(object):
1137
+ def __init__(self, address=None, account=None, bank_name=None):
1138
+ self.address = address
1139
+ self.account = account
1140
+ self.bank_name = bank_name
1141
+
1142
+ def __str__(self):
1143
+ return 'InternationalAccountDetails: %s %s %s' % \
1144
+ (self.address, self.account, self.bank_name)
1145
+
1146
+ def to_api_json(self):
1147
+ return {
1148
+ "Address": self.address,
1149
+ "Account": self.account,
1150
+ "BankName": self.bank_name
1151
+ }
1152
+
1153
+
1154
+ class VirtualAccountCapabilities(object):
1155
+ def __init__(self, local_pay_in_available=None, international_pay_in_available=None, currencies=None):
1156
+ self.local_pay_in_available = local_pay_in_available
1157
+ self.international_pay_in_available = international_pay_in_available
1158
+ self.currencies = currencies
1159
+
1160
+ def __str__(self):
1161
+ return 'VirtualAccountCapabilities: %s %s %s' % \
1162
+ (self.local_pay_in_available, self.international_pay_in_available, self.currencies)
1163
+
1164
+ def to_api_json(self):
1165
+ return {
1166
+ "LocalPayinAvailable": self.local_pay_in_available,
1167
+ "InternationalPayinAvailable": self.international_pay_in_available,
1168
+ "Currencies": self.currencies
1169
+ }
1170
+
1171
+
1172
+ @add_camelcase_aliases
1173
+ class PendingUserAction(object):
1174
+ def __init__(self, redirect_url=None):
1175
+ self.redirect_url = redirect_url
1176
+
1177
+ def __str__(self):
1178
+ return 'PendingUserAction: %s' % self.redirect_url
1179
+
1180
+ def __eq__(self, other):
1181
+ if isinstance(other, PendingUserAction):
1182
+ stat = (self.redirect_url == other.redirect_url)
1183
+ return stat
1184
+ return False
1185
+
1186
+ def to_api_json(self):
1187
+ return {
1188
+ "RedirectUrl": self.redirect_url
1189
+ }
1190
+
1191
+
1192
+ @add_camelcase_aliases
1193
+ class LegalRepresentative(object):
1194
+ def __init__(self, first_name=None, last_name=None, birthday=None, nationality=None, country_of_residence=None,
1195
+ email=None, phone_number=None, phone_number_country=None):
1196
+ self.first_name = first_name
1197
+ self.last_name = last_name
1198
+ self.birthday = birthday
1199
+ self.nationality = nationality
1200
+ self.country_of_residence = country_of_residence
1201
+ self.email = email
1202
+ self.phone_number = phone_number
1203
+ self.phone_number_country = phone_number_country
1204
+
1205
+ def __str__(self):
1206
+ return 'LegalRepresentative: %s , %s, %s, %s, %s, %s, %s, %s' % \
1207
+ (self.first_name, self.last_name, self.birthday, self.nationality,
1208
+ self.country_of_residence, self.email, self.phone_number, self.phone_number_country)
1209
+
1210
+ def __eq__(self, other):
1211
+ if isinstance(other, LegalRepresentative):
1212
+ stat = ((self.first_name == other.first_name) and
1213
+ (self.last_name == other.last_name) and
1214
+ (self.birthday == other.birthday) and
1215
+ (self.nationality == other.nationality) and
1216
+ (self.country_of_residence == other.country_of_residence) and
1217
+ (self.email == other.email) and
1218
+ (self.phone_number == other.phone_number) and
1219
+ (self.phone_number_country == other.phone_number_country))
1220
+ return stat
1221
+ return False
1222
+
1223
+ def to_api_json(self):
1224
+ return {
1225
+ "FirstName": self.first_name,
1226
+ "LastName": self.last_name,
1227
+ "Birthday": self.birthday,
1228
+ "Nationality": self.nationality,
1229
+ "CountryOfResidence": self.country_of_residence,
1230
+ "Email": self.email,
1231
+ "PhoneNumber": self.phone_number,
1232
+ "PhoneNumberCountry": self.phone_number_country
1233
+ }
1234
+
1235
+
1236
+ @add_camelcase_aliases
1237
+ class IndividualRecipient(object):
1238
+ def __init__(self, first_name=None, last_name=None, address=None):
1239
+ self.first_name = first_name
1240
+ self.last_name = last_name
1241
+ self.address = address
1242
+
1243
+ def __str__(self):
1244
+ return 'IndividualRecipient: %s , %s, %s' % \
1245
+ (self.first_name, self.last_name, self.address)
1246
+
1247
+ def __eq__(self, other):
1248
+ if isinstance(other, IndividualRecipient):
1249
+ stat = ((self.first_name == other.first_name) and
1250
+ (self.last_name == other.last_name) and
1251
+ (self.address == other.address))
1252
+ return stat
1253
+ return False
1254
+
1255
+ def to_api_json(self):
1256
+ return {
1257
+ "FirstName": self.first_name,
1258
+ "LastName": self.last_name,
1259
+ "Address": self.address
1260
+ }
1261
+
1262
+
1263
+ @add_camelcase_aliases
1264
+ class BusinessRecipient(object):
1265
+ def __init__(self, business_name=None, address=None):
1266
+ self.business_name = business_name
1267
+ self.address = address
1268
+
1269
+ def __str__(self):
1270
+ return 'BusinessRecipient: %s , %s' % \
1271
+ (self.business_name, self.address)
1272
+
1273
+ def __eq__(self, other):
1274
+ if isinstance(other, BusinessRecipient):
1275
+ stat = ((self.business_name == other.business_name) and
1276
+ (self.address == other.address))
1277
+ return stat
1278
+ return False
1279
+
1280
+ def to_api_json(self):
1281
+ return {
1282
+ "BusinessName": self.business_name,
1283
+ "Address": self.address
1284
+ }
1285
+
1286
+
1287
+ @add_camelcase_aliases
1288
+ class RecipientPropertySchema(object):
1289
+ def __init__(self, required=None, max_length=None, min_length=None, pattern=None, allowed_values=None, label=None,
1290
+ end_user_display=None):
1291
+ self.required = required
1292
+ self.max_length = max_length
1293
+ self.min_length = min_length
1294
+ self.pattern = pattern
1295
+ self.allowed_values = allowed_values
1296
+ self.label = label
1297
+ self.end_user_display = end_user_display
1298
+
1299
+ def __str__(self):
1300
+ return 'RecipientPropertySchema: %s , %s, %s, %s, %s, %s, %s' % \
1301
+ (self.required, self.max_length, self.min_length, self.pattern, self.allowed_values, self.label,
1302
+ self.end_user_display)
1303
+
1304
+ def __eq__(self, other):
1305
+ if isinstance(other, RecipientPropertySchema):
1306
+ stat = ((self.required == other.required) and
1307
+ (self.max_length == other.max_length) and
1308
+ (self.min_length == other.min_length) and
1309
+ (self.pattern == other.pattern) and
1310
+ (self.allowed_values == other.allowed_values) and
1311
+ (self.label == other.label) and
1312
+ (self.end_user_display == other.end_user_display))
1313
+ return stat
1314
+ return False
1315
+
1316
+ def to_api_json(self):
1317
+ return {
1318
+ "Required": self.required,
1319
+ "MaxLength": self.max_length,
1320
+ "MinLength": self.min_length,
1321
+ "Pattern": self.pattern,
1322
+ "AllowedValues": self.allowed_values,
1323
+ "Label": self.label,
1324
+ "EndUserDisplay": self.end_user_display
1325
+ }
1326
+
1327
+
1328
+ @add_camelcase_aliases
1329
+ class IndividualRecipientPropertySchema(object):
1330
+ def __init__(self, first_name=None, last_name=None, address=None):
1331
+ self.first_name = first_name
1332
+ self.last_name = last_name
1333
+ self.address = address
1334
+
1335
+ def __str__(self):
1336
+ return 'IndividualRecipientPropertySchema: %s , %s, %s' % \
1337
+ (self.first_name, self.last_name, self.address)
1338
+
1339
+ def __eq__(self, other):
1340
+ if isinstance(other, IndividualRecipientPropertySchema):
1341
+ stat = ((self.first_name == other.first_name) and
1342
+ (self.last_name == other.last_name) and
1343
+ (self.address == other.address))
1344
+ return stat
1345
+ return False
1346
+
1347
+ def to_api_json(self):
1348
+ return {
1349
+ "FirstName": self.first_name,
1350
+ "LastName": self.last_name,
1351
+ "Address": self.address
1352
+ }
1353
+
1354
+
1355
+ @add_camelcase_aliases
1356
+ class BusinessRecipientPropertySchema(object):
1357
+ def __init__(self, business_name=None, address=None):
1358
+ self.business_name = business_name
1359
+ self.address = address
1360
+
1361
+ def __str__(self):
1362
+ return 'BusinessRecipientPropertySchema: %s , %s' % \
1363
+ (self.business_name, self.address)
1364
+
1365
+ def __eq__(self, other):
1366
+ if isinstance(other, BusinessRecipientPropertySchema):
1367
+ stat = ((self.business_name == other.business_name) and
1368
+ (self.address == other.address))
1369
+ return stat
1370
+ return False
1371
+
1372
+ def to_api_json(self):
1373
+ return {
1374
+ "BusinessName": self.business_name,
1375
+ "Address": self.address
1376
+ }
1377
+
1378
+
1379
+ @add_camelcase_aliases
1380
+ class CompanyNumberValidation(object):
1381
+ def __init__(self, company_number=None, country_code=None, is_valid=None, validation_rules=None):
1382
+ self.company_number = company_number
1383
+ self.country_code = country_code
1384
+ self.is_valid = is_valid
1385
+ self.validation_rules = validation_rules
1386
+
1387
+ def __str__(self):
1388
+ return 'CompanyNumberValidation: %s , %s, %s, %s' % \
1389
+ (self.company_number, self.country_code, self.is_valid, self.validation_rules)
1390
+
1391
+ def __eq__(self, other):
1392
+ if isinstance(other, CompanyNumberValidation):
1393
+ stat = ((self.company_number == other.company_number) and
1394
+ (self.country_code == other.country_code) and
1395
+ (self.is_valid == other.is_valid) and
1396
+ (self.validation_rules == other.validation_rules))
1397
+ return stat
1398
+ return False
1399
+
1400
+ def to_api_json(self):
1401
+ return {
1402
+ "CompanyNumber": self.company_number,
1403
+ "CountryCode": self.country_code,
1404
+ "IsValid": self.is_valid,
1405
+ "ValidationRules": self.validation_rules
1406
+ }
1407
+
1408
+
1409
+ @add_camelcase_aliases
1410
+ class ReportFilter(object):
1411
+ def __init__(self, currency=None, user_id=None, wallet_id=None, payment_method=None, status=None, type=None,
1412
+ intent_id=None, external_provider_name=None, scheduled=None, settlement_id=None):
1413
+ self.currency = currency
1414
+ self.user_id = user_id
1415
+ self.wallet_id = wallet_id
1416
+ self.payment_method = payment_method
1417
+ self.status = status
1418
+ self.type = type
1419
+ self.intent_id = intent_id
1420
+ self.external_provider_name = external_provider_name
1421
+ self.scheduled = scheduled
1422
+ self.settlement_id = settlement_id
1423
+
1424
+ def __str__(self):
1425
+ return 'ReportFilter: %s, %s, %s, %s, %s, %s, %s, %s, %s %s' % \
1426
+ (self.currency, self.user_id, self.wallet_id, self.payment_method, self.status, self.type, self.intent_id,
1427
+ self.external_provider_name, self.scheduled, self.settlement_id)
1428
+
1429
+ def __eq__(self, other):
1430
+ if isinstance(other, ReportFilter):
1431
+ stat = ((self.currency == other.currency) and
1432
+ (self.user_id == other.user_id) and
1433
+ (self.wallet_id == other.wallet_id) and
1434
+ (self.payment_method == other.payment_method) and
1435
+ (self.status == other.status) and
1436
+ (self.type == other.type) and
1437
+ (self.intent_id == other.intent_id) and
1438
+ (self.external_provider_name == other.external_provider_name) and
1439
+ (self.scheduled == other.scheduled) and
1440
+ (self.settlement_id == other.settlement_id))
1441
+ return stat
1442
+ return False
1443
+
1444
+ def to_api_json(self):
1445
+ return {
1446
+ "Currency": self.currency,
1447
+ "UserId": self.user_id,
1448
+ "WalletId": self.wallet_id,
1449
+ "PaymentMethod": self.payment_method,
1450
+ "Status": self.status,
1451
+ "Type": self.type,
1452
+ "IntentId": self.intent_id,
1453
+ "ExternalProviderName": self.external_provider_name,
1454
+ "Scheduled": self.scheduled,
1455
+ "SettlementId": self.settlement_id
1456
+ }
1457
+
1458
+
1459
+ @add_camelcase_aliases
1460
+ class PayInIntentExternalData(object):
1461
+ def __init__(self, external_processing_date=None, external_provider_reference=None,
1462
+ external_merchant_reference=None, external_provider_name=None, external_provider_payment_method=None):
1463
+ self.external_processing_date = external_processing_date
1464
+ self.external_provider_reference = external_provider_reference
1465
+ self.external_merchant_reference = external_merchant_reference
1466
+ self.external_provider_name = external_provider_name
1467
+ self.external_provider_payment_method = external_provider_payment_method
1468
+
1469
+ def __str__(self):
1470
+ return 'PayInIntentExternalData: %s %s %s %s %s' % \
1471
+ (self.external_processing_date, self.external_provider_reference, self.external_merchant_reference,
1472
+ self.external_provider_name, self.external_provider_payment_method)
1473
+
1474
+ def __eq__(self, other):
1475
+ if isinstance(other, PayInIntentExternalData):
1476
+ stat = ((self.external_processing_date == other.external_processing_date) and
1477
+ (self.external_provider_reference == other.external_provider_reference) and
1478
+ (self.external_merchant_reference == other.external_merchant_reference) and
1479
+ (self.external_provider_name == other.external_provider_name) and
1480
+ (self.external_provider_payment_method == other.external_provider_payment_method))
1481
+ return stat
1482
+ return False
1483
+
1484
+ def to_api_json(self):
1485
+ return {
1486
+ "ExternalProcessingDate": self.external_processing_date,
1487
+ "ExternalProviderReference": self.external_provider_reference,
1488
+ "ExternalMerchantReference": self.external_merchant_reference,
1489
+ "ExternalProviderName": self.external_provider_name,
1490
+ "ExternalProviderPaymentMethod": self.external_provider_payment_method
1491
+ }
1492
+
1493
+
1494
+ @add_camelcase_aliases
1495
+ class PayInIntentBuyer(object):
1496
+ def __init__(self, id=None):
1497
+ self.id = id
1498
+
1499
+ def __str__(self):
1500
+ return 'PayInIntentBuyer: %s' % self.id
1501
+
1502
+ def __eq__(self, other):
1503
+ if isinstance(other, PayInIntentBuyer):
1504
+ stat = (self.id == other.id)
1505
+ return stat
1506
+ return False
1507
+
1508
+ def to_api_json(self):
1509
+ return {
1510
+ "Id": self.id
1511
+ }
1512
+
1513
+
1514
+ @add_camelcase_aliases
1515
+ class PayInIntentLineItem(object):
1516
+ def __init__(self, id=None, seller=None, sku=None, name=None, description=None, quantity=None, unit_amount=None, amount=None,
1517
+ tax_amount=None, discount_amount=None, category=None, shipping_address=None,
1518
+ total_line_item_amount=None, canceled_amount=None, captured_amount=None, refunded_amount=None,
1519
+ disputed_amount=None, split_amount=None, unfunded_seller_amount=None):
1520
+ self.id = id
1521
+ self.seller = seller
1522
+ self.sku = sku
1523
+ self.name = name
1524
+ self.description = description
1525
+ self.quantity = quantity
1526
+ self.unit_amount = unit_amount
1527
+ self.amount = amount
1528
+ self.tax_amount = tax_amount
1529
+ self.discount_amount = discount_amount
1530
+ self.category = category
1531
+ self.shipping_address = shipping_address
1532
+ self.total_line_item_amount = total_line_item_amount
1533
+ self.canceled_amount = canceled_amount
1534
+ self.captured_amount = captured_amount
1535
+ self.refunded_amount = refunded_amount
1536
+ self.disputed_amount = disputed_amount
1537
+ self.split_amount = split_amount
1538
+ self.unfunded_seller_amount = unfunded_seller_amount
1539
+
1540
+ def __str__(self):
1541
+ return 'PayInIntentLineItem: %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s' % \
1542
+ (self.id, self.seller, self.sku, self.name, self.description, self.quantity, self.unit_amount, self.amount,
1543
+ self.tax_amount, self.discount_amount, self.category, self.shipping_address, self.total_line_item_amount,
1544
+ self.canceled_amount, self.captured_amount, self.refunded_amount, self.disputed_amount, self.split_amount,
1545
+ self.unfunded_seller_amount)
1546
+
1547
+ def to_api_json(self):
1548
+ return {
1549
+ "Id": self.id,
1550
+ "Seller": self.seller,
1551
+ "Sku": self.sku,
1552
+ "Name": self.name,
1553
+ "Description": self.description,
1554
+ "Quantity": self.quantity,
1555
+ "UnitAmount": self.unit_amount,
1556
+ "Amount": self.amount,
1557
+ "TaxAmount": self.tax_amount,
1558
+ "DiscountAmount": self.discount_amount,
1559
+ "Category": self.category,
1560
+ "ShippingAddress": self.shipping_address,
1561
+ "TotalLineItemAmount": self.total_line_item_amount,
1562
+ "CanceledAmount": self.canceled_amount,
1563
+ "CapturedAmount": self.captured_amount,
1564
+ "RefundedAmount": self.refunded_amount,
1565
+ "DisputedAmount": self.disputed_amount,
1566
+ "SplitAmount": self.split_amount,
1567
+ "UnfundedSellerAmount": self.unfunded_seller_amount
1568
+ }
1569
+
1570
+
1571
+ @add_camelcase_aliases
1572
+ class PayInIntentSeller(object):
1573
+ def __init__(self, author_id=None, wallet_id=None, fees_amount=None, transfer_date=None):
1574
+ self.author_id = author_id
1575
+ self.wallet_id = wallet_id
1576
+ self.fees_amount = fees_amount
1577
+ self.transfer_date = transfer_date
1578
+
1579
+ def __str__(self):
1580
+ return 'PayInIntentSeller: %s %s %s %s' % \
1581
+ (self.author_id, self.wallet_id, self.fees_amount, self.transfer_date)
1582
+
1583
+ def to_api_json(self):
1584
+ return {
1585
+ "AuthorId": self.author_id,
1586
+ "WalletId": self.wallet_id,
1587
+ "FeesAmount": self.fees_amount,
1588
+ "TransferDate": self.transfer_date
1589
+ }
1590
+
1591
+ @add_camelcase_aliases
1592
+ class IntentSplit(object):
1593
+ def __init__(self, line_item_id=None, wallet_id=None, seller_id=None, split_amount=None, fees_amount=None,
1594
+ transfer_date=None, description=None, status=None, tag=None):
1595
+ self.line_item_id = line_item_id
1596
+ self.wallet_id = wallet_id
1597
+ self.seller_id = seller_id
1598
+ self.split_amount = split_amount
1599
+ self.fees_amount = fees_amount
1600
+ self.description = description
1601
+ self.status = status
1602
+ self.transfer_date = transfer_date
1603
+ self.tag = tag
1604
+
1605
+ def __str__(self):
1606
+ return 'PayInIntentSplit: %s %s %s %s %s %s %s %s %s' % \
1607
+ (self.line_item_id, self.wallet_id, self.seller_id, self.split_amount, self.fees_amount, self.description,
1608
+ self.status, self.transfer_date, self.tag)
1609
+
1610
+ def to_api_json(self):
1611
+ return {
1612
+ "LineItemId": self.line_item_id,
1613
+ "WalletId": self.wallet_id,
1614
+ "SellerId": self.seller_id,
1615
+ "SplitAmount": self.split_amount,
1616
+ "FeesAmount": self.fees_amount,
1617
+ "Description": self.description,
1618
+ "Status": self.status,
1619
+ "TransferDate": self.transfer_date,
1620
+ "Tag": self.tag
1621
+ }
1622
+
1623
+
1624
+ @add_camelcase_aliases
1625
+ class SupportedBank(object):
1626
+ def __init__(self, countries=None):
1627
+ self.countries = countries
1628
+
1629
+ def __str__(self):
1630
+ return 'SupportedBank: %s' % self.countries
1631
+
1632
+ def __eq__(self, other):
1633
+ if isinstance(other, SupportedBank):
1634
+ stat = (self.countries == other.countries)
1635
+ return stat
1636
+ return False
1637
+
1638
+ def to_api_json(self):
1639
+ return {
1640
+ "Countries": self.countries
1641
+ }
1642
+
1643
+
1644
+ @add_camelcase_aliases
1645
+ class VerificationOfPayee(object):
1646
+ def __init__(self, recipient_verification_id=None, recipient_verification_check=None,
1647
+ recipient_verification_message=None):
1648
+ self.recipient_verification_id = recipient_verification_id
1649
+ self.recipient_verification_check = recipient_verification_check
1650
+ self.recipient_verification_message = recipient_verification_message
1651
+
1652
+ def __str__(self):
1653
+ return ('VerificationOfPayee: %s %s %s' % self.recipient_verification_id, self.recipient_verification_check,
1654
+ self.recipient_verification_message)
1655
+
1656
+ def to_api_json(self):
1657
+ return {
1658
+ "RecipientVerificationId": self.recipient_verification_id,
1659
+ "RecipientVerificationCheck": self.recipient_verification_check,
1660
+ "RecipientVerificationMessage": self.recipient_verification_message
1661
+ }
1662
+
1663
+
1664
+ @add_camelcase_aliases
1665
+ class CustomFees(object):
1666
+ def __init__(self, amount=None, currency=None,
1667
+ type=None, value=None):
1668
+ self.currency = currency
1669
+ self.type = type
1670
+
1671
+ if amount is not None:
1672
+ self.amount = decimal.Decimal(amount)
1673
+ else:
1674
+ self.amount = None
1675
+
1676
+ if value is not None:
1677
+ self.value = decimal.Decimal(value)
1678
+ else:
1679
+ self.value = None
1680
+
1681
+ def __str__(self):
1682
+ return force_text("CustomFees: {:,.2f} {} {} {:,.2f}".format(
1683
+ self.amount if self.amount is not None else 0.0,
1684
+ self.currency or "",
1685
+ self.type or "",
1686
+ self.value if self.value is not None else 0.0)
1687
+ )
1688
+
1689
+ def to_api_json(self):
1690
+ return {
1691
+ "Amount": self.amount,
1692
+ "Currency": self.currency,
1693
+ "Type": self.type,
1694
+ "Value": self.value
1695
+ }
1696
+
1697
+
1698
+ @add_camelcase_aliases
1699
+ class MarginsResponse(object):
1700
+ def __init__(self, mangopay=None, user=None):
1701
+ self.mangopay = mangopay
1702
+ self.user = user
1703
+
1704
+ def __str__(self):
1705
+ return 'MarginsResponse: %s %s' % self.mangopay, self.user
1706
+
1707
+ def to_api_json(self):
1708
+ return {
1709
+ "Mangopay": self.mangopay,
1710
+ "User": self.user
1711
+ }
1712
+
1713
+
1714
+ @add_camelcase_aliases
1715
+ class UserMargin(object):
1716
+ def __init__(self, type=None, value=None):
1717
+ self.type = type
1718
+
1719
+ if value is not None:
1720
+ self.value = decimal.Decimal(value)
1721
+ else:
1722
+ self.value = None
1723
+
1724
+ def __str__(self):
1725
+ return force_text(
1726
+ "UserMargin: {} {:,.2f}".format(
1727
+ self.type or "",
1728
+ self.value if self.value is not None else 0.0)
1729
+ )
1730
+
1731
+ def to_api_json(self):
1732
+ return {
1733
+ "Type": self.type,
1734
+ "Value": self.value
1735
+ }
1736
+
1737
+
1738
+ @add_camelcase_aliases
1739
+ class ConsentScope(object):
1740
+ def __init__(self, contact_information_update=None, recipient_registration=None,
1741
+ transfer=None, view_account_information=None):
1742
+ self.contact_information_update = contact_information_update
1743
+ self.recipient_registration = recipient_registration
1744
+ self.transfer = transfer
1745
+ self.view_account_information = view_account_information
1746
+
1747
+ def __str__(self):
1748
+ return ('ConsentScope: %s %s %s %s' % self.contact_information_update, self.recipient_registration,
1749
+ self.transfer, self.view_account_information)
1750
+
1751
+ def to_api_json(self):
1752
+ return {
1753
+ "ContactInformationUpdate": self.contact_information_update,
1754
+ "RecipientRegistration": self.recipient_registration,
1755
+ "Transfer": self.transfer,
1756
+ "ViewAccountInformation": self.view_account_information
1757
+ }
1758
+
1759
+
1760
+ @add_camelcase_aliases
1761
+ class PayInIntentRefund(object):
1762
+ def __init__(self, id=None):
1763
+ self.id = id
1764
+
1765
+ def __str__(self):
1766
+ return ('PayInIntentRefund: %s' % self.id)
1767
+
1768
+ def to_api_json(self):
1769
+ return {
1770
+ "Id": self.id
1771
+ }
1772
+
1773
+
1774
+ @add_camelcase_aliases
1775
+ class PayInIntentCapture(object):
1776
+ def __init__(self, id=None):
1777
+ self.id = id
1778
+
1779
+ def __str__(self):
1780
+ return ('PayInIntentCapture: %s' % self.id)
1781
+
1782
+ def to_api_json(self):
1783
+ return {
1784
+ "Id": self.id
1785
+ }
1786
+
1787
+
1788
+ @add_camelcase_aliases
1789
+ class PayInIntentDispute(object):
1790
+ def __init__(self, id=None):
1791
+ self.id = id
1792
+
1793
+ def __str__(self):
1794
+ return ('PayInIntentDispute: %s' % self.id)
1795
+
1796
+ def to_api_json(self):
1797
+ return {
1798
+ "Id": self.id
1799
+ }
1800
+
1801
+
1802
+ @add_camelcase_aliases
1803
+ class AuthenticationResult(object):
1804
+ def __init__(self, authentication_type=None):
1805
+ self.authentication_type = authentication_type
1806
+
1807
+ def __str__(self):
1808
+ return 'AuthenticationResult: %s' % self.authentication_type
1809
+
1810
+ def to_api_json(self):
1811
+ return {
1812
+ "AuthenticationType": self.authentication_type
1813
+ }
1814
+
1815
+
1816
+ @add_camelcase_aliases
1817
+ class FlowDescriptor(object):
1818
+ def __init__(self, flow_id=None, beneficiaries=None):
1819
+ self.flow_id = flow_id
1820
+ self.beneficiaries = beneficiaries
1821
+
1822
+ def __str__(self):
1823
+ return 'FlowDescriptor: %s %s' % (self.flow_id, self.beneficiaries)
1824
+
1825
+ def to_api_json(self):
1826
+ return {
1827
+ "FlowId": self.flow_id,
1828
+ "Beneficiaries": self.beneficiaries
1829
+ }
1830
+
1831
+
1832
+ @add_camelcase_aliases
1833
+ class SettlementFooterError(object):
1834
+ def __init__(self, footer_name=None, code=None, description=None):
1835
+ self.footer_name = footer_name
1836
+ self.code = code
1837
+ self.description = description
1838
+
1839
+ def __str__(self):
1840
+ return 'SettlementFooterError: %s %s %s' % (self.footer_name, self.code, self.description)
1841
+
1842
+ def to_api_json(self):
1843
+ return {
1844
+ "FooterName": self.footer_name,
1845
+ "Code": self.code,
1846
+ "Description": self.description
1847
+ }
1848
+
1849
+
1850
+ @add_camelcase_aliases
1851
+ class SettlementLineErrorDetail(object):
1852
+ def __init__(self, code=None, description=None):
1853
+ self.code = code
1854
+ self.description = description
1855
+
1856
+ def __str__(self):
1857
+ return 'SettlementLineErrorDetail: %s %s' % (self.code, self.description)
1858
+
1859
+ def to_api_json(self):
1860
+ return {
1861
+ "Code": self.code,
1862
+ "Description": self.description
1863
+ }
1864
+
1865
+
1866
+ @add_camelcase_aliases
1867
+ class SettlementLineError(object):
1868
+ def __init__(self, external_provider_reference=None, external_transaction_type=None, details=None):
1869
+ self.external_provider_reference = external_provider_reference
1870
+ self.external_transaction_type = external_transaction_type
1871
+ self.details = details
1872
+
1873
+ def __str__(self):
1874
+ return 'SettlementLineError: %s %s' % (self.external_provider_reference, self.external_transaction_type)
1875
+
1876
+ def to_api_json(self):
1877
+ details = self.details
1878
+ if isinstance(details, list):
1879
+ details = [d.to_api_json() if isinstance(d, SettlementLineErrorDetail) else d for d in details]
1880
+
1881
+ return {
1882
+ "ExternalProviderReference": self.external_provider_reference,
1883
+ "ExternalTransactionType": self.external_transaction_type,
1884
+ "Details": details
1885
+ }