Managing Order and Payment Statuses in the Online Store
Changing the payment status of an online store order
The change_order_shop_status function allows you to programmatically change the payment status of an online store order and manage stock levels.
Function syntax
change_order_shop_status(order_id, status, update_stock)
Function parameters
| Parameter | Required | Description |
|---|---|---|
order_id |
Yes | Online store order ID. When an order is created, its ID is stored in the client's callback_order_id variable. |
status |
No | Payment status: paid — paid, unpaid — not paid. The default value is paid. |
update_stock |
No | Controls whether stock levels are updated. Pass "1" to update stock quantities. By default, stock levels remain unchanged. |
Available payment statuses
| Value | Payment status |
|---|---|
paid |
Paid |
unpaid |
Not paid |
Managing stock levels
If update_stock is set to "1", changing the payment status also updates stock quantities:
-
paid— the quantity of items in stock decreases. -
unpaid— the quantity of items in stock increases.
If update_stock is omitted, only the order's payment status changes.
Examples
Set the payment status to Paid
change_order_shop_status(#{callback_order_id}, "paid")
The payment status changes to Paid. Stock levels remain unchanged.
Set the payment status to Paid and update stock levels
change_order_shop_status(#{callback_order_id}, "paid", "1")
The order is marked as paid, and the quantity of items in stock decreases.
Set the payment status to Not paid and update stock levels
change_order_shop_status(#{callback_order_id}, "unpaid", "1")
The payment status changes to Not paid, and the quantity of items in stock increases.
Usage notes
The change_order_shop_status function changes the payment status of an order, not its fulfillment status.
To change an order's status to In delivery, Completed, or Canceled, use the Calculator function or API method set_shop_order_status, described in the next section.
Changing order statuses in the online store
The Calculator function and API method set_shop_order_status allow you to automatically change an order's status directly in the MaviBot online store. They work in the same way as the order management buttons in the Orders section.
Changing an order's status does not require moving the associated deal to another CRM stage beforehand. However, certain actions, such as shipping an order, may automatically change the stage of the associated deal.

Available statuses
| Value | Order status | What happens |
|---|---|---|
shipping |
In delivery | If a delivery service is connected to the order, a shipment is created. The deal moves to the next pipeline stage. If there is no pipeline, the order is marked as shipped. |
done |
Completed | The order is closed as completed. For cash-on-delivery orders, the order is also marked as paid. |
cancel |
Canceled | The shipment is canceled with the delivery service, and paid items are returned to stock. |
Rules and limitations
- An order cannot be returned to the New status.
- Completed and canceled orders cannot be moved to another status.
- The customer sees the updated status in their personal account.
- If the corresponding event is enabled in the settings, an order status change event is sent to the bot flow.
- The function and API method are available on plans that include API access. Each call consumes one message from the plan's message allowance.
Calculator function set_shop_order_status
Use this function in the Calculator field of a block to change an order's status within a bot flow.
Syntax
set_shop_order_status(status, order_id)
Parameters
| Parameter | Required | Description |
|---|---|---|
status |
Yes | New status: shipping, done, or cancel. |
order_id |
No | Order ID. If omitted, the current customer's most recent open online store order is used. |
Return value
-
True— the status was successfully changed. - Error text — the action could not be completed.
If an unsupported status is supplied, the function returns status must be one of: shipping, done, cancel. Other possible errors are described in the Errors section below (for example, order not found, order_closed, and invalid_action).
Example 1. Move the most recent open order to In delivery
Enter the following code in the Calculator field:
result = set_shop_order_status("shipping")

The function selects the current customer's most recent open order and changes its status to In delivery. The result is stored in the result variable.
To check the result, display the variable value in a test block's message:
Result: #{result}
Example 2. Complete a specific order
result = set_shop_order_status("done", #{callback_order_id})
In this example, the order ID is taken from the callback_order_id variable. Before calling the function, make sure the variable contains the ID of the intended order.
Example 3. Cancel an order by ID
result = set_shop_order_status("cancel", 12345)
Replace 12345 with the ID of the intended order. If the function succeeds, the order status changes to Canceled.

API method set_shop_order_status
Use this method to change an order's status from an external system via an HTTP request.
Request URL
POST https://chatter.mavibot.ai/api/{api_key}/set_shop_order_status
Replace {api_key} with your project's API access key. The key must have permission to edit CRM data.
Pass the parameters in the request body as JSON. Set the request header to Content-Type: application/json.
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
status |
string | Yes | Order status: shipping, done, or cancel. |
order_id |
integer / string | No* | Order ID. Supports the client-order format, as used in the #{order_id} variable. |
client_id |
integer | No* | Client ID. If order_id is omitted, the client's most recent open online store order is selected. If both parameters are supplied, the method checks whether the order belongs to the specified client. |
* At least one parameter must be supplied: order_id or client_id.
Example 1. Change the status by order ID
curl -X POST "https://chatter.mavibot.ai/api/{api_key}/set_shop_order_status" \
-H "Content-Type: application/json" \
-d '{"order_id": 12345, "status": "shipping"}'
Example 2. Complete the client's most recent open order
POST request body:
{
"client_id": 123456789,
"status": "done"
}
Example 3. Cancel an order and verify that it belongs to the client
POST request body:
{
"client_id": 123456789,
"order_id": 12345,
"status": "cancel"
}
All examples use placeholder IDs. Replace them with actual client and order IDs from your project.
Successful response
{
"status": "success",
"fulfillment_status": "shipping"
}
fulfillment_status is the order status after the request is processed. If the order already has the requested status, the method makes no changes and returns a successful response.
Errors
| API response | Cause |
|---|---|
{"status": "status required"} |
The status parameter is missing. |
{"status": "error", "error": "invalid_status", "message": "status must be one of: shipping, done, cancel"} |
An unsupported status was supplied. The allowed values are listed in message. |
{"status": "order_id or client_id required"} |
Neither order_id nor client_id was supplied. |
{"status": "order_id is invalid"} / {"status": "client_id is invalid"}
|
Invalid ID. Check the supported format of the corresponding parameter. |
{"status": "order not found"} |
The client has no open online store orders. |
{"status": "error", "message": "..."} |
Invalid API key, missing permission to edit CRM data, or a plan that does not support API access. |
{"status": "error", "error": "order_not_found"} |
The order was not found, is not an online store order, or belongs to another client. |
{"status": "error", "error": "order_closed"} |
The order has already been completed or canceled. |
{"status": "error", "error": "invalid_action", "message": "..."} |
The transition is not possible. For example, the cash-on-delivery amount exceeds the delivery service's limit. |
{"status": "error", "error": "next_state_not_found"} |
The pipeline has no next stage for the transition to In delivery. |
{"status": "error", "error": "..._create_failed", "message": "..."} |
The delivery service did not accept the shipment. See message for details. |
{"status": "error", "error": "other"} |
Internal error. Retry the request later. |
Testing the configuration
Before using the function or API method in a live automation, test the status change on a test order. Make sure the intended order is selected, the operation returns a successful result, and the new status appears in the Orders section. Remember that completing or canceling an order is irreversible.