python-amcards 1.2.33__py3-none-any.whl → 1.3.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.
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
@@ -266,12 +266,14 @@ class Campaign:
266
266
  self,
267
267
  id: int,
268
268
  name: str,
269
+ drip_count: int,
269
270
  send_if_duplicate: bool,
270
271
  has_anniversary_drip: bool = False,
271
272
  has_birthday_drip: bool = False,
272
273
  ) -> None:
273
274
  self._id = id
274
275
  self._name = name
276
+ self._drip_count = drip_count
275
277
  self._send_if_duplicate = send_if_duplicate
276
278
  self._has_anniversary_drip = has_anniversary_drip
277
279
  self._has_birthday_drip = has_birthday_drip
@@ -888,4 +890,97 @@ class CardsResponse:
888
890
  user_email=json['user'],
889
891
  message=json['message'],
890
892
  shipping_addresses=json['shipping_addresses'],
891
- )
893
+ )
894
+
895
+ class CreditTransaction:
896
+ """Represents an AMcards CreditTransaction."""
897
+ def __init__(
898
+ self,
899
+ id: int,
900
+ wallet_id: str,
901
+ amount_granted: int,
902
+ amount_before: int,
903
+ amount_after: int,
904
+ amount_paid: int,
905
+ amount: int,
906
+ description: str,
907
+ credit_card_details: str,
908
+ date_created: datetime,
909
+ ) -> None:
910
+ self._id = id
911
+ self._wallet_id = wallet_id
912
+ self._amount_granted = amount_granted
913
+ self._amount_before = amount_before
914
+ self._amount_after = amount_after
915
+ self._amount_paid = amount_paid
916
+ self._amount = amount
917
+ self._description = description
918
+ self._credit_card_details = credit_card_details
919
+ self._date_created = date_created
920
+
921
+ __repr__ = helpers.repr
922
+
923
+ @property
924
+ def id(self) -> int:
925
+ """CreditTransaction's unique identifier."""
926
+ return self._id
927
+
928
+ @property
929
+ def wallet_id(self) -> str:
930
+ """CreditTransaction's wallet id."""
931
+ return self._wallet_id
932
+
933
+ @property
934
+ def amount_granted(self) -> int:
935
+ """CreditTransaction's amount granted in `cents`."""
936
+ return self._amount_granted
937
+
938
+ @property
939
+ def amount_before(self) -> int:
940
+ """CreditTransaction's amount before in `cents`."""
941
+ return self._amount_before
942
+
943
+ @property
944
+ def amount_after(self) -> int:
945
+ """CreditTransaction's amount after in `cents`."""
946
+ return self._amount_after
947
+
948
+ @property
949
+ def amount_paid(self) -> int:
950
+ """CreditTransaction's amount paid in `cents`."""
951
+ return self._amount_paid
952
+
953
+ @property
954
+ def amount(self) -> int:
955
+ """CreditTransaction's amount in `cents`."""
956
+ return self._amount
957
+
958
+ @property
959
+ def description(self) -> str:
960
+ """CreditTransaction's description."""
961
+ return self._description
962
+
963
+ @property
964
+ def credit_card_details(self) -> str:
965
+ """CreditTransaction's credit card details."""
966
+ return self._credit_card_details
967
+
968
+ @property
969
+ def date_created(self) -> datetime:
970
+ """Date and time CreditTransaction was created."""
971
+ return self._date_created
972
+
973
+ @classmethod
974
+ def _from_json(cls, json: dict):
975
+ return cls(
976
+ id=int(json['id']),
977
+ wallet_id=json['wallet_id'],
978
+ amount_granted=json['grant_volume'],
979
+ amount_before=json['before_int'],
980
+ amount_after=json['after_int'],
981
+ amount_paid=json['amount_paid_int'],
982
+ amount=json['amount_int'],
983
+ description=json['description'],
984
+ credit_card_details=json['credit_card_details'],
985
+ date_created=helpers.to_datetime(json['date_time']),
986
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-amcards
3
- Version: 1.2.33
3
+ Version: 1.3.0
4
4
  Summary: A wrapper for the AMcards API.
5
5
  Home-page: https://github.com/simonesestili/python-amcards
6
6
  Author: Simone Sestili
@@ -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=bwOogJjUH9prg0hUuLkuMtjSpvpClW0L8lUiPEGXjB0,30696
6
+ python_amcards-1.3.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
+ python_amcards-1.3.0.dist-info/METADATA,sha256=uQ8FPtgUkjRAWsEpyD3OXt25OuM6nGccOmdzrBzFZS4,3077
8
+ python_amcards-1.3.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
9
+ python_amcards-1.3.0.dist-info/top_level.txt,sha256=xst-AU0pzvWXz3DQR-QICIruzgcf4Bkt6FF_GldcIck,8
10
+ python_amcards-1.3.0.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=42n-NRajIDru5udF4sr_ukEBV_mrcT97sL6ksoQKquA,27888
6
- python_amcards-1.2.33.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
- python_amcards-1.2.33.dist-info/METADATA,sha256=t9grR0Ma_DJiXqGSxq1pAX4UbugH0C7JYkYLjIunX7w,3078
8
- python_amcards-1.2.33.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
9
- python_amcards-1.2.33.dist-info/top_level.txt,sha256=xst-AU0pzvWXz3DQR-QICIruzgcf4Bkt6FF_GldcIck,8
10
- python_amcards-1.2.33.dist-info/RECORD,,