Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/wppconnect-team/wa-js/llms.txt

Use this file to discover all available pages before exploring further.

The WPP.order module gives WhatsApp Business accounts programmatic access to incoming order messages. When a customer submits a cart through WhatsApp, their order appears as a special ORDER message type in your chat. The functions in this module let you read order details, accept or decline orders, and send follow-up status updates (shipped, delivered, complete, etc.) as the fulfillment progresses.
Order messages are identified by their message ID (msgId), not a standalone order ID. Every WPP.order function requires you to pass the ID of the order message in the chat, which you obtain from the chat’s message store or from a real-time message event.

Reading an order

get(msgId)

Fetches full order details for a given order message. The message must exist in the local MsgStore and must be of type ORDER. Returns an OrderModel populated from WhatsApp’s queryOrder API.
msgId
string | MsgKey
required
The message ID string or MsgKey object of the order message.
// Listen for incoming messages and read orders
WPP.on('chat.new_message', async (msg) => {
  if (msg.type === 'order') {
    const order = await WPP.order.get(msg.id);
    console.log('Order ID:', order.id);
    console.log('Products:', order.products.length);
    console.log('Total:', order.total, order.currency);
  }
});
// Retrieve an order by a known message ID string
const order = await WPP.order.get('3EB0C9A1B2C3D4E5F6A7B8');
console.log(order);
returns
OrderModel
Throws msg_not_found if the message ID does not exist in the store, and msg_not_is_a_order if the message exists but is not an order type.

Accepting an order

accept(options)

Accepts an incoming order. This function performs two operations atomically:
  1. Updates the order message’s persistent status to ACCEPTED (status 2), which hides the “Accept Order” button in the WhatsApp UI.
  2. Sends an interactive ORDER_DETAILS message back to the customer with a “Review and pay” button.
options
AcceptOrderOptions
required
// Accept an order
await WPP.order.accept({
  msgId: '3EB0C9A1B2C3D4E5F6A7B8',
});
returns
Promise<void>
Resolves when both the status update and the reply message have been sent successfully.
Call accept only once per order. Calling it again on an already-accepted order does not produce an error, but it will send a duplicate interactive message to the customer.

Declining an order

decline(options)

Declines an incoming order. Like accept, this performs two operations:
  1. Updates the order message status to DECLINED (status 3).
  2. Sends a cancellation message to the customer showing “Canceled” status, with an optional decline note.
options
DeclineOrderOptions
required
// Decline with an explanation
await WPP.order.decline({
  msgId: '3EB0C9A1B2C3D4E5F6A7B8',
  declineNote: 'Sorry, this item is currently out of stock.',
});
// Decline without a note
await WPP.order.decline({
  msgId: '3EB0C9A1B2C3D4E5F6A7B8',
});
returns
Promise<void>
Resolves when the status update and the cancellation message are both sent.

Updating order status

update(options)

Sends a status update message to the customer after an order has already been accepted or declined. Use this function for lifecycle updates such as shipping, delivery, or payment confirmation.
The order message must already be in ACCEPTED or DECLINED state. Calling update on a fresh INQUIRY order (status 1) throws order_not_processed. Use accept or decline first.
options
UpdateOrderOptions
required
// Mark as shipped
await WPP.order.update({
  msgId: '3EB0C9A1B2C3D4E5F6A7B8',
  orderStatus: WPP.order.OrderStatus.Shipped,
  orderNote: 'Your order has been shipped via Express Delivery.',
});
// Mark as delivered
await WPP.order.update({
  msgId: '3EB0C9A1B2C3D4E5F6A7B8',
  orderStatus: WPP.order.OrderStatus.Delivered,
  orderNote: 'Your order was delivered. Thank you!',
});
// Mark as complete with payment confirmation
await WPP.order.update({
  msgId: '3EB0C9A1B2C3D4E5F6A7B8',
  orderStatus: WPP.order.OrderStatus.Complete,
  paymentStatus: WPP.order.PaymentStatus.Captured,
  orderNote: 'Order completed and payment received.',
});
returns
Promise<void>
Resolves when the status update message is sent to the customer.

Enumerations

OrderStatus

Available values for the orderStatus parameter in update.
ValueStringDescription
OrderStatus.PendingpendingOrder is pending confirmation.
OrderStatus.ProcessingprocessingOrder is being processed.
OrderStatus.PreparingToShippreparing_to_shipOrder is being prepared for shipping.
OrderStatus.PartiallyShippedpartially_shippedOrder has been partially shipped.
OrderStatus.ShippedshippedOrder has been shipped.
OrderStatus.OutForDeliveryout_for_deliveryOrder is out for delivery.
OrderStatus.DelivereddeliveredOrder has been delivered.
OrderStatus.CompletecompletedOrder is complete.
OrderStatus.CanceledcanceledOrder has been canceled.
OrderStatus.DelayeddelayedOrder delivery is delayed.
OrderStatus.FailedfailedOrder has failed.
OrderStatus.RefundedrefundedOrder has been refunded.
OrderStatus.PaymentRequestedpayment_requestedPayment has been requested from the customer.
OrderStatus.ConfirmedconfirmedOrder has been confirmed.

PaymentStatus

Available values for the paymentStatus parameter in update.
ValueStringDescription
PaymentStatus.PendingpendingPayment is pending.
PaymentStatus.CapturedcapturedPayment has been captured/completed.
PaymentStatus.FailedfailedPayment failed.
PaymentStatus.CanceledcanceledPayment was canceled.

Complete order handling workflow

The following example shows a full order lifecycle from receipt through delivery using all four WPP.order functions.
const ORDER_MSG_ID = '3EB0C9A1B2C3D4E5F6A7B8';

// Step 1 — Read the incoming order
const order = await WPP.order.get(ORDER_MSG_ID);
console.log(`New order: ${order.itemCount} item(s), total ${order.total} ${order.currency}`);

// Step 2 — Decide whether to accept or decline
const canFulfill = order.products.every((p) => p.quantity <= 10);

if (!canFulfill) {
  // Decline with a reason
  await WPP.order.decline({
    msgId: ORDER_MSG_ID,
    declineNote: 'One or more items in your order exceed our stock limit.',
  });
  return;
}

// Step 3 — Accept the order
await WPP.order.accept({ msgId: ORDER_MSG_ID });
console.log('Order accepted.');

// Step 4 — Update to "preparing to ship" after packing
await WPP.order.update({
  msgId: ORDER_MSG_ID,
  orderStatus: WPP.order.OrderStatus.PreparingToShip,
  orderNote: 'We are packing your order.',
});

// Step 5 — Mark as shipped when dispatched
await WPP.order.update({
  msgId: ORDER_MSG_ID,
  orderStatus: WPP.order.OrderStatus.Shipped,
  orderNote: 'Your order is on its way! Tracking: BR123456789.',
});

// Step 6 — Confirm delivery and payment
await WPP.order.update({
  msgId: ORDER_MSG_ID,
  orderStatus: WPP.order.OrderStatus.Complete,
  paymentStatus: WPP.order.PaymentStatus.Captured,
  orderNote: 'Thank you for your purchase!',
});

Error codes

Thrown by get, accept, decline, and update when the provided msgId does not match any message in the local MsgStore.
Thrown by get when the message exists but its type is not ORDER.
Thrown by accept, decline, and update when the message exists but its type is not ORDER.
Thrown by accept, decline, and update when the order message is missing required fields (orderId, token, chat, or sellerJid).
Thrown by update when the order message status is still INQUIRY (1). You must call accept or decline before sending status updates.

Build docs developers (and LLMs) love