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:

  1. Receive an order request
  2. Verify the availability of the items in stock
  3. Process the payment
  4. Initiate the dispatch of the order
  5. 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

  1. Stock Verification: Ensures items are available in stock before processing the payment, avoiding issues with unavailable products.

  2. Payment Processing: Handles payment securely and only proceeds to dispatch if successful.

  3. Customer Notifications: Keeps the customer informed at each step of the order process, improving user experience.