// Example Rhai script demonstrating non-blocking payment functions // This script shows how to use the new async payment functions print("šŸš€ Non-Blocking Payment Example"); print("================================"); // Create a product asynchronously print("šŸ“¦ Creating product..."); let product = new_product() .name("Premium Subscription") .description("Monthly premium subscription service") .metadata("category", "subscription") .metadata("tier", "premium"); let product_result = product.create_async( "payment-worker-1", "product-context-123", "sk_test_your_stripe_secret_key" ); print(`Product creation dispatched: ${product_result}`); // Create a price asynchronously print("šŸ’° Creating price..."); let price = new_price() .amount(2999) // $29.99 in cents .currency("usd") .product("prod_premium_subscription") // Would be the actual product ID .recurring("month") .metadata("billing_cycle", "monthly"); let price_result = price.create_async( "payment-worker-1", "price-context-456", "sk_test_your_stripe_secret_key" ); print(`Price creation dispatched: ${price_result}`); // Create a payment intent asynchronously print("šŸ’³ Creating payment intent..."); let payment_intent = new_payment_intent() .amount(2999) .currency("usd") .customer("cus_customer123") .description("Premium subscription payment") .add_payment_method_type("card") .metadata("subscription_type", "premium") .metadata("billing_period", "monthly"); let payment_result = payment_intent.create_async( "payment-worker-1", "payment-context-789", "sk_test_your_stripe_secret_key" ); print(`Payment intent creation dispatched: ${payment_result}`); // Create a subscription asynchronously print("šŸ“… Creating subscription..."); let subscription = new_subscription() .customer("cus_customer123") .add_price("price_premium_monthly") // Would be the actual price ID .trial_days(7) .metadata("plan", "premium") .metadata("source", "website"); let subscription_result = subscription.create_async( "payment-worker-1", "subscription-context-101", "sk_test_your_stripe_secret_key" ); print(`Subscription creation dispatched: ${subscription_result}`); // Create a coupon asynchronously print("šŸŽ« Creating coupon..."); let coupon = new_coupon() .duration("once") .percent_off(20) .metadata("campaign", "new_user_discount") .metadata("valid_until", "2024-12-31"); let coupon_result = coupon.create_async( "payment-worker-1", "coupon-context-202", "sk_test_your_stripe_secret_key" ); print(`Coupon creation dispatched: ${coupon_result}`); print("\nāœ… All payment operations dispatched!"); print("šŸ”„ HTTP requests are happening in the background"); print("šŸ“Ø Response/error scripts will be triggered when complete"); print("\nšŸ“‹ Summary:"); print(` Product: ${product_result}`); print(` Price: ${price_result}`); print(` Payment Intent: ${payment_result}`); print(` Subscription: ${subscription_result}`); print(` Coupon: ${coupon_result}`); print("\nšŸŽÆ Key Benefits:"); print(" āœ“ Immediate returns - no blocking"); print(" āœ“ Concurrent processing capability"); print(" āœ“ Event-driven response handling"); print(" āœ“ No global state dependencies"); print(" āœ“ Configurable per request");