- Set up your environment
- Create a Stripe Cardholder
- Create a Virtual Card with spending controls
- Retrieve Virtual Card Details
- Make a Purchase
Build an agentic credit card automation
1. Set up your environment
Install the required dependencies and set up your API keys.- Node.js
- Python
.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.- Node.js
- Python
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.- Node.js
- Python
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.- Node.js
- Python
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.- Node.js
- Python
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