python-amcards 1.2.34__py3-none-any.whl → 1.3.1__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.
- amcards/amcards.py +51 -1
- amcards/models.py +102 -1
- {python_amcards-1.2.34.dist-info → python_amcards-1.3.1.dist-info}/METADATA +1 -1
- python_amcards-1.3.1.dist-info/RECORD +10 -0
- python_amcards-1.2.34.dist-info/RECORD +0 -10
- {python_amcards-1.2.34.dist-info → python_amcards-1.3.1.dist-info}/LICENSE +0 -0
- {python_amcards-1.2.34.dist-info → python_amcards-1.3.1.dist-info}/WHEEL +0 -0
- {python_amcards-1.2.34.dist-info → python_amcards-1.3.1.dist-info}/top_level.txt +0 -0
amcards/amcards.py
CHANGED
|
@@ -2,7 +2,7 @@ import requests
|
|
|
2
2
|
from typing import List, Optional, Callable, Any
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
from .models import User, Template, Gift, Campaign, CardResponse, CardsResponse, CampaignResponse, Card, Contact, Mailing
|
|
5
|
+
from .models import User, Template, Gift, Campaign, CardResponse, CardsResponse, CampaignResponse, Card, Contact, Mailing, CreditTransaction
|
|
6
6
|
from . import exceptions
|
|
7
7
|
from . import __helpers as helpers
|
|
8
8
|
|
|
@@ -97,6 +97,56 @@ class AMcardsClient:
|
|
|
97
97
|
user_json = res.json().get('objects', [{}])[0]
|
|
98
98
|
return User._from_json(user_json)
|
|
99
99
|
|
|
100
|
+
def credit_transactions(self, limit: int = 25, skip: int = 0, filters: dict = None) -> List[CreditTransaction]:
|
|
101
|
+
"""Fetches client's AMcards credit transactions.
|
|
102
|
+
|
|
103
|
+
:param int limit: Defaults to ``25``. Max number of credit transactions to be fetched.
|
|
104
|
+
:param int skip: Defaults to ``0``. Number of credit transactions to be skipped.
|
|
105
|
+
:param Optional[dict] filters: Defaults to ``None``. Filters to be applied when fetching credit transactions.
|
|
106
|
+
|
|
107
|
+
A common use case is to use ``filter = {'amount_paid_int__gt': 0}``, this will count all credit transactions that have ``amount_paid > 0``.
|
|
108
|
+
|
|
109
|
+
:return: The client's :py:class:`credit transactions <amcards.models.CreditTransaction>`.
|
|
110
|
+
:rtype: List[:py:class:`CreditTransaction <amcards.models.CreditTransaction>`]
|
|
111
|
+
|
|
112
|
+
:raises AuthenticationError: When the client's ``access_token`` is invalid.
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
params = {
|
|
116
|
+
'limit': limit,
|
|
117
|
+
'offset': skip,
|
|
118
|
+
} | (filters or {})
|
|
119
|
+
|
|
120
|
+
res = requests.get(url=f'{DOMAIN}/.api/v1/credittransaction/', headers=self._HEADERS, params=params)
|
|
121
|
+
if not res.ok:
|
|
122
|
+
raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
|
|
123
|
+
|
|
124
|
+
credit_transactions_json = res.json().get('objects', [])
|
|
125
|
+
return [CreditTransaction._from_json(credit_transaction_json) for credit_transaction_json in credit_transactions_json]
|
|
126
|
+
|
|
127
|
+
def credit_transaction_count(self, filters: dict = None) -> int:
|
|
128
|
+
"""Fetches count of client's AMcards credit transactions.
|
|
129
|
+
|
|
130
|
+
:param Optional[dict] filters: Defaults to ``None``. Filters to be applied when counting credit transactions.
|
|
131
|
+
|
|
132
|
+
A common use case is to use ``filter = {'amount_paid_int__gt': 0}``, this will count all credit transactions that have ``amount_paid > 0``.
|
|
133
|
+
|
|
134
|
+
:return: The count of client's credit transactions.
|
|
135
|
+
:rtype: int
|
|
136
|
+
|
|
137
|
+
:raises AuthenticationError: When the client's ``access_token`` is invalid.
|
|
138
|
+
|
|
139
|
+
"""
|
|
140
|
+
params = {
|
|
141
|
+
'limit': 1,
|
|
142
|
+
} | (filters or {})
|
|
143
|
+
|
|
144
|
+
res = requests.get(url=f'{DOMAIN}/.api/v1/credittransaction/', headers=self._HEADERS, params=params)
|
|
145
|
+
if not res.ok:
|
|
146
|
+
raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
|
|
147
|
+
|
|
148
|
+
return res.json()['meta']['total_count']
|
|
149
|
+
|
|
100
150
|
def templates(self, limit: int = 25, skip: int = 0) -> List[Template]:
|
|
101
151
|
"""Fetches client's AMcards templates.
|
|
102
152
|
|
amcards/models.py
CHANGED
|
@@ -353,6 +353,7 @@ class Card:
|
|
|
353
353
|
shipping_address: dict,
|
|
354
354
|
return_address: dict,
|
|
355
355
|
gifts: List[Gift],
|
|
356
|
+
extra_data: dict,
|
|
356
357
|
) -> None:
|
|
357
358
|
self._id = id
|
|
358
359
|
self._amount_charged = amount_charged
|
|
@@ -369,6 +370,7 @@ class Card:
|
|
|
369
370
|
self._shipping_address = shipping_address
|
|
370
371
|
self._return_address = return_address
|
|
371
372
|
self._gifts = gifts
|
|
373
|
+
self._extra_data = extra_data
|
|
372
374
|
|
|
373
375
|
__repr__ = helpers.repr
|
|
374
376
|
|
|
@@ -489,6 +491,11 @@ class Card:
|
|
|
489
491
|
"""Gifts attached to this card."""
|
|
490
492
|
return self._gifts
|
|
491
493
|
|
|
494
|
+
@property
|
|
495
|
+
def extra_data(self) -> dict:
|
|
496
|
+
"""Extra data attached to this card."""
|
|
497
|
+
return self._gifts
|
|
498
|
+
|
|
492
499
|
@classmethod
|
|
493
500
|
def _from_json(cls, json: dict):
|
|
494
501
|
return cls(
|
|
@@ -512,6 +519,7 @@ class Card:
|
|
|
512
519
|
base_cost=gift['price'],
|
|
513
520
|
shipping_and_handling_cost=gift['shipping_and_handling'],
|
|
514
521
|
) for gift in json['gifts']],
|
|
522
|
+
extra_data=json.get('extra_data') or {},
|
|
515
523
|
)
|
|
516
524
|
|
|
517
525
|
class MailingStatus(Enum):
|
|
@@ -890,4 +898,97 @@ class CardsResponse:
|
|
|
890
898
|
user_email=json['user'],
|
|
891
899
|
message=json['message'],
|
|
892
900
|
shipping_addresses=json['shipping_addresses'],
|
|
893
|
-
)
|
|
901
|
+
)
|
|
902
|
+
|
|
903
|
+
class CreditTransaction:
|
|
904
|
+
"""Represents an AMcards CreditTransaction."""
|
|
905
|
+
def __init__(
|
|
906
|
+
self,
|
|
907
|
+
id: int,
|
|
908
|
+
wallet_id: str,
|
|
909
|
+
amount_granted: int,
|
|
910
|
+
amount_before: int,
|
|
911
|
+
amount_after: int,
|
|
912
|
+
amount_paid: int,
|
|
913
|
+
amount: int,
|
|
914
|
+
description: str,
|
|
915
|
+
credit_card_details: str,
|
|
916
|
+
date_created: datetime,
|
|
917
|
+
) -> None:
|
|
918
|
+
self._id = id
|
|
919
|
+
self._wallet_id = wallet_id
|
|
920
|
+
self._amount_granted = amount_granted
|
|
921
|
+
self._amount_before = amount_before
|
|
922
|
+
self._amount_after = amount_after
|
|
923
|
+
self._amount_paid = amount_paid
|
|
924
|
+
self._amount = amount
|
|
925
|
+
self._description = description
|
|
926
|
+
self._credit_card_details = credit_card_details
|
|
927
|
+
self._date_created = date_created
|
|
928
|
+
|
|
929
|
+
__repr__ = helpers.repr
|
|
930
|
+
|
|
931
|
+
@property
|
|
932
|
+
def id(self) -> int:
|
|
933
|
+
"""CreditTransaction's unique identifier."""
|
|
934
|
+
return self._id
|
|
935
|
+
|
|
936
|
+
@property
|
|
937
|
+
def wallet_id(self) -> str:
|
|
938
|
+
"""CreditTransaction's wallet id."""
|
|
939
|
+
return self._wallet_id
|
|
940
|
+
|
|
941
|
+
@property
|
|
942
|
+
def amount_granted(self) -> int:
|
|
943
|
+
"""CreditTransaction's amount granted in `cents`."""
|
|
944
|
+
return self._amount_granted
|
|
945
|
+
|
|
946
|
+
@property
|
|
947
|
+
def amount_before(self) -> int:
|
|
948
|
+
"""CreditTransaction's amount before in `cents`."""
|
|
949
|
+
return self._amount_before
|
|
950
|
+
|
|
951
|
+
@property
|
|
952
|
+
def amount_after(self) -> int:
|
|
953
|
+
"""CreditTransaction's amount after in `cents`."""
|
|
954
|
+
return self._amount_after
|
|
955
|
+
|
|
956
|
+
@property
|
|
957
|
+
def amount_paid(self) -> int:
|
|
958
|
+
"""CreditTransaction's amount paid in `cents`."""
|
|
959
|
+
return self._amount_paid
|
|
960
|
+
|
|
961
|
+
@property
|
|
962
|
+
def amount(self) -> int:
|
|
963
|
+
"""CreditTransaction's amount in `cents`."""
|
|
964
|
+
return self._amount
|
|
965
|
+
|
|
966
|
+
@property
|
|
967
|
+
def description(self) -> str:
|
|
968
|
+
"""CreditTransaction's description."""
|
|
969
|
+
return self._description
|
|
970
|
+
|
|
971
|
+
@property
|
|
972
|
+
def credit_card_details(self) -> str:
|
|
973
|
+
"""CreditTransaction's credit card details."""
|
|
974
|
+
return self._credit_card_details
|
|
975
|
+
|
|
976
|
+
@property
|
|
977
|
+
def date_created(self) -> datetime:
|
|
978
|
+
"""Date and time CreditTransaction was created."""
|
|
979
|
+
return self._date_created
|
|
980
|
+
|
|
981
|
+
@classmethod
|
|
982
|
+
def _from_json(cls, json: dict):
|
|
983
|
+
return cls(
|
|
984
|
+
id=int(json['id']),
|
|
985
|
+
wallet_id=json['wallet_id'],
|
|
986
|
+
amount_granted=json['grant_volume'],
|
|
987
|
+
amount_before=json['before_int'],
|
|
988
|
+
amount_after=json['after_int'],
|
|
989
|
+
amount_paid=json['amount_paid_int'],
|
|
990
|
+
amount=json['amount_int'],
|
|
991
|
+
description=json['description'],
|
|
992
|
+
credit_card_details=json['credit_card_details'],
|
|
993
|
+
date_created=helpers.to_datetime(json['date_time']),
|
|
994
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
amcards/__helpers.py,sha256=iQ3L-79XyDBoE8ZsenCac7xii-1LN86Go3w_yu95VaE,5466
|
|
2
|
+
amcards/__init__.py,sha256=nl-oq4BKdYSQZPNbtraEMHFf_8MU8gSOlJZIYxKudcM,34
|
|
3
|
+
amcards/amcards.py,sha256=e_8xSulvtRVT40iOl9mQNWnq0QZnH9WyCYpNaOFpSqs,61560
|
|
4
|
+
amcards/exceptions.py,sha256=wPu5lipT4oTJ2h-NY82jO_AjG68flmbFpcA-0xy0t_w,1978
|
|
5
|
+
amcards/models.py,sha256=Yk9l6TZ5AUB6h-ArBvIR0Da_XuVcupXGA8MxL0HWzkE,30937
|
|
6
|
+
python_amcards-1.3.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
+
python_amcards-1.3.1.dist-info/METADATA,sha256=Y7bVDNFQblUsgA7mzcB2c-vJZg9W47yfBW7EpEE97ss,3077
|
|
8
|
+
python_amcards-1.3.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
9
|
+
python_amcards-1.3.1.dist-info/top_level.txt,sha256=xst-AU0pzvWXz3DQR-QICIruzgcf4Bkt6FF_GldcIck,8
|
|
10
|
+
python_amcards-1.3.1.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
amcards/__helpers.py,sha256=iQ3L-79XyDBoE8ZsenCac7xii-1LN86Go3w_yu95VaE,5466
|
|
2
|
-
amcards/__init__.py,sha256=nl-oq4BKdYSQZPNbtraEMHFf_8MU8gSOlJZIYxKudcM,34
|
|
3
|
-
amcards/amcards.py,sha256=xuL68Qu23fj9zv_NxdAiutDWzbAV0y_rQWlQH46KgpI,59157
|
|
4
|
-
amcards/exceptions.py,sha256=wPu5lipT4oTJ2h-NY82jO_AjG68flmbFpcA-0xy0t_w,1978
|
|
5
|
-
amcards/models.py,sha256=0upN9pX65121XrX9nZGQbU3kLFM6fs1OT6XDH_S4jEU,27951
|
|
6
|
-
python_amcards-1.2.34.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
-
python_amcards-1.2.34.dist-info/METADATA,sha256=des1lsXof80dO7rD71wLivbm1Ubd0qiDlY61VqBI6hQ,3078
|
|
8
|
-
python_amcards-1.2.34.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
9
|
-
python_amcards-1.2.34.dist-info/top_level.txt,sha256=xst-AU0pzvWXz3DQR-QICIruzgcf4Bkt6FF_GldcIck,8
|
|
10
|
-
python_amcards-1.2.34.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|