# Online Order

### Introduction

Selldone provides webhooks to notify your system about events occurring in your online store. This allows for real-time updates, triggering actions like order processing, payment confirmations, and delivery tracking. The webhooks send POST requests to your specified endpoints whenever these events are triggered.

<figure><img src="/files/0H54FjN3CMVRHALYiu4O" alt=""><figcaption></figcaption></figure>

### How Webhooks Work

When certain events occur in your Selldone shop (such as an order being placed or paid), the system sends a POST request to your endpoint, providing detailed information about the event.

***

### Available Triggers

These are the main events that can trigger a webhook:

1. **CheckoutOrder**: When a customer checks out an order. (User clicks on on payment options like Stripe, so <mark style="color:green;">checkout is finalized</mark>)
2. **PaymentOrder**: When payment for an order is completed. (User <mark style="color:purple;">paid the money</mark>!)
3. **CancelProduct**: When a product in an order is canceled.
4. **OrderConfirm**: When an order is confirmed.
5. **PreparingOrder**: When the shop starts preparing an order.
6. **SentOrder**: When the order is dispatched.
7. **ToCustomer**: When the order is delivered to the customer.
8. **ReturnOrder**: When a customer returns an order.
9. **DeliveryCanceled**: When a delivery is canceled.

***

### Webhook Payload Format

Each webhook POST request contains the following payload structure:

```json
{
  "event": "OnlineOrder",
  "action": "CheckoutOrder, PaymentOrder, CancelProduct, OrderConfirm, PreparingOrder, SentOrder, ToCustomer, ReturnOrder, DeliveryCanceled",
  "shop": {
    "id": 1,
    "name": "pajuhaan",
    "title": "Rocketiox",
    "domain": "http://localhost:9000/@pajuhaan"
  },
  "basket": "Order object",
  "user": "User object {id, name, email, phone} or null",
  "customer": "Customer object or null"
}
```

***

### Example Webhook Payloads

#### 1. Checkout Order Event

**Description**: This payload is sent when a customer completes the checkout process, and the order is created.

**Request:**

```json
{
  "event": "OnlineOrder",
  "action": "CheckoutOrder",
  "shop": {
    "id": 1,
    "name": "pajuhaan",
    "title": "Rocketiox",
    "domain": "http://localhost:9000/@pajuhaan"
  },
  "basket": {
    "id": 1001,
    "label": "SINX-1",
    "shop_id": 1,
    "user_id": 2,
    "customer_id": 74,
    "status": "Reserved",
    "price": 451.16,
    "currency": "USD",
    "delivery_price": 5.51,
    "discount": 136.48,
    "tax": 63.75,
    "delivery_state": "CheckQueue",
    "created_at": "2024-09-30T10:41:59.000000Z",
    "updated_at": "2024-09-30T10:42:24.000000Z",
    "items": [
      {
        "id": 1906,
        "basket_id": 1001,
        "product_id": 9361,
        "price": 287,
        "currency": "USD",
        "tax": {
          "amount": 57.4
        }
      }
    ]
  },
  "user": {
    "id": 2,
    "name": "John Doe",
    "email": "user*****@mail.com",
    "phone": "*****000"
  },
  "customer": {
    "id": 74,
    "name": "John Doe",
    "email": "customer*****@mail.com",
    "phone": "*****603"
  }
}
```

***

#### 2. Payment Order Event

**Description**: This payload is sent when the payment for an order is successfully completed.

**Request:**

```json
{
  "event": "OnlineOrder",
  "action": "PaymentOrder",
  "shop": {
    "id": 1,
    "name": "pajuhaan",
    "title": "Rocketiox",
    "domain": "http://localhost:9000/@pajuhaan"
  },
  "basket": {
    "id": 1001,
    "label": "SINX-1",
    "shop_id": 1,
    "user_id": 2,
    "customer_id": 74,
    "status": "Payed",
    "price": 451.16,
    "currency": "USD",
    "payment_type": "stripe",
    "payment_id": 934,
    "created_at": "2024-09-30T10:41:59.000000Z",
    "updated_at": "2024-09-30T10:43:44.000000Z",
    "items": [
      {
        "id": 1906,
        "basket_id": 1001,
        "product_id": 9361,
        "price": 287,
        "currency": "USD",
        "tax": {
          "amount": 57.4
        }
      }
    ]
  },
  "user": {
    "id": 2,
    "name": "John Doe",
    "email": "user*****@mail.com",
    "phone": "*****000"
  },
  "customer": {
    "id": 74,
    "name": "John Doe",
    "email": "customer*****@mail.com",
    "phone": "*****603"
  }
}
```

***

### Handling Webhook Responses

Your server must respond with a `200 OK` status to acknowledge receipt of the webhook. If Selldone does not receive this response, it will retry the request several times.

***

### Securing Webhooks

1. **Verify Request Source**: Validate webhook requests to ensure they come from Selldone.
2. **HTTPS**: Always use HTTPS for your webhook endpoint to encrypt data and ensure it is securely transmitted.

***

Here’s a structured table for the **Order Types**, **Status**, and **Delivery State Codes**:

#### Order Types

<table><thead><tr><th width="201">Type</th><th>Description</th></tr></thead><tbody><tr><td>PHYSICAL</td><td>A physical product that requires shipping or delivery.</td></tr><tr><td>VIRTUAL</td><td>A virtual product, such as software or online assets.</td></tr><tr><td>SERVICE</td><td>A service that is provided, rather than a tangible product.</td></tr><tr><td>FILE</td><td>A digital file, like documents, media, or data.</td></tr><tr><td>SUBSCRIPTION</td><td>A recurring service or product that is billed on a subscription basis.</td></tr></tbody></table>

#### Status

<table><thead><tr><th width="154">Code</th><th>Description</th></tr></thead><tbody><tr><td>Open</td><td>The order is open but not yet processed.</td></tr><tr><td>Reserved</td><td>The order is reserved but not yet paid.</td></tr><tr><td>Payed</td><td>The order has been paid for by the customer.</td></tr><tr><td>Canceled</td><td>The order has been canceled.</td></tr><tr><td>COD</td><td>The order is cash on delivery.</td></tr></tbody></table>

#### Delivery State Codes

<table><thead><tr><th width="192">Code</th><th>Description</th></tr></thead><tbody><tr><td>CheckQueue</td><td>The order is in the queue waiting for confirmation.</td></tr><tr><td>OrderConfirm</td><td>The order has been confirmed by the shop.</td></tr><tr><td>PreparingOrder</td><td>The shop is preparing the order.</td></tr><tr><td>SentOrder</td><td>The order has been shipped or dispatched.</td></tr><tr><td>ToCustomer</td><td>The order is en route to the customer.</td></tr></tbody></table>

***

This provides a clean, well-structured GitBook section with obfuscated sensitive details. Each sample includes a description, and the payload details are adjusted for demonstration purposes. Let me know if you need further customization!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.webhook.selldone.com/orders/online-order.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
