agent-payment-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,176 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-payment-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for AI Agent Payment Network - Hybrid crypto + fiat payments
5
+ Home-page: https://github.com/SuryaRaut/agent-payment-network
6
+ Author: Surya Raut
7
+ Author-email: itssuryaraut@gmail.com
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: requests>=2.28.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
22
+ Requires-Dist: black>=22.0.0; extra == "dev"
23
+ Requires-Dist: mypy>=0.950; extra == "dev"
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: provides-extra
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ # Agent Payment Network SDK
36
+
37
+ Python SDK for integrating with the AI Agent Payment Network - enabling hybrid crypto + fiat payments for AI agents.
38
+
39
+ ## Installation
40
+ ```bash
41
+ pip install agent-payment-sdk
42
+ ```
43
+
44
+ Or install from source:
45
+ ```bash
46
+ git clone https://github.com/yourusername/agent-payment-network
47
+ cd agent-payment-network/sdk/python
48
+ pip install -e .
49
+ ```
50
+
51
+ ## Quick Start
52
+ ```python
53
+ from agent_payment_sdk import AgentPaymentClient
54
+
55
+ # Initialize client
56
+ client = AgentPaymentClient(
57
+ api_key="your_api_key_here", # Optional for testing
58
+ base_url="http://localhost:8002"
59
+ )
60
+
61
+ # Create a payment
62
+ payment = client.create_payment(
63
+ to_agent_id="agent_456",
64
+ amount=50.00,
65
+ currency="USD",
66
+ payment_method="stripe_card", # or "crypto" or "auto"
67
+ memo="Payment for API usage"
68
+ )
69
+
70
+ print(f"Payment ID: {payment['payment_id']}")
71
+ print(f"Status: {payment['status']}")
72
+ print(f"Client Secret: {payment['client_secret']}")
73
+
74
+ # Check payment status
75
+ status = client.get_payment(payment['payment_id'])
76
+ print(f"Current status: {status['status']}")
77
+ ```
78
+
79
+ ## Payment Methods
80
+
81
+ ### Crypto Payments (ETH on Base)
82
+ ```python
83
+ # Add crypto wallet
84
+ method = client.add_payment_method(
85
+ agent_id="agent_123",
86
+ method_type="crypto_wallet",
87
+ wallet_address="0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
88
+ is_default=True
89
+ )
90
+
91
+ # Make crypto payment
92
+ payment = client.create_payment(
93
+ to_agent_id="agent_456",
94
+ amount=0.01,
95
+ currency="ETH",
96
+ payment_method="crypto"
97
+ )
98
+ ```
99
+
100
+ ### Stripe Payments (Credit/Debit Cards)
101
+ ```python
102
+ # Add Stripe card (payment_method_id from Stripe.js frontend)
103
+ method = client.add_payment_method(
104
+ agent_id="agent_123",
105
+ method_type="stripe_card",
106
+ stripe_payment_method_id="pm_1234567890",
107
+ is_default=True
108
+ )
109
+
110
+ # Make card payment
111
+ payment = client.create_payment(
112
+ to_agent_id="agent_456",
113
+ amount=100.00,
114
+ currency="USD",
115
+ payment_method="stripe_card"
116
+ )
117
+ ```
118
+
119
+ ## API Reference
120
+
121
+ ### AgentPaymentClient
122
+
123
+ #### `__init__(api_key, base_url, timeout)`
124
+ Initialize the client.
125
+
126
+ #### `create_payment(to_agent_id, amount, currency, payment_method, memo)`
127
+ Create a new payment.
128
+
129
+ #### `get_payment(payment_id)`
130
+ Get payment status.
131
+
132
+ #### `health_check()`
133
+ Check API health.
134
+
135
+ #### `add_payment_method(agent_id, method_type, ...)`
136
+ Add payment method.
137
+
138
+ #### `list_payment_methods(agent_id)`
139
+ List all payment methods.
140
+
141
+ #### `delete_payment_method(method_id)`
142
+ Remove payment method.
143
+
144
+ ## Error Handling
145
+ ```python
146
+ from agent_payment_sdk import PaymentError, NetworkError
147
+
148
+ try:
149
+ payment = client.create_payment(
150
+ to_agent_id="agent_456",
151
+ amount=50.00
152
+ )
153
+ except PaymentError as e:
154
+ print(f"Payment failed: {e}")
155
+ except NetworkError as e:
156
+ print(f"Network error: {e}")
157
+ ```
158
+
159
+ ## Features
160
+
161
+ - ✅ Hybrid crypto + fiat payments
162
+ - ✅ Automatic payment method selection
163
+ - ✅ Payment method management
164
+ - ✅ Type hints for better IDE support
165
+ - ✅ Comprehensive error handling
166
+ - ✅ Simple, intuitive API
167
+
168
+ ## Support
169
+
170
+ - Documentation: https://docs.agentpayment.network
171
+ - Issues: https://github.com/yourusername/agent-payment-network/issues
172
+ - Email: support@agentpayment.network
173
+
174
+ ## License
175
+
176
+ MIT License - see LICENSE file for details
@@ -0,0 +1,142 @@
1
+ # Agent Payment Network SDK
2
+
3
+ Python SDK for integrating with the AI Agent Payment Network - enabling hybrid crypto + fiat payments for AI agents.
4
+
5
+ ## Installation
6
+ ```bash
7
+ pip install agent-payment-sdk
8
+ ```
9
+
10
+ Or install from source:
11
+ ```bash
12
+ git clone https://github.com/yourusername/agent-payment-network
13
+ cd agent-payment-network/sdk/python
14
+ pip install -e .
15
+ ```
16
+
17
+ ## Quick Start
18
+ ```python
19
+ from agent_payment_sdk import AgentPaymentClient
20
+
21
+ # Initialize client
22
+ client = AgentPaymentClient(
23
+ api_key="your_api_key_here", # Optional for testing
24
+ base_url="http://localhost:8002"
25
+ )
26
+
27
+ # Create a payment
28
+ payment = client.create_payment(
29
+ to_agent_id="agent_456",
30
+ amount=50.00,
31
+ currency="USD",
32
+ payment_method="stripe_card", # or "crypto" or "auto"
33
+ memo="Payment for API usage"
34
+ )
35
+
36
+ print(f"Payment ID: {payment['payment_id']}")
37
+ print(f"Status: {payment['status']}")
38
+ print(f"Client Secret: {payment['client_secret']}")
39
+
40
+ # Check payment status
41
+ status = client.get_payment(payment['payment_id'])
42
+ print(f"Current status: {status['status']}")
43
+ ```
44
+
45
+ ## Payment Methods
46
+
47
+ ### Crypto Payments (ETH on Base)
48
+ ```python
49
+ # Add crypto wallet
50
+ method = client.add_payment_method(
51
+ agent_id="agent_123",
52
+ method_type="crypto_wallet",
53
+ wallet_address="0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
54
+ is_default=True
55
+ )
56
+
57
+ # Make crypto payment
58
+ payment = client.create_payment(
59
+ to_agent_id="agent_456",
60
+ amount=0.01,
61
+ currency="ETH",
62
+ payment_method="crypto"
63
+ )
64
+ ```
65
+
66
+ ### Stripe Payments (Credit/Debit Cards)
67
+ ```python
68
+ # Add Stripe card (payment_method_id from Stripe.js frontend)
69
+ method = client.add_payment_method(
70
+ agent_id="agent_123",
71
+ method_type="stripe_card",
72
+ stripe_payment_method_id="pm_1234567890",
73
+ is_default=True
74
+ )
75
+
76
+ # Make card payment
77
+ payment = client.create_payment(
78
+ to_agent_id="agent_456",
79
+ amount=100.00,
80
+ currency="USD",
81
+ payment_method="stripe_card"
82
+ )
83
+ ```
84
+
85
+ ## API Reference
86
+
87
+ ### AgentPaymentClient
88
+
89
+ #### `__init__(api_key, base_url, timeout)`
90
+ Initialize the client.
91
+
92
+ #### `create_payment(to_agent_id, amount, currency, payment_method, memo)`
93
+ Create a new payment.
94
+
95
+ #### `get_payment(payment_id)`
96
+ Get payment status.
97
+
98
+ #### `health_check()`
99
+ Check API health.
100
+
101
+ #### `add_payment_method(agent_id, method_type, ...)`
102
+ Add payment method.
103
+
104
+ #### `list_payment_methods(agent_id)`
105
+ List all payment methods.
106
+
107
+ #### `delete_payment_method(method_id)`
108
+ Remove payment method.
109
+
110
+ ## Error Handling
111
+ ```python
112
+ from agent_payment_sdk import PaymentError, NetworkError
113
+
114
+ try:
115
+ payment = client.create_payment(
116
+ to_agent_id="agent_456",
117
+ amount=50.00
118
+ )
119
+ except PaymentError as e:
120
+ print(f"Payment failed: {e}")
121
+ except NetworkError as e:
122
+ print(f"Network error: {e}")
123
+ ```
124
+
125
+ ## Features
126
+
127
+ - ✅ Hybrid crypto + fiat payments
128
+ - ✅ Automatic payment method selection
129
+ - ✅ Payment method management
130
+ - ✅ Type hints for better IDE support
131
+ - ✅ Comprehensive error handling
132
+ - ✅ Simple, intuitive API
133
+
134
+ ## Support
135
+
136
+ - Documentation: https://docs.agentpayment.network
137
+ - Issues: https://github.com/yourusername/agent-payment-network/issues
138
+ - Email: support@agentpayment.network
139
+
140
+ ## License
141
+
142
+ MIT License - see LICENSE file for details
@@ -0,0 +1,22 @@
1
+ """
2
+ Agent Payment Network SDK
3
+ A simple Python SDK for integrating with the AI Agent Payment Network
4
+ """
5
+
6
+ __version__ = "0.1.0"
7
+
8
+ from .client import (
9
+ AgentPaymentClient,
10
+ PaymentError,
11
+ AuthenticationError,
12
+ InvalidRequestError,
13
+ NetworkError
14
+ )
15
+
16
+ __all__ = [
17
+ "AgentPaymentClient",
18
+ "PaymentError",
19
+ "AuthenticationError",
20
+ "InvalidRequestError",
21
+ "NetworkError"
22
+ ]
@@ -0,0 +1,250 @@
1
+ """Main SDK Client for Agent Payment Network"""
2
+
3
+ import requests
4
+ from typing import Optional, Dict, Any, List
5
+ from decimal import Decimal
6
+
7
+
8
+ class AgentPaymentClient:
9
+ """
10
+ Client for interacting with Agent Payment Network API
11
+
12
+ Example:
13
+ >>> client = AgentPaymentClient(
14
+ ... api_key="your_api_key",
15
+ ... base_url="http://localhost:8002"
16
+ ... )
17
+ >>> payment = client.create_payment(
18
+ ... to_agent_id="agent_123",
19
+ ... amount=50.00,
20
+ ... currency="USD",
21
+ ... payment_method="stripe_card"
22
+ ... )
23
+ >>> print(payment["payment_id"])
24
+ """
25
+
26
+ def __init__(
27
+ self,
28
+ api_key: Optional[str] = None,
29
+ base_url: str = "http://localhost:8002",
30
+ timeout: int = 30
31
+ ):
32
+ """
33
+ Initialize the Agent Payment Network client
34
+
35
+ Args:
36
+ api_key: Your API key (optional for testing)
37
+ base_url: Base URL of the API (default: localhost)
38
+ timeout: Request timeout in seconds
39
+ """
40
+ self.api_key = api_key
41
+ self.base_url = base_url.rstrip("/")
42
+ self.timeout = timeout
43
+ self.session = requests.Session()
44
+
45
+ if api_key:
46
+ self.session.headers.update({
47
+ "Authorization": f"Bearer {api_key}"
48
+ })
49
+
50
+ def _request(
51
+ self,
52
+ method: str,
53
+ endpoint: str,
54
+ **kwargs
55
+ ) -> Dict[str, Any]:
56
+ """Make HTTP request to API"""
57
+ url = f"{self.base_url}{endpoint}"
58
+
59
+ try:
60
+ response = self.session.request(
61
+ method=method,
62
+ url=url,
63
+ timeout=self.timeout,
64
+ **kwargs
65
+ )
66
+ response.raise_for_status()
67
+ return response.json()
68
+
69
+ except requests.exceptions.HTTPError as e:
70
+ error_detail = "Unknown error"
71
+ try:
72
+ error_data = e.response.json()
73
+ error_detail = error_data.get("detail", str(e))
74
+ except:
75
+ error_detail = str(e)
76
+
77
+ raise PaymentError(f"API Error: {error_detail}")
78
+
79
+ except requests.exceptions.Timeout:
80
+ raise NetworkError("Request timed out")
81
+
82
+ except requests.exceptions.RequestException as e:
83
+ raise NetworkError(f"Network error: {str(e)}")
84
+
85
+ # Payment Operations
86
+
87
+ def create_payment(
88
+ self,
89
+ to_agent_id: str,
90
+ amount: float,
91
+ currency: str = "USD",
92
+ payment_method: str = "auto",
93
+ memo: Optional[str] = None
94
+ ) -> Dict[str, Any]:
95
+ """
96
+ Create a new payment
97
+
98
+ Args:
99
+ to_agent_id: Recipient agent ID
100
+ amount: Payment amount
101
+ currency: Currency code (USD, ETH, etc.)
102
+ payment_method: Payment method (auto, crypto, stripe_card)
103
+ memo: Optional payment memo
104
+
105
+ Returns:
106
+ Payment response with payment_id, status, and client_secret
107
+
108
+ Example:
109
+ >>> payment = client.create_payment(
110
+ ... to_agent_id="agent_456",
111
+ ... amount=100.00,
112
+ ... currency="USD",
113
+ ... payment_method="stripe_card",
114
+ ... memo="Monthly API usage"
115
+ ... )
116
+ >>> print(f"Payment ID: {payment['payment_id']}")
117
+ """
118
+ data = {
119
+ "to_agent_id": to_agent_id,
120
+ "amount": amount,
121
+ "currency": currency,
122
+ "payment_method": payment_method,
123
+ "memo": memo
124
+ }
125
+
126
+ return self._request(
127
+ "POST",
128
+ "/api/v1/payments/create",
129
+ json=data
130
+ )
131
+
132
+ def get_payment(self, payment_id: str) -> Dict[str, Any]:
133
+ """
134
+ Get payment status by ID
135
+
136
+ Args:
137
+ payment_id: Payment ID
138
+
139
+ Returns:
140
+ Payment details including status
141
+ """
142
+ return self._request(
143
+ "GET",
144
+ f"/api/v1/payments/{payment_id}"
145
+ )
146
+
147
+ def health_check(self) -> Dict[str, Any]:
148
+ """
149
+ Check API health and available payment methods
150
+
151
+ Returns:
152
+ Health status and configuration
153
+ """
154
+ return self._request(
155
+ "GET",
156
+ "/api/v1/payments/health"
157
+ )
158
+
159
+ # Payment Method Management
160
+
161
+ def add_payment_method(
162
+ self,
163
+ agent_id: str,
164
+ method_type: str,
165
+ wallet_address: Optional[str] = None,
166
+ stripe_payment_method_id: Optional[str] = None,
167
+ is_default: bool = False
168
+ ) -> Dict[str, Any]:
169
+ """
170
+ Add a new payment method
171
+
172
+ Args:
173
+ agent_id: Your agent ID
174
+ method_type: Type (crypto_wallet, stripe_card, stripe_bank)
175
+ wallet_address: Wallet address (for crypto)
176
+ stripe_payment_method_id: Stripe payment method ID (for cards)
177
+ is_default: Set as default payment method
178
+
179
+ Returns:
180
+ Payment method details
181
+ """
182
+ data = {
183
+ "agent_id": agent_id,
184
+ "method_type": method_type,
185
+ "is_default": is_default
186
+ }
187
+
188
+ if wallet_address:
189
+ data["wallet_address"] = wallet_address
190
+
191
+ if stripe_payment_method_id:
192
+ data["stripe_payment_method_id"] = stripe_payment_method_id
193
+
194
+ return self._request(
195
+ "POST",
196
+ "/api/v1/payment-methods/add",
197
+ json=data
198
+ )
199
+
200
+ def list_payment_methods(self, agent_id: str) -> List[Dict[str, Any]]:
201
+ """
202
+ List all payment methods for an agent
203
+
204
+ Args:
205
+ agent_id: Agent ID
206
+
207
+ Returns:
208
+ List of payment methods
209
+ """
210
+ return self._request(
211
+ "GET",
212
+ f"/api/v1/payment-methods/list/{agent_id}"
213
+ )
214
+
215
+ def delete_payment_method(self, method_id: str) -> Dict[str, Any]:
216
+ """
217
+ Delete a payment method
218
+
219
+ Args:
220
+ method_id: Payment method ID
221
+
222
+ Returns:
223
+ Success confirmation
224
+ """
225
+ return self._request(
226
+ "DELETE",
227
+ f"/api/v1/payment-methods/{method_id}"
228
+ )
229
+
230
+
231
+ # Exceptions
232
+
233
+ class PaymentError(Exception):
234
+ """Base exception for payment errors"""
235
+ pass
236
+
237
+
238
+ class AuthenticationError(PaymentError):
239
+ """Authentication failed"""
240
+ pass
241
+
242
+
243
+ class InvalidRequestError(PaymentError):
244
+ """Invalid request parameters"""
245
+ pass
246
+
247
+
248
+ class NetworkError(PaymentError):
249
+ """Network communication error"""
250
+ pass