@@ -136,11 +136,14 @@ async def create_request(
136136 * ,
137137 label : str | None = None ,
138138 idempotency_key : str | None = None ,
139+ use_preauth : bool = False ,
139140 ) -> CreateRequestResponse :
140141 """Create a STK request to another user."""
141142 body : dict [str , Any ] = {"amount" : amount }
142143 if label is not None :
143144 body ["label" ] = label
145+ if use_preauth :
146+ body ["use_preauth" ] = True
144147 headers : dict [str , str ] = {}
145148 if idempotency_key is not None :
146149 headers ["Idempotency-Key" ] = idempotency_key
@@ -152,6 +155,29 @@ async def create_request(
152155 self ._raise_for_error (resp )
153156 return CreateRequestResponse .model_validate (resp .json ())
154157
158+ async def create_preauth (
159+ self ,
160+ user_id : int ,
161+ max_amount : int ,
162+ window_hours : int ,
163+ ) -> dict :
164+ """Request a preauthorization from a user."""
165+ resp = await self ._http .post (
166+ f"/api/user/{ user_id } /preauth" ,
167+ json = {"max_amount" : max_amount , "window_hours" : window_hours },
168+ )
169+ self ._raise_for_error (resp )
170+ return resp .json ()
171+
172+ async def get_preauths (self , * , user_id : int | None = None ) -> list [dict ]:
173+ """List preauths for this bot, optionally filtered by user_id."""
174+ params : dict [str , Any ] = {}
175+ if user_id is not None :
176+ params ["user_id" ] = user_id
177+ resp = await self ._http .get ("/api/preauths" , params = params )
178+ self ._raise_for_error (resp )
179+ return resp .json ().get ("preauths" , [])
180+
155181 async def get_request (self , request_id : int ) -> Request :
156182 """Return a single request by its ID."""
157183 resp = await self ._http .get (f"/api/request/{ request_id } " )
0 commit comments