|
| 1 | +# π Agentic Credit Card Automation - Python |
| 2 | + |
| 3 | +Effortlessly create virtual cards with **Stripe** and automate purchases using **Browserbase** in Python. |
| 4 | + |
| 5 | +## π Overview |
| 6 | + |
| 7 | +This Python implementation enables you to: |
| 8 | +- **Create virtual cards** with spending controls using Stripe Issuing |
| 9 | +- **Retrieve virtual card details** securely |
| 10 | +- **Automate online purchases** with Playwright and Browserbase |
| 11 | + |
| 12 | +## π οΈ Setup |
| 13 | + |
| 14 | +### Prerequisites |
| 15 | +- Python 3.8+ |
| 16 | +- pip or poetry |
| 17 | +- Stripe account with Issuing enabled |
| 18 | +- Browserbase account |
| 19 | + |
| 20 | +### Installation |
| 21 | + |
| 22 | +1. **Install dependencies**: |
| 23 | +```bash |
| 24 | +pip install -r requirements.txt |
| 25 | +``` |
| 26 | + |
| 27 | +2. **Configure environment variables**: |
| 28 | +Create a `.env` file in this directory: |
| 29 | +```env |
| 30 | +STRIPE_API_KEY=sk_test_your_stripe_secret_key |
| 31 | +BROWSERBASE_API_KEY=your_browserbase_api_key |
| 32 | +BROWSERBASE_PROJECT_ID=your_browserbase_project_id |
| 33 | +``` |
| 34 | + |
| 35 | +3. **Install Playwright browsers**: |
| 36 | +```bash |
| 37 | +playwright install |
| 38 | +``` |
| 39 | + |
| 40 | +## π Usage |
| 41 | + |
| 42 | +### Step 1: Create a Cardholder |
| 43 | +```bash |
| 44 | +python create_cardholder.py |
| 45 | +``` |
| 46 | + |
| 47 | +### Step 2: Create a Virtual Card |
| 48 | +```bash |
| 49 | +python create_card.py |
| 50 | +``` |
| 51 | +β οΈ **Important**: Update the `cardholder_id` variable with the ID from Step 1 |
| 52 | + |
| 53 | +### Step 3: Retrieve Card Details |
| 54 | +```bash |
| 55 | +python get_card.py |
| 56 | +``` |
| 57 | +β οΈ **Important**: Uncomment and update the `card_id` variable with the ID from Step 2 |
| 58 | + |
| 59 | +### Step 4: Make an Automated Payment |
| 60 | +```bash |
| 61 | +python make-payment.py |
| 62 | +``` |
| 63 | +β οΈ **Important**: Update the `cardId` variable with the ID from Step 2 |
| 64 | + |
| 65 | +## π Files |
| 66 | + |
| 67 | +| File | Description | |
| 68 | +|------|-------------| |
| 69 | +| `create_cardholder.py` | Creates a Stripe cardholder with billing information | |
| 70 | +| `create_card.py` | Creates a virtual card with spending limits | |
| 71 | +| `get_card.py` | Retrieves card details including sensitive information | |
| 72 | +| `make-payment.py` | Automates a donation using Playwright and Browserbase | |
| 73 | +| `requirements.txt` | Python dependencies | |
| 74 | +| `.env` | Environment variables (not tracked in git) | |
| 75 | + |
| 76 | +## π§ Configuration |
| 77 | + |
| 78 | +### Spending Controls |
| 79 | +Edit `create_card.py` to customize: |
| 80 | +- **Allowed categories**: Restrict card usage to specific merchant categories |
| 81 | +- **Spending limits**: Set daily/monthly/yearly limits |
| 82 | +- **Blocked categories**: Prevent usage at certain merchant types |
| 83 | + |
| 84 | +### Payment Automation |
| 85 | +Modify `make-payment.py` to: |
| 86 | +- Change the target website |
| 87 | +- Customize form filling logic |
| 88 | +- Add error handling and validation |
| 89 | + |
| 90 | +## π Python-Specific Features |
| 91 | + |
| 92 | +### Virtual Environment (Recommended) |
| 93 | +```bash |
| 94 | +python -m venv venv |
| 95 | +source venv/bin/activate # On Windows: venv\Scripts\activate |
| 96 | +pip install -r requirements.txt |
| 97 | +``` |
| 98 | + |
| 99 | +### Error Handling |
| 100 | +The Python implementation includes: |
| 101 | +- Environment variable validation |
| 102 | +- Stripe API error handling |
| 103 | +- Playwright timeout management |
| 104 | + |
| 105 | +### Dependencies |
| 106 | +- **stripe**: Official Stripe Python library |
| 107 | +- **browserbasehq**: Browserbase SDK for Python |
| 108 | +- **playwright**: Browser automation framework |
| 109 | +- **python-dotenv**: Environment variable management |
| 110 | + |
| 111 | +## π Security Notes |
| 112 | + |
| 113 | +- Never commit `.env` files to version control |
| 114 | +- Use test API keys for development |
| 115 | +- Implement proper exception handling in production |
| 116 | +- Consider using Stripe webhooks for real-time updates |
| 117 | +- Always validate sensitive card data before use |
| 118 | + |
| 119 | +## π Documentation |
| 120 | + |
| 121 | +For full API documentation and advanced usage: |
| 122 | +π **[Stripe Python SDK](https://stripe.com/docs/api/python)** |
| 123 | +π **[Browserbase Python SDK](https://docs.browserbase.com/sdk/python)** |
| 124 | +π **[Playwright Python](https://playwright.dev/python/)** |
| 125 | + |
| 126 | +## π― Example Use Cases |
| 127 | + |
| 128 | +- **Financial automation**: Automate expense reporting and payment processing |
| 129 | +- **E-commerce testing**: Test payment flows across multiple platforms |
| 130 | +- **Budget management**: Create spending-limited cards for different departments |
| 131 | +- **Subscription automation**: Programmatically manage recurring payments |
| 132 | + |
| 133 | +## π¨ Troubleshooting |
| 134 | + |
| 135 | +### Common Issues |
| 136 | +- **Import errors**: Ensure all dependencies are installed via `pip install -r requirements.txt` |
| 137 | +- **Playwright errors**: Run `playwright install` to download browser binaries |
| 138 | +- **Stripe API errors**: Verify your API keys and account permissions |
| 139 | +- **Environment variables**: Double-check your `.env` file formatting |
0 commit comments