Skip to main content
Here are the steps:
  1. Set up your environment
  2. Create a Stripe Cardholder
  3. Create a Virtual Card with spending controls
  4. Retrieve Virtual Card Details
  5. Make a Purchase

Build an agentic credit card automation

1. Set up your environment

Install the required dependencies and set up your API keys.
Create a .env file with your API keys (securely store keys for Stripe, Browserbase, and optional AI models for Stagehand):
.env

2. Create a Stripe cardholder

You must create a cardholder before issuing virtual cards. The cardholder will have a verified billing address and be eligible to receive virtual cards.
create-cardholder.ts
Save the cardholder ID from the console output for the next step.

3. Create a virtual card

Once you have a cardholder, you can create a virtual card under their name. This step generates a virtual card with a predefined spending limit. Stripe lets you customize the card’s spending controls, including daily, monthly, or per-transaction limits. Find more information on spending controls in the Stripe docs.
create-card.ts
This function returns all the details needed to complete an online purchase.

4. Retrieve virtual card details

After creating a virtual card, you’ll need to retrieve its details (card number, expiration date, and CVC) to use it for transactions. You can use the returned data to automatically enter the card details when needed.
get-card.ts

5. Make a purchase

In this step, you’ll automate filling in the credit card payment form. This example walks you through navigating to the Red Cross donation page, selecting a donation amount, and completing the payment process using the virtual card details retrieved earlier.
🎉 You made an online purchase with Stripe and Browserbase!

Next steps

With this foundation, you can build more advanced payment automation:
  • Create multiple virtual cards for different departments or spending categories
  • Integrate with expense management systems
  • Set up automated subscription payments
  • Build checkout automation for testing payment flows

Best practices

  • Track your transactions: Monitor card usage through the Stripe Dashboard
  • Handle errors gracefully: Implement robust error handling for form fields and payment rejections
  • Add verification steps: Verify successful transactions by checking for confirmation elements
  • Secure your credentials: Never expose API keys in client-side code