.. | ||
.env.example | ||
main.rs | ||
payment.rhai | ||
README.md |
Payment Example with Stripe Integration
This example demonstrates how to use the async HTTP API architecture to make real Stripe API calls from Rhai scripts.
Setup
-
Get Stripe API Keys
- Sign up at Stripe Dashboard
- Go to API Keys
- Copy your Secret key (starts with
sk_test_
for test mode)
-
Configure Environment
# Copy the example file cp .env.example .env # Edit .env and add your real Stripe secret key STRIPE_SECRET_KEY=sk_test_your_actual_key_here
-
Run the Example
# From the rhailib root directory cd src/dsl && cargo run --example payment
What This Example Does
- Loads environment variables from
.env
file - Configures async HTTP architecture with real Stripe API credentials
- Creates Stripe objects using the builder pattern:
- Products
- Prices (one-time and recurring)
- Coupons (percentage and fixed amount)
- Payment Intents
- Subscriptions
Architecture Features Demonstrated
- ✅ Async HTTP calls from synchronous Rhai scripts
- ✅ MPSC channel communication between Rhai and async workers
- ✅ Environment variable loading for secure API key management
- ✅ Error handling with proper Stripe API error propagation
- ✅ Builder pattern for creating complex Stripe objects
- ✅ Multi-threaded execution with dedicated async worker threads
Expected Output
With a valid Stripe API key, you'll see:
🔧 Configuring async HTTP client with timeouts...
🚀 Async worker thread started
🔄 Processing POST request to products
📥 Stripe response: {"id":"prod_...","object":"product",...}
✅ Product created successfully with ID: prod_...
Without a valid key, you'll see the demo behavior with error handling.