1- from typing import Union , Optional
1+ import typing as t
22
33from payme .classes .cards import Cards
44from payme .classes .http import HttpClient
@@ -20,7 +20,8 @@ class Receipts:
2020 """
2121 The Receipts class provides methods to interact with the Payme Receipts.
2222 """
23- def __init__ (self , payme_id : str , payme_key : str , url : str ) -> "Receipts" :
23+
24+ def __init__ (self , payme_id : str , payme_key : str , url : str ) -> None :
2425 """
2526 Initialize the Receipts client.
2627
@@ -32,33 +33,33 @@ def __init__(self, payme_id: str, payme_key: str, url: str) -> "Receipts":
3233
3334 headers = {
3435 "X-Auth" : f"{ payme_id } :{ payme_key } " ,
35- "Content-Type" : "application/json"
36+ "Content-Type" : "application/json" ,
3637 }
3738 self .http = HttpClient (url , headers )
3839
3940 def create (
4041 self ,
4142 account : dict ,
42- amount : Union [float , int ],
43- description : Optional [str ] = None ,
44- detail : Optional [dict ] = None ,
45- timeout : int = 10
43+ amount : t . Union [float , int ],
44+ description : t . Optional [str ] = None ,
45+ detail : t . Optional [t . Dict ] = None ,
46+ timeout : int = 10 ,
4647 ) -> response .CreateResponse :
4748 """
4849 Create a new receipt.
4950
5051 :param account: The account details for the receipt.
5152 :param amount: The amount of the receipt.
52- :param description: Optional description for the receipt.
53- :param detail: Optional additional details for the receipt.
53+ :param description: t. Optional description for the receipt.
54+ :param detail: t. Optional additional details for the receipt.
5455 :param timeout: The request timeout duration in seconds (default 10).
5556 """
5657 method = "receipts.create"
5758 params = {
5859 "amount" : amount ,
5960 "account" : account ,
6061 "description" : description ,
61- "detail" : detail
62+ "detail" : detail ,
6263 }
6364 return self ._post_request (method , params , timeout )
6465
@@ -74,10 +75,7 @@ def pay(
7475 The request timeout duration in seconds (default is 10).
7576 """
7677 method = "receipts.pay"
77- params = {
78- "id" : receipts_id ,
79- "token" : token
80- }
78+ params = {"id" : receipts_id , "token" : token }
8179 return self ._post_request (method , params , timeout )
8280
8381 def send (
@@ -91,76 +89,56 @@ def send(
9189 :param timeout: The request timeout duration in seconds (default 10).
9290 """
9391 method = "receipts.send"
94- params = {
95- "id" : receipts_id ,
96- "phone" : phone
97- }
92+ params = {"id" : receipts_id , "phone" : phone }
9893 return self ._post_request (method , params , timeout )
9994
100- def cancel (
101- self , receipts_id : str , timeout : int = 10
102- ) -> response .CancelResponse :
95+ def cancel (self , receipts_id : str , timeout : int = 10 ) -> response .CancelResponse :
10396 """
10497 Cancel the receipt.
10598
10699 :param receipts_id: The ID of the cheque used for payment.
107100 :param timeout: The request timeout duration in seconds (default 10).
108101 """
109102 method = "receipts.cancel"
110- params = {
111- "id" : receipts_id
112- }
103+ params = {"id" : receipts_id }
113104 return self ._post_request (method , params , timeout )
114105
115- def check (
116- self , receipts_id : str , timeout : int = 10
117- ) -> response .CheckResponse :
106+ def check (self , receipts_id : str , timeout : int = 10 ) -> response .CheckResponse :
118107 """
119108 Check the status of a cheque.
120109
121110 :param receipts_id: The ID of the cheque used for payment.
122111 :param timeout: The request timeout duration in seconds (default 10).
123112 """
124113 method = "receipts.check"
125- params = {
126- "id" : receipts_id
127- }
114+ params = {"id" : receipts_id }
128115 return self ._post_request (method , params , timeout )
129116
130- def get (
131- self , receipts_id : str , timeout : int = 10
132- ) -> response .GetResponse :
117+ def get (self , receipts_id : str , timeout : int = 10 ) -> response .GetResponse :
133118 """
134119 Get the details of a specific cheque.
135120
136121 :param receipts_id: The ID of the cheque used for payment.
137122 :param timeout: The request timeout duration in seconds (default 10).
138123 """
139124 method = "receipts.get"
140- params = {
141- "id" : receipts_id
142- }
125+ params = {"id" : receipts_id }
143126 return self ._post_request (method , params , timeout )
144127
145128 def get_all (
146129 self , count : int , from_ : int , to : int , offset : int , timeout : int = 10
147130 ) -> response .GetAllResponse :
148131 """
149- Get all cheques for a specific account.
132+ Get all cheques for a specific account.
150133
151- :param count: The number of cheques to retrieve.
152- :param from_: The start index of the cheques to retrieve.
153- :param to: The end index of the cheques to retrieve.
154- :param offset: The offset for pagination.
155- :param timeout: The request timeout duration in seconds (default 10).
134+ :param count: The number of cheques to retrieve.
135+ :param from_: The start index of the cheques to retrieve.
136+ :param to: The end index of the cheques to retrieve.
137+ :param offset: The offset for pagination.
138+ :param timeout: The request timeout duration in seconds (default 10).
156139 """
157140 method = "receipts.get_all"
158- params = {
159- "count" : count ,
160- "from" : from_ ,
161- "to" : to ,
162- "offset" : offset
163- }
141+ params = {"count" : count , "from" : from_ , "to" : to , "offset" : offset }
164142 return self ._post_request (method , params , timeout )
165143
166144 def _post_request (
@@ -185,6 +163,7 @@ def test(self):
185163 covering creation, payment, sending, cancellation, status checks,
186164 retrieval of a single receipt, and retrieval of multiple receipts.
187165 """
166+
188167 # Helper to assert conditions with messaging
189168 def assert_condition (condition , message , test_case ):
190169 self ._assert_and_print (condition , message , test_case = test_case )
@@ -195,36 +174,34 @@ def create_sample_receipt():
195174 account = {"id" : 12345 },
196175 amount = 1000 ,
197176 description = "Test receipt" ,
198- detail = {"key" : "value" }
177+ detail = {"key" : "value" },
199178 )
200179
201180 # Test 1: Initialization check
202181 assert_condition (
203182 isinstance (self , Receipts ),
204183 "Initialized Receipts class successfully." ,
205- test_case = "Initialization Test"
184+ test_case = "Initialization Test" ,
206185 )
207186
208187 # Test 2: Create and Pay Receipt
209188 create_response = create_sample_receipt ()
210189 assert_condition (
211190 isinstance (create_response , response .CreateResponse ),
212191 "Created a new receipt successfully." ,
213- test_case = "Receipt Creation Test"
192+ test_case = "Receipt Creation Test" ,
214193 )
215194
216195 # pylint: disable=W0212
217196 assert_condition (
218197 isinstance (create_response .result .receipt ._id , str ),
219198 "Created a valid receipt ID." ,
220- test_case = "Receipt ID Test"
199+ test_case = "Receipt ID Test" ,
221200 )
222201
223202 # Prepare card and verification
224203 cards_create_response = self .__cards .create (
225- number = "8600495473316478" ,
226- expire = "0399" ,
227- save = True
204+ number = "8600495473316478" , expire = "0399" , save = True
228205 )
229206 token = cards_create_response .result .card .token
230207 self .__cards .get_verify_code (token = token )
@@ -236,7 +213,7 @@ def create_sample_receipt():
236213 assert_condition (
237214 pay_response .result .receipt .state == 4 ,
238215 "Paid the receipt successfully." ,
239- test_case = "Payment Test"
216+ test_case = "Payment Test" ,
240217 )
241218
242219 # Test 3: Create and Send Receipt
@@ -246,7 +223,7 @@ def create_sample_receipt():
246223 assert_condition (
247224 send_response .result .success is True ,
248225 "Sent the receipt successfully." ,
249- test_case = "Send Test"
226+ test_case = "Send Test" ,
250227 )
251228
252229 # Test 4: Create and Cancel Receipt
@@ -256,43 +233,37 @@ def create_sample_receipt():
256233 assert_condition (
257234 cancel_response .result .receipt .state == 50 ,
258235 "Cancelled the receipt successfully." ,
259- test_case = "Cancel Test"
236+ test_case = "Cancel Test" ,
260237 )
261238
262239 # Test 5: Check Receipt Status
263240 check_response = self .check (receipts_id = receipt_id )
264241 assert_condition (
265242 check_response .result .state == 50 ,
266243 "Checked the receipt status successfully." ,
267- test_case = "Check Test"
244+ test_case = "Check Test" ,
268245 )
269246
270247 # Test 6: Get Receipt Details
271248 get_response = self .get (receipts_id = receipt_id )
272249 assert_condition (
273250 get_response .result .receipt ._id == receipt_id ,
274251 "Retrieved the receipt details successfully." ,
275- test_case = "Get Test"
252+ test_case = "Get Test" ,
276253 )
277254
278255 # Test 7: Retrieve All Receipts
279256 get_all_response = self .get_all (
280- count = 1 ,
281- from_ = 1730322122000 ,
282- to = 1730398982000 ,
283- offset = 0
257+ count = 1 , from_ = 1730322122000 , to = 1730398982000 , offset = 0
284258 )
285259 assert_condition (
286260 isinstance (get_all_response .result , list ),
287261 "Retrieved all receipts successfully." ,
288- test_case = "Get All Test"
262+ test_case = "Get All Test" ,
289263 )
290264
291265 # pylint: disable=W0212
292266 def _assert_and_print (
293- self ,
294- condition : bool ,
295- success_message : str ,
296- test_case : Optional [str ] = None
267+ self , condition : bool , success_message : str , test_case : t .Optional [str ] = None
297268 ):
298269 self .__cards ._assert_and_print (condition , success_message , test_case )
0 commit comments