How to Integrate LangChain for fintech with Stripe for multi-agent systems
Combining LangChain for fintech with Stripe gives you a clean way to build agentic payment workflows: one agent can reason over customer intent, another can fetch billing context, and a third can execute payment actions through Stripe. That matters when you need AI systems that do more than chat — they need to create invoices, reconcile payments, trigger refunds, and hand off safely between agents.
Prerequisites
- •Python 3.10+
- •A Stripe account with API keys
- •A LangChain-compatible fintech setup
- •Access to your chosen LLM provider
- •Environment variables configured:
- •
STRIPE_SECRET_KEY - •
OPENAI_API_KEYor equivalent model key
- •
- •Installed packages:
- •
stripe - •
langchain - •
langchain-openai - •
langchain-community - •Any fintech-specific LangChain package or wrapper your stack uses
- •
Integration Steps
- •
Install dependencies and load secrets
Keep Stripe credentials out of code. For multi-agent systems, each worker should read the same secret source so payment tools behave consistently across agents.
pip install stripe langchain langchain-openai langchain-community python-dotenvimport os from dotenv import load_dotenv load_dotenv() STRIPE_SECRET_KEY = os.environ["STRIPE_SECRET_KEY"] OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] - •
Initialize Stripe and define a payment tool
Stripe’s Python SDK is straightforward. For agent systems, wrap only the operations you want an agent to perform: create customers, create checkout sessions, issue refunds, or look up invoices.
import stripe stripe.api_key = STRIPE_SECRET_KEY def create_stripe_customer(email: str, name: str): return stripe.Customer.create( email=email, name=name, ) def create_payment_intent(amount_cents: int, currency: str = "usd", customer_id: str | None = None): params = { "amount": amount_cents, "currency": currency, "automatic_payment_methods": {"enabled": True}, } if customer_id: params["customer"] = customer_id return stripe.PaymentIntent.create(**params) - •
Expose Stripe actions as LangChain tools
In LangChain, tools are the bridge between reasoning and execution. Use
@toolso an agent can call your Stripe functions explicitly instead of inventing API calls in free text.from langchain_core.tools import tool @tool def stripe_create_customer(email: str, name: str) -> str: """Create a Stripe customer and return the customer ID.""" customer = stripe.Customer.create(email=email, name=name) return customer.id @tool def stripe_create_payment_intent(amount_cents: int, currency: str = "usd", customer_id: str | None = None) -> str: """Create a Stripe PaymentIntent and return its client secret.""" intent = stripe.PaymentIntent.create( amount=amount_cents, currency=currency, customer=customer_id, automatic_payment_methods={"enabled": True}, ) return intent.client_secret - •
Build the LangChain agent that orchestrates payments
For multi-agent systems, one agent can handle conversation and another can handle payment execution. Start with a single agent wired to your Stripe tools; then split responsibilities later.
from langchain_openai import ChatOpenAI from langchain.agents import initialize_agent, AgentType llm = ChatOpenAI(model="gpt-4o-mini", temperature=0) tools = [stripe_create_customer, stripe_create_payment_intent] payment_agent = initialize_agent( tools=tools, llm=llm, agent=AgentType.OPENAI_FUNCTIONS, verbose=True, ) response = payment_agent.invoke({ "input": "Create a Stripe customer for jane.doe@acme.com named Jane Doe and prepare a $25 payment intent." }) print(response["output"]) - •
Add a second agent for fintech context and handoff
This is where LangChain for fintech becomes useful. One agent can retrieve account state or transaction context before the payment agent acts. In production, this usually means calling internal APIs or vectorized policy docs before touching Stripe.
from langchain_core.prompts import ChatPromptTemplate from langchain_core.output_parsers import StrOutputParser context_prompt = ChatPromptTemplate.from_messages([ ("system", "You are a fintech ops assistant. Summarize whether this request is safe to execute."), ("human", "{request}") ]) # Example chain for pre-checks before payment execution context_chain = context_prompt | llm | StrOutputParser() safety_check = context_chain.invoke({ "request": "Customer requests $250 refund on invoice inv_12345." }) print(safety_check)
Testing the Integration
Use test mode in Stripe and verify you can create objects without charging real cards.
import stripe
stripe.api_key = STRIPE_SECRET_KEY
customer = stripe.Customer.create(
email="test.user@example.com",
name="Test User"
)
intent = stripe.PaymentIntent.create(
amount=1500,
currency="usd",
customer=customer.id,
automatic_payment_methods={"enabled": True},
)
print("Customer ID:", customer.id)
print("PaymentIntent ID:", intent.id)
print("Client Secret:", intent.client_secret[:20] + "...")
Expected output:
Customer ID: cus_1234567890abcdef
PaymentIntent ID: pi_1234567890abcdef
Client Secret: pi_1234567890abcdef...
If that works, your LangChain tool layer can safely call the same Stripe methods through the agent.
Real-World Use Cases
- •
Autonomous billing support
- •One agent answers “Why was I charged?” using transaction history.
- •Another creates refunds in Stripe after policy checks pass.
- •
Invoice collection workflows
- •A reminder agent detects overdue invoices.
- •A payment agent generates Checkout Sessions or PaymentIntents for collection.
- •
Fraud-aware ops assistants
- •A context agent reviews risk signals from internal fintech systems.
- •A transaction agent only executes Stripe actions when policy thresholds are met.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit