python-amcards 1.2.34__tar.gz → 1.3.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-amcards
3
- Version: 1.2.34
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
@@ -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
 
@@ -890,4 +890,97 @@ class CardsResponse:
890
890
  user_email=json['user'],
891
891
  message=json['message'],
892
892
  shipping_addresses=json['shipping_addresses'],
893
- )
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.34
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
@@ -7,7 +7,7 @@ def README():
7
7
 
8
8
  setup(
9
9
  name='python-amcards',
10
- version='1.2.34',
10
+ version='1.3.0',
11
11
  description='A wrapper for the AMcards API.',
12
12
  long_description=README(),
13
13
  long_description_content_type='text/x-rst',
File without changes