@@ -26,6 +26,10 @@ The library provides a
2626class to handle payments. You can use handle them manually or use the
2727` as_tools() ` method to create tools for autonomous agents.
2828
29+ ### Making Payments
30+
31+ Obtain information about your account and perform payments:
32+
2933``` python
3034from fewsats.core import *
3135```
@@ -49,13 +53,14 @@ fs.payment_methods().json(), fs.balance().json(), fs.me().json()
4953 'exp_month': 12,
5054 'exp_year': 2034,
5155 'is_default': True}],
52- [{'id': 1, 'balance': 4468 , 'currency': 'usd'}],
56+ [{'id': 1, 'balance': 4464 , 'currency': 'usd'}],
5357 {'name': 'Pol',
5458 'last_name': 'Alvarez Vecino',
5559 'email': 'pol@fewsats.com',
5660 'billing_info': None,
5761 'id': 1,
58- 'created_at': '2024-08-20T16:13:01.255Z'})
62+ 'created_at': '2024-08-20T16:13:01.255Z',
63+ 'webhook_url': 'https://example.com/webhook'})
5964
6065The ` pay ` method uses the information returned by a [ L402
6166Protocol] ( https://github.com/l402-protocol/l402?tab=readme-ov-file#402-response-format )
@@ -92,8 +97,8 @@ l402_offer = {
9297fs.pay_offer(l402_offer).json()
9398```
9499
95- {'id': 118 ,
96- 'created_at': '2025-02-06T13:57:59.586Z ',
100+ {'id': 121 ,
101+ 'created_at': '2025-02-10T11:04:48.083Z ',
97102 'status': 'success',
98103 'payment_method': 'lightning'}
99104
@@ -109,6 +114,67 @@ requires you to specify the amount you are expecting to pay in cents.
109114This is done for accounting purposes and convenience, but the amount
110115paid will be the sats in the invoice.
111116
117+ ### Getting Paid
118+
119+ Fewsats also provides methods for receiving payments. You can create
120+ offers for receiving payments as follows.
121+
122+ ``` python
123+ # Create offers for receiving payments
124+ offers_data = [{
125+ " offer_id" : " offer_example" ,
126+ " amount" : 1 ,
127+ " currency" : " USD" ,
128+ " description" : " Receive payment for your service" ,
129+ " title" : " 1 Credit Package" ,
130+ " payment_methods" : [" lightning" , " stripe" ]
131+ }]
132+ r = fs.create_offers(offers_data)
133+ offers = r.json()
134+ offers
135+ ```
136+
137+ {'offers': [{'offer_id': 'offer_example',
138+ 'amount': 1,
139+ 'currency': 'USD',
140+ 'description': 'Receive payment for your service',
141+ 'title': '1 Credit Package',
142+ 'payment_methods': ['lightning', 'stripe'],
143+ 'type': 'one-off'}],
144+ 'payment_context_token': 'a175fd73-cb68-4a22-8685-b236eff2f1a0',
145+ 'payment_request_url': 'http://localhost:8000/v0/l402/payment-request',
146+ 'version': '0.2.2'}
147+
148+ You can check if an offer has been paid using the payment context token
149+ as follows.
150+
151+ ``` python
152+ fs.get_payment_status(payment_context_token = offers[" payment_context_token" ]).json()
153+ ```
154+
155+ {'payment_context_token': 'a175fd73-cb68-4a22-8685-b236eff2f1a0',
156+ 'status': 'pending',
157+ 'offer_id': None,
158+ 'paid_at': None,
159+ 'amount': None,
160+ 'currency': None}
161+
162+ If you prefer to be notified whenever an offer is paid, you can set up a
163+ webhook as follows, and we will call it whenever a payment is made.
164+
165+ ``` python
166+ r = fs.set_webhook(webhook_url = " https://example.com/webhook" )
167+ r.json()
168+ ```
169+
170+ {'name': 'Pol',
171+ 'last_name': 'Alvarez Vecino',
172+ 'email': 'pol@fewsats.com',
173+ 'billing_info': None,
174+ 'id': 1,
175+ 'created_at': '2024-08-20T16:13:01.255Z',
176+ 'webhook_url': 'https://example.com/webhook'}
177+
112178### AI Agent Integration
113179
114180We will show how to enable your AI assistant to handle payments using
0 commit comments