11import logging
22import os
33from platform import python_version
4- from typing import Optional , Dict , Any , Union
4+ from typing import Any , Dict , Optional
55
66import requests
77
8- from tappay .models import Models
98from tappay .exceptions import Exceptions
9+ from tappay .models import Models
1010
1111logger = logging .getLogger (__name__ )
1212
13- # We need to access __version__ from somewhere, commonly from a package level or hardcoded here then imported.
14- # For now I will hardcode it here or pass it in.
15- # Better yet, I will define __version__ in __init__.py and import it here? No, circular import.
16- # I will put __version__ in a separate file or keep it in __init__ and pass it to Client if needed,
17- # or just duplicate/move it.
18- # Let's define it in client.py for now to avoid circular dependency if __init__ imports client.
19- # Actually, the original code used it in User-Agent.
13+ # We need to access __version__ from somewhere, commonly from a package
14+ # level or hardcoded here then imported. For now I will hardcode it here
15+ # or pass it in. Better yet, I will define __version__ in __init__.py and
16+ # import it here? No, circular import. I will put __version__ in a
17+ # separate file or keep it in __init__ and pass it to Client if needed,
18+ # or just duplicate/move it. Let's define it in client.py for now to
19+ # avoid circular dependency if __init__ imports client. Actually, the
20+ # original code used it in User-Agent.
2021VERSION = "0.5.0"
2122
2223
@@ -81,7 +82,8 @@ def pay_by_prime(
8182 """
8283 if not isinstance (card_holder_data , Models .CardHolderData ):
8384 raise TypeError (
84- f"expected `CardHolderData` type for parameter `card_holder_data`, { type (card_holder_data )} found"
85+ f"expected `CardHolderData` type for parameter "
86+ f"`card_holder_data`, { type (card_holder_data )} found"
8587 )
8688
8789 params = {
@@ -126,9 +128,7 @@ def pay_by_token(
126128 "/tpc/payment/pay-by-token" , params
127129 )
128130
129- def refund (
130- self , rec_trade_id : str , amount : int , ** kwargs : Any
131- ) -> Dict [str , Any ]:
131+ def refund (self , rec_trade_id : str , amount : int , ** kwargs : Any ) -> Dict [str , Any ]:
132132 """
133133 Refund a payment
134134 Ref: https://docs.tappaysdk.com/tutorial/zh/back.html#refund-api
@@ -196,9 +196,7 @@ def get_trade_history(self, rec_trade_id: str) -> Dict[str, Any]:
196196 "rec_trade_id" : rec_trade_id ,
197197 }
198198
199- return self .__post_with_partner_key (
200- "/tpc/transaction/trade-history" , params
201- )
199+ return self .__post_with_partner_key ("/tpc/transaction/trade-history" , params )
202200
203201 def bind_card (
204202 self ,
@@ -212,7 +210,8 @@ def bind_card(
212210 """
213211 if not isinstance (card_holder_data , Models .CardHolderData ):
214212 raise TypeError (
215- f"expected `CardHolderData` type for parameter `card_holder_data`, { type (card_holder_data )} found"
213+ f"expected `CardHolderData` type for parameter "
214+ f"`card_holder_data`, { type (card_holder_data )} found"
216215 )
217216
218217 params = {
@@ -224,9 +223,7 @@ def bind_card(
224223 if kwargs :
225224 params .update (** kwargs )
226225
227- return self .__post_with_partner_key_and_merchant_id (
228- "/tpc/card/bind" , params
229- )
226+ return self .__post_with_partner_key_and_merchant_id ("/tpc/card/bind" , params )
230227
231228 def remove_card (self , card_key : str , card_token : str ) -> Dict [str , Any ]:
232229 """
@@ -240,9 +237,7 @@ def remove_card(self, card_key: str, card_token: str) -> Dict[str, Any]:
240237
241238 return self .__post_with_partner_key ("/tpc/card/remove" , params )
242239
243- def cancel_refund (
244- self , rec_trade_id : str , ** kwargs : Any
245- ) -> Dict [str , Any ]:
240+ def cancel_refund (self , rec_trade_id : str , ** kwargs : Any ) -> Dict [str , Any ]:
246241 """
247242 Cancel a single refund
248243 Ref: https://docs.tappaysdk.com/tutorial/zh/advanced.html#refund-cancel-api
@@ -254,9 +249,7 @@ def cancel_refund(
254249 if kwargs :
255250 params .update (** kwargs )
256251
257- return self .__post_with_partner_key (
258- "/tpc/transaction/refund/cancel" , params
259- )
252+ return self .__post_with_partner_key ("/tpc/transaction/refund/cancel" , params )
260253
261254 def __post_with_partner_key (
262255 self , request_uri : str , params : Dict [str , Any ]
@@ -297,7 +290,7 @@ def __parse(self, response: requests.Response) -> Optional[Dict[str, Any]]:
297290 elif 500 <= response .status_code < 600 :
298291 message = f"{ response .status_code } response from { self .api_host } "
299292 raise Exceptions .ServerError (message )
300-
293+
301294 # Fallback for unexpected status codes
302295 message = f"Unexpected status code { response .status_code } from { self .api_host } "
303296 raise Exceptions .ServerError (message )
0 commit comments