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+ if not api_key :
35+ raise ValueError ("api_key must be a non-empty string" )
36+ self .api_key = api_key
37+ self ._base_url = base_url or self ._DEFAULT_BASE_URL
38+ self ._http = SyncHTTPClient (
39+ base_url = self ._base_url ,
40+ api_key = api_key ,
41+ max_retries = max_retries ,
42+ timeout = timeout ,
43+ )
44+ self ._async_http = AsyncHTTPClient (
45+ base_url = self ._base_url ,
46+ api_key = api_key ,
47+ max_retries = max_retries ,
48+ timeout = timeout ,
49+ )
50+
51+ # ------------------------------------------------------------------
52+ # Sync API
53+ # ------------------------------------------------------------------
54+
55+ def process_payment (self , amount : float , currency : str ) -> Dict [str , Any ]:
956 """
10- Process a payment (placeholder).
57+ Process a payment (sync).
58+
59+ Parameters
60+ ----------
61+ amount : float
62+ Payment amount.
63+ currency : str
64+ ISO 4217 currency code (e.g. ``"USD"``).
65+
66+ Returns
67+ -------
68+ dict
69+ API response body.
1170 """
12- print (f"Processing payment of { amount } { currency } ..." )
13- return True
71+ return self ._http .request (
72+ "POST" ,
73+ "/payments" ,
74+ {"amount" : amount , "currency" : currency },
75+ )
76+
77+ # ------------------------------------------------------------------
78+ # Async API
79+ # ------------------------------------------------------------------
80+
81+ async def process_payment_async (
82+ self , amount : float , currency : str
83+ ) -> Dict [str , Any ]:
84+ """Async variant of :meth:`process_payment`."""
85+ return await self ._async_http .request (
86+ "POST" ,
87+ "/payments" ,
88+ {"amount" : amount , "currency" : currency },
89+ )
0 commit comments