mangopay4-python-sdk 3.52.0__py2.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,1582 @@
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 CurrentState(object):
575
+ def __init__(self, payins_linked=None, cumulated_debited_amount=None, cumulated_debited_fees=None,
576
+ last_payin_id=None):
577
+ self.payins_linked = payins_linked
578
+ self.cumulated_debited_amount = cumulated_debited_amount
579
+ self.cumulated_debited_fees = cumulated_debited_fees
580
+ self.last_payin_id = last_payin_id
581
+
582
+ def __str__(self):
583
+ return 'CurrentState: %s' % \
584
+ (self.cumulated_debited_amount, self.cumulated_debited_fees, self.last_payin_id, self.payins_linked)
585
+
586
+
587
+ @add_camelcase_aliases
588
+ class ScopeBlocked(object):
589
+ def __init__(self, inflows=None, outflows=None):
590
+ self.inflows = inflows
591
+ self.outflows = outflows
592
+
593
+ def __str__(self):
594
+ return 'ScopeBlocked: %s, %s' % (self.inflows, self.outflows)
595
+
596
+ def __eq__(self, other):
597
+ if isinstance(other, ScopeBlocked):
598
+ stat = ((self.inflows == other.inflows) and
599
+ (self.outflows == other.outflows))
600
+ return stat
601
+ return False
602
+
603
+ def to_api_json(self):
604
+ return {
605
+ "Inflows": self.inflows,
606
+ "Outflows": self.outflows,
607
+ }
608
+
609
+
610
+ # This code belongs to https://github.com/carljm/django-model-utils
611
+ class Choices(object):
612
+ """
613
+ A class to encapsulate handy functionality for lists of choices
614
+ for a Django model field.
615
+ Each argument to ``Choices`` is a choice, represented as either a
616
+ string, a two-tuple, or a three-tuple.
617
+ If a single string is provided, that string is used as the
618
+ database representation of the choice as well as the
619
+ human-readable presentation.
620
+ If a two-tuple is provided, the first item is used as the database
621
+ representation and the second the human-readable presentation.
622
+ If a triple is provided, the first item is the database
623
+ representation, the second a valid Python identifier that can be
624
+ used as a readable label in code, and the third the human-readable
625
+ presentation. This is most useful when the database representation
626
+ must sacrifice readability for some reason: to achieve a specific
627
+ ordering, to use an integer rather than a character field, etc.
628
+ Regardless of what representation of each choice is originally
629
+ given, when iterated over or indexed into, a ``Choices`` object
630
+ behaves as the standard Django choices list of two-tuples.
631
+ If the triple form is used, the Python identifier names can be
632
+ accessed as attributes on the ``Choices`` object, returning the
633
+ database representation. (If the single or two-tuple forms are
634
+ used and the database representation happens to be a valid Python
635
+ identifier, the database representation itself is available as an
636
+ attribute on the ``Choices`` object, returning itself.)
637
+ Option groups can also be used with ``Choices``; in that case each
638
+ argument is a tuple consisting of the option group name and a list
639
+ of options, where each option in the list is either a string, a
640
+ two-tuple, or a triple as outlined above.
641
+ """
642
+
643
+ def __init__(self, *choices):
644
+ # list of choices expanded to triples - can include optgroups
645
+ self._triples = []
646
+ # list of choices as (db, human-readable) - can include optgroups
647
+ self._doubles = []
648
+ # dictionary mapping db representation to human-readable
649
+ self._display_map = {}
650
+ # dictionary mapping Python identifier to db representation
651
+ self._identifier_map = {}
652
+ # set of db representations
653
+ self._db_values = set()
654
+
655
+ self._process(choices)
656
+
657
+ def _store(self, triple, triple_collector, double_collector):
658
+ self._identifier_map[triple[1]] = triple[0]
659
+ self._display_map[triple[0]] = triple[2]
660
+ self._db_values.add(triple[0])
661
+ triple_collector.append(triple)
662
+ double_collector.append((triple[0], triple[2]))
663
+
664
+ def _process(self, choices, triple_collector=None, double_collector=None):
665
+ if triple_collector is None:
666
+ triple_collector = self._triples
667
+ if double_collector is None:
668
+ double_collector = self._doubles
669
+
670
+ store = lambda c: self._store(c, triple_collector, double_collector)
671
+
672
+ for choice in choices:
673
+ if isinstance(choice, (list, tuple)):
674
+ if len(choice) == 3:
675
+ store(choice)
676
+ elif len(choice) == 2:
677
+ if isinstance(choice[1], (list, tuple)):
678
+ # option group
679
+ group_name = choice[0]
680
+ subchoices = choice[1]
681
+ tc = []
682
+ triple_collector.append((group_name, tc))
683
+ dc = []
684
+ double_collector.append((group_name, dc))
685
+ self._process(subchoices, tc, dc)
686
+ else:
687
+ store((choice[0], choice[0], choice[1]))
688
+ else:
689
+ raise ValueError(
690
+ "Choices can't take a list of length %s, only 2 or 3"
691
+ % len(choice))
692
+ else:
693
+ store((choice, choice, choice))
694
+
695
+ def __len__(self):
696
+ return len(self._doubles)
697
+
698
+ def __iter__(self):
699
+ return iter(self._doubles)
700
+
701
+ def __getattr__(self, attname):
702
+ try:
703
+ return self._identifier_map[attname]
704
+ except KeyError:
705
+ raise AttributeError(attname)
706
+
707
+ def __getitem__(self, key):
708
+ return self._display_map[key]
709
+
710
+ def __add__(self, other):
711
+ if isinstance(other, self.__class__):
712
+ other = other._triples
713
+ else:
714
+ other = list(other)
715
+ return Choices(*(self._triples + other))
716
+
717
+ def __radd__(self, other):
718
+ # radd is never called for matching types, so we don't check here
719
+ other = list(other)
720
+ return Choices(*(other + self._triples))
721
+
722
+ def __eq__(self, other):
723
+ if isinstance(other, self.__class__):
724
+ return self._triples == other._triples
725
+ return False
726
+
727
+ def __repr__(self):
728
+ return '%s(%s)' % (
729
+ self.__class__.__name__,
730
+ ', '.join(("%s" % repr(i) for i in self._triples)))
731
+
732
+ def __contains__(self, item):
733
+ return item in self._db_values
734
+
735
+ def __deepcopy__(self, memo):
736
+ return self.__class__(*copy.deepcopy(self._triples, memo))
737
+
738
+
739
+ def timestamp_from_datetime(dt):
740
+ """
741
+ Compute timestamp from a datetime object that could be timezone aware
742
+ or unaware.
743
+ """
744
+ try:
745
+ utc_dt = dt.astimezone(pytz.utc)
746
+ except ValueError:
747
+ utc_dt = dt.replace(tzinfo=pytz.utc)
748
+ return timegm(utc_dt.timetuple())
749
+
750
+
751
+ def timestamp_from_date(date):
752
+ epoch = datetime.date(1970, 1, 1)
753
+ diff = date - epoch
754
+ return diff.days * 24 * 3600 + diff.seconds
755
+
756
+
757
+ if six.PY3:
758
+ memoryview = memoryview
759
+ else:
760
+ memoryview = buffer # noqa
761
+
762
+
763
+ def is_protected_type(obj):
764
+ """Determine if the object instance is of a protected type.
765
+
766
+ Objects of protected types are preserved as-is when passed to
767
+ force_text(strings_only=True).
768
+ """
769
+ return isinstance(obj, six.integer_types + (type(None), float, decimal.Decimal,
770
+ datetime.datetime, datetime.date, datetime.time))
771
+
772
+
773
+ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
774
+ """
775
+ Similar to smart_text, except that lazy instances are resolved to
776
+ strings, rather than kept as lazy objects.
777
+
778
+ If strings_only is True, don't convert (some) non-string-like objects.
779
+ """
780
+ # Handle the common case first, saves 30-40% when s is an instance of
781
+ # six.text_type. This function gets called often in that setting.
782
+ if isinstance(s, six.text_type):
783
+ return s
784
+ if strings_only and is_protected_type(s):
785
+ return s
786
+ try:
787
+ if not isinstance(s, six.string_types):
788
+ if hasattr(s, '__unicode__'):
789
+ s = s.__unicode__()
790
+ else:
791
+ if six.PY3:
792
+ if isinstance(s, bytes):
793
+ s = six.text_type(s, encoding, errors)
794
+ else:
795
+ s = six.text_type(s)
796
+ else:
797
+ s = six.text_type(bytes(s), encoding, errors)
798
+ else:
799
+ # Note: We use .decode() here, instead of six.text_type(s, encoding,
800
+ # errors), so that if s is a SafeBytes, it ends up being a
801
+ # SafeText at the end.
802
+ s = s.decode(encoding, errors)
803
+ except UnicodeDecodeError:
804
+ # If we get to here, the caller has passed in an Exception
805
+ # subclass populated with non-ASCII bytestring data without a
806
+ # working unicode method. Try to handle this without raising a
807
+ # further exception by individually forcing the exception args
808
+ # to unicode.
809
+ s = ' '.join([force_text(arg, encoding, strings_only,
810
+ errors) for arg in s])
811
+ return s
812
+
813
+
814
+ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
815
+ """
816
+ Similar to smart_bytes, except that lazy instances are resolved to
817
+ strings, rather than kept as lazy objects.
818
+
819
+ If strings_only is True, don't convert (some) non-string-like objects.
820
+ """
821
+ if isinstance(s, memoryview):
822
+ s = bytes(s)
823
+ if isinstance(s, bytes):
824
+ if encoding == 'utf-8':
825
+ return s
826
+ else:
827
+ return s.decode('utf-8', errors).encode(encoding, errors)
828
+ if strings_only and (s is None or isinstance(s, int)):
829
+ return s
830
+ if not isinstance(s, six.string_types):
831
+ try:
832
+ if six.PY3:
833
+ return six.text_type(s).encode(encoding)
834
+ else:
835
+ return bytes(s)
836
+ except UnicodeEncodeError:
837
+ if isinstance(s, Exception):
838
+ # An Exception subclass containing non-ASCII data that doesn't
839
+ # know how to print itself properly. We shouldn't raise a
840
+ # further exception.
841
+ return b' '.join([force_bytes(arg, encoding, strings_only,
842
+ errors) for arg in s])
843
+ return six.text_type(s).encode(encoding, errors)
844
+ else:
845
+ return s.encode(encoding, errors)
846
+
847
+
848
+ if six.PY3:
849
+ force_str = force_text
850
+ else:
851
+ force_str = force_bytes
852
+
853
+
854
+ def memoize(func, cache, num_args):
855
+ """
856
+ Wrap a function so that results for any argument tuple are stored in
857
+ 'cache'. Note that the args to the function must be usable as dictionary
858
+ keys.
859
+ Only the first num_args are considered when creating the key.
860
+ """
861
+
862
+ @wraps(func)
863
+ def wrapper(*args):
864
+ mem_args = args[:num_args]
865
+ if mem_args in cache:
866
+ return cache[mem_args]
867
+ result = func(*args)
868
+ cache[mem_args] = result
869
+ return result
870
+
871
+ return wrapper
872
+
873
+
874
+ def reraise_as(new_exception_or_type):
875
+ """
876
+ Obtained from https://github.com/dcramer/reraise/blob/master/src/reraise.py
877
+ >>> try:
878
+ >>> do_something_crazy()
879
+ >>> except Exception:
880
+ >>> reraise_as(UnhandledException)
881
+ """
882
+ __traceback_hide__ = True # NOQA
883
+
884
+ e_type, e_value, e_traceback = sys.exc_info()
885
+
886
+ if inspect.isclass(new_exception_or_type):
887
+ new_type = new_exception_or_type
888
+ new_exception = new_exception_or_type()
889
+ else:
890
+ new_type = type(new_exception_or_type)
891
+ new_exception = new_exception_or_type
892
+
893
+ new_exception.__cause__ = e_value
894
+
895
+ try:
896
+ six.reraise(new_type, new_exception, e_traceback)
897
+ finally:
898
+ del e_traceback
899
+
900
+
901
+ def truncatechars(value, length=255):
902
+ if isinstance(value, dict):
903
+ for k, v in value.items():
904
+ value[k] = truncatechars(v)
905
+ elif isinstance(value, six.string_types):
906
+ return (value[:length] + '...') if len(value) > length else value
907
+
908
+ return value
909
+
910
+
911
+ class CountryAuthorizationData(object):
912
+ def __init__(self, block_user_creation=None, block_bank_account_creation=None, block_payout=None):
913
+ self.block_user_creation = block_user_creation
914
+ self.block_bank_account_creation = block_bank_account_creation
915
+ self.block_payout = block_payout
916
+
917
+ def __str__(self):
918
+ return 'CountryAuthorizationData: %s, %s , %s' % \
919
+ (self.block_user_creation, self.block_bank_account_creation, self.block_payout)
920
+
921
+ def __eq__(self, other):
922
+ if isinstance(other, CountryAuthorizationData):
923
+ stat = ((self.block_user_creation == other.block_user_creation) and
924
+ (self.block_bank_account_creation == other.block_bank_account_creation) and
925
+ (self.block_payout == other.block_payout))
926
+ return stat
927
+ return False
928
+
929
+ def to_api_json(self):
930
+ return {
931
+ "BlockUserCreation": self.block_user_creation,
932
+ "BlockBankAccountCreation": self.block_bank_account_creation,
933
+ "BlockPayout": self.block_payout
934
+ }
935
+
936
+
937
+ class PayinsLinked(object):
938
+ def __init__(self, payin_capture_id=None, payin_complement_id=None):
939
+ self.payin_capture_id = payin_capture_id
940
+ self.payin_complement_id = payin_complement_id
941
+
942
+ def __str__(self):
943
+ return 'PayinsLinked: %s, %s' % \
944
+ (self.payin_capture_id, self.payin_complement_id)
945
+
946
+ def to_api_json(self):
947
+ return {
948
+ "PayinCaptureId": self.payin_capture_id,
949
+ "PayinComplementId": self.payin_complement_id
950
+ }
951
+
952
+
953
+ class LineItem(object):
954
+ def __init__(self, name=None, quantity=None, unit_amount=None, tax_amount=None, description=None, category=None,
955
+ sku=None):
956
+ self.name = name
957
+ self.quantity = quantity
958
+ self.unit_amount = unit_amount
959
+ self.tax_amount = tax_amount
960
+ self.description = description
961
+ self.category = category
962
+ self.sku = sku
963
+
964
+ def __str__(self):
965
+ return 'LineItem: %s %s %s %s %s %s %s' % \
966
+ (self.name, self.quantity, self.unit_amount, self.tax_amount, self.description, self.category, self.sku)
967
+
968
+ def to_api_json(self):
969
+ return {
970
+ "Name": self.name,
971
+ "Quantity": self.quantity,
972
+ "UnitAmount": self.unit_amount,
973
+ "TaxAmount": self.tax_amount,
974
+ "Description": self.description,
975
+ "Category": self.category,
976
+ "Sku": self.sku
977
+ }
978
+
979
+
980
+ @add_camelcase_aliases
981
+ class ConversionRate(object):
982
+ def __init__(self, client_rate=None, market_rate=None):
983
+ self.client_rate = client_rate
984
+ self.market_rate = market_rate
985
+
986
+ def __str__(self):
987
+ return 'Conversion rate: %s %s' % \
988
+ (self.client_rate, self.market_rate)
989
+
990
+ def to_api_json(self):
991
+ return {
992
+ "ClientRate": self.client_rate,
993
+ "MarketRate": self.market_rate
994
+ }
995
+
996
+
997
+ @add_camelcase_aliases
998
+ class CardInfo(object):
999
+ def __init__(self,
1000
+ bin=None,
1001
+ issuing_bank=None,
1002
+ issuer_country_code=None,
1003
+ type=None,
1004
+ brand=None,
1005
+ sub_type=None):
1006
+ self.bin = bin
1007
+ self.issuing_bank = issuing_bank
1008
+ self.issuer_country_code = issuer_country_code
1009
+ self.type = type
1010
+ self.brand = brand
1011
+ self.sub_type = sub_type
1012
+
1013
+ def __str__(self):
1014
+ return 'Card info: %s %s %s %s %s %s' % \
1015
+ (self.bin, self.issuing_bank, self.issuer_country_code, self.type, self.brand, self.sub_type)
1016
+
1017
+ def to_api_json(self):
1018
+ return {
1019
+ "BIN": self.bin,
1020
+ "IssuingBank": self.issuing_bank,
1021
+ "IssuerCountryCode": self.issuer_country_code,
1022
+ "Type": self.type,
1023
+ "Brand": self.brand,
1024
+ "SubType": self.sub_type
1025
+ }
1026
+
1027
+
1028
+ class PayPalTrackingInformation(object):
1029
+ def __init__(self, tracking_number=None, carrier=None, notify_buyer=None):
1030
+ self.tracking_number = tracking_number
1031
+ self.carrier = carrier
1032
+ self.notify_buyer = notify_buyer
1033
+
1034
+ def __str__(self):
1035
+ return 'PayPalTrackingInformation: %s %s %s' % \
1036
+ (self.tracking_number, self.carrier, self.notify_buyer)
1037
+
1038
+ def to_api_json(self):
1039
+ return {
1040
+ "TrackingNumber": self.tracking_number,
1041
+ "Carrier": self.carrier,
1042
+ "NotifyBuyer": self.notify_buyer
1043
+ }
1044
+
1045
+
1046
+ class LocalAccountDetails(object):
1047
+ def __init__(self, address=None, account=None, bank_name=None):
1048
+ self.address = address
1049
+ self.account = account
1050
+ self.bank_name = bank_name
1051
+
1052
+ def __str__(self):
1053
+ return 'LocalAccountDetails: %s %s %s' % \
1054
+ (self.address, self.account, self.bank_name)
1055
+
1056
+ def to_api_json(self):
1057
+ return {
1058
+ "Address": self.address,
1059
+ "Account": self.account,
1060
+ "BankName": self.bank_name
1061
+ }
1062
+
1063
+
1064
+ class InternationalAccountDetails(object):
1065
+ def __init__(self, address=None, account=None, bank_name=None):
1066
+ self.address = address
1067
+ self.account = account
1068
+ self.bank_name = bank_name
1069
+
1070
+ def __str__(self):
1071
+ return 'InternationalAccountDetails: %s %s %s' % \
1072
+ (self.address, self.account, self.bank_name)
1073
+
1074
+ def to_api_json(self):
1075
+ return {
1076
+ "Address": self.address,
1077
+ "Account": self.account,
1078
+ "BankName": self.bank_name
1079
+ }
1080
+
1081
+
1082
+ class VirtualAccountCapabilities(object):
1083
+ def __init__(self, local_pay_in_available=None, international_pay_in_available=None, currencies=None):
1084
+ self.local_pay_in_available = local_pay_in_available
1085
+ self.international_pay_in_available = international_pay_in_available
1086
+ self.currencies = currencies
1087
+
1088
+ def __str__(self):
1089
+ return 'VirtualAccountCapabilities: %s %s %s' % \
1090
+ (self.local_pay_in_available, self.international_pay_in_available, self.currencies)
1091
+
1092
+ def to_api_json(self):
1093
+ return {
1094
+ "LocalPayinAvailable": self.local_pay_in_available,
1095
+ "InternationalPayinAvailable": self.international_pay_in_available,
1096
+ "Currencies": self.currencies
1097
+ }
1098
+
1099
+
1100
+ @add_camelcase_aliases
1101
+ class PendingUserAction(object):
1102
+ def __init__(self, redirect_url=None):
1103
+ self.redirect_url = redirect_url
1104
+
1105
+ def __str__(self):
1106
+ return 'PendingUserAction: %s' % self.redirect_url
1107
+
1108
+ def __eq__(self, other):
1109
+ if isinstance(other, PendingUserAction):
1110
+ stat = (self.redirect_url == other.redirect_url)
1111
+ return stat
1112
+ return False
1113
+
1114
+ def to_api_json(self):
1115
+ return {
1116
+ "RedirectUrl": self.redirect_url
1117
+ }
1118
+
1119
+
1120
+ @add_camelcase_aliases
1121
+ class LegalRepresentative(object):
1122
+ def __init__(self, first_name=None, last_name=None, birthday=None, nationality=None, country_of_residence=None,
1123
+ email=None, phone_number=None, phone_number_country=None):
1124
+ self.first_name = first_name
1125
+ self.last_name = last_name
1126
+ self.birthday = birthday
1127
+ self.nationality = nationality
1128
+ self.country_of_residence = country_of_residence
1129
+ self.email = email
1130
+ self.phone_number = phone_number
1131
+ self.phone_number_country = phone_number_country
1132
+
1133
+ def __str__(self):
1134
+ return 'LegalRepresentative: %s , %s, %s, %s, %s, %s, %s, %s' % \
1135
+ (self.first_name, self.last_name, self.birthday, self.nationality,
1136
+ self.country_of_residence, self.email, self.phone_number, self.phone_number_country)
1137
+
1138
+ def __eq__(self, other):
1139
+ if isinstance(other, LegalRepresentative):
1140
+ stat = ((self.first_name == other.first_name) and
1141
+ (self.last_name == other.last_name) and
1142
+ (self.birthday == other.birthday) and
1143
+ (self.nationality == other.nationality) and
1144
+ (self.country_of_residence == other.country_of_residence) and
1145
+ (self.email == other.email) and
1146
+ (self.phone_number == other.phone_number) and
1147
+ (self.phone_number_country == other.phone_number_country))
1148
+ return stat
1149
+ return False
1150
+
1151
+ def to_api_json(self):
1152
+ return {
1153
+ "FirstName": self.first_name,
1154
+ "LastName": self.last_name,
1155
+ "Birthday": self.birthday,
1156
+ "Nationality": self.nationality,
1157
+ "CountryOfResidence": self.country_of_residence,
1158
+ "Email": self.email,
1159
+ "PhoneNumber": self.phone_number,
1160
+ "PhoneNumberCountry": self.phone_number_country
1161
+ }
1162
+
1163
+
1164
+ @add_camelcase_aliases
1165
+ class IndividualRecipient(object):
1166
+ def __init__(self, first_name=None, last_name=None, address=None):
1167
+ self.first_name = first_name
1168
+ self.last_name = last_name
1169
+ self.address = address
1170
+
1171
+ def __str__(self):
1172
+ return 'IndividualRecipient: %s , %s, %s' % \
1173
+ (self.first_name, self.last_name, self.address)
1174
+
1175
+ def __eq__(self, other):
1176
+ if isinstance(other, IndividualRecipient):
1177
+ stat = ((self.first_name == other.first_name) and
1178
+ (self.last_name == other.last_name) and
1179
+ (self.address == other.address))
1180
+ return stat
1181
+ return False
1182
+
1183
+ def to_api_json(self):
1184
+ return {
1185
+ "FirstName": self.first_name,
1186
+ "LastName": self.last_name,
1187
+ "Address": self.address
1188
+ }
1189
+
1190
+
1191
+ @add_camelcase_aliases
1192
+ class BusinessRecipient(object):
1193
+ def __init__(self, business_name=None, address=None):
1194
+ self.business_name = business_name
1195
+ self.address = address
1196
+
1197
+ def __str__(self):
1198
+ return 'BusinessRecipient: %s , %s' % \
1199
+ (self.business_name, self.address)
1200
+
1201
+ def __eq__(self, other):
1202
+ if isinstance(other, BusinessRecipient):
1203
+ stat = ((self.business_name == other.business_name) and
1204
+ (self.address == other.address))
1205
+ return stat
1206
+ return False
1207
+
1208
+ def to_api_json(self):
1209
+ return {
1210
+ "BusinessName": self.business_name,
1211
+ "Address": self.address
1212
+ }
1213
+
1214
+
1215
+ @add_camelcase_aliases
1216
+ class RecipientPropertySchema(object):
1217
+ def __init__(self, required=None, max_length=None, min_length=None, pattern=None, allowed_values=None, label=None,
1218
+ end_user_display=None):
1219
+ self.required = required
1220
+ self.max_length = max_length
1221
+ self.min_length = min_length
1222
+ self.pattern = pattern
1223
+ self.allowed_values = allowed_values
1224
+ self.label = label
1225
+ self.end_user_display = end_user_display
1226
+
1227
+ def __str__(self):
1228
+ return 'RecipientPropertySchema: %s , %s, %s, %s, %s, %s, %s' % \
1229
+ (self.required, self.max_length, self.min_length, self.pattern, self.allowed_values, self.label,
1230
+ self.end_user_display)
1231
+
1232
+ def __eq__(self, other):
1233
+ if isinstance(other, RecipientPropertySchema):
1234
+ stat = ((self.required == other.required) and
1235
+ (self.max_length == other.max_length) and
1236
+ (self.min_length == other.min_length) and
1237
+ (self.pattern == other.pattern) and
1238
+ (self.allowed_values == other.allowed_values) and
1239
+ (self.label == other.label) and
1240
+ (self.end_user_display == other.end_user_display))
1241
+ return stat
1242
+ return False
1243
+
1244
+ def to_api_json(self):
1245
+ return {
1246
+ "Required": self.required,
1247
+ "MaxLength": self.max_length,
1248
+ "MinLength": self.min_length,
1249
+ "Pattern": self.pattern,
1250
+ "AllowedValues": self.allowed_values,
1251
+ "Label": self.label,
1252
+ "EndUserDisplay": self.end_user_display
1253
+ }
1254
+
1255
+
1256
+ @add_camelcase_aliases
1257
+ class IndividualRecipientPropertySchema(object):
1258
+ def __init__(self, first_name=None, last_name=None, address=None):
1259
+ self.first_name = first_name
1260
+ self.last_name = last_name
1261
+ self.address = address
1262
+
1263
+ def __str__(self):
1264
+ return 'IndividualRecipientPropertySchema: %s , %s, %s' % \
1265
+ (self.first_name, self.last_name, self.address)
1266
+
1267
+ def __eq__(self, other):
1268
+ if isinstance(other, IndividualRecipientPropertySchema):
1269
+ stat = ((self.first_name == other.first_name) and
1270
+ (self.last_name == other.last_name) and
1271
+ (self.address == other.address))
1272
+ return stat
1273
+ return False
1274
+
1275
+ def to_api_json(self):
1276
+ return {
1277
+ "FirstName": self.first_name,
1278
+ "LastName": self.last_name,
1279
+ "Address": self.address
1280
+ }
1281
+
1282
+
1283
+ @add_camelcase_aliases
1284
+ class BusinessRecipientPropertySchema(object):
1285
+ def __init__(self, business_name=None, address=None):
1286
+ self.business_name = business_name
1287
+ self.address = address
1288
+
1289
+ def __str__(self):
1290
+ return 'BusinessRecipientPropertySchema: %s , %s' % \
1291
+ (self.business_name, self.address)
1292
+
1293
+ def __eq__(self, other):
1294
+ if isinstance(other, BusinessRecipientPropertySchema):
1295
+ stat = ((self.business_name == other.business_name) and
1296
+ (self.address == other.address))
1297
+ return stat
1298
+ return False
1299
+
1300
+ def to_api_json(self):
1301
+ return {
1302
+ "BusinessName": self.business_name,
1303
+ "Address": self.address
1304
+ }
1305
+
1306
+
1307
+ @add_camelcase_aliases
1308
+ class CompanyNumberValidation(object):
1309
+ def __init__(self, company_number=None, country_code=None, is_valid=None, validation_rules=None):
1310
+ self.company_number = company_number
1311
+ self.country_code = country_code
1312
+ self.is_valid = is_valid
1313
+ self.validation_rules = validation_rules
1314
+
1315
+ def __str__(self):
1316
+ return 'CompanyNumberValidation: %s , %s, %s, %s' % \
1317
+ (self.company_number, self.country_code, self.is_valid, self.validation_rules)
1318
+
1319
+ def __eq__(self, other):
1320
+ if isinstance(other, CompanyNumberValidation):
1321
+ stat = ((self.company_number == other.company_number) and
1322
+ (self.country_code == other.country_code) and
1323
+ (self.is_valid == other.is_valid) and
1324
+ (self.validation_rules == other.validation_rules))
1325
+ return stat
1326
+ return False
1327
+
1328
+ def to_api_json(self):
1329
+ return {
1330
+ "CompanyNumber": self.company_number,
1331
+ "CountryCode": self.country_code,
1332
+ "IsValid": self.is_valid,
1333
+ "ValidationRules": self.validation_rules
1334
+ }
1335
+
1336
+
1337
+ @add_camelcase_aliases
1338
+ class ReportFilter(object):
1339
+ def __init__(self, currency=None, user_id=None, wallet_id=None, payment_method=None, status=None, type=None,
1340
+ intent_id=None,
1341
+ external_provider_name=None, scheduled=None):
1342
+ self.currency = currency
1343
+ self.user_id = user_id
1344
+ self.wallet_id = wallet_id
1345
+ self.payment_method = payment_method
1346
+ self.status = status
1347
+ self.type = type
1348
+ self.intent_id = intent_id
1349
+ self.external_provider_name = external_provider_name
1350
+ self.scheduled = scheduled
1351
+
1352
+ def __str__(self):
1353
+ return 'ReportFilter: %s, %s, %s, %s, %s, %s, %s, %s, %s' % \
1354
+ (self.currency, self.user_id, self.wallet_id, self.payment_method, self.status, self.type, self.intent_id,
1355
+ self.external_provider_name, self.scheduled)
1356
+
1357
+ def __eq__(self, other):
1358
+ if isinstance(other, ReportFilter):
1359
+ stat = ((self.currency == other.currency) and
1360
+ (self.user_id == other.user_id) and
1361
+ (self.wallet_id == other.wallet_id) and
1362
+ (self.payment_method == other.payment_method) and
1363
+ (self.status == other.status) and
1364
+ (self.type == other.type) and
1365
+ (self.intent_id == other.intent_id) and
1366
+ (self.external_provider_name == other.external_provider_name) and
1367
+ (self.scheduled == other.scheduled))
1368
+ return stat
1369
+ return False
1370
+
1371
+ def to_api_json(self):
1372
+ return {
1373
+ "Currency": self.currency,
1374
+ "UserId": self.user_id,
1375
+ "WalletId": self.wallet_id,
1376
+ "PaymentMethod": self.payment_method,
1377
+ "Status": self.status,
1378
+ "Type": self.type,
1379
+ "IntentId": self.intent_id,
1380
+ "ExternalProviderName": self.external_provider_name,
1381
+ "Scheduled": self.scheduled
1382
+ }
1383
+
1384
+
1385
+ @add_camelcase_aliases
1386
+ class PayInIntentExternalData(object):
1387
+ def __init__(self, external_processing_date=None, external_provider_reference=None,
1388
+ external_merchant_reference=None, external_provider_name=None, external_provider_payment_method=None):
1389
+ self.external_processing_date = external_processing_date
1390
+ self.external_provider_reference = external_provider_reference
1391
+ self.external_merchant_reference = external_merchant_reference
1392
+ self.external_provider_name = external_provider_name
1393
+ self.external_provider_payment_method = external_provider_payment_method
1394
+
1395
+ def __str__(self):
1396
+ return 'PayInIntentExternalData: %s %s %s %s %s' % \
1397
+ (self.external_processing_date, self.external_provider_reference, self.external_merchant_reference,
1398
+ self.external_provider_name, self.external_provider_payment_method)
1399
+
1400
+ def __eq__(self, other):
1401
+ if isinstance(other, PayInIntentExternalData):
1402
+ stat = ((self.external_processing_date == other.external_processing_date) and
1403
+ (self.external_provider_reference == other.external_provider_reference) and
1404
+ (self.external_merchant_reference == other.external_merchant_reference) and
1405
+ (self.external_provider_name == other.external_provider_name) and
1406
+ (self.external_provider_payment_method == other.external_provider_payment_method))
1407
+ return stat
1408
+ return False
1409
+
1410
+ def to_api_json(self):
1411
+ return {
1412
+ "ExternalProcessingDate": self.external_processing_date,
1413
+ "ExternalProviderReference": self.external_provider_reference,
1414
+ "ExternalMerchantReference": self.external_merchant_reference,
1415
+ "ExternalProviderName": self.external_provider_name,
1416
+ "ExternalProviderPaymentMethod": self.external_provider_payment_method
1417
+ }
1418
+
1419
+
1420
+ @add_camelcase_aliases
1421
+ class PayInIntentBuyer(object):
1422
+ def __init__(self, id=None):
1423
+ self.id = id
1424
+
1425
+ def __str__(self):
1426
+ return 'PayInIntentBuyer: %s' % self.id
1427
+
1428
+ def __eq__(self, other):
1429
+ if isinstance(other, PayInIntentBuyer):
1430
+ stat = (self.id == other.id)
1431
+ return stat
1432
+ return False
1433
+
1434
+ def to_api_json(self):
1435
+ return {
1436
+ "Id": self.id
1437
+ }
1438
+
1439
+
1440
+ @add_camelcase_aliases
1441
+ class PayInIntentLineItem(object):
1442
+ def __init__(self, id=None, seller=None, sku=None, name=None, description=None, quantity=None, unit_amount=None, amount=None,
1443
+ tax_amount=None, discount_amount=None, category=None, shipping_address=None,
1444
+ total_line_item_amount=None, canceled_amount=None, captured_amount=None, refunded_amount=None,
1445
+ disputed_amount=None, split_amount=None):
1446
+ self.id = id
1447
+ self.seller = seller
1448
+ self.sku = sku
1449
+ self.name = name
1450
+ self.description = description
1451
+ self.quantity = quantity
1452
+ self.unit_amount = unit_amount
1453
+ self.amount = amount
1454
+ self.tax_amount = tax_amount
1455
+ self.discount_amount = discount_amount
1456
+ self.category = category
1457
+ self.shipping_address = shipping_address
1458
+ self.total_line_item_amount = total_line_item_amount
1459
+ self.canceled_amount = canceled_amount
1460
+ self.captured_amount = captured_amount
1461
+ self.refunded_amount = refunded_amount
1462
+ self.disputed_amount = disputed_amount
1463
+ self.split_amount = split_amount
1464
+
1465
+ def __str__(self):
1466
+ return 'PayInIntentLineItem: %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s' % \
1467
+ (self.id, self.seller, self.sku, self.name, self.description, self.quantity, self.unit_amount, self.amount,
1468
+ self.tax_amount, self.discount_amount, self.category, self.shipping_address, self.total_line_item_amount,
1469
+ self.canceled_amount, self.captured_amount, self.refunded_amount, self.disputed_amount, self.split_amount)
1470
+
1471
+ def to_api_json(self):
1472
+ return {
1473
+ "Id": self.id,
1474
+ "Seller": self.seller,
1475
+ "Sku": self.sku,
1476
+ "Name": self.name,
1477
+ "Description": self.description,
1478
+ "Quantity": self.quantity,
1479
+ "UnitAmount": self.unit_amount,
1480
+ "Amount": self.amount,
1481
+ "TaxAmount": self.tax_amount,
1482
+ "DiscountAmount": self.discount_amount,
1483
+ "Category": self.category,
1484
+ "ShippingAddress": self.shipping_address,
1485
+ "TotalLineItemAmount": self.total_line_item_amount,
1486
+ "CanceledAmount": self.canceled_amount,
1487
+ "CapturedAmount": self.captured_amount,
1488
+ "RefundedAmount": self.refunded_amount,
1489
+ "DisputedAmount": self.disputed_amount,
1490
+ "SplitAmount": self.split_amount
1491
+ }
1492
+
1493
+
1494
+ @add_camelcase_aliases
1495
+ class PayInIntentSeller(object):
1496
+ def __init__(self, author_id=None, wallet_id=None, fees_amount=None, transfer_date=None):
1497
+ self.author_id = author_id
1498
+ self.wallet_id = wallet_id
1499
+ self.fees_amount = fees_amount
1500
+ self.transfer_date = transfer_date
1501
+
1502
+ def __str__(self):
1503
+ return 'PayInIntentSeller: %s %s %s %s' % \
1504
+ (self.author_id, self.wallet_id, self.fees_amount, self.transfer_date)
1505
+
1506
+ def to_api_json(self):
1507
+ return {
1508
+ "AuthorId": self.author_id,
1509
+ "WalletId": self.wallet_id,
1510
+ "FeesAmount": self.fees_amount,
1511
+ "TransferDate": self.transfer_date
1512
+ }
1513
+
1514
+ @add_camelcase_aliases
1515
+ class IntentSplit(object):
1516
+ def __init__(self, line_item_id=None, wallet_id=None, seller_id=None, split_amount=None, fees_amount=None,
1517
+ transfer_date=None, description=None, status=None):
1518
+ self.line_item_id = line_item_id
1519
+ self.wallet_id = wallet_id
1520
+ self.seller_id = seller_id
1521
+ self.split_amount = split_amount
1522
+ self.fees_amount = fees_amount
1523
+ self.description = description
1524
+ self.status = status
1525
+ self.transfer_date = transfer_date
1526
+
1527
+ def __str__(self):
1528
+ return 'PayInIntentSplit: %s %s %s %s %s %s %s %s' % \
1529
+ (self.line_item_id, self.wallet_id, self.seller_id, self.split_amount, self.fees_amount, self.description,
1530
+ self.status, self.transfer_date)
1531
+
1532
+ def to_api_json(self):
1533
+ return {
1534
+ "LineItemId": self.line_item_id,
1535
+ "WalletId": self.wallet_id,
1536
+ "SellerId": self.seller_id,
1537
+ "SplitAmount": self.split_amount,
1538
+ "FeesAmount": self.fees_amount,
1539
+ "Description": self.description,
1540
+ "Status": self.status,
1541
+ "TransferDate": self.transfer_date
1542
+ }
1543
+
1544
+
1545
+ @add_camelcase_aliases
1546
+ class SupportedBank(object):
1547
+ def __init__(self, countries=None):
1548
+ self.countries = countries
1549
+
1550
+ def __str__(self):
1551
+ return 'SupportedBank: %s' % self.countries
1552
+
1553
+ def __eq__(self, other):
1554
+ if isinstance(other, SupportedBank):
1555
+ stat = (self.countries == other.countries)
1556
+ return stat
1557
+ return False
1558
+
1559
+ def to_api_json(self):
1560
+ return {
1561
+ "Countries": self.countries
1562
+ }
1563
+
1564
+
1565
+ @add_camelcase_aliases
1566
+ class VerificationOfPayee(object):
1567
+ def __init__(self, recipient_verification_id=None, recipient_verification_check=None,
1568
+ recipient_verification_message=None):
1569
+ self.recipient_verification_id = recipient_verification_id
1570
+ self.recipient_verification_check = recipient_verification_check
1571
+ self.recipient_verification_message = recipient_verification_message
1572
+
1573
+ def __str__(self):
1574
+ return ('VerificationOfPayee: %s %s %s' % self.recipient_verification_id, self.recipient_verification_check,
1575
+ self.recipient_verification_message)
1576
+
1577
+ def to_api_json(self):
1578
+ return {
1579
+ "RecipientVerificationId": self.recipient_verification_id,
1580
+ "RecipientVerificationCheck": self.recipient_verification_check,
1581
+ "RecipientVerificationMessage": self.recipient_verification_message
1582
+ }