Build Virtual Cards in Minutes: A Step-by-Step Guide
May 13, 2026
▶ Watch the 60-second version on YouTube
Issuing Virtual Cards with Stripe: Step-by-Step
Building a virtual card issuance system can significantly enhance your fintech application, allowing for seamless payments and spending controls. By using Stripe's Issuing and Treasury APIs, you can issue virtual cards quickly, manage cardholder spending, and integrate with your existing infrastructure. Let's dive into how to set up virtual card issuance in just a few minutes.Prerequisites
Before you start, ensure you have: - A Stripe account with access to Issuing and Treasury. - Your API keys (secret and publishable). - A basic understanding of Python and RESTful API calls.Step 1: Set Up Your Environment
First, ensure you have the necessary libraries installed. You'll need the popular `requests` library for making API calls. If you haven't installed it yet, use:
pip install requests
Next, set up your Python script where you'll handle the API calls.
Step 2: Create a Card Program
Stripe requires a card program before issuing virtual cards. This program will define the parameters for your cards, such as spending controls. Here's how to create it:
import requests
stripe_secret_key = 'sk_test_...'
def create_card_program():
url = 'https://api.stripe.com/v1/issuing/card_programs'
headers = {
'Authorization': f'Bearer {stripe_secret_key}',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = {
'name': 'My Virtual Card Program',
'spending_controls[allowed_categories]': ['food_and_drink', 'entertainment'],
'spending_controls[blocked_categories]': ['gambling'],
'spending_controls[spending_limits][amount]': 10000,
'spending_controls[spending_limits][interval]': 'monthly',
}
response = requests.post(url, headers=headers, data=data)
return response.json()
program = create_card_program()
print('Card Program Created:', program)
This code creates a card program that allows spending in certain categories while blocking others, and sets a monthly limit.
Step 3: Issue a Virtual Card
Once your card program is set up, you can issue a virtual card. Here’s how:
def issue_virtual_card(card_program_id):
url = 'https://api.stripe.com/v1/issuing/cards'
headers = {
'Authorization': f'Bearer {stripe_secret_key}',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = {
'card_program': card_program_id,
'currency': 'usd',
'type': 'virtual',
'holder[name]': 'Jane Doe',
'holder[address][line1]': '1234 Main St',
'holder[address][city]': 'San Francisco',
'holder[address][state]': 'CA',
'holder[address][postal_code]': '94103',
'holder[address][country]': 'US',
}
response = requests.post(url, headers=headers, data=data)
return response.json()
card = issue_virtual_card(program['id'])
print('Virtual Card Issued:', card)
This function issues a virtual card linked to your previously created program with a specified holder’s information.
Step 4: Manage Spending Controls
Managing spending controls post-issuance is crucial for any virtual card system. You can update spending limits or block/unblock categories as needed:
def update_card_spending_control(card_id):
url = f'https://api.stripe.com/v1/issuing/cards/{card_id}'
headers = {
'Authorization': f'Bearer {stripe_secret_key}',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = {
'spending_controls[spending_limits][amount]': 5000,
'spending_controls[spending_limits][interval]': 'weekly',
}
response = requests.post(url, headers=headers, data=data)
return response.json()
updated_card = update_card_spending_control(card['id'])
print('Updated Card Spending Controls:', updated_card)
This allows you to fine-tune how much the cardholder can spend, giving you better oversight and control.
Non-Obvious Gotcha: Handling Card Activation
One key insight that many tutorials miss is the card activation step. By default, newly issued cards may not be automatically activated. The cardholder typically needs to activate it before use. You can automate this activation process through the API or set up notifications to inform the user to perform this step. To activate a card, you might want to send a reminder email through your application or use a webhook to listen for card issuance events and follow up accordingly.Conclusion
With these steps, you can quickly set up a virtual card issuance system using Stripe's APIs. The flexibility of the spending controls allows for tailored solutions, whether you're building a corporate expense management tool or a consumer fintech app. As you implement this, keep an eye on the nuances of API responses and manage user experience for activation to ensure a smooth process for your cardholders.💳 Best card for API and cloud spend — earn rewards on every Stripe, AWS, and OpenAI charge.