Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat: Integrate stripe (#1261)

Simon Chan7d9c906ab1c8
diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.py
index cb97a3252..cd8a88c0f 100644
--- a/camel/toolkits/__init__.py
+++ b/camel/toolkits/__init__.py
@@ -41,6 +41,7 @@ from .open_api_toolkit import OpenAPIToolkit
from .retrieval_toolkit import RetrievalToolkit
from .notion_toolkit import NotionToolkit
from .human_toolkit import HumanToolkit
+from .stripe_toolkit import StripeToolkit
from .video_toolkit import VideoDownloaderToolkit
__all__ = [
@@ -70,5 +71,6 @@ __all__ = [
'ArxivToolkit',
'HumanToolkit',
'VideoDownloaderToolkit',
+ 'StripeToolkit',
'MeshyToolkit',
]
diff --git a/camel/toolkits/stripe_toolkit.py b/camel/toolkits/stripe_toolkit.py
new file mode 100644
index 000000000..07ca9f193
--- /dev/null
+++ b/camel/toolkits/stripe_toolkit.py
@@ -0,0 +1,273 @@
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+
+import json
+import logging
+import os
+from typing import List
+
+from camel.toolkits import FunctionTool
+from camel.toolkits.base import BaseToolkit
+from camel.utils import api_keys_required
+
+
+class StripeToolkit(BaseToolkit):
+ r"""A class representing a toolkit for Stripe operations.
+
+ This toolkit provides methods to interact with the Stripe API,
+ allowing users to operate stripe core resources, including Customer,
+ Balance, BalanceTransaction, Payment, Refund
+
+ Use the Developers Dashboard https://dashboard.stripe.com/test/apikeys to
+ create an API keys as STRIPE_API_KEY.
+
+ Attributes:
+ logger (Logger): a logger to write logs.
+ """
+
+ @api_keys_required("STRIPE_API_KEY")
+ def __init__(self, retries: int = 3):
+ r"""Initializes the StripeToolkit with the specified number of
+ retries.
+
+ Args:
+ retries (int,optional): Number of times to retry the request in
+ case of failure. (default: :obj:`3`)
+ """
+ import stripe
+
+ stripe.max_network_retries = retries
+ stripe.log = 'info'
+ self.logger = logging.getLogger(__name__)
+ self.logger.setLevel(logging.INFO)
+ handler = logging.StreamHandler()
+ formatter = logging.Formatter(
+ '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
+ )
+ handler.setFormatter(formatter)
+ if not self.logger.handlers:
+ self.logger.addHandler(handler)
+ stripe.api_key = os.environ.get("STRIPE_API_KEY")
+
+ def customer_get(self, customer_id: str) -> str:
+ r"""Retrieve a customer by ID.
+
+ Args:
+ customer_id (str): The ID of the customer to retrieve.
+
+ Returns:
+ str: The customer data as a str.
+ """
+ import stripe
+
+ try:
+ self.logger.info(f"Retrieving customer with ID: {customer_id}")
+ customer = stripe.Customer.retrieve(customer_id)
+ self.logger.info(f"Retrieved customer: {customer.id}")
+ json_string = json.dumps(customer)
+ return json_string
+ except Exception as e:
+ return self.handle_exception("customer_get", e)
+
+ def customer_list(self, limit: int = 100) -> str:
+ r"""List customers.
+
+ Args:
+ limit (int, optional): Number of customers to retrieve. (default:
+ :obj:`100`)
+
+ Returns:
+ str: An output str if successful, or an error message string if
+ failed.
+ """
+ import stripe
+
+ try:
+ self.logger.info(f"Listing customers with limit={limit}")
+ customers = stripe.Customer.list(limit=limit).data
+ self.logger.info(
+ f"Successfully retrieved {len(customers)} customers."
+ )
+ return json.dumps([customer for customer in customers])
+ except Exception as e:
+ return self.handle_exception("customer_list", e)
+
+ def balance_get(self) -> str:
+ r"""Retrieve your account balance.
+
+ Returns:
+ str: A str containing the account balance if successful, or an
+ error message string if failed.
+ """
+ import stripe
+
+ try:
+ self.logger.info("Retrieving account balance.")
+ balance = stripe.Balance.retrieve()
+ self.logger.info(
+ f"Successfully retrieved account balance: {balance}."
+ )
+ return json.dumps(balance)
+ except Exception as e:
+ return self.handle_exception("balance_get", e)
+
+ def balance_transaction_list(self, limit: int = 100) -> str:
+ r"""List your balance transactions.
+
+ Args:
+ limit (int, optional): Number of balance transactions to retrieve.
+ (default::obj:`100`)
+
+ Returns:
+ str: A list of balance transaction data if successful, or an error
+ message string if failed.
+ """
+ import stripe
+
+ try:
+ self.logger.info(
+ f"Listing balance transactions with limit={limit}"
+ )
+ transactions = stripe.BalanceTransaction.list(limit=limit).data
+ self.logger.info(
+ f"Successfully retrieved {len(transactions)} "
+ "balance transactions."
+ )
+ return json.dumps([transaction for transaction in transactions])
+ except Exception as e:
+ return self.handle_exception("balance_transaction_list", e)
+
+ def payment_get(self, payment_id: str) -> str:
+ r"""Retrieve a payment by ID.
+
+ Args:
+ payment_id (str): The ID of the payment to retrieve.
+
+ Returns:
+ str:The payment data as a str if successful, or an error message
+ string if failed.
+ """
+ import stripe
+
+ try:
+ self.logger.info(f"Retrieving payment with ID: {payment_id}")
+ payment = stripe.PaymentIntent.retrieve(payment_id)
+ self.logger.info(f"Retrieved payment: {payment.id}")
+ return json.dumps(payment)
+ except Exception as e:
+ return self.handle_exception("payment_get", e)
+
+ def payment_list(self, limit: int = 100) -> str:
+ r"""List payments.
+
+ Args:
+ limit (int, optional): Number of payments to retrieve.
+ (default::obj:`100`)
+
+ Returns:
+ str: A list of payment data if successful, or an error message
+ string if failed.
+ """
+ import stripe
+
+ try:
+ self.logger.info(f"Listing payments with limit={limit}")
+ payments = stripe.PaymentIntent.list(limit=limit).data
+ self.logger.info(
+ f"Successfully retrieved {len(payments)} payments."
+ )
+ return json.dumps([payment for payment in payments])
+ except Exception as e:
+ return self.handle_exception("payment_list", e)
+
+ def refund_get(self, refund_id: str) -> str:
+ r"""Retrieve a refund by ID.
+
+ Args:
+ refund_id (str): The ID of the refund to retrieve.
+
+ Returns:
+ str: The refund data as a str if successful, or an error message
+ string if failed.
+ """
+ import stripe
+
+ try:
+ self.logger.info(f"Retrieving refund with ID: {refund_id}")
+ refund = stripe.Refund.retrieve(refund_id)
+ self.logger.info(f"Retrieved refund: {refund.id}")
+ return json.dumps(refund)
+ except Exception as e:
+ return self.handle_exception("refund_get", e)
+
+ def refund_list(self, limit: int = 100) -> str:
+ r"""List refunds.
+
+ Args:
+ limit (int, optional): Number of refunds to retrieve.
+ (default::obj:`100`)
+
+ Returns:
+ str: A list of refund data as a str if successful, or an error
+ message string if failed.
+ """
+ import stripe
+
+ try:
+ self.logger.info(f"Listing refunds with limit={limit}")
+ refunds = stripe.Refund.list(limit=limit).data
+ self.logger.info(f"Successfully retrieved {len(refunds)} refunds.")
+ return json.dumps([refund for refund in refunds])
+ except Exception as e:
+ return self.handle_exception("refund_list", e)
+
+ def handle_exception(self, func_name: str, error: Exception) -> str:
+ r"""Handle exceptions by logging and returning an error message.
+
+ Args:
+ func_name (str): The name of the function where the exception
+ occurred.
+ error (Exception): The exception instance.
+
+ Returns:
+ str: An error message string.
+ """
+ from stripe import StripeError
+
+ if isinstance(error, StripeError):
+ message = error.user_message or str(error)
+ self.logger.error(f"Stripe error in {func_name}: {message}")
+ return f"Stripe error in {func_name}: {message}"
+ else:
+ self.logger.error(f"Unexpected error in {func_name}: {error!s}")
+ return f"Unexpected error in {func_name}: {error!s}"
+
+ def get_tools(self) -> List[FunctionTool]:
+ r"""Returns a list of FunctionTool objects representing the
+ functions in the toolkit.
+
+ Returns:
+ List[FunctionTool]: A list of FunctionTool objects for the
+ toolkit methods.
+ """
+ return [
+ FunctionTool(self.customer_get),
+ FunctionTool(self.customer_list),
+ FunctionTool(self.balance_get),
+ FunctionTool(self.balance_transaction_list),
+ FunctionTool(self.payment_get),
+ FunctionTool(self.payment_list),
+ FunctionTool(self.refund_get),
+ FunctionTool(self.refund_list),
+ ]
diff --git a/poetry.lock b/poetry.lock
index b1c131784..b9f1fe7fa 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -663,13 +663,13 @@ css = ["tinycss2 (>=1.1.0,<1.5)"]
[[package]]
name = "botocore"
-version = "1.35.79"
+version = "1.35.80"
description = "Low-level, data-driven core of boto 3."
optional = true
python-versions = ">=3.8"
files = [
- {file = "botocore-1.35.79-py3-none-any.whl", hash = "sha256:e6b10bb9a357e3f5ca2e60f6dd15a85d311b9a476eb21b3c0c2a3b364a2897c8"},
- {file = "botocore-1.35.79.tar.gz", hash = "sha256:245bfdda1b1508539ddd1819c67a8a2cc81780adf0715d3de418d64c4247f346"},
+ {file = "botocore-1.35.80-py3-none-any.whl", hash = "sha256:36e589dccb62380abd628b08fecfa2f7c89b99f41ec9fc42c467c94008c0be4a"},
+ {file = "botocore-1.35.80.tar.gz", hash = "sha256:b8dfceca58891cb2711bd6455ec4f7159051f3796e0f64adef9bb334f19d8a92"},
]
[package.dependencies]
@@ -3493,13 +3493,13 @@ files = [
[[package]]
name = "litellm"
-version = "1.54.1"
+version = "1.55.0"
description = "Library to easily interface with LLM API providers"
optional = true
python-versions = "!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,!=3.7.*,>=3.8"
files = [
- {file = "litellm-1.54.1-py3-none-any.whl", hash = "sha256:d8e60d4a5e8decb0234a1e8c20351c904aec561fb4025df7df3d0d7ea81ca442"},
- {file = "litellm-1.54.1.tar.gz", hash = "sha256:b5a8fc99160fab0699b9258457432b3975499218ffcf1b515709808b2ce5a2d7"},
+ {file = "litellm-1.55.0-py3-none-any.whl", hash = "sha256:b257242039cc0753cdf7e7e288f9379d8ccad58015ce95bdc8a8ec337d2fa7eb"},
+ {file = "litellm-1.55.0.tar.gz", hash = "sha256:d33dfabb7aa6f18294c43f20429d7d962b48104a0c2ddce08df7370029ac4780"},
]
[package.dependencies]
@@ -8213,6 +8213,21 @@ files = [
{file = "stem-1.8.2.tar.gz", hash = "sha256:83fb19ffd4c9f82207c006051480389f80af221a7e4783000aedec4e384eb582"},
]
+[[package]]
+name = "stripe"
+version = "11.3.0"
+description = "Python bindings for the Stripe API"
+optional = true
+python-versions = ">=3.6"
+files = [
+ {file = "stripe-11.3.0-py2.py3-none-any.whl", hash = "sha256:9d2e86943e1e4f325835d3860c4f58aa98d49229c9caf67588f9f9b2451e8e56"},
+ {file = "stripe-11.3.0.tar.gz", hash = "sha256:98e625d9ddbabcecf02666867169696e113d9eaba27979fb310a7a8dfd44097c"},
+]
+
+[package.dependencies]
+requests = {version = ">=2.20", markers = "python_version >= \"3.0\""}
+typing-extensions = {version = ">=4.5.0", markers = "python_version >= \"3.7\""}
+
[[package]]
name = "sympy"
version = "1.13.1"
@@ -8526,31 +8541,36 @@ files = [
[[package]]
name = "torch"
-version = "2.1.0"
+version = "2.2.1"
description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration"
optional = true
python-versions = ">=3.8.0"
files = [
- {file = "torch-2.1.0-cp310-cp310-manylinux1_x86_64.whl", hash = "sha256:bf57f8184b2c317ef81fb33dc233ce4d850cd98ef3f4a38be59c7c1572d175db"},
- {file = "torch-2.1.0-cp310-cp310-manylinux2014_aarch64.whl", hash = "sha256:a04a0296d47f28960f51c18c5489a8c3472f624ec3b5bcc8e2096314df8c3342"},
- {file = "torch-2.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:0bd691efea319b14ef239ede16d8a45c246916456fa3ed4f217d8af679433cc6"},
- {file = "torch-2.1.0-cp310-none-macosx_10_9_x86_64.whl", hash = "sha256:101c139152959cb20ab370fc192672c50093747906ee4ceace44d8dd703f29af"},
- {file = "torch-2.1.0-cp310-none-macosx_11_0_arm64.whl", hash = "sha256:a6b7438a90a870e4cdeb15301519ae6c043c883fcd224d303c5b118082814767"},
- {file = "torch-2.1.0-cp311-cp311-manylinux1_x86_64.whl", hash = "sha256:2224622407ca52611cbc5b628106fde22ed8e679031f5a99ce286629fc696128"},
- {file = "torch-2.1.0-cp311-cp311-manylinux2014_aarch64.whl", hash = "sha256:8132efb782cd181cc2dcca5e58effbe4217cdb2581206ac71466d535bf778867"},
- {file = "torch-2.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:5c3bfa91ce25ba10116c224c59d5b64cdcce07161321d978bd5a1f15e1ebce72"},
- {file = "torch-2.1.0-cp311-none-macosx_10_9_x86_64.whl", hash = "sha256:601b0a2a9d9233fb4b81f7d47dca9680d4f3a78ca3f781078b6ad1ced8a90523"},
- {file = "torch-2.1.0-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:3cd1dedff13884d890f18eea620184fb4cd8fd3c68ce3300498f427ae93aa962"},
- {file = "torch-2.1.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:fb7bf0cc1a3db484eb5d713942a93172f3bac026fcb377a0cd107093d2eba777"},
- {file = "torch-2.1.0-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:761822761fffaa1c18a62c5deb13abaa780862577d3eadc428f1daa632536905"},
- {file = "torch-2.1.0-cp38-cp38-win_amd64.whl", hash = "sha256:458a6d6d8f7d2ccc348ac4d62ea661b39a3592ad15be385bebd0a31ced7e00f4"},
- {file = "torch-2.1.0-cp38-none-macosx_10_9_x86_64.whl", hash = "sha256:c8bf7eaf9514465e5d9101e05195183470a6215bb50295c61b52302a04edb690"},
- {file = "torch-2.1.0-cp38-none-macosx_11_0_arm64.whl", hash = "sha256:05661c32ec14bc3a157193d0f19a7b19d8e61eb787b33353cad30202c295e83b"},
- {file = "torch-2.1.0-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:556d8dd3e0c290ed9d4d7de598a213fb9f7c59135b4fee144364a8a887016a55"},
- {file = "torch-2.1.0-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:de7d63c6ecece118684415a3dbd4805af4a4c1ee1490cccf7405d8c240a481b4"},
- {file = "torch-2.1.0-cp39-cp39-win_amd64.whl", hash = "sha256:2419cf49aaf3b2336c7aa7a54a1b949fa295b1ae36f77e2aecb3a74e3a947255"},
- {file = "torch-2.1.0-cp39-none-macosx_10_9_x86_64.whl", hash = "sha256:6ad491e70dbe4288d17fdbfc7fbfa766d66cbe219bc4871c7a8096f4a37c98df"},
- {file = "torch-2.1.0-cp39-none-macosx_11_0_arm64.whl", hash = "sha256:421739685eba5e0beba42cb649740b15d44b0d565c04e6ed667b41148734a75b"},
+ {file = "torch-2.2.1-cp310-cp310-manylinux1_x86_64.whl", hash = "sha256:8d3bad336dd2c93c6bcb3268e8e9876185bda50ebde325ef211fb565c7d15273"},
+ {file = "torch-2.2.1-cp310-cp310-manylinux2014_aarch64.whl", hash = "sha256:5297f13370fdaca05959134b26a06a7f232ae254bf2e11a50eddec62525c9006"},
+ {file = "torch-2.2.1-cp310-cp310-win_amd64.whl", hash = "sha256:5f5dee8433798888ca1415055f5e3faf28a3bad660e4c29e1014acd3275ab11a"},
+ {file = "torch-2.2.1-cp310-none-macosx_10_9_x86_64.whl", hash = "sha256:b6d78338acabf1fb2e88bf4559d837d30230cf9c3e4337261f4d83200df1fcbe"},
+ {file = "torch-2.2.1-cp310-none-macosx_11_0_arm64.whl", hash = "sha256:6ab3ea2e29d1aac962e905142bbe50943758f55292f1b4fdfb6f4792aae3323e"},
+ {file = "torch-2.2.1-cp311-cp311-manylinux1_x86_64.whl", hash = "sha256:d86664ec85902967d902e78272e97d1aff1d331f7619d398d3ffab1c9b8e9157"},
+ {file = "torch-2.2.1-cp311-cp311-manylinux2014_aarch64.whl", hash = "sha256:d6227060f268894f92c61af0a44c0d8212e19cb98d05c20141c73312d923bc0a"},
+ {file = "torch-2.2.1-cp311-cp311-win_amd64.whl", hash = "sha256:77e990af75fb1675490deb374d36e726f84732cd5677d16f19124934b2409ce9"},
+ {file = "torch-2.2.1-cp311-none-macosx_10_9_x86_64.whl", hash = "sha256:46085e328d9b738c261f470231e987930f4cc9472d9ffb7087c7a1343826ac51"},
+ {file = "torch-2.2.1-cp311-none-macosx_11_0_arm64.whl", hash = "sha256:2d9e7e5ecbb002257cf98fae13003abbd620196c35f85c9e34c2adfb961321ec"},
+ {file = "torch-2.2.1-cp312-cp312-manylinux1_x86_64.whl", hash = "sha256:ada53aebede1c89570e56861b08d12ba4518a1f8b82d467c32665ec4d1f4b3c8"},
+ {file = "torch-2.2.1-cp312-cp312-manylinux2014_aarch64.whl", hash = "sha256:be21d4c41ecebed9e99430dac87de1439a8c7882faf23bba7fea3fea7b906ac1"},
+ {file = "torch-2.2.1-cp312-cp312-win_amd64.whl", hash = "sha256:79848f46196750367dcdf1d2132b722180b9d889571e14d579ae82d2f50596c5"},
+ {file = "torch-2.2.1-cp312-none-macosx_10_9_x86_64.whl", hash = "sha256:7ee804847be6be0032fbd2d1e6742fea2814c92bebccb177f0d3b8e92b2d2b18"},
+ {file = "torch-2.2.1-cp312-none-macosx_11_0_arm64.whl", hash = "sha256:84b2fb322ab091039fdfe74e17442ff046b258eb5e513a28093152c5b07325a7"},
+ {file = "torch-2.2.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:5c0c83aa7d94569997f1f474595e808072d80b04d34912ce6f1a0e1c24b0c12a"},
+ {file = "torch-2.2.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:91a1b598055ba06b2c386415d2e7f6ac818545e94c5def597a74754940188513"},
+ {file = "torch-2.2.1-cp38-cp38-win_amd64.whl", hash = "sha256:8f93ddf3001ecec16568390b507652644a3a103baa72de3ad3b9c530e3277098"},
+ {file = "torch-2.2.1-cp38-none-macosx_10_9_x86_64.whl", hash = "sha256:0e8bdd4c77ac2584f33ee14c6cd3b12767b4da508ec4eed109520be7212d1069"},
+ {file = "torch-2.2.1-cp38-none-macosx_11_0_arm64.whl", hash = "sha256:6a21bcd7076677c97ca7db7506d683e4e9db137e8420eb4a68fb67c3668232a7"},
+ {file = "torch-2.2.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:f1b90ac61f862634039265cd0f746cc9879feee03ff962c803486301b778714b"},
+ {file = "torch-2.2.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:ed9e29eb94cd493b36bca9cb0b1fd7f06a0688215ad1e4b3ab4931726e0ec092"},
+ {file = "torch-2.2.1-cp39-cp39-win_amd64.whl", hash = "sha256:c47bc25744c743f3835831a20efdcfd60aeb7c3f9804a213f61e45803d16c2a5"},
+ {file = "torch-2.2.1-cp39-none-macosx_10_9_x86_64.whl", hash = "sha256:0952549bcb43448c8d860d5e3e947dd18cbab491b14638e21750cb3090d5ad3e"},
+ {file = "torch-2.2.1-cp39-none-macosx_11_0_arm64.whl", hash = "sha256:26bd2272ec46fc62dcf7d24b2fb284d44fcb7be9d529ebf336b9860350d674ed"},
]
[package.dependencies]
@@ -8559,10 +8579,11 @@ fsspec = "*"
jinja2 = "*"
networkx = "*"
sympy = "*"
-typing-extensions = "*"
+typing-extensions = ">=4.8.0"
[package.extras]
opt-einsum = ["opt-einsum (>=3.3)"]
+optree = ["optree (>=0.9.1)"]
[[package]]
name = "torch"
@@ -8618,38 +8639,42 @@ optree = ["optree (>=0.12.0)"]
[[package]]
name = "torchvision"
-version = "0.16.0"
+version = "0.17.1"
description = "image and video datasets and models for torch deep learning"
optional = true
python-versions = ">=3.8"
files = [
- {file = "torchvision-0.16.0-cp310-cp310-macosx_10_13_x86_64.whl", hash = "sha256:16c300fdbbe91469f5e9feef8d24c6acabd8849db502a06160dd76ba68e897a0"},
- {file = "torchvision-0.16.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ef5dec6c48b715353781b83749efcdea03835720a71b377684453ee117aab3c7"},
- {file = "torchvision-0.16.0-cp310-cp310-manylinux1_x86_64.whl", hash = "sha256:9e3a2012e463f498de21f6598cc7a266b9a8c6fe15788472fdc419233ea6f3f2"},
- {file = "torchvision-0.16.0-cp310-cp310-manylinux2014_aarch64.whl", hash = "sha256:e4327e082b703921ae52caeee4f7839f7e6c73cfc5eedea468ecb5c1487ecdbf"},
- {file = "torchvision-0.16.0-cp310-cp310-win_amd64.whl", hash = "sha256:62f01513687cce3480df8928fcc6c09b4aa0433d05ac75e82877acc773f6a568"},
- {file = "torchvision-0.16.0-cp311-cp311-macosx_10_13_x86_64.whl", hash = "sha256:31fdf289bdfb2976f65a14f79f6ddd1ee60113db34622674918e61521c2dc41f"},
- {file = "torchvision-0.16.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:2294a6514a31a6fda562288b28cf6db57877237f4b56ff693262f237a7ed4035"},
- {file = "torchvision-0.16.0-cp311-cp311-manylinux1_x86_64.whl", hash = "sha256:6a24a1e83e4bc7a31b39ef05d2ca4cd2182e95ff10f525edffe1473f7ce16ca1"},
- {file = "torchvision-0.16.0-cp311-cp311-manylinux2014_aarch64.whl", hash = "sha256:9ed5f21e5a56e466667c6f9f6f93dba2a75e29921108bd70043eaf8e9ba0a7cc"},
- {file = "torchvision-0.16.0-cp311-cp311-win_amd64.whl", hash = "sha256:9ee3d4df7d4a84f883f8ad11fb6510549f40f68dd5469eae601d7e02fb4809b2"},
- {file = "torchvision-0.16.0-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:0c6f36d00b9ce412e367ad6f42e9054cbc890cd9ddd0d200ed9b3b52dd9c225b"},
- {file = "torchvision-0.16.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:597f60cb03e6f758a00b36b38506f6f38b6c3f1fdfd3921bb9abd60b72d522fd"},
- {file = "torchvision-0.16.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:eddd91da4603f1dbb340d9aca82344df64605a0897b17014ac8e0b54dd6e5716"},
- {file = "torchvision-0.16.0-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:79875f5247337723ec363762c2716bcfc13b78b3045e4e58847c696f03d9ed4d"},
- {file = "torchvision-0.16.0-cp38-cp38-win_amd64.whl", hash = "sha256:550c9793637c5369fbcb4e4b6b0e6d53a4f6cc22389f0563ad60ab90e4f1c8ba"},
- {file = "torchvision-0.16.0-cp39-cp39-macosx_10_13_x86_64.whl", hash = "sha256:de7c7302fa2f67a2a151e595a8e7dc3865a445d952e99d5c682ba78f312fedc3"},
- {file = "torchvision-0.16.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:f044cffd252fd293b6df46f38d7eeb2fd4fe931e0114c5263735e3b8c9c60a4f"},
- {file = "torchvision-0.16.0-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:8cb501061f6654da494dd975acc1fa301c4b8aacf96bdbcf1553f51a53ebfd1f"},
- {file = "torchvision-0.16.0-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:5a47108ae6a8effdf09fe35fd0c4d5414e69ca8d2334e87339de497b7b64b0c9"},
- {file = "torchvision-0.16.0-cp39-cp39-win_amd64.whl", hash = "sha256:9b8f06e6a2f80576007b88846f74b680a1ad3b59d2e22b075587b430180e9cfa"},
+ {file = "torchvision-0.17.1-cp310-cp310-macosx_10_13_x86_64.whl", hash = "sha256:06418880212b66e45e855dd39f536e7fd48b4e6b034a11dd9fe9e2384afb51ec"},
+ {file = "torchvision-0.17.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:33d65d0c7fdcb3f7bc1dd8ed30ea3cd7e0587b4ad1b104b5677c8191a8bad9f1"},
+ {file = "torchvision-0.17.1-cp310-cp310-manylinux1_x86_64.whl", hash = "sha256:aaefef2be6a02f206085ce4bb6c0078b03ebf48cb6ff82bd762ff6248475e08e"},
+ {file = "torchvision-0.17.1-cp310-cp310-manylinux2014_aarch64.whl", hash = "sha256:ebe5fdb466aff8a8e8e755de84a843418b6f8d500624752c05eaa638d7700f3d"},
+ {file = "torchvision-0.17.1-cp310-cp310-win_amd64.whl", hash = "sha256:9d4d45a996f4313e9c5db4da71d31508d44f7ccfbf29d3442bdcc2ad13e0b6f3"},
+ {file = "torchvision-0.17.1-cp311-cp311-macosx_10_13_x86_64.whl", hash = "sha256:ea2ccdbf5974e0bf27fd6644a33b19cb0700297cf397bb0469e762c11c6c4105"},
+ {file = "torchvision-0.17.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:9106e32c9f1e70afa8172cf1b064cf9c2998d8dff0769ec69d537b20209ee43d"},
+ {file = "torchvision-0.17.1-cp311-cp311-manylinux1_x86_64.whl", hash = "sha256:5966936c669a08870f6547cd0a90d08b157aeda03293f79e2adbb934687175ed"},
+ {file = "torchvision-0.17.1-cp311-cp311-manylinux2014_aarch64.whl", hash = "sha256:e74f5a26ef8190eab0c38b3f63914fea94e58e3b2f0e5466611c9f63bd91a80b"},
+ {file = "torchvision-0.17.1-cp311-cp311-win_amd64.whl", hash = "sha256:a2109c1a1dcf71e8940d43e91f78c4dd5bf0fcefb3a0a42244102752009f5862"},
+ {file = "torchvision-0.17.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:5d241d2a5fb4e608677fccf6f80b34a124446d324ee40c7814ce54bce888275b"},
+ {file = "torchvision-0.17.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:e0fe98d9d92c23d2262ff82f973242951b9357fb640f8888ac50848bd00f5b45"},
+ {file = "torchvision-0.17.1-cp312-cp312-manylinux1_x86_64.whl", hash = "sha256:32dc5de86d2ade399e11087095674ca08a1649fb322cfe69336d28add467edcb"},
+ {file = "torchvision-0.17.1-cp312-cp312-manylinux2014_aarch64.whl", hash = "sha256:54902877410ffb5458ee52b6d0de4b25cf01496bee736d6825301a5f0398536e"},
+ {file = "torchvision-0.17.1-cp312-cp312-win_amd64.whl", hash = "sha256:cc22c1ed0f1aba3f98fd72b6f60021f57aec1d2f6af518522e8a0a83848de3a8"},
+ {file = "torchvision-0.17.1-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:2621097065fa1c827885e2b52102e839a3541b933b7a90e0fa3c42c3de1bc3cf"},
+ {file = "torchvision-0.17.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:5ce76466af2b5a30573939cae1e6e62e29316ceb3ee748091002f312ab0912f6"},
+ {file = "torchvision-0.17.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:bd5dcd14a32945c72f5c19341add94aa7c23dd7bca2bafde44d0f3c4344d17ed"},
+ {file = "torchvision-0.17.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:dca22795cc02ca0d5ddc08c1422ff620bc9899f63d15dc36f71ef37250e17b75"},
+ {file = "torchvision-0.17.1-cp38-cp38-win_amd64.whl", hash = "sha256:524405457dd97d9ab0e48df502f819d0f41a113ce8f00470bb9926d9d36efcf1"},
+ {file = "torchvision-0.17.1-cp39-cp39-macosx_10_13_x86_64.whl", hash = "sha256:58299a724b37b893c7ce4d0b32ea1480c30e467cc114167964b45f6013f6c2d3"},
+ {file = "torchvision-0.17.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8a1b17fb158b2b881f2c8796fe1839a624e49d5fd07aa61f6dae60ba4819421a"},
+ {file = "torchvision-0.17.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:429d63eb7551aa4d8f6cdf08d109b5570c20cbcce36d9cb95b24556418e4dc82"},
+ {file = "torchvision-0.17.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:0ecc9a58171bd555aed583bf2f72e7fd6cc4f767c14f8b80b6a8725eacf4ceb1"},
+ {file = "torchvision-0.17.1-cp39-cp39-win_amd64.whl", hash = "sha256:5f427ebee15521edcd836bfe05e86feb5189b5c943b9e3999ed0e3f391fbaa1d"},
]
[package.dependencies]
numpy = "*"
pillow = ">=5.3.0,<8.3.dev0 || >=8.4.dev0"
-requests = "*"
-torch = "2.1.0"
+torch = "2.2.1"
[package.extras]
scipy = ["scipy"]
@@ -9944,7 +9969,7 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools",
type = ["pytest-mypy"]
[extras]
-all = ["PyMuPDF", "accelerate", "agentops", "anthropic", "apify_client", "arxiv", "arxiv2text", "asknews", "azure-storage-blob", "beautifulsoup4", "botocore", "cohere", "cohere", "datacommons", "datacommons_pandas", "datasets", "diffusers", "discord.py", "docker", "docx2txt", "duckduckgo-search", "ffmpeg-python", "firecrawl-py", "google-cloud-storage", "google-generativeai", "googlemaps", "imageio", "ipykernel", "jupyter_client", "litellm", "mistralai", "nebula3-python", "neo4j", "newspaper3k", "nltk", "notion-client", "openapi-spec-validator", "opencv-python", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pymilvus", "pyowm", "pyyaml", "qdrant-client", "rank-bm25", "redis", "reka-api", "requests_oauthlib", "scholarly", "sentence-transformers", "sentencepiece", "sglang", "slack-bolt", "slack-sdk", "soundfile", "tavily-python", "textblob", "torch", "torch", "transformers", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]
+all = ["PyMuPDF", "accelerate", "agentops", "anthropic", "apify_client", "arxiv", "arxiv2text", "asknews", "azure-storage-blob", "beautifulsoup4", "botocore", "cohere", "cohere", "datacommons", "datacommons_pandas", "datasets", "diffusers", "discord.py", "docker", "docx2txt", "duckduckgo-search", "ffmpeg-python", "firecrawl-py", "google-cloud-storage", "google-generativeai", "googlemaps", "imageio", "ipykernel", "jupyter_client", "litellm", "mistralai", "nebula3-python", "neo4j", "newspaper3k", "nltk", "notion-client", "openapi-spec-validator", "opencv-python", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pymilvus", "pyowm", "pyyaml", "qdrant-client", "rank-bm25", "redis", "reka-api", "requests_oauthlib", "scholarly", "sentence-transformers", "sentencepiece", "sglang", "slack-bolt", "slack-sdk", "soundfile", "stripe", "tavily-python", "textblob", "torch", "torch", "transformers", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]
encoders = ["sentence-transformers"]
graph-storages = ["nebula3-python", "neo4j"]
huggingface-agent = ["accelerate", "datasets", "diffusers", "opencv-python", "sentencepiece", "soundfile", "torch", "torch", "transformers"]
@@ -9956,10 +9981,10 @@ retrievers = ["cohere", "rank-bm25"]
runtime = ["docker"]
search-tools = ["duckduckgo-search", "tavily-python", "wikipedia", "wolframalpha"]
test = ["mock", "pytest", "pytest-asyncio"]
-tools = ["PyMuPDF", "agentops", "apify_client", "arxiv", "arxiv2text", "asknews", "beautifulsoup4", "datacommons", "datacommons_pandas", "discord.py", "docker", "docx2txt", "duckduckgo-search", "ffmpeg-python", "firecrawl-py", "googlemaps", "imageio", "ipykernel", "jupyter_client", "newspaper3k", "nltk", "notion-client", "openapi-spec-validator", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pyowm", "pyyaml", "requests_oauthlib", "scholarly", "slack-bolt", "slack-sdk", "textblob", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]
+tools = ["PyMuPDF", "agentops", "apify_client", "arxiv", "arxiv2text", "asknews", "beautifulsoup4", "datacommons", "datacommons_pandas", "discord.py", "docker", "docx2txt", "duckduckgo-search", "ffmpeg-python", "firecrawl-py", "googlemaps", "imageio", "ipykernel", "jupyter_client", "newspaper3k", "nltk", "notion-client", "openapi-spec-validator", "pdfplumber", "pillow", "prance", "praw", "pyTelegramBotAPI", "pydub", "pygithub", "pyowm", "pyyaml", "requests_oauthlib", "scholarly", "slack-bolt", "slack-sdk", "stripe", "textblob", "unstructured", "wikipedia", "wolframalpha", "yt-dlp"]
vector-databases = ["pymilvus", "qdrant-client"]
[metadata]
lock-version = "2.0"
python-versions = ">=3.10,<3.13"
-content-hash = "f131fd25b9baded1d7b3695ef0b732e49e149f138c2c79443af87e72e99c6972"
+content-hash = "00f9266244b3166cee0bbf28c5da7ba2c64055819ed2ee2c45a63eeecf6eec37"
diff --git a/pyproject.toml b/pyproject.toml
index 1791ba228..b84a17595 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -58,8 +58,8 @@ accelerate = { version = "^0", optional = true }
datasets = { version = "^2", optional = true }
torch = [
{ version = "^2", optional = true, markers = "platform_system != 'Darwin' or platform_machine == 'arm64'" },
- # Torch 2.1.0 is used on non-arm64 macOS systems.
- { version = "2.1.0", optional = true, markers = "platform_system == 'Darwin' and platform_machine != 'arm64'" }
+ # Torch 2.2.1 is used on non-arm64 macOS systems.
+ { version = "2.2.1", optional = true, markers = "platform_system == 'Darwin' and platform_machine != 'arm64'" }
]
soundfile = { version = "^0", optional = true }
sentencepiece = { version = "^0", optional = true }
@@ -107,11 +107,11 @@ ipykernel = { version = "^6.0.0", optional = true }
pdfplumber = { version = "^0.11.0", optional = true }
apify_client = { version = "^1.8.1", optional = true }
notion-client = { version = "^2.2.1", optional = true }
+stripe = { version = "^11.3.0", optional = true }
yt-dlp = { version = "^2024.11.4", optional = true }
ffmpeg-python = { version = "^0.2.0", optional = true }
pyyaml = { version = "^6.0.2", optional = true }
-
# encoders
sentence-transformers = { version = "^3.0.1", optional = true }
@@ -220,6 +220,7 @@ tools = [
"pdfplumber",
"apify_client",
"notion-client",
+ "stripe",
"yt-dlp",
"ffmpeg-python",
"pyyaml",
@@ -337,6 +338,7 @@ all = [
"apify_client",
"fastapi",
"uvicorn",
+ "stripe",
]
[tool.poetry.group.dev]
diff --git a/test/toolkits/test_stripe_function.py b/test/toolkits/test_stripe_function.py
new file mode 100644
index 000000000..31bc21479
--- /dev/null
+++ b/test/toolkits/test_stripe_function.py
@@ -0,0 +1,363 @@
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+import json
+import os
+from unittest.mock import MagicMock, patch
+
+import pytest
+from stripe import (
+ Balance,
+ BalanceTransaction,
+ Customer,
+ PaymentIntent,
+ Refund,
+)
+
+from camel.toolkits.stripe_toolkit import StripeToolkit
+
+
[email protected](scope="function")
+def stripe_toolkit_fixture():
+ import stripe
+
+ r"""Fixture to set up the StripeToolkit with a mock API key."""
+ with patch.dict(os.environ, {"STRIPE_API_KEY": "sk_test_xxxx"}):
+ stripe.api_key = os.environ.get("STRIPE_API_KEY", None)
+ toolkit = StripeToolkit()
+ return toolkit
+
+
+r"""Customer Tests
+"""
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Customer.retrieve')
+def test_customer_get_success(mock_customer_retrieve, stripe_toolkit_fixture):
+ # Arrange
+ customer_id = "cus_abc"
+ customer_name = "Jody Telar"
+ customer_data = Customer()
+ customer_data.id = customer_id
+ customer_data.name = customer_name
+ mock_customer_retrieve.return_value = customer_data
+
+ result = stripe_toolkit_fixture.customer_get(customer_id)
+ # Assert
+ mock_customer_retrieve.assert_called_once_with(customer_id)
+ expected_result = json.dumps(customer_data)
+ assert result == expected_result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Customer.retrieve')
+def test_customer_get_exception(
+ mock_customer_retrieve, stripe_toolkit_fixture
+):
+ # Arrange
+ customer_id = "invalid_id"
+ exception_message = "Customer not found"
+ mock_customer_retrieve.side_effect = Exception(exception_message)
+ result = stripe_toolkit_fixture.customer_get(customer_id)
+ expected_error = f"Unexpected error in customer_get: {exception_message}"
+ assert expected_error in result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Customer.list')
+def test_customer_list_success(mock_customer_list, stripe_toolkit_fixture):
+ # Arrange
+ limit = 2
+ customer1 = Customer()
+ customer1.id = "cus_123"
+ customer1.name = "Alice"
+
+ customer2 = Customer()
+ customer2.id = "cus_456"
+ customer2.name = "Bob"
+
+ customer_list = MagicMock()
+ customer_list.data = [customer1, customer2]
+ mock_customer_list.return_value = customer_list
+
+ # Act
+ result = stripe_toolkit_fixture.customer_list(limit=limit)
+
+ # Assert
+ mock_customer_list.assert_called_once_with(limit=limit)
+ expected_result = json.dumps([customer1, customer2])
+ assert result == expected_result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Customer.list')
+def test_customer_list_exception(mock_customer_list, stripe_toolkit_fixture):
+ # Arrange
+ limit = 2
+ exception_message = "List customers failed"
+ mock_customer_list.side_effect = Exception(exception_message)
+
+ # Act
+ result = stripe_toolkit_fixture.customer_list(limit=limit)
+
+ # Assert
+ expected_error = f"Unexpected error in customer_list: {exception_message}"
+ assert expected_error in result
+
+
+r"""Balance Tests
+"""
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Balance.retrieve')
+def test_balance_get_success(mock_balance_retrieve, stripe_toolkit_fixture):
+ # Arrange
+ balance_data = Balance()
+ balance_data.object = 'balance'
+ balance_data.available = []
+ balance_data.pending = []
+ mock_balance_retrieve.return_value = balance_data
+
+ # Act
+ result = stripe_toolkit_fixture.balance_get()
+
+ # Assert
+ mock_balance_retrieve.assert_called_once()
+ expected_result = json.dumps(balance_data)
+ assert result == expected_result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Balance.retrieve')
+def test_balance_get_exception(mock_balance_retrieve, stripe_toolkit_fixture):
+ # Arrange
+ exception_message = "Balance retrieval failed"
+ mock_balance_retrieve.side_effect = Exception(exception_message)
+
+ # Act
+ result = stripe_toolkit_fixture.balance_get()
+
+ # Assert
+ expected_error = f"Unexpected error in balance_get: {exception_message}"
+ assert expected_error in result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.BalanceTransaction.list')
+def test_balance_transaction_list_success(
+ mock_balance_transaction_list, stripe_toolkit_fixture
+):
+ # Arrange
+ limit = 2
+ transaction1 = BalanceTransaction()
+ transaction1.id = 'txn_1'
+ transaction1.amount = 1000
+
+ transaction2 = BalanceTransaction()
+ transaction2.id = 'txn_2'
+ transaction2.amount = 2000
+
+ transaction_list = MagicMock()
+ transaction_list.data = [transaction1, transaction2]
+ mock_balance_transaction_list.return_value = transaction_list
+
+ # Act
+ result = stripe_toolkit_fixture.balance_transaction_list(limit=limit)
+
+ # Assert
+ mock_balance_transaction_list.assert_called_once_with(limit=limit)
+ expected_result = json.dumps([transaction1, transaction2])
+ assert result == expected_result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.BalanceTransaction.list')
+def test_balance_transaction_list_exception(
+ mock_balance_transaction_list, stripe_toolkit_fixture
+):
+ # Arrange
+ limit = 2
+ exception_message = "List balance transactions failed"
+ mock_balance_transaction_list.side_effect = Exception(exception_message)
+ # Act
+ result = stripe_toolkit_fixture.balance_transaction_list(limit=limit)
+
+ # Assert
+ expected_error = (
+ f"Unexpected error in balance_transaction_list: {exception_message}"
+ )
+ assert expected_error in result
+
+
+r"""Payment Tests
+"""
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.PaymentIntent.retrieve')
+def test_payment_get_success(mock_payment_retrieve, stripe_toolkit_fixture):
+ # Arrange
+ payment_id = "pi_123"
+ payment_data = PaymentIntent()
+ payment_data.id = payment_id
+ payment_data.amount = 1000
+ mock_payment_retrieve.return_value = payment_data
+
+ # Act
+ result = stripe_toolkit_fixture.payment_get(payment_id)
+
+ # Assert
+ mock_payment_retrieve.assert_called_once_with(payment_id)
+ expected_result = json.dumps(payment_data)
+ assert result == expected_result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.PaymentIntent.retrieve')
+def test_payment_get_exception(mock_payment_retrieve, stripe_toolkit_fixture):
+ # Arrange
+ payment_id = "invalid_id"
+ exception_message = "Payment not found"
+ mock_payment_retrieve.side_effect = Exception(exception_message)
+
+ # Act
+ result = stripe_toolkit_fixture.payment_get(payment_id)
+
+ # Assert
+ expected_error = f"Unexpected error in payment_get: {exception_message}"
+ assert expected_error in result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.PaymentIntent.list')
+def test_payment_list_success(mock_payment_list, stripe_toolkit_fixture):
+ # Arrange
+ limit = 2
+ payment1 = PaymentIntent()
+ payment1.id = 'pi_123'
+ payment1.amount = 1000
+
+ payment2 = PaymentIntent()
+ payment2.id = 'pi_456'
+ payment2.amount = 2000
+
+ payment_list = MagicMock()
+ payment_list.data = [payment1, payment2]
+ mock_payment_list.return_value = payment_list
+
+ # Act
+ result = stripe_toolkit_fixture.payment_list(limit=limit)
+
+ # Assert
+ mock_payment_list.assert_called_once_with(limit=limit)
+ expected_result = json.dumps([payment1, payment2])
+ assert result == expected_result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.PaymentIntent.list')
+def test_payment_list_exception(mock_payment_list, stripe_toolkit_fixture):
+ # Arrange
+ limit = 2
+ exception_message = "List payments failed"
+ mock_payment_list.side_effect = Exception(exception_message)
+
+ # Act
+ result = stripe_toolkit_fixture.payment_list(limit=limit)
+
+ # Assert
+ expected_error = f"Unexpected error in payment_list: {exception_message}"
+ assert expected_error in result
+
+
+r"""Refund Tests
+"""
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Refund.retrieve')
+def test_refund_get_success(mock_refund_retrieve, stripe_toolkit_fixture):
+ # Arrange
+ refund_id = "re_123"
+ refund_data = Refund()
+ refund_data.id = refund_id
+ refund_data.amount = 500
+ mock_refund_retrieve.return_value = refund_data
+
+ # Act
+ result = stripe_toolkit_fixture.refund_get(refund_id)
+
+ # Assert
+ mock_refund_retrieve.assert_called_once_with(refund_id)
+ expected_result = json.dumps(refund_data)
+ assert result == expected_result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Refund.retrieve')
+def test_refund_get_exception(mock_refund_retrieve, stripe_toolkit_fixture):
+ # Arrange
+ refund_id = "invalid_id"
+ exception_message = "Refund not found"
+ mock_refund_retrieve.side_effect = Exception(exception_message)
+
+ # Act
+ result = stripe_toolkit_fixture.refund_get(refund_id)
+
+ # Assert
+ expected_error = f"Unexpected error in refund_get: {exception_message}"
+ assert expected_error in result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Refund.list')
+def test_refund_list_success(mock_refund_list, stripe_toolkit_fixture):
+ # Arrange
+ limit = 2
+ refund1 = Refund()
+ refund1.id = 're_123'
+ refund1.amount = 500
+
+ refund2 = Refund()
+ refund2.id = 're_456'
+ refund2.amount = 1000
+
+ refund_list = MagicMock()
+ refund_list.data = [refund1, refund2]
+ mock_refund_list.return_value = refund_list
+
+ # Act
+ result = stripe_toolkit_fixture.refund_list(limit=limit)
+
+ # Assert
+ mock_refund_list.assert_called_once_with(limit=limit)
+ expected_result = json.dumps([refund1, refund2])
+ assert result == expected_result
+
+
[email protected]("stripe_toolkit_fixture")
+@patch('stripe.Refund.list')
+def test_refund_list_exception(mock_refund_list, stripe_toolkit_fixture):
+ # Arrange
+ limit = 2
+ exception_message = "List refunds failed"
+ mock_refund_list.side_effect = Exception(exception_message)
+
+ # Act
+ result = stripe_toolkit_fixture.refund_list(limit=limit)
+
+ # Assert
+ expected_error = f"Unexpected error in refund_list: {exception_message}"
+ assert expected_error in result