@@ -20,7 +20,7 @@ class Fewsats:
2020 "Client for interacting with the Fewsats API"
2121 def __init__ (self ,
2222 api_key : str = None , # The API key for the Fewsats account
23- base_url : str = "https://hub-5n97k.ondigitalocean.app " ): # The Fewsats API base URL
23+ base_url : str = "https://api.fewsats.com " ): # The Fewsats API base URL
2424 self .api_key = api_key or os .environ .get ("FEWSATS_API_KEY" )
2525 if not self .api_key :
2626 raise ValueError ("The api_key client option must be set either by passing api_key to the client or by setting the FEWSATS_API_KEY environment variable" )
@@ -90,26 +90,26 @@ def get_payment_details(self:Fewsats,
9090 return httpx .post (payment_request_url , json = data )
9191
9292
93- # %% ../nbs/00_core.ipynb 32
93+ # %% ../nbs/00_core.ipynb 33
9494@patch
9595def get_payment_status (self :Fewsats ,
9696 payment_context_token :str ,
9797 ) -> dict :
9898 return self ._request ("GET" , f"v0/l402/payment-status?payment_context_token={ payment_context_token } " )
9999
100- # %% ../nbs/00_core.ipynb 34
100+ # %% ../nbs/00_core.ipynb 35
101101@patch
102102def set_webhook (self :Fewsats ,
103103 webhook_url :str ,
104104 ) -> dict :
105105 return self ._request ("POST" , f"v0/users/webhook/set" , json = {"webhook_url" : webhook_url })
106106
107- # %% ../nbs/00_core.ipynb 37
107+ # %% ../nbs/00_core.ipynb 38
108108@patch
109109def pay_lightning (self : Fewsats ,
110110 invoice : str , # lightning invoice
111111 amount : int , # amount in cents
112- currency : str = "USD " , # currency
112+ currency : str = "usd " , # currency
113113 description : str = "" ): # description of the payment
114114 "Pay for a lightning invoice"
115115 data = {
@@ -120,7 +120,7 @@ def pay_lightning(self: Fewsats,
120120 }
121121 return self ._request ("POST" , "v0/l402/purchases/lightning" , json = data )
122122
123- # %% ../nbs/00_core.ipynb 41
123+ # %% ../nbs/00_core.ipynb 42
124124class Offer (BasicRepr ):
125125 "Represents a single L402 offer"
126126 def __init__ (self ,
@@ -175,9 +175,24 @@ def from_dict(cls, d: Dict[str, Any]) -> 'L402Offers':
175175 )
176176
177177
178- # %% ../nbs/00_core.ipynb 44
178+ # %% ../nbs/00_core.ipynb 46
179179@patch
180180def pay_offer (self :Fewsats ,
181+ offer_id : str , # the offer id to pay for
182+ l402_offer : L402Offers , # a dictionary containing L402 offers
183+ ) -> dict : # payment status response
184+ """Pays an offer_id from the l402_offers. This tools requires the LLM caller to
185+ support custom classes as parameters like Claudette does.
186+
187+ Returns payment status response"""
188+ offer_dict = l402_offer .as_dict ()
189+ data = {"offer_id" : offer_id , ** offer_dict }
190+ return self ._request ("POST" , "v0/l402/purchases/from-offer" , json = data )
191+
192+
193+ # %% ../nbs/00_core.ipynb 50
194+ @patch
195+ def pay_offer_str (self :Fewsats ,
181196 offer_id : str , # the offer id to pay for
182197 l402_offer : str , # JSON string containing L402 offers
183198) -> dict : # payment status response
@@ -189,7 +204,7 @@ def pay_offer(self:Fewsats,
189204 {
190205 'offer_id': 'test_offer_2', # String identifier for the offer
191206 'amount': 1, # Numeric cost value
192- 'currency': 'USD ', # Currency code
207+ 'currency': 'usd ', # Currency code
193208 'description': 'Test offer', # Text description
194209 'title': 'Test Package' # Title of the package
195210 }
@@ -212,21 +227,21 @@ def pay_offer(self:Fewsats,
212227
213228 return self ._request ("POST" , "v0/l402/purchases/from-offer" , timeout = 20 , json = data )
214229
215- # %% ../nbs/00_core.ipynb 51
230+ # %% ../nbs/00_core.ipynb 54
216231@patch
217232def payment_info (self :Fewsats ,
218233 pid :str ): # purchase id
219234 "Retrieve the details of a payment."
220235 return self ._request ("GET" , f"v0/l402/outgoing-payments/{ pid } " )
221236
222- # %% ../nbs/00_core.ipynb 54
237+ # %% ../nbs/00_core.ipynb 57
223238@patch
224239def as_tools (self :Fewsats ):
225240 "Return list of available tools for AI agents"
226241 return [
227242 self .me ,
228243 self .balance ,
229244 self .payment_methods ,
230- self .pay_offer ,
245+ self .pay_offer_str ,
231246 self .payment_info ,
232247 ]
0 commit comments