agentpay-global 0.3.0__py3-none-any.whl

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.
agentpay/__init__.py ADDED
@@ -0,0 +1,181 @@
1
+ """Official AgentPay SDK for Python.
2
+
3
+ Issue capped virtual cards and let your agent complete real checkouts. Card controls, 3DS,
4
+ and fraud caps are handled for you. Zero dependencies (uses the standard library).
5
+
6
+ from agentpay import AgentPay
7
+ agentpay = AgentPay(api_key="mk_live_...")
8
+ card = agentpay.cards.create(amount=20, merchant="namecheap", single_use=True)
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import json
14
+ import urllib.error
15
+ import urllib.request
16
+ from typing import Any, Optional
17
+
18
+ __version__ = "0.3.0"
19
+ __all__ = ["AgentPay", "AgentPayError"]
20
+
21
+ DEFAULT_BASE_URL = "https://api.joomjoo.com"
22
+
23
+
24
+ class AgentPayError(Exception):
25
+ """Raised on any non-2xx response. Carries the HTTP status, the AgentPay error code, and the request id."""
26
+
27
+ def __init__(self, message: str, status: int, code: Optional[str] = None, request_id: Optional[str] = None):
28
+ super().__init__(message)
29
+ self.status = status
30
+ self.code = code
31
+ self.request_id = request_id
32
+
33
+
34
+ class _Resource:
35
+ def __init__(self, client: "AgentPay") -> None:
36
+ self._client = client
37
+
38
+
39
+ class _Cards(_Resource):
40
+ def create(self, *, amount: float, merchant: str, single_use: Optional[bool] = None,
41
+ network: Optional[str] = None, card_name: Optional[str] = None) -> dict:
42
+ """Issue a virtual card capped at `amount` USD."""
43
+ body: dict = {"amount": amount, "merchant": merchant}
44
+ if single_use is not None:
45
+ body["single_use"] = single_use
46
+ if network is not None:
47
+ body["network"] = network
48
+ if card_name is not None:
49
+ body["card_name"] = card_name
50
+ return self._client._request("POST", "/v1/cards", body)
51
+
52
+ def reveal(self, card_id: str) -> dict:
53
+ """Return the full PAN/CVC/expiry for a card you issued."""
54
+ return self._client._request("GET", f"/v1/cards/{card_id}")
55
+
56
+ def close(self, card_id: str) -> dict:
57
+ """Close a card and release its unused reserve to your wallet."""
58
+ return self._client._request("POST", f"/v1/cards/{card_id}/close")
59
+
60
+
61
+ class _Spend(_Resource):
62
+ def get(self, spend_request_id: str) -> dict:
63
+ """Check whether a card was charged (not_started / authorized / cleared / declined)."""
64
+ return self._client._request("GET", f"/v1/spend/{spend_request_id}")
65
+
66
+
67
+ class _Checkout(_Resource):
68
+ def create(self, *, task: str, merchant: str, amount: float, confirm_pay: Optional[bool] = None,
69
+ connection_id: Optional[str] = None, card_holder_name: Optional[str] = None,
70
+ start_url: Optional[str] = None, idempotency_key: Optional[str] = None) -> dict:
71
+ """Let AgentPay drive a full checkout. Async: returns a checkout_id to poll with get()."""
72
+ body: dict = {"task": task, "merchant": merchant, "amount": amount}
73
+ if confirm_pay is not None:
74
+ body["confirm_pay"] = confirm_pay
75
+ if connection_id is not None:
76
+ body["connection_id"] = connection_id
77
+ if card_holder_name is not None:
78
+ body["card_holder_name"] = card_holder_name
79
+ if start_url is not None:
80
+ body["start_url"] = start_url
81
+ if idempotency_key is not None:
82
+ body["idempotency_key"] = idempotency_key
83
+ return self._client._request("POST", "/v1/checkout", body)
84
+
85
+ def get(self, checkout_id: str) -> dict:
86
+ """Poll a checkout run."""
87
+ return self._client._request("GET", f"/v1/checkout/{checkout_id}")
88
+
89
+
90
+ class _Connections(_Resource):
91
+ def create(self, *, merchant: str, user_ref: Optional[str] = None) -> dict:
92
+ body: dict = {"merchant": merchant}
93
+ if user_ref is not None:
94
+ body["user_ref"] = user_ref
95
+ return self._client._request("POST", "/v1/connections", body)
96
+
97
+ def complete(self, connection_id: str) -> dict:
98
+ return self._client._request("POST", f"/v1/connections/{connection_id}/complete")
99
+
100
+ def list(self) -> Any:
101
+ return self._client._request("GET", "/v1/connections")
102
+
103
+ def get(self, connection_id: str) -> dict:
104
+ return self._client._request("GET", f"/v1/connections/{connection_id}")
105
+
106
+
107
+ class _Wallet(_Resource):
108
+ def get(self) -> dict:
109
+ """The wallet: balance, available, reserved, pending (dollars) plus display strings."""
110
+ return self._client._request("GET", "/v1/wallet")
111
+
112
+ def create_funding_session(self, *, amount: float, success_url: Optional[str] = None,
113
+ cancel_url: Optional[str] = None) -> dict:
114
+ """A Stripe Checkout link (card or stablecoin). Open `url` for the person; the wallet is credited when Stripe confirms."""
115
+ body: dict = {"amount": amount}
116
+ if success_url is not None:
117
+ body["success_url"] = success_url
118
+ if cancel_url is not None:
119
+ body["cancel_url"] = cancel_url
120
+ return self._client._request("POST", "/v1/wallet/funding-sessions", body)
121
+
122
+ def declare_bank_transfer(self, *, amount: float, rail: Optional[str] = None, currency: Optional[str] = None,
123
+ sent_on: Optional[str] = None, sender_bank_name: Optional[str] = None,
124
+ sender_account_name: Optional[str] = None, sender_reference: Optional[str] = None,
125
+ idempotency_key: Optional[str] = None) -> dict:
126
+ """Declare a bank transfer. Returns the account to send to and the reference code for the memo; pending until the money lands."""
127
+ body: dict = {"amount": amount}
128
+ for k, v in (("rail", rail), ("currency", currency), ("sent_on", sent_on), ("sender_bank_name", sender_bank_name),
129
+ ("sender_account_name", sender_account_name), ("sender_reference", sender_reference), ("idempotency_key", idempotency_key)):
130
+ if v is not None:
131
+ body[k] = v
132
+ return self._client._request("POST", "/v1/wallet/bank-transfers", body)
133
+
134
+
135
+ class AgentPay:
136
+ """AgentPay API client.
137
+
138
+ Args:
139
+ api_key: your secret key, e.g. "mk_live_...".
140
+ base_url: override the API base URL (defaults to the live AgentPay gateway).
141
+ timeout: per-request timeout in seconds.
142
+ """
143
+
144
+ def __init__(self, api_key: str, *, base_url: str = DEFAULT_BASE_URL, timeout: float = 60.0) -> None:
145
+ if not api_key:
146
+ raise ValueError("AgentPay: api_key is required")
147
+ self.api_key = api_key
148
+ self.base_url = base_url.rstrip("/")
149
+ self.timeout = timeout
150
+ self.cards = _Cards(self)
151
+ self.spend = _Spend(self)
152
+ self.checkout = _Checkout(self)
153
+ self.connections = _Connections(self)
154
+ self.wallet = _Wallet(self)
155
+
156
+ def _request(self, method: str, path: str, body: Optional[dict] = None) -> Any:
157
+ url = f"{self.base_url}{path}"
158
+ data = None
159
+ headers = {"Authorization": f"Bearer {self.api_key}"}
160
+ if body is not None:
161
+ data = json.dumps(body).encode("utf-8")
162
+ headers["Content-Type"] = "application/json"
163
+ req = urllib.request.Request(url, data=data, method=method, headers=headers)
164
+ try:
165
+ with urllib.request.urlopen(req, timeout=self.timeout) as resp:
166
+ text = resp.read().decode("utf-8")
167
+ return json.loads(text) if text else None
168
+ except urllib.error.HTTPError as e:
169
+ raw = e.read().decode("utf-8", "replace")
170
+ request_id = e.headers.get("X-Mooj-Request-Id") if e.headers else None
171
+ parsed: Any = None
172
+ try:
173
+ parsed = json.loads(raw)
174
+ except Exception:
175
+ parsed = None
176
+ code = parsed.get("error") if isinstance(parsed, dict) else None
177
+ message = (parsed.get("message") or parsed.get("error")) if isinstance(parsed, dict) else None
178
+ req_id = (parsed.get("request_id") if isinstance(parsed, dict) else None) or request_id
179
+ raise AgentPayError(message or f"AgentPay API error {e.code}", e.code, code, req_id) from None
180
+ except urllib.error.URLError as e:
181
+ raise AgentPayError(f"AgentPay request failed: {e.reason}", 0) from None
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.5
2
+ Name: agentpay-global
3
+ Version: 0.3.0
4
+ Summary: Official AgentPay SDK. Issue capped virtual cards and let your agent complete real checkouts.
5
+ Project-URL: Homepage, https://agentpay.global
6
+ Author: AgentPay
7
+ License: MIT
8
+ Keywords: 3ds,agentpay,agentpay-global,ai-agents,checkout,payments,virtual-cards
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Software Development :: Libraries
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+
16
+ # agentpay
17
+
18
+ The official AgentPay SDK for Python. Issue capped virtual cards and let your agent complete real checkouts. Card controls, 3DS, and fraud caps are handled for you. Zero dependencies.
19
+
20
+ ## Install
21
+
22
+ ```
23
+ pip install agentpay-global
24
+ ```
25
+
26
+ Requires Python 3.8+.
27
+
28
+ ## Quickstart
29
+
30
+ ```python
31
+ import os
32
+ from agentpay import AgentPay
33
+
34
+ agentpay = AgentPay(api_key=os.environ["AGENTPAY_API_KEY"]) # key looks like mk_live_...
35
+
36
+ # Issue a single-use card capped at $20
37
+ card = agentpay.cards.create(amount=20, merchant="namecheap", single_use=True)
38
+ print(card["id"], card["last4"], card["spend_limit"])
39
+ ```
40
+
41
+ Get your API key from the AgentPay console (Developer -> API keys). Keep it server-side; never commit it.
42
+
43
+ ## Tools
44
+
45
+ ### Cards
46
+
47
+ ```python
48
+ card = agentpay.cards.create(amount=20, merchant="namecheap", single_use=True)
49
+ full = agentpay.cards.reveal(card["id"]) # {"number","cvc","exp",...}: use at the moment of purchase
50
+ closed = agentpay.cards.close(card["id"]) # release the unused reserve back to your wallet
51
+ ```
52
+
53
+ ### Spend status
54
+
55
+ ```python
56
+ spend = agentpay.spend.get(card["spend_request_id"])
57
+ # spend["status"]: "not_started" | "authorized" | "cleared" | "declined"
58
+ ```
59
+
60
+ ### Checkout (AgentPay drives the buy)
61
+
62
+ ```python
63
+ run = agentpay.checkout.create(
64
+ task="buy the domain example.click for 1 year",
65
+ merchant="namecheap",
66
+ amount=20,
67
+ confirm_pay=False, # dry run: stops at the final review. True = pay up to the cap.
68
+ )
69
+
70
+ status = agentpay.checkout.get(run["checkout_id"])
71
+ # status["status"]: "queued" | "running" | "awaiting_approval" | "needs_login" | "submitted" | "blocked"
72
+ ```
73
+
74
+ ### Connections (login-gated merchants)
75
+
76
+ ```python
77
+ conn = agentpay.connections.create(merchant="namecheap", user_ref="user-123")
78
+ # open conn["connect_url"] so the user signs in, then:
79
+ agentpay.connections.complete(conn["connection_id"])
80
+ # now pass connection_id to checkout.create to run signed-in
81
+ ```
82
+
83
+ ## Errors
84
+
85
+ Any non-2xx response raises `AgentPayError` with the HTTP status, the AgentPay error code, and the request id.
86
+
87
+ ```python
88
+ from agentpay import AgentPay, AgentPayError
89
+
90
+ try:
91
+ agentpay.cards.create(amount=999999, merchant="namecheap")
92
+ except AgentPayError as e:
93
+ print(e.status, e.code, e.request_id) # e.g. 402 insufficient_funds
94
+ ```
95
+
96
+ ## Configuration
97
+
98
+ ```python
99
+ AgentPay(
100
+ api_key=os.environ["AGENTPAY_API_KEY"],
101
+ base_url="https://api.joomjoo.com", # optional override
102
+ timeout=60.0,
103
+ )
104
+ ```
105
+
106
+ ## Docs
107
+
108
+ ## The wallet
109
+
110
+ ```python
111
+ w = agentpay.wallet.get() # balance, available, reserved, pending, in dollars
112
+ s = agentpay.wallet.create_funding_session(amount=50, success_url="https://yourapp.example/funded")
113
+ # open s["url"] for the person; the wallet is credited when Stripe confirms (webhook event money.funded)
114
+ t = agentpay.wallet.declare_bank_transfer(amount=500, rail="wire_domestic")
115
+ # t["instructions"] holds the account to send to and t["reference_code"] goes in the memo
116
+ ```
117
+
118
+ Full API reference: https://app.agentpay.global (Developer, Docs)
@@ -0,0 +1,4 @@
1
+ agentpay/__init__.py,sha256=3JpTd1VqdEhJXwQAPME7fez6JIekMfXp2tF8amqW59o,8153
2
+ agentpay_global-0.3.0.dist-info/METADATA,sha256=2PeQvU2JoClZSd2NtEWqKlCtPZZuis0D3bwlSxLKdbI,3605
3
+ agentpay_global-0.3.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
4
+ agentpay_global-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any