How to Integrate LangChain for banking with Stripe for multi-agent systems
Combining LangChain for banking with Stripe gives you a clean path to build agentic payment workflows that can reason over customer context, generate payment actions, and execute them through a real billing rail. For multi-agent systems, this means one agent can handle account or policy reasoning while another handles payment collection, refunds, or invoice lookup through Stripe.
Prerequisites
- •Python 3.10+
- •A LangChain for banking setup with access to your banking tools, retrievers, or agent wrappers
- •A Stripe account in test mode
- •Stripe secret key and webhook signing secret
- •Installed packages:
- •
langchain - •
stripe - •
python-dotenv
- •
- •Access to whatever internal banking data source your LangChain for banking agent uses
- •Basic understanding of tool calling in LangChain
Integration Steps
- •Install dependencies and configure secrets.
pip install langchain stripe python-dotenv
from dotenv import load_dotenv
import os
load_dotenv()
STRIPE_SECRET_KEY = os.getenv("STRIPE_SECRET_KEY")
STRIPE_WEBHOOK_SECRET = os.getenv("STRIPE_WEBHOOK_SECRET")
- •Create a Stripe client and wrap the payment actions as tools.
In production, do not let the LLM call Stripe directly. Expose only the methods you want the agent to use.
import stripe
from langchain_core.tools import tool
stripe.api_key = STRIPE_SECRET_KEY
@tool
def create_stripe_customer(email: str, name: str) -> str:
"""Create a Stripe customer."""
customer = stripe.Customer.create(
email=email,
name=name,
)
return customer.id
@tool
def create_payment_intent(amount_cents: int, currency: str, customer_id: str) -> str:
"""Create a Stripe PaymentIntent."""
intent = stripe.PaymentIntent.create(
amount=amount_cents,
currency=currency,
customer=customer_id,
automatic_payment_methods={"enabled": True},
)
return intent.client_secret
@tool
def refund_payment(payment_intent_id: str) -> str:
"""Refund a captured payment."""
refund = stripe.Refund.create(payment_intent=payment_intent_id)
return refund.id
- •Build the LangChain for banking side as a separate agent that provides account context.
The point here is not to mix banking logic with billing logic. Keep them as separate agents and pass only the minimum data needed between them.
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
banking_prompt = ChatPromptTemplate.from_messages([
("system", "You are a banking assistant. Return only verified account context."),
("human", "{input}")
])
# Example placeholder tool from your banking stack.
# Replace with your actual LangChain for banking retriever/tool.
banking_tools = []
banking_agent = create_tool_calling_agent(llm, banking_tools, banking_prompt)
banking_executor = AgentExecutor(agent=banking_agent, tools=banking_tools)
- •Orchestrate both agents in a coordinator that decides when to bill.
This is where multi-agent systems pay off. The banking agent verifies eligibility or outstanding balance; the payments agent handles Stripe operations.
from langchain_core.messages import HumanMessage
def collect_premium_for_customer(customer_query: str):
bank_result = banking_executor.invoke({
"input": customer_query
})
# Example extracted fields from your bank workflow.
# In real code, parse structured output from your banking agent.
email = bank_result.get("email")
name = bank_result.get("name")
amount_cents = bank_result.get("amount_cents", 2500)
customer_id = create_stripe_customer.invoke({"email": email, "name": name})
client_secret = create_payment_intent.invoke({
"amount_cents": amount_cents,
"currency": "usd",
"customer_id": customer_id,
})
return {
"stripe_customer_id": customer_id,
"payment_client_secret": client_secret,
}
- •Add webhook handling so your system reacts to payment completion.
Do not poll Stripe for state changes if you can avoid it. Webhooks are the correct production pattern.
from flask import Flask, request, abort
app = Flask(__name__)
@app.post("/stripe/webhook")
def stripe_webhook():
payload = request.data
sig_header = request.headers.get("Stripe-Signature")
try:
event = stripe.Webhook.construct_event(
payload=payload,
sig_header=sig_header,
secret=STRIPE_WEBHOOK_SECRET,
)
except Exception:
abort(400)
if event["type"] == "payment_intent.succeeded":
payment_intent = event["data"]["object"]
# Update your bank-side ledger or notify the orchestration layer here.
print(f"Payment succeeded: {payment_intent['id']}")
return {"status": "ok"}
Testing the Integration
Run a simple end-to-end test in Stripe test mode using known test cards and mock banking output.
def test_flow():
fake_bank_context = {
"email": "customer@example.com",
"name": "Jane Doe",
"amount_cents": 2500,
}
customer_id = create_stripe_customer.invoke({
"email": fake_bank_context["email"],
"name": fake_bank_context["name"],
})
client_secret = create_payment_intent.invoke({
"amount_cents": fake_bank_context["amount_cents"],
"currency": "usd",
"customer_id": customer_id,
})
print("customer_id:", customer_id)
print("client_secret_prefix:", client_secret[:20])
test_flow()
Expected output:
customer_id: cus_1234567890abcdef
client_secret_prefix: pi_1234567890abcdef_
If you wire up webhooks and complete the payment in the Stripe test UI, you should also see:
Payment succeeded: pi_1234567890abcdef
Real-World Use Cases
- •Premium collection for insurance agents that verify policy status in LangChain for banking and then create a Stripe PaymentIntent for renewal.
- •Dispute resolution workflows where one agent checks transaction history while another issues refunds or partial credits through Stripe.
- •Collections automation where an agent summarizes delinquent accounts, generates outreach text, and triggers secure payment links via Stripe Checkout.
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