1+ from __future__ import annotations
2+
3+ from typing import Any , Dict , Optional
4+
5+ from .http import AsyncHTTPClient , SyncHTTPClient , DEFAULT_MAX_RETRIES
6+
7+
18class Gateway :
29 """
310 Main entry point for the Shade Payment Gateway.
11+
12+ Parameters
13+ ----------
14+ api_key : str
15+ Your Shade API key.
16+ base_url : str
17+ Override the default API base URL (useful for testing).
18+ max_retries : int
19+ Number of automatic retries on HTTP 429. Defaults to
20+ ``DEFAULT_MAX_RETRIES`` (3). Set to ``0`` to disable.
21+ timeout : float
22+ Per-request socket timeout in seconds.
423 """
5- def __init__ (self ):
6- pass
724
8- def process_payment (self , amount : float , currency : str ):
25+ _DEFAULT_BASE_URL = "https://api.shadeprotocol.io/v1"
26+
27+ def __init__ (
28+ self ,
29+ api_key : str = "" ,
30+ base_url : str = "" ,
31+ max_retries : int = DEFAULT_MAX_RETRIES ,
32+ timeout : float = 30.0 ,
33+ ) -> None :
34+ self .api_key = api_key
35+ self ._base_url = base_url or self ._DEFAULT_BASE_URL
36+ self ._http = SyncHTTPClient (
37+ base_url = self ._base_url ,
38+ api_key = api_key ,
39+ max_retries = max_retries ,
40+ timeout = timeout ,
41+ )
42+ self ._async_http = AsyncHTTPClient (
43+ base_url = self ._base_url ,
44+ api_key = api_key ,
45+ max_retries = max_retries ,
46+ timeout = timeout ,
47+ )
48+
49+ # ------------------------------------------------------------------
50+ # Sync API
51+ # ------------------------------------------------------------------
52+
53+ def process_payment (self , amount : float , currency : str ) -> Dict [str , Any ]:
954 """
10- Process a payment (placeholder).
55+ Process a payment (sync).
56+
57+ Parameters
58+ ----------
59+ amount : float
60+ Payment amount.
61+ currency : str
62+ ISO 4217 currency code (e.g. ``"USD"``).
63+
64+ Returns
65+ -------
66+ dict
67+ API response body.
1168 """
12- print (f"Processing payment of { amount } { currency } ..." )
13- return True
69+ return self ._http .request (
70+ "POST" ,
71+ "/payments" ,
72+ {"amount" : amount , "currency" : currency },
73+ )
74+
75+ # ------------------------------------------------------------------
76+ # Async API
77+ # ------------------------------------------------------------------
78+
79+ async def process_payment_async (
80+ self , amount : float , currency : str
81+ ) -> Dict [str , Any ]:
82+ """Async variant of :meth:`process_payment`."""
83+ return await self ._async_http .request (
84+ "POST" ,
85+ "/payments" ,
86+ {"amount" : amount , "currency" : currency },
87+ )
0 commit comments