跳转到内容

Stripe 集成

让你的智能体通过 Stripe 管理支付、订阅和客户账单。你可以处理客户数据、管理订阅、管理产品并跟踪财务交易,从而借助 AI 驱动的自动化简化支付工作流。

在使用 Stripe 集成之前,请确保你已具备:

  • 一个拥有有效订阅的 CrewAI AMP 账户
  • 一个具备相应 API 权限的 Stripe 账户
  • 通过 集成页面 连接了你的 Stripe 账户
  1. 访问 CrewAI AMP Integrations
  2. 在 Authentication Integrations 部分找到 Stripe
  3. 点击 Connect 并完成 OAuth 流程
  4. 授予支付处理所需权限
  5. Integration Settings 复制你的 Enterprise Token
Terminal window
uv add crewai-tools
Terminal window
export CREWAI_PLATFORM_INTEGRATION_TOKEN="your_enterprise_token"

或者将其添加到你的 .env 文件中:

CREWAI_PLATFORM_INTEGRATION_TOKEN=your_enterprise_token
stripe/create_customer

说明: 在你的 Stripe 账户中创建新客户。

参数:

  • emailCreateCustomer (string, required): 客户电子邮件地址
  • name (string, optional): 客户全名
  • description (string, optional): 用于内部参考的客户描述
  • metadataCreateCustomer (object, optional): 作为键值对的附加元数据(例如 {"field1": 1, "field2": 2}
stripe/get_customer_by_id

说明: 通过 Stripe 客户 ID 检索指定客户。

参数:

  • idGetCustomer (string, required): 要检索的 Stripe 客户 ID
stripe/get_customers

说明: 检索客户列表,可选筛选。

参数:

  • emailGetCustomers (string, optional): 按电子邮件地址筛选客户
  • createdAfter (string, optional): 仅返回在此日期之后创建的客户(Unix 时间戳)
  • createdBefore (string, optional): 仅返回在此日期之前创建的客户(Unix 时间戳)
  • limitGetCustomers (string, optional): 要返回的客户最大数量(默认值为 10)
stripe/update_customer

说明: 更新现有客户信息。

参数:

  • customerId (string, required): 要更新的客户 ID
  • emailUpdateCustomer (string, optional): 更新后的电子邮件地址
  • name (string, optional): 更新后的客户名称
  • description (string, optional): 更新后的客户描述
  • metadataUpdateCustomer (object, optional): 作为键值对的更新元数据
stripe/create_subscription

说明: 为客户创建新的订阅。

参数:

  • customerIdCreateSubscription (string, required): 将为其创建订阅的客户 ID
  • plan (string, required): 订阅的计划 ID - 使用 Connect Portal Workflow Settings 让用户选择一个计划
  • metadataCreateSubscription (object, optional): 订阅的附加元数据
stripe/get_subscriptions

说明: 检索订阅,可选筛选。

参数:

  • customerIdGetSubscriptions (string, optional): 按客户 ID 筛选订阅
  • subscriptionStatus (string, optional): 按订阅状态筛选 - 选项:incomplete, incomplete_expired, trialing, active, past_due, canceled, unpaid
  • limitGetSubscriptions (string, optional): 要返回的订阅最大数量(默认值为 10)
stripe/create_product

说明: 在你的 Stripe 目录中创建新产品。

参数:

  • productName (string, required): 产品名称
  • description (string, optional): 产品描述
  • metadataProduct (object, optional): 作为键值对的附加产品元数据
stripe/get_product_by_id

说明: 通过 Stripe 产品 ID 检索指定产品。

参数:

  • productId (string, required): 要检索的 Stripe 产品 ID
stripe/get_products

说明: 检索产品列表,可选筛选。

参数:

  • createdAfter (string, optional): 仅返回在此日期之后创建的产品(Unix 时间戳)
  • createdBefore (string, optional): 仅返回在此日期之前创建的产品(Unix 时间戳)
  • limitGetProducts (string, optional): 要返回的产品最大数量(默认值为 10)
stripe/get_balance_transactions

说明: 检索你 Stripe 账户中的余额交易记录。

参数:

  • balanceTransactionType (string, optional): 按交易类型筛选 - 选项:charge, refund, payment, payment_refund
  • paginationParameters (object, optional): 分页设置
    • pageCursor (string, optional): 分页游标
stripe/get_plans

说明: 检索你 Stripe 账户中的订阅计划。

参数:

  • isPlanActive (boolean, optional): 按计划状态筛选 - true 表示活动计划,false 表示非活动计划
  • paginationParameters (object, optional): 分页设置
    • pageCursor (string, optional): 分页游标
from crewai import Agent, Task, Crew
from crewai import Agent, Task, Crew
# Create an agent with Stripe capabilities
stripe_agent = Agent(
role="Payment Manager",
goal="Manage customer payments, subscriptions, and billing operations efficiently",
backstory="An AI assistant specialized in payment processing and subscription management.",
apps=['stripe'] # All Stripe actions will be available
)
# Task to create a new customer
create_customer_task = Task(
description="Create a new premium customer John Doe with email [email protected]",
agent=stripe_agent,
expected_output="Customer created successfully with customer ID"
)
# Run the task
crew = Crew(
agents=[stripe_agent],
tasks=[create_customer_task]
)
crew.kickoff()
billing_manager = Agent(
role="Billing Manager",
goal="Handle customer billing, subscriptions, and payment processing",
backstory="An experienced billing manager who handles subscription lifecycle and payment operations.",
apps=['stripe']
)
# Task to manage billing operations
billing_task = Task(
description="Create a new customer and set up their premium subscription plan",
agent=billing_manager,
expected_output="Customer created and subscription activated successfully"
)
crew = Crew(
agents=[billing_manager],
tasks=[billing_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
subscription_manager = Agent(
role="Subscription Manager",
goal="Manage customer subscriptions and optimize recurring revenue",
backstory="An AI assistant that specializes in subscription lifecycle management and customer retention.",
apps=['stripe']
)
# Task to manage subscription operations
subscription_task = Task(
description="""
1. Create a new product "Premium Service Plan" with advanced features
2. Set up subscription plans with different tiers
3. Create customers and assign them to appropriate plans
4. Monitor subscription status and handle billing issues
""",
agent=subscription_manager,
expected_output="Subscription management system configured with customers and active plans"
)
crew = Crew(
agents=[subscription_manager],
tasks=[subscription_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
financial_analyst = Agent(
role="Financial Analyst",
goal="Analyze payment data and generate financial insights",
backstory="An analytical AI that excels at extracting insights from payment and subscription data.",
apps=['stripe']
)
# Complex task involving financial analysis
analytics_task = Task(
description="""
1. Retrieve balance transactions for the current month
2. Analyze customer payment patterns and subscription trends
3. Identify high-value customers and subscription performance
4. Generate monthly financial performance report
""",
agent=financial_analyst,
expected_output="Comprehensive financial analysis with payment insights and recommendations"
)
crew = Crew(
agents=[financial_analyst],
tasks=[analytics_task]
)
crew.kickoff()

了解订阅状态:

  • incomplete - 订阅需要支付方式或支付确认
  • incomplete_expired - 在支付确认前已过期的订阅
  • trialing - 订阅处于试用期
  • active - 订阅处于活动状态且有效
  • past_due - 支付失败,但订阅仍然有效
  • canceled - 订阅已取消
  • unpaid - 支付失败,且订阅不再有效

元数据可让你存储关于客户、订阅和产品的附加信息:

{
"customer_segment": "enterprise",
"acquisition_source": "google_ads",
"lifetime_value": "high",
"custom_field_1": "value1"
}

此集成可实现全面的支付和订阅管理自动化,让你的 AI 智能体能够在 Stripe 生态系统中无缝处理账单操作。