Overview
File:src/tools/PaymentTool.ts
Demonstrates payment integration using Stripe API with secure environment variable management.
Complete Code
Key Concepts
1. Environment Variables
Never hardcode API keys!2. Validation
Always check environment variables exist:3. Error Handling
Handle external API failures gracefully:4. Amount Conversion
Stripe uses cents, not dollars:Setup Required
1. Get Stripe API Key
- Create account at https://stripe.com
- Go to Dashboard → Developers → API Keys
- Copy “Secret key” (starts with
sk_test_)
2. Add to .env File
Create.env in project root:
3. Test
create_payment_link:
- Amount:
29.99 - Currency:
USD - Description:
Product Purchase
Customization Ideas
Add Customer Info
Add Success/Cancel URLs
Add Metadata
Other Payment Providers
Same pattern works for other providers:- PayPal
- Square
- Custom Gateway
Security Best Practices
Use Test Keys in Development
Use Test Keys in Development
Never Log API Keys
Never Log API Keys
Validate Amounts
Validate Amounts
Add .env to .gitignore
Add .env to .gitignore
What You’ll Learn
Environment Variables
Secure secret management
External Integration
Third-party API integration
Payment Processing
Real payment workflows
Error Handling
Graceful failure handling

