How to Integrate LangChain for retail banking with Stripe for AI agents
Combining LangChain for retail banking with Stripe gives you a clean way to let an AI agent reason over customer intent while still executing payments, subscriptions, and refunds through a real billing system. In practice, this means your agent can answer banking questions, trigger payment actions, and keep the interaction grounded in controlled tool calls instead of free-form text.
Prerequisites
- •Python 3.10+
- •A LangChain setup with access to your retail banking tools or chain wrappers
- •A Stripe account with:
- •
STRIPE_SECRET_KEY - •test mode enabled
- •
- •Install these packages:
- •
langchain - •
langchain-openai - •
stripe - •any retail-banking-specific LangChain package or internal tool wrapper you use
- •
- •API keys stored in environment variables
- •A test customer and test payment method in Stripe
Integration Steps
- •Set up your Python environment and install dependencies.
pip install langchain langchain-openai stripe python-dotenv
If your retail banking layer is exposed as custom LangChain tools, keep those imports available in the same environment. The important part is that LangChain can call a banking tool and Stripe can execute payment operations.
- •Configure Stripe and load your secrets.
import os
from dotenv import load_dotenv
import stripe
load_dotenv()
stripe.api_key = os.environ["STRIPE_SECRET_KEY"]
STRIPE_CUSTOMER_ID = os.environ["STRIPE_CUSTOMER_ID"]
At this point, Stripe is ready for direct API calls like stripe.PaymentIntent.create(...) or stripe.Invoice.create(...). For agent systems, I usually start with PaymentIntents because they’re explicit and easy to control.
- •Wrap Stripe actions as LangChain tools.
from typing import Optional
from langchain_core.tools import tool
@tool
def create_stripe_payment_intent(amount_cents: int, currency: str = "usd", customer_id: Optional[str] = None) -> str:
"""
Create a Stripe PaymentIntent for a retail banking payment flow.
"""
intent = stripe.PaymentIntent.create(
amount=amount_cents,
currency=currency,
customer=customer_id,
automatic_payment_methods={"enabled": True},
description="AI agent initiated retail banking payment",
)
return intent.id
@tool
def refund_stripe_payment(payment_intent_id: str) -> str:
"""
Refund a captured payment by PaymentIntent ID.
"""
charges = stripe.Charge.list(payment_intent=payment_intent_id, limit=1)
if not charges.data:
return "No charge found for that PaymentIntent"
refund = stripe.Refund.create(charge=charges.data[0].id)
return refund.id
This is the pattern I recommend: keep Stripe side effects behind narrow tools. Your agent should not build raw API payloads in the middle of a conversation.
- •Add your retail banking tool or chain into the same agent context.
If you already have LangChain-based banking tools, expose them the same way. Here’s a simple example of a balance lookup tool that an agent can use before deciding whether to charge or refund.
from langchain_core.tools import tool
@tool
def get_account_balance(account_id: str) -> str:
"""
Fetch a customer's current available balance from the retail banking system.
Replace this stub with your bank API or internal service call.
"""
# Example response from your bank service
available_balance = 1250.75
return f"Account {account_id} available balance: {available_balance} USD"
Now you have two classes of tools in the same agent:
- •bank context tools for balance, eligibility, transaction history
- •Stripe execution tools for payments and refunds
- •Build the LangChain agent that chooses between banking context and Stripe execution.
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
tools = [
get_account_balance,
create_stripe_payment_intent,
refund_stripe_payment,
]
agent = initialize_agent(
tools=tools,
llm=llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True,
)
result = agent.invoke({
"input": "Check account ABC123 balance and if it is above 500 USD, create a Stripe payment intent for 250 USD."
})
print(result["output"])
This gives you one conversational layer that can inspect banking state and then decide whether to call Stripe. In production, you’d add policy checks before any write action like payment creation or refunding.
Testing the Integration
Use a controlled test prompt and verify both tool paths are reachable.
test_response = agent.invoke({
"input": "Get account ABC123 balance. If sufficient, create a Stripe payment intent for 100 USD."
})
print(test_response["output"])
Expected output will vary by model routing, but it should look like this:
Account ABC123 available balance: 1250.75 USD
Created payment intent: pi_3Qxxxxxxxxxxxx
If you want to test the Stripe side directly without the agent loop:
intent_id = create_stripe_payment_intent.invoke({
"amount_cents": 10000,
"currency": "usd",
"customer_id": STRIPE_CUSTOMER_ID,
})
print(intent_id)
Expected output:
pi_3Qxxxxxxxxxxxx
Real-World Use Cases
- •
Smart bill pay assistant
- •The agent checks available balance through your banking layer, then creates a Stripe PaymentIntent only when funds are sufficient.
- •
Dispute and refund workflow
- •The agent reads transaction context from the bank system and issues a targeted Stripe refund when support approves it.
- •
Subscription servicing
- •The agent answers account questions from banking data while managing recurring billing events through Stripe invoices or subscriptions.
The main rule here is simple: let LangChain handle reasoning and orchestration, but keep Stripe as the execution layer behind explicit tools. That gives you traceability, safer permissions, and fewer surprises when the agent moves from chat to money movement.
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