rhailib/src/dsl/examples/payment
2025-07-21 20:56:29 +02:00
..
.env.example implement payment dsl 2025-07-08 22:55:47 +02:00
main.rs workflow orchestration wip 2025-07-21 20:56:29 +02:00
payment.rhai workflow orchestration wip 2025-07-21 20:56:29 +02:00
README.md implement payment dsl 2025-07-08 22:55:47 +02:00

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

  1. Get Stripe API Keys

  2. 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
    
  3. 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.