move rhailib to herolib
This commit is contained in:
38
rhailib/examples/flows/new_create_payment_intent_error.rhai
Normal file
38
rhailib/examples/flows/new_create_payment_intent_error.rhai
Normal file
@@ -0,0 +1,38 @@
|
||||
// Error handler for failed payment intent creation
|
||||
// This script is triggered when a payment intent creation fails
|
||||
|
||||
print("❌ Payment Intent Creation Failed!");
|
||||
print("==================================");
|
||||
|
||||
// The error data is available as 'parsed_error'
|
||||
if parsed_error != () {
|
||||
print(`Error: ${parsed_error}`);
|
||||
|
||||
// You can handle different types of errors
|
||||
if parsed_error.contains("authentication") {
|
||||
print("🔑 Authentication error - check API key");
|
||||
// eval_file("flows/handle_auth_error.rhai");
|
||||
} else if parsed_error.contains("insufficient_funds") {
|
||||
print("💰 Insufficient funds error");
|
||||
// eval_file("flows/handle_insufficient_funds.rhai");
|
||||
} else if parsed_error.contains("card_declined") {
|
||||
print("💳 Card declined error");
|
||||
// eval_file("flows/handle_card_declined.rhai");
|
||||
} else {
|
||||
print("⚠️ General payment error");
|
||||
// eval_file("flows/handle_general_payment_error.rhai");
|
||||
}
|
||||
|
||||
// Log the error for monitoring
|
||||
print("📊 Logging error for analytics...");
|
||||
// eval_file("flows/log_payment_error.rhai");
|
||||
|
||||
// Notify relevant parties
|
||||
print("📧 Sending error notifications...");
|
||||
// eval_file("flows/send_error_notification.rhai");
|
||||
|
||||
} else {
|
||||
print("⚠️ No error data received");
|
||||
}
|
||||
|
||||
print("🔄 Error handling complete!");
|
@@ -0,0 +1,34 @@
|
||||
// Response handler for successful payment intent creation
|
||||
// This script is triggered when a payment intent is successfully created
|
||||
|
||||
print("✅ Payment Intent Created Successfully!");
|
||||
print("=====================================");
|
||||
|
||||
// The response data is available as 'parsed_data'
|
||||
if parsed_data != () {
|
||||
print(`Payment Intent ID: ${parsed_data.id}`);
|
||||
print(`Amount: ${parsed_data.amount}`);
|
||||
print(`Currency: ${parsed_data.currency}`);
|
||||
print(`Status: ${parsed_data.status}`);
|
||||
|
||||
if parsed_data.client_secret != () {
|
||||
print(`Client Secret: ${parsed_data.client_secret}`);
|
||||
}
|
||||
|
||||
// You can now trigger additional workflows
|
||||
print("🔄 Triggering next steps...");
|
||||
|
||||
// Example: Send confirmation email
|
||||
// eval_file("flows/send_payment_confirmation_email.rhai");
|
||||
|
||||
// Example: Update user account
|
||||
// eval_file("flows/update_user_payment_status.rhai");
|
||||
|
||||
// Example: Log analytics event
|
||||
// eval_file("flows/log_payment_analytics.rhai");
|
||||
|
||||
} else {
|
||||
print("⚠️ No response data received");
|
||||
}
|
||||
|
||||
print("🎉 Payment intent response processing complete!");
|
Reference in New Issue
Block a user