Stop Fraud Cold with Single-Use Virtual Card Numbers
May 7, 2026
▶ Watch the 60-second version on YouTube
Understanding Single-Use Virtual Card Numbers
Single-use virtual card numbers are a powerful tool in the battle against payment fraud. By dynamically generating card numbers for each transaction, you can drastically reduce the risk of data breaches and unauthorized charges. This approach isn't just about security—it's also a game-changer for user experience, enabling developers to build more robust and user-friendly payment systems. In this post, we'll dive into implementing single-use virtual card numbers using Stripe Issuing. We’ll cover the API calls necessary to set up and manage these cards, and I’ll share a non-obvious gotcha that can save you time and headaches in the long run.Getting Started with Stripe Issuing
To get started, you first need to have a Stripe account and access to the Issuing API. If you haven't already set this up, follow the [Stripe Issuing documentation](https://stripe.com/docs/issuing) for account creation and API key retrieval. Once you have your API keys, we can create a virtual card. Here’s a quick example of how to create a single-use card using Python with the Stripe API:
import stripe
# Set your Stripe secret key
stripe.api_key = 'sk_test_YOUR_SECRET_KEY'
def create_single_use_card(customer_id):
card = stripe.Issuing.Card.create(
cardholder=customer_id,
currency='usd',
type='virtual',
spending_controls={
'allowed_categories': ['online'],
'spending_limits': [{
'amount': 1000, # Limit in cents
'interval': 'all_time'
}],
},
metadata={
'purpose': 'single-use transaction'
},
)
return card
# Replace with your actual customer ID
card = create_single_use_card('ich_1JH0Zs2eZvKYlo2C7JpH8zQ1')
print(f"Created virtual card: {card.id}")
This function will create a virtual card associated with a specified customer, with a spending limit of $10.00 (1000 cents) for online transactions. The metadata can be useful for tracking the purpose of the card in your system.
Using the Card for Transactions
Once you have the single-use card, you can use it just like a physical card for online transactions. Pass the card details to your payment processor (e.g., Stripe, PayPal) in the same way you would with a regular card. Here’s an example of how to make a charge using the newly created card:
def charge_with_virtual_card(card_id, amount):
try:
charge = stripe.Charge.create(
amount=amount, # Amount in cents
currency='usd',
source=card_id,
description='Charge for single-use virtual card'
)
return charge
except stripe.error.StripeError as e:
print(f"Charge failed: {e.user_message}")
# Example charge of $5.00
charge = charge_with_virtual_card(card.id, 500)
print(f"Charge successful: {charge.id}")
This will create a charge of $5.00 using the single-use card. After the transaction, the card can become inactive or deleted to prevent further use.
Non-Obvious Gotcha: Handling Card Creation Failures
When dealing with API calls, especially in a production environment, error handling can often be an afterthought. However, with Stripe Issuing, you may encounter instances where card creation fails due to various reasons—such as exceeding limits, invalid parameters, or network issues. Here's a quick checklist of things to keep in mind: 1. **Rate Limits**: Stripe has rate limits on API requests. If you're creating multiple cards in a short period, you might hit those limits, resulting in failures. Implement exponential backoff for retries. 2. **Spending Controls**: If you set spending controls too restrictively, card creation could fail. Always validate the spending limits and ensure they align with your intended use case. 3. **Error Logging**: Implement robust logging for your API calls. This will help you quickly diagnose and resolve issues when they arise. 4. **Customer Verification**: Ensure that the customer you’re associating the card with is verified to prevent issues with card creation. Stripe has specific requirements around customer verification that can cause card creation to fail. 5. **Testing**: Use the Stripe test environment extensively. Test various scenarios, including limits and error responses, to see how your application behaves. By preparing for these potential pitfalls, you can create a smoother integration experience and enhance your application's robustness.Conclusion
Single-use virtual card numbers are not just a security feature; they are a strategic advantage in the ever-evolving landscape of payment fraud. By using Stripe Issuing, you can offer your users a seamless and secure way to manage transactions. With the right implementation and error handling, you'll be well on your way to shipping a secure payment system that stands out in the market.💳 Best card for API and cloud spend — earn rewards on every Stripe, AWS, and OpenAI charge.