Unlock Agentic Commerce with Stripe and OpenAI's ACP
May 7, 2026
▶ Watch the 60-second version on YouTube
Seamless AI-driven Purchases with ACP
The Agentic Commerce Protocol (ACP) by Stripe and OpenAI has reached production readiness, and it’s open-sourced! This powerful update allows you to enable AI agents to make purchases on behalf of users via your existing Stripe checkout integration. This means that you can start leveraging AI capabilities to create a more dynamic and user-friendly payment experience without overhauling your entire payment infrastructure. When you think about agent-driven commerce, consider the implications: virtual assistants, chatbots, or even AI agents that can handle purchases based on user preferences. What’s crucial here is how effortless it is to integrate this capability into your existing applications.Getting Started with ACP
To get started, you’ll need to install the Stripe API if you haven’t already. Assuming you’re using Python, you can install the Stripe library with pip:
pip install stripe
Once you’ve set up the SDK, you can start building out the functionality that will allow your AI agents to interact with Stripe’s API.
Setup Your Environment
Before diving into code, ensure you have your Stripe API keys at hand. You can find these in your Stripe dashboard under Developers > API keys. For this example, we'll use the `/v1/checkout/sessions` endpoint to create a checkout session that allows your AI agents to initiate a payment. Here’s how to set up a simple checkout session for agent purchases:
import stripe
# Set your secret key
stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
def create_checkout_session(agent_id, line_items):
try:
session = stripe.checkout.Session.create(
payment_method_types=['card'],
line_items=line_items,
mode='payment',
success_url='https://yourdomain.com/success',
cancel_url='https://yourdomain.com/cancel',
metadata={'agent_id': agent_id}
)
return session
except Exception as e:
print(f"Error creating checkout session: {e}")
return None
# Define line items for agent purchase
line_items = [{
'price_data': {
'currency': 'usd',
'product_data': {
'name': 'AI Subscription',
},
'unit_amount': 5000, # $50.00
},
'quantity': 1,
}]
# Create a checkout session for the agent
session = create_checkout_session("agent_123", line_items)
print(f"Checkout session created: {session.url}")
This will initiate a checkout session where your AI agent can make purchases. The `metadata` field is crucial here as it allows you to track which agent initiated the session.
Non-Obvious Gotcha: Handling Payment Methods
One aspect that isn't always highlighted in tutorials is the importance of handling payment methods correctly in conjunction with the ACP. The Stripe API allows users to save payment methods for future use, but when integrating ACP, you need to ensure that the AI agent has the proper permissions and that the right payment method is selected. If your agents are using saved payment methods, you’ll want to ensure that these methods are associated with the correct customer objects. If not handled properly, you might find that your agents are unable to make purchases due to permissions issues or invalid payment method errors. You can check for saved payment methods using:
def list_payment_methods(customer_id):
try:
payment_methods = stripe.PaymentMethod.list(
customer=customer_id,
type="card",
)
return payment_methods
except Exception as e:
print(f"Error listing payment methods: {e}")
return None
This function allows you to retrieve the payment methods for a specific customer, ensuring that your AI agents are equipped to make purchases seamlessly.
Enabling AI Agents to Make Purchases
To enable AI agents to make purchases, you'll need to set up a webhook to listen for events that indicate a successful payment or a failed attempt. Here’s a quick example of how you can handle that:
from flask import Flask, request
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def stripe_webhook():
payload = request.get_data(as_text=True)
sig_header = request.headers.get('Stripe-Signature')
try:
event = stripe.Webhook.construct_event(
payload, sig_header, YOUR_ENDPOINT_SECRET
)
except ValueError as e:
print(f"Invalid payload: {e}")
return '', 400
except stripe.error.SignatureVerificationError as e:
print(f"Invalid signature: {e}")
return '', 400
# Handle the event
if event['type'] == 'checkout.session.completed':
session = event['data']['object']
print('Checkout session completed:', session)
return '', 200
Make sure to replace `YOUR_ENDPOINT_SECRET` with your actual endpoint secret from the Stripe dashboard.
Final Thoughts
With the Agentic Commerce Protocol, you're now empowered to allow AI agents to handle purchases seamlessly within your existing Stripe checkout flow. This capability not only enhances the user experience but also opens the door for innovative applications in fintech products. As you implement this, keep an eye on the handling of payment methods and ensure that your agents are equipped to operate with the right permissions. It’s the little details that can make or break your implementation. Now go ahead and get this into production; your AI agents are waiting!💳 Best card for API and cloud spend — earn rewards on every Stripe, AWS, and OpenAI charge.