1- from typing import Union , Optional
21from urllib .parse import parse_qs
32
43from payme .classes .cards import Cards
@@ -22,7 +21,8 @@ class Receipts:
2221 """
2322 The Receipts class provides methods to interact with the Payme Receipts.
2423 """
25- def __init__ (self , payme_id : str , payme_key : str , url : str ) -> "Receipts" :
24+
25+ def __init__ (self , payme_id : str , payme_key : str , url : str ) -> None :
2626 """
2727 Initialize the Receipts client.
2828
@@ -34,33 +34,33 @@ def __init__(self, payme_id: str, payme_key: str, url: str) -> "Receipts":
3434
3535 headers = {
3636 "X-Auth" : f"{ payme_id } :{ payme_key } " ,
37- "Content-Type" : "application/json"
37+ "Content-Type" : "application/json" ,
3838 }
3939 self .http = HttpClient (url , headers )
4040
4141 def create (
4242 self ,
4343 account : dict ,
44- amount : Union [float , int ],
45- description : Optional [str ] = None ,
46- detail : Optional [dict ] = None ,
47- timeout : int = 10
44+ amount : t . Union [float , int ],
45+ description : t . Optional [str ] = None ,
46+ detail : t . Optional [t . Dict ] = None ,
47+ timeout : int = 10 ,
4848 ) -> response .CreateResponse :
4949 """
5050 Create a new receipt.
5151
5252 :param account: The account details for the receipt.
5353 :param amount: The amount of the receipt.
54- :param description: Optional description for the receipt.
55- :param detail: Optional additional details for the receipt.
54+ :param description: t. Optional description for the receipt.
55+ :param detail: t. Optional additional details for the receipt.
5656 :param timeout: The request timeout duration in seconds (default 10).
5757 """
5858 method = "receipts.create"
5959 params = {
6060 "amount" : amount ,
6161 "account" : account ,
6262 "description" : description ,
63- "detail" : detail
63+ "detail" : detail ,
6464 }
6565 return self ._post_request (method , params , timeout )
6666
@@ -76,10 +76,7 @@ def pay(
7676 The request timeout duration in seconds (default is 10).
7777 """
7878 method = "receipts.pay"
79- params = {
80- "id" : receipts_id ,
81- "token" : token
82- }
79+ params = {"id" : receipts_id , "token" : token }
8380 return self ._post_request (method , params , timeout )
8481
8582 def send (
@@ -93,76 +90,56 @@ def send(
9390 :param timeout: The request timeout duration in seconds (default 10).
9491 """
9592 method = "receipts.send"
96- params = {
97- "id" : receipts_id ,
98- "phone" : phone
99- }
93+ params = {"id" : receipts_id , "phone" : phone }
10094 return self ._post_request (method , params , timeout )
10195
102- def cancel (
103- self , receipts_id : str , timeout : int = 10
104- ) -> response .CancelResponse :
96+ def cancel (self , receipts_id : str , timeout : int = 10 ) -> response .CancelResponse :
10597 """
10698 Cancel the receipt.
10799
108100 :param receipts_id: The ID of the cheque used for payment.
109101 :param timeout: The request timeout duration in seconds (default 10).
110102 """
111103 method = "receipts.cancel"
112- params = {
113- "id" : receipts_id
114- }
104+ params = {"id" : receipts_id }
115105 return self ._post_request (method , params , timeout )
116106
117- def check (
118- self , receipts_id : str , timeout : int = 10
119- ) -> response .CheckResponse :
107+ def check (self , receipts_id : str , timeout : int = 10 ) -> response .CheckResponse :
120108 """
121109 Check the status of a cheque.
122110
123111 :param receipts_id: The ID of the cheque used for payment.
124112 :param timeout: The request timeout duration in seconds (default 10).
125113 """
126114 method = "receipts.check"
127- params = {
128- "id" : receipts_id
129- }
115+ params = {"id" : receipts_id }
130116 return self ._post_request (method , params , timeout )
131117
132- def get (
133- self , receipts_id : str , timeout : int = 10
134- ) -> response .GetResponse :
118+ def get (self , receipts_id : str , timeout : int = 10 ) -> response .GetResponse :
135119 """
136120 Get the details of a specific cheque.
137121
138122 :param receipts_id: The ID of the cheque used for payment.
139123 :param timeout: The request timeout duration in seconds (default 10).
140124 """
141125 method = "receipts.get"
142- params = {
143- "id" : receipts_id
144- }
126+ params = {"id" : receipts_id }
145127 return self ._post_request (method , params , timeout )
146128
147129 def get_all (
148130 self , count : int , from_ : int , to : int , offset : int , timeout : int = 10
149131 ) -> response .GetAllResponse :
150132 """
151- Get all cheques for a specific account.
133+ Get all cheques for a specific account.
152134
153- :param count: The number of cheques to retrieve.
154- :param from_: The start index of the cheques to retrieve.
155- :param to: The end index of the cheques to retrieve.
156- :param offset: The offset for pagination.
157- :param timeout: The request timeout duration in seconds (default 10).
135+ :param count: The number of cheques to retrieve.
136+ :param from_: The start index of the cheques to retrieve.
137+ :param to: The end index of the cheques to retrieve.
138+ :param offset: The offset for pagination.
139+ :param timeout: The request timeout duration in seconds (default 10).
158140 """
159141 method = "receipts.get_all"
160- params = {
161- "count" : count ,
162- "from" : from_ ,
163- "to" : to ,
164- "offset" : offset
165- }
142+ params = {"count" : count , "from" : from_ , "to" : to , "offset" : offset }
166143 return self ._post_request (method , params , timeout )
167144
168145 def set_fiscal_data (
@@ -184,13 +161,13 @@ def set_fiscal_data(
184161 fiscal_date = check_params ["c" ][0 ]
185162
186163 params = {
187- "id" : receipt_id , # required
164+ "id" : receipt_id , # required
188165 "fiscal_data" : {
189166 "terminal_id" : terminal_id ,
190- "receipt_id" : int (fiscal_receipt_id ), # required
167+ "receipt_id" : int (fiscal_receipt_id ), # required
191168 "date" : fiscal_date ,
192169 "fiscal_sign" : fiscal_sign ,
193- "qr_code_url" : qr_code_url , # required
170+ "qr_code_url" : qr_code_url , # required
194171 }
195172 }
196173 return self ._post_request (method , params , timeout )
@@ -217,6 +194,7 @@ def test(self):
217194 covering creation, payment, sending, cancellation, status checks,
218195 retrieval of a single receipt, and retrieval of multiple receipts.
219196 """
197+
220198 # Helper to assert conditions with messaging
221199 def assert_condition (condition , message , test_case ):
222200 self ._assert_and_print (condition , message , test_case = test_case )
@@ -227,36 +205,34 @@ def create_sample_receipt():
227205 account = {"id" : 12345 },
228206 amount = 1000 ,
229207 description = "Test receipt" ,
230- detail = {"key" : "value" }
208+ detail = {"key" : "value" },
231209 )
232210
233211 # Test 1: Initialization check
234212 assert_condition (
235213 isinstance (self , Receipts ),
236214 "Initialized Receipts class successfully." ,
237- test_case = "Initialization Test"
215+ test_case = "Initialization Test" ,
238216 )
239217
240218 # Test 2: Create and Pay Receipt
241219 create_response = create_sample_receipt ()
242220 assert_condition (
243221 isinstance (create_response , response .CreateResponse ),
244222 "Created a new receipt successfully." ,
245- test_case = "Receipt Creation Test"
223+ test_case = "Receipt Creation Test" ,
246224 )
247225
248226 # pylint: disable=W0212
249227 assert_condition (
250228 isinstance (create_response .result .receipt ._id , str ),
251229 "Created a valid receipt ID." ,
252- test_case = "Receipt ID Test"
230+ test_case = "Receipt ID Test" ,
253231 )
254232
255233 # Prepare card and verification
256234 cards_create_response = self .__cards .create (
257- number = "8600495473316478" ,
258- expire = "0399" ,
259- save = True
235+ number = "8600495473316478" , expire = "0399" , save = True
260236 )
261237 token = cards_create_response .result .card .token
262238 self .__cards .get_verify_code (token = token )
@@ -268,7 +244,7 @@ def create_sample_receipt():
268244 assert_condition (
269245 pay_response .result .receipt .state == 4 ,
270246 "Paid the receipt successfully." ,
271- test_case = "Payment Test"
247+ test_case = "Payment Test" ,
272248 )
273249
274250 # Test 3: Create and Send Receipt
@@ -278,7 +254,7 @@ def create_sample_receipt():
278254 assert_condition (
279255 send_response .result .success is True ,
280256 "Sent the receipt successfully." ,
281- test_case = "Send Test"
257+ test_case = "Send Test" ,
282258 )
283259
284260 # Test 4: Create and Cancel Receipt
@@ -288,43 +264,37 @@ def create_sample_receipt():
288264 assert_condition (
289265 cancel_response .result .receipt .state == 50 ,
290266 "Cancelled the receipt successfully." ,
291- test_case = "Cancel Test"
267+ test_case = "Cancel Test" ,
292268 )
293269
294270 # Test 5: Check Receipt Status
295271 check_response = self .check (receipts_id = receipt_id )
296272 assert_condition (
297273 check_response .result .state == 50 ,
298274 "Checked the receipt status successfully." ,
299- test_case = "Check Test"
275+ test_case = "Check Test" ,
300276 )
301277
302278 # Test 6: Get Receipt Details
303279 get_response = self .get (receipts_id = receipt_id )
304280 assert_condition (
305281 get_response .result .receipt ._id == receipt_id ,
306282 "Retrieved the receipt details successfully." ,
307- test_case = "Get Test"
283+ test_case = "Get Test" ,
308284 )
309285
310286 # Test 7: Retrieve All Receipts
311287 get_all_response = self .get_all (
312- count = 1 ,
313- from_ = 1730322122000 ,
314- to = 1730398982000 ,
315- offset = 0
288+ count = 1 , from_ = 1730322122000 , to = 1730398982000 , offset = 0
316289 )
317290 assert_condition (
318291 isinstance (get_all_response .result , list ),
319292 "Retrieved all receipts successfully." ,
320- test_case = "Get All Test"
293+ test_case = "Get All Test" ,
321294 )
322295
323296 # pylint: disable=W0212
324297 def _assert_and_print (
325- self ,
326- condition : bool ,
327- success_message : str ,
328- test_case : Optional [str ] = None
298+ self , condition : bool , success_message : str , test_case : t .Optional [str ] = None
329299 ):
330300 self .__cards ._assert_and_print (condition , success_message , test_case )
0 commit comments