stripe-agent-toolkit 0.1.16__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.
- stripe_agent_toolkit-0.1.16/LICENSE +21 -0
- stripe_agent_toolkit-0.1.16/PKG-INFO +97 -0
- stripe_agent_toolkit-0.1.16/README.md +64 -0
- stripe_agent_toolkit-0.1.16/pyproject.toml +40 -0
- stripe_agent_toolkit-0.1.16/setup.cfg +4 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/__init__.py +0 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/api.py +60 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/configuration.py +54 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/crewai/tool.py +30 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/crewai/toolkit.py +37 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/functions.py +181 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/langchain/tool.py +30 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/langchain/toolkit.py +37 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/prompts.py +80 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/schema.py +151 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit/tools.py +153 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit.egg-info/PKG-INFO +97 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit.egg-info/SOURCES.txt +20 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit.egg-info/dependency_links.txt +1 -0
- stripe_agent_toolkit-0.1.16/stripe_agent_toolkit.egg-info/top_level.txt +1 -0
- stripe_agent_toolkit-0.1.16/tests/test_configuration.py +58 -0
- stripe_agent_toolkit-0.1.16/tests/test_functions.py +256 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Stripe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: stripe-agent-toolkit
|
|
3
|
+
Version: 0.1.16
|
|
4
|
+
Summary: Stripe Agent Toolkit
|
|
5
|
+
Author-email: Stripe <support@stripe.com>
|
|
6
|
+
License: The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Stripe
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Bug Tracker, https://github.com/stripe/agent-toolkit/issues
|
|
29
|
+
Project-URL: Source Code, https://github.com/stripe/agent-toolkit
|
|
30
|
+
Keywords: stripe,api,payments
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
|
|
34
|
+
# Stripe Agent Toolkit - Python
|
|
35
|
+
|
|
36
|
+
The Stripe Agent Toolkit library enables popular agent frameworks including LangChain and CrewAI to integrate with Stripe APIs through function calling. The
|
|
37
|
+
library is not exhaustive of the entire Stripe API. It is built directly on top
|
|
38
|
+
of the [Stripe Python SDK][python-sdk].
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
You don't need this source code unless you want to modify the package. If you just
|
|
43
|
+
want to use the package, just run:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
pip install stripe-agent-toolkit
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Requirements
|
|
50
|
+
|
|
51
|
+
- Python 3.11+
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
The library needs to be configured with your account's secret key which is
|
|
56
|
+
available in your [Stripe Dashboard][api-keys].
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from stripe_agent_toolkit.crewai.toolkit import StripeAgentToolkit
|
|
60
|
+
|
|
61
|
+
stripe_agent_toolkit = StripeAgentToolkit(
|
|
62
|
+
secret_key="sk_test_...",
|
|
63
|
+
configuration={
|
|
64
|
+
"actions": {
|
|
65
|
+
"payment_links": {
|
|
66
|
+
"create": True,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The toolkit works with LangChain and CrewAI and can be passed as a list of tools. For example:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from crewai import Agent
|
|
77
|
+
|
|
78
|
+
stripe_agent = Agent(
|
|
79
|
+
role="Stripe Agent",
|
|
80
|
+
goal="Integrate with Stripe",
|
|
81
|
+
backstory="You are an expert at integrating with Stripe",
|
|
82
|
+
tools=[*stripe_toolkit.get_tools()]
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Examples for LangChain and CrewAI are included in `/examples`.
|
|
87
|
+
|
|
88
|
+
[python-sdk]: https://github.com/stripe/stripe-python
|
|
89
|
+
[api-keys]: https://dashboard.stripe.com/account/apikeys
|
|
90
|
+
|
|
91
|
+
## Development
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
python3 -m venv venv
|
|
95
|
+
source venv/bin/activate
|
|
96
|
+
pip install -r requirements.txt
|
|
97
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Stripe Agent Toolkit - Python
|
|
2
|
+
|
|
3
|
+
The Stripe Agent Toolkit library enables popular agent frameworks including LangChain and CrewAI to integrate with Stripe APIs through function calling. The
|
|
4
|
+
library is not exhaustive of the entire Stripe API. It is built directly on top
|
|
5
|
+
of the [Stripe Python SDK][python-sdk].
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
You don't need this source code unless you want to modify the package. If you just
|
|
10
|
+
want to use the package, just run:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pip install stripe-agent-toolkit
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Requirements
|
|
17
|
+
|
|
18
|
+
- Python 3.11+
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
The library needs to be configured with your account's secret key which is
|
|
23
|
+
available in your [Stripe Dashboard][api-keys].
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from stripe_agent_toolkit.crewai.toolkit import StripeAgentToolkit
|
|
27
|
+
|
|
28
|
+
stripe_agent_toolkit = StripeAgentToolkit(
|
|
29
|
+
secret_key="sk_test_...",
|
|
30
|
+
configuration={
|
|
31
|
+
"actions": {
|
|
32
|
+
"payment_links": {
|
|
33
|
+
"create": True,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The toolkit works with LangChain and CrewAI and can be passed as a list of tools. For example:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from crewai import Agent
|
|
44
|
+
|
|
45
|
+
stripe_agent = Agent(
|
|
46
|
+
role="Stripe Agent",
|
|
47
|
+
goal="Integrate with Stripe",
|
|
48
|
+
backstory="You are an expert at integrating with Stripe",
|
|
49
|
+
tools=[*stripe_toolkit.get_tools()]
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Examples for LangChain and CrewAI are included in `/examples`.
|
|
54
|
+
|
|
55
|
+
[python-sdk]: https://github.com/stripe/stripe-python
|
|
56
|
+
[api-keys]: https://dashboard.stripe.com/account/apikeys
|
|
57
|
+
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
python3 -m venv venv
|
|
62
|
+
source venv/bin/activate
|
|
63
|
+
pip install -r requirements.txt
|
|
64
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "stripe-agent-toolkit"
|
|
3
|
+
version = "0.1.16"
|
|
4
|
+
description = "Stripe Agent Toolkit"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = {file = "LICENSE"}
|
|
7
|
+
authors = [
|
|
8
|
+
{name = "Stripe", email = "support@stripe.com"}
|
|
9
|
+
]
|
|
10
|
+
keywords = ["stripe", "api", "payments"]
|
|
11
|
+
|
|
12
|
+
[project.urls]
|
|
13
|
+
"Bug Tracker" = "https://github.com/stripe/agent-toolkit/issues"
|
|
14
|
+
"Source Code" = "https://github.com/stripe/agent-toolkit"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
include = ["stripe_agent_toolkit*"]
|
|
18
|
+
exclude = ["tests*", "examples*"]
|
|
19
|
+
|
|
20
|
+
[tool.ruff]
|
|
21
|
+
# same as our black config
|
|
22
|
+
line-length = 79
|
|
23
|
+
extend-exclude = ["build"]
|
|
24
|
+
|
|
25
|
+
[tool.ruff.format]
|
|
26
|
+
# currently the default value, but opt-out in the future
|
|
27
|
+
docstring-code-format = false
|
|
28
|
+
|
|
29
|
+
[tool.pyright]
|
|
30
|
+
include = [
|
|
31
|
+
"*",
|
|
32
|
+
]
|
|
33
|
+
exclude = ["build", "**/__pycache__"]
|
|
34
|
+
reportMissingTypeArgument = true
|
|
35
|
+
reportUnnecessaryCast = true
|
|
36
|
+
reportUnnecessaryComparison = true
|
|
37
|
+
reportUnnecessaryContains = true
|
|
38
|
+
reportUnnecessaryIsInstance = true
|
|
39
|
+
reportPrivateImportUsage = true
|
|
40
|
+
reportUnnecessaryTypeIgnoreComment = true
|
|
File without changes
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Util that calls Stripe."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import stripe
|
|
7
|
+
from pydantic import BaseModel
|
|
8
|
+
|
|
9
|
+
from .functions import (
|
|
10
|
+
create_customer,
|
|
11
|
+
list_customers,
|
|
12
|
+
create_product,
|
|
13
|
+
list_products,
|
|
14
|
+
create_price,
|
|
15
|
+
list_prices,
|
|
16
|
+
create_payment_link,
|
|
17
|
+
create_invoice,
|
|
18
|
+
create_invoice_item,
|
|
19
|
+
finalize_invoice,
|
|
20
|
+
retrieve_balance,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class StripeAPI(BaseModel):
|
|
25
|
+
""" "Wrapper for Stripe API"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, secret_key: str):
|
|
28
|
+
super().__init__()
|
|
29
|
+
stripe.api_key = secret_key
|
|
30
|
+
stripe.set_app_info(
|
|
31
|
+
"stripe-agent-toolkit-python",
|
|
32
|
+
version="0.1.16",
|
|
33
|
+
url="https://github.com/stripe/agent-toolkit",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def run(self, method: str, *args, **kwargs) -> str:
|
|
37
|
+
if method == "create_customer":
|
|
38
|
+
return json.dumps(create_customer(*args, **kwargs))
|
|
39
|
+
elif method == "list_customers":
|
|
40
|
+
return json.dumps(list_customers(*args, **kwargs))
|
|
41
|
+
elif method == "create_product":
|
|
42
|
+
return json.dumps(create_product(*args, **kwargs))
|
|
43
|
+
elif method == "list_products":
|
|
44
|
+
return json.dumps(list_products(*args, **kwargs))
|
|
45
|
+
elif method == "create_price":
|
|
46
|
+
return json.dumps(create_price(*args, **kwargs))
|
|
47
|
+
elif method == "list_prices":
|
|
48
|
+
return json.dumps(list_prices(*args, **kwargs))
|
|
49
|
+
elif method == "create_payment_link":
|
|
50
|
+
return json.dumps(create_payment_link(*args, **kwargs))
|
|
51
|
+
elif method == "create_invoice":
|
|
52
|
+
return json.dumps(create_invoice(*args, **kwargs))
|
|
53
|
+
elif method == "create_invoice_item":
|
|
54
|
+
return json.dumps(create_invoice_item(*args, **kwargs))
|
|
55
|
+
elif method == "finalize_invoice":
|
|
56
|
+
return json.dumps(finalize_invoice(*args, **kwargs))
|
|
57
|
+
elif method == "retrieve_balance":
|
|
58
|
+
return json.dumps(retrieve_balance(*args, **kwargs))
|
|
59
|
+
else:
|
|
60
|
+
raise ValueError("Invalid method " + method)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from typing import TypedDict, Literal, Optional
|
|
2
|
+
|
|
3
|
+
# Define Object type
|
|
4
|
+
Object = Literal[
|
|
5
|
+
"customers",
|
|
6
|
+
"invoices",
|
|
7
|
+
"invoiceItems",
|
|
8
|
+
"paymentLinks",
|
|
9
|
+
"products",
|
|
10
|
+
"prices",
|
|
11
|
+
"balance",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Define Permission type
|
|
16
|
+
class Permission(TypedDict, total=False):
|
|
17
|
+
create: Optional[bool]
|
|
18
|
+
update: Optional[bool]
|
|
19
|
+
read: Optional[bool]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Define BalancePermission type
|
|
23
|
+
class BalancePermission(TypedDict, total=False):
|
|
24
|
+
read: Optional[bool]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# Define Actions type
|
|
28
|
+
class Actions(TypedDict, total=False):
|
|
29
|
+
customers: Optional[Permission]
|
|
30
|
+
invoices: Optional[Permission]
|
|
31
|
+
invoice_items: Optional[Permission]
|
|
32
|
+
payment_links: Optional[Permission]
|
|
33
|
+
products: Optional[Permission]
|
|
34
|
+
prices: Optional[Permission]
|
|
35
|
+
balance: Optional[BalancePermission]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Define Configuration type
|
|
39
|
+
class Configuration(TypedDict, total=False):
|
|
40
|
+
actions: Optional[Actions]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def is_tool_allowed(tool, configuration):
|
|
44
|
+
for resource, permissions in tool.get("actions").items():
|
|
45
|
+
if resource not in configuration.get("actions", {}):
|
|
46
|
+
return False
|
|
47
|
+
for permission in permissions:
|
|
48
|
+
if (
|
|
49
|
+
not configuration["actions"]
|
|
50
|
+
.get(resource, {})
|
|
51
|
+
.get(permission, False)
|
|
52
|
+
):
|
|
53
|
+
return False
|
|
54
|
+
return True
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This tool allows agents to interact with the Stripe API.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Any, Optional, Type
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
|
|
10
|
+
from crewai_tools import BaseTool
|
|
11
|
+
|
|
12
|
+
from ..api import StripeAPI
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class StripeTool(BaseTool):
|
|
16
|
+
"""Tool for interacting with the Stripe API."""
|
|
17
|
+
|
|
18
|
+
stripe_api: StripeAPI
|
|
19
|
+
method: str
|
|
20
|
+
name: str = ""
|
|
21
|
+
description: str = ""
|
|
22
|
+
args_schema: Optional[Type[BaseModel]] = None
|
|
23
|
+
|
|
24
|
+
def _run(
|
|
25
|
+
self,
|
|
26
|
+
*args: Any,
|
|
27
|
+
**kwargs: Any,
|
|
28
|
+
) -> str:
|
|
29
|
+
"""Use the Stripe API to run an operation."""
|
|
30
|
+
return self.stripe_api.run(self.method, *args, **kwargs)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Stripe Agent Toolkit."""
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
from pydantic import PrivateAttr
|
|
5
|
+
|
|
6
|
+
from ..api import StripeAPI
|
|
7
|
+
from ..tools import tools
|
|
8
|
+
from ..configuration import Configuration, is_tool_allowed
|
|
9
|
+
from .tool import StripeTool
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StripeAgentToolkit:
|
|
13
|
+
_tools: List = PrivateAttr(default=[])
|
|
14
|
+
|
|
15
|
+
def __init__(self, secret_key: str, configuration: Configuration = None):
|
|
16
|
+
super().__init__()
|
|
17
|
+
|
|
18
|
+
stripe_api = StripeAPI(secret_key=secret_key)
|
|
19
|
+
|
|
20
|
+
filtered_tools = [
|
|
21
|
+
tool for tool in tools if is_tool_allowed(tool, configuration)
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
self._tools = [
|
|
25
|
+
StripeTool(
|
|
26
|
+
name=tool["name"],
|
|
27
|
+
description=tool["description"],
|
|
28
|
+
method=tool["method"],
|
|
29
|
+
stripe_api=stripe_api,
|
|
30
|
+
args_schema=tool.get("args_schema", None),
|
|
31
|
+
)
|
|
32
|
+
for tool in filtered_tools
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
def get_tools(self) -> List:
|
|
36
|
+
"""Get the tools in the toolkit."""
|
|
37
|
+
return self._tools
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import stripe
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def create_customer(name: str, email: str = None):
|
|
5
|
+
"""
|
|
6
|
+
Create a customer.
|
|
7
|
+
|
|
8
|
+
Parameters:
|
|
9
|
+
name (str): The name of the customer.
|
|
10
|
+
email (str, optional): The email address of the customer.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
stripe.Customer: The created customer.
|
|
14
|
+
"""
|
|
15
|
+
customer = stripe.Customer.create(name=name, email=email)
|
|
16
|
+
return {"id": customer.id}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def list_customers(email: str = None, limit: int = None):
|
|
20
|
+
"""
|
|
21
|
+
List Customers.
|
|
22
|
+
|
|
23
|
+
Parameters:
|
|
24
|
+
email (str, optional): The email address of the customer.
|
|
25
|
+
limit (int, optional): The number of customers to return.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
stripe.ListObject: A list of customers.
|
|
29
|
+
"""
|
|
30
|
+
customers = stripe.Customer.list(email=email, limit=limit)
|
|
31
|
+
return [{"id": customer.id} for customer in customers.data]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def create_product(name: str, description: str = None):
|
|
35
|
+
"""
|
|
36
|
+
Create a product.
|
|
37
|
+
|
|
38
|
+
Parameters:
|
|
39
|
+
name (str): The name of the product.
|
|
40
|
+
description (str, optional): The description of the product.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
stripe.Product: The created product.
|
|
44
|
+
"""
|
|
45
|
+
return stripe.Product.create(name=name, description=description)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def list_products(limit: int = None):
|
|
49
|
+
"""
|
|
50
|
+
List Products.
|
|
51
|
+
Parameters:
|
|
52
|
+
limit (int, optional): The number of products to return.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
stripe.ListObject: A list of products.
|
|
56
|
+
"""
|
|
57
|
+
return stripe.Product.list(limit=limit).data
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def create_price(product: str, currency: str, unit_amount: int):
|
|
61
|
+
"""
|
|
62
|
+
Create a price.
|
|
63
|
+
|
|
64
|
+
Parameters:
|
|
65
|
+
product (str): The ID of the product.
|
|
66
|
+
currency (str): The currency of the price.
|
|
67
|
+
unit_amount (int): The unit amount of the price.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
stripe.Price: The created price.
|
|
71
|
+
"""
|
|
72
|
+
return stripe.Price.create(
|
|
73
|
+
product=product, currency=currency, unit_amount=unit_amount
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def list_prices(product: str = None, limit: int = None):
|
|
78
|
+
"""
|
|
79
|
+
List Prices.
|
|
80
|
+
|
|
81
|
+
Parameters:
|
|
82
|
+
product (str, optional): The ID of the product to list prices for.
|
|
83
|
+
limit (int, optional): The number of prices to return.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
stripe.ListObject: A list of prices.
|
|
87
|
+
"""
|
|
88
|
+
return stripe.Price.list(product=product, limit=limit).data
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def create_payment_link(price: str, quantity: int):
|
|
92
|
+
"""
|
|
93
|
+
Create a payment link.
|
|
94
|
+
|
|
95
|
+
Parameters:
|
|
96
|
+
price (str): The ID of the price.
|
|
97
|
+
quantity (int): The quantity of the product.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
stripe.PaymentLink: The created payment link.
|
|
101
|
+
"""
|
|
102
|
+
payment_link = stripe.PaymentLink.create(
|
|
103
|
+
line_items=[{"price": price, "quantity": quantity}]
|
|
104
|
+
)
|
|
105
|
+
return {"id": payment_link.id, "url": payment_link.url}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def create_invoice(customer: str, days_until_due: int = 30):
|
|
109
|
+
"""
|
|
110
|
+
Create an invoice.
|
|
111
|
+
|
|
112
|
+
Parameters:
|
|
113
|
+
customer (str): The ID of the customer.
|
|
114
|
+
days_until_due (int, optional): The number of days until the
|
|
115
|
+
invoice is due.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
stripe.Invoice: The created invoice.
|
|
119
|
+
"""
|
|
120
|
+
invoice = stripe.Invoice.create(
|
|
121
|
+
customer=customer,
|
|
122
|
+
collection_method="send_invoice",
|
|
123
|
+
days_until_due=days_until_due,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
"id": invoice.id,
|
|
128
|
+
"hosted_invoice_url": invoice.hosted_invoice_url,
|
|
129
|
+
"customer": invoice.customer,
|
|
130
|
+
"status": invoice.status,
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def create_invoice_item(customer: str, price: str, invoice: str):
|
|
135
|
+
"""
|
|
136
|
+
Create an invoice item.
|
|
137
|
+
|
|
138
|
+
Parameters:
|
|
139
|
+
customer (str): The ID of the customer.
|
|
140
|
+
price (str): The ID of the price.
|
|
141
|
+
invoice (str): The ID of the invoice.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
stripe.InvoiceItem: The created invoice item.
|
|
145
|
+
"""
|
|
146
|
+
invoice_item = stripe.InvoiceItem.create(
|
|
147
|
+
customer=customer,
|
|
148
|
+
price=price,
|
|
149
|
+
invoice=invoice,
|
|
150
|
+
)
|
|
151
|
+
return {"id": invoice_item.id, "invoice": invoice_item.invoice}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def finalize_invoice(invoice: str):
|
|
155
|
+
"""
|
|
156
|
+
Finalize an invoice.
|
|
157
|
+
|
|
158
|
+
Parameters:
|
|
159
|
+
invoice (str): The ID of the invoice.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
stripe.Invoice: The finalized invoice.
|
|
163
|
+
"""
|
|
164
|
+
invoice = stripe.Invoice.finalize_invoice(invoice=invoice)
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
"id": invoice.id,
|
|
168
|
+
"hosted_invoice_url": invoice.hosted_invoice_url,
|
|
169
|
+
"customer": invoice.customer,
|
|
170
|
+
"status": invoice.status,
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def retrieve_balance():
|
|
175
|
+
"""
|
|
176
|
+
Retrieve the balance.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
stripe.Balance: The balance.
|
|
180
|
+
"""
|
|
181
|
+
return stripe.Balance.retrieve()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This tool allows agents to interact with the Stripe API.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Any, Optional, Type
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
|
|
10
|
+
from langchain.tools import BaseTool
|
|
11
|
+
|
|
12
|
+
from ..api import StripeAPI
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class StripeTool(BaseTool):
|
|
16
|
+
"""Tool for interacting with the Stripe API."""
|
|
17
|
+
|
|
18
|
+
stripe_api: StripeAPI
|
|
19
|
+
method: str
|
|
20
|
+
name: str = ""
|
|
21
|
+
description: str = ""
|
|
22
|
+
args_schema: Optional[Type[BaseModel]] = None
|
|
23
|
+
|
|
24
|
+
def _run(
|
|
25
|
+
self,
|
|
26
|
+
*args: Any,
|
|
27
|
+
**kwargs: Any,
|
|
28
|
+
) -> str:
|
|
29
|
+
"""Use the Stripe API to run an operation."""
|
|
30
|
+
return self.stripe_api.run(self.method, *args, **kwargs)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Stripe Agent Toolkit."""
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
from pydantic import PrivateAttr
|
|
5
|
+
|
|
6
|
+
from ..api import StripeAPI
|
|
7
|
+
from ..tools import tools
|
|
8
|
+
from ..configuration import Configuration, is_tool_allowed
|
|
9
|
+
from .tool import StripeTool
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StripeAgentToolkit:
|
|
13
|
+
_tools: List = PrivateAttr(default=[])
|
|
14
|
+
|
|
15
|
+
def __init__(self, secret_key: str, configuration: Configuration = None):
|
|
16
|
+
super().__init__()
|
|
17
|
+
|
|
18
|
+
stripe_api = StripeAPI(secret_key=secret_key)
|
|
19
|
+
|
|
20
|
+
filtered_tools = [
|
|
21
|
+
tool for tool in tools if is_tool_allowed(tool, configuration)
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
self._tools = [
|
|
25
|
+
StripeTool(
|
|
26
|
+
name=tool["name"],
|
|
27
|
+
description=tool["description"],
|
|
28
|
+
method=tool["method"],
|
|
29
|
+
stripe_api=stripe_api,
|
|
30
|
+
args_schema=tool.get("args_schema", None),
|
|
31
|
+
)
|
|
32
|
+
for tool in filtered_tools
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
def get_tools(self) -> List:
|
|
36
|
+
"""Get the tools in the toolkit."""
|
|
37
|
+
return self._tools
|