Introduction#
This example demonstrates an automated e-commerce order fulfillment process using Upstash Workflow. The workflow takes an order, verifies the stock, processes the payment, and handles order dispatch and customer notifications.
Use Case#
Our workflow will:
- Receive an order request
- Verify the availability of the items in stock
- Process the payment
- Initiate the dispatch of the order
- Send confirmation and delivery notifications to the customer
Code Example#
Code Breakdown#
1. Verifying Stock Availability#
We start by creating an order id and verifying if the items in the order are available in stock. If not, we throw an error to halt the process:
2. Processing Payment#
Once the stock is verified, the workflow processes the payment for the order:
3. Dispatching the Order#
After payment confirmation, we dispatch the order for delivery:
4. Sending Confirmation and Notification Emails#
Lastly, we send an order confirmation email to the customer and notify them when the order is dispatched:
Key Features#
-
Stock Verification: Ensures items are available in stock before processing the payment, avoiding issues with unavailable products.
-
Payment Processing: Handles payment securely and only proceeds to dispatch if successful.
-
Customer Notifications: Keeps the customer informed at each step of the order process, improving user experience.