@Moullablad

Guide customers through order completion

This sounds like a crucial customer experience flow! To design this system, we need to outline the steps and how the system would interact with the user and your backend services. Since I don't have direct access to your backend APIs or user data, I'll describe the workflow and the logic. You'll need to implement the actual API calls and data fetching based on this plan.

Here's a proposed workflow:

**Objective:** Guide customers through order completion, ensuring they have a valid Gmail account for login and a WhatsApp-enabled phone number, while offering language preference and payment options.

**Trigger:** Order creation for a single product.

**Workflow Steps:**

1. **Language Preference:**
    *   **Action:** Greet the customer and immediately ask for their preferred language for interaction.
    *   **System Check:** Store the selected language for the current session.
    *   **Tool Needed:** (None directly, this is conversational logic)

2. **User Information Compilation:**
    *   **Action:** Retrieve the following for the "connected user":
        *   User's current email address.
        *   User's phone number.
        *   Any unpaid orders created *today*.
        *   Details of the current order (product, payment type: `cod` or `instant`).
    *   **System Check:**
        *   Is the email a Gmail address (ends with `@gmail.com`)?
        *   Does the phone number indicate WhatsApp availability (e.g., a specific prefix or format)?
        *   Are there any unpaid orders from today?
    *   **Tool Needed:**
        *   A hypothetical `get_user_details(user_id)` function that returns email, phone, and order history.
        *   A hypothetical `get_order_details(order_id)` function.

3. **Email Verification Update:**
    *   **Condition:** If the user's email is *not* a `@gmail.com` address.
    *   **Action:** Inform the user about the Gmail requirement for login and provide a link to update their email.
    *   **System Check:** Prompt the user to click the link and confirm when their email has been updated. (This might require a separate user-facing UI element or a follow-up prompt).
    *   **Tool Needed:** A predefined URL for email update, e.g., `https://jomti.com/update-email?userId=<user_id>`.

4. **WhatsApp Confirmation:**
    *   **Condition:** After email is verified (or if it was already Gmail).
    *   **Action:** Ask if their phone number is linked to WhatsApp.
    *   **System Check:** Based on the phone number data.
    *   **Tool Needed:** (None directly, conversational logic based on retrieved phone number)

5. **Order Confirmation Product Query:**
    *   **Condition:** If the user has any unpaid orders from today, *or* if the current order is being processed.
    *   **Action:**
        *   If unpaid orders exist today, ask: "You have an unpaid order from today. Would you like to confirm it?"
        *   Regardless of previous orders, confirm the current order details (e.g., "You are about to purchase [Product Name].").
        *   Ask: "Do you have any questions about the product?"
    *   **Tool Needed:** (None directly, conversational logic)

6. **Payment Processing:**
    *   **Condition:** If the current order's payment field is `instant` (credit card).
    *   **Action:** Prompt the user to proceed with credit card payment. Provide any necessary links or instructions for the payment gateway.
    *   **Tool Needed:** A hypothetical function or URL for initiating credit card payment, e.g., `https://jomti.com/pay?orderId=<order_id>`.

7. **Final Confirmation Next Steps:**
    *   **Condition:** After all checks, queries, and potential payment initiation.
    *   **Action:** Provide a final confirmation message, summarizing what will happen next (e.g., "Your order is confirmed. You will receive an update via [selected language]..." or "Your payment is being processed. Thank you for shopping with us!").

**Example Interaction Snippet (in English, assuming user selects English initially):**

> **Robot:** Hello! To help you complete your purchase, what language would you prefer I use for our conversation? (e.g., English, Spanish, French)
>
> **User:** English.
>
> **Robot:** Great. I see you have an unpaid order from today for [Product Name]. Would you like to confirm this order?
>
> **User:** Yes.
>
> **Robot:** Understood. I also see your registered email is `[current_email]` and your phone number is `[phone_number]`.
>
> **Action:**
    *   *If `current_email` is NOT `@gmail.com`*:
        > **Robot:** For login purposes, we require a Gmail account. Please update your email by visiting: `https://jomti.com/update-email?userId=...` Let me know once you've updated it.
    *   *If `current_email` IS `@gmail.com`*:
        > **Robot:** Your email is correctly set up for login.
>
> **Robot:** And is your phone number `[phone_number]` connected to WhatsApp?
>
> **User:** Yes, it is.
>
> **Robot:** Wonderful. Your order is confirmed. Since your payment method is 'instant', please proceed with card payment here: `https://jomti.com/pay?orderId=...` Do you have any questions about the product?
>
> *(... waits for user input or payment confirmation ...)*

**To implement this, you would need:**

* **User Authentication/Session Management:** To know who the "connected user" is.
* **Order Management API:** To fetch order details, check payment status, and product types.
* **User Profile API:** To get email and phone number, and potentially to update email.
* **Payment Gateway Integration:** To direct users for credit card payments.

Let me know if you'd like to refine any part of this, or if you can provide more details about how your backend systems work!