Skip to content

Developer notes

Overview · Installation · Configuration · Usage · Troubleshooting · FAQ

WhatsApp Cloud API (official documentation used)

Section titled “WhatsApp Cloud API (official documentation used)”

All calls go to https://graph.facebook.com/<version>/... with the merchant’s system-user token (Authorization: Bearer). The version is pinned in the settings (default v25.0, choices v23.0 to v27.0). Sources (developers.facebook.com/documentation/business-messaging/whatsapp/):

Use Endpoint / object Doc page
Send messages, read receipts POST /{phone-number-id}/messages (text, image, interactive button, list, product, product_list, cta_url, flow, template; {"status":"read","message_id"}) messages/*, catalogs/multi-product-messages, flows/guides/sendingaflow
Limits applied by Wa\Message reply buttons 1-3, title 20, body 1024; list button 20, 1-10 sections, 1-10 rows in total, row id 200, row title 24, description 72; product list max 30 items messages/interactive-list-messages, catalogs/multi-product-messages
Users without a phone (usernames) business-scoped user id user_id / from_user_id; sending with recipient instead of to business-scoped-user-ids
Connection test GET /{phone-number-id}?fields=display_phone_number,verified_name,quality_rating
Flow encryption key POST /{phone-number-id}/whatsapp_business_encryption (form field business_public_key, 2048-bit RSA PEM) flows/guides/whatsapp-business-encryption
Checkout Flow POST /{waba-id}/flows (name, categories ["OTHER"], flow_json, endpoint_uri), POST /{flow-id}/publish flows/reference/flowsapi
Webhooks object whatsapp_business_account, field messages: messages[] (text, interactive button_reply / list_reply / nfm_reply, order with catalog_id, text, product_items[], template button), statuses[] with pricing (billable, pricing_model, type, category) webhooks/reference/messages/*, flows/guides/flowswebhooks, pricing/non-template-messages
Webhook security handshake hub.mode, hub.verify_token, hub.challenge; X-Hub-Signature-256: sha256=<HMAC-SHA256(app secret, raw body)>
Flow endpoint request encrypted_flow_data, encrypted_aes_key, initial_vector; RSA-OAEP SHA-256 (MGF1 SHA-256) → AES-128 key; AES-128-GCM with the tag appended; response encrypted with the bit-flipped IV, base64; ping → {"data":{"status":"active"}}; error notification → {"data":{"acknowledged":true}}; HTTP 421 when it cannot be decrypted, 432 when the signature fails flows/guides/implementingyourflowendpoint, flows/reference/error-codes
Errors {"error":{"message","type","code","error_subcode","error_data":{"details"},"fbtrace_id"}}; retried: 1, 2, 4, 17, 341, 80007, 130429, 131000, 131016, 131056, 133004 support/error-codes
Pricing per delivered message; service messages billed since 2026-10-01 (category service in the status webhook) pricing, pricing/non-template-messages

Honest notes:

  • No real WhatsApp account was used in development. The tests use a mock server and fixtures built field by field from the documentation above (tests/mock-server/server.js, tests/unit.php). The Flow encryption was checked against Node.js crypto (OAEP-SHA256 + AES-128-GCM), independent of our PHP code.
  • The Flow JSON (version 7.3, the version Meta recommends, with data_api_version 3.0, whose encryption the endpoint guide documents; Data API 4.0 only adds the optional flow_token_signature) follows the Flow JSON guide; Meta validates it when the Flow is created and the add-on shows validation_errors on the Connection page. It has not been through Meta’s validator yet (no account); the “Download Flow JSON” button lets you paste it into the Flow Builder.
  • order webhooks report item_price as shown in the catalog; the order price always comes from CS-Cart.

Meta documentation used (read 2026-11-25):

Wa\Inbound::referral() keeps ctwa_clid (printable ASCII, up to 255), source_id, source_type, source_url and headline; a referral without click id (Status ads) is kept with an empty click id. Only referrals from signature-verified webhooks reach Referrals::record(); the referral is removed from the message before the inbound job is queued, so the click id is never written to the job queue, the transcript or the log.

Referrals (table ?:kv_whatsapp_ordering_referrals: referral_id, account_id, session_id, phone_hash (HMAC-SHA256 of the digits with the store’s crypt key), ctwa_clid, click (Y/N), source_id, source_type, source_url, headline, first_seen, order_id, linked_at, event_status (empty, Q queued, S sent, F failed, N not sent), event_note, event_sent_at). linkOrder() runs in the place_order hook of the order that Placer is placing and uses Referrals::pickOpen(). prune() runs in the daily cleanup job.

Public functions for other add-ons (used by Meta Conversions API 1.2): fn_kv_whatsapp_ordering_ad_referral($order_id), fn_kv_whatsapp_ordering_ad_referral_claim($referral_id) (true once), fn_kv_whatsapp_ordering_ad_referral_mark($referral_id, $status, $note), fn_kv_whatsapp_ordering_waba_id($account_id).

Hooks used in addition: delete_order and kv_data_retention_processed (Data Retention & Guest Anonymizer 1.x; types guest_orders, customer_orders, orders).

Tygh\Addons\KvWhatsappOrdering\OrderCore contains no WhatsApp code. Other Kavio conversational products (phone agent, Telegram shop, site assistant) ship a copy under their own namespace; Context::REVISION tells which revision a copy has.

Class Job
Context company / vendor scope, storefront, language, customer auth (guest by default)
Catalog categories (user groups, Ultimate storefront, vendor scope, blocked categories), products() through fn_get_products + fn_gather_additional_products_data, product() through fn_get_product_data with choice options and variation siblings, catalog item id mapping
Quote server-side cart (never the visitor’s session cart): fn_add_product_to_cart, fn_calculate_cart_content with shipping for an address, coupon, chosen shipping (cheapest per vendor group when several), stock problems, totals and a fingerprint of what the customer confirmed
Placer guards (maximum total and items) and fn_place_order($cart, $auth, 'save'), idempotent per checkout reference: the reference row is written before, the place_order hook records the order id, a repeated confirmation returns the existing order; a changed quote (prices, stock, shipping) is refused with changed
PayLink signed expiring token (HMAC with the store’s crypt key), payment page with the core repay logic (payment change, surcharge, status Open, fn_start_payment, fn_order_placement_routines('repay')); paid = statuses with “payment received” (fn_get_settled_order_statuses)
Status order status, total, tracking numbers; Multi-Vendor parent orders are described by their vendor orders; phone ownership check

Usage example:

use Tygh\Addons\KvWhatsappOrdering\OrderCore\{Context, Quote, Placer};
$ctx = Context::create(0, false, 'phone');
$lines = [['product_id' => 12, 'amount' => 2, 'options' => [5 => 52]]];
$customer = ['firstname' => 'Alex', 'phone' => '+447700900123', 'address' => '1 Main St', 'city' => 'London', 'zipcode' => 'N1', 'country' => 'GB'];
$quote = Quote::calculate($ctx, $lines, $customer, ['shipping_id' => 1, 'payment_id' => 6], true);
$res = Placer::place($ctx, 'call-123', $lines, $customer, ['shipping_id' => 1, 'payment_id' => 6], Quote::fingerprint($quote), ['max_total' => 500, 'max_items' => 20]);
  1. kv_whatsapp_ordering.webhook?a=<number> checks the signature with the app secret of that number, stores each message once (unique wamid), queues an inbound job and answers Meta at once.
  2. The job runs right after the answer (cron picks up anything left): Chat::process() takes a per-conversation lock, runs Bot\Conversation (state machine, no AI) against Bot\CoreShop (the Order-Taking Core) and sends the replies through Client\Api.
  3. The Flow endpoint kv_whatsapp_ordering.flow?a=<number> decrypts, finds the conversation by flow_token, runs Bot\FlowEndpoint and stores the confirmed checkout; the nfm_reply webhook then places the order with that checkout.
  4. change_order_status_post queues status_update jobs for the statuses you selected (text inside the 24-hour window, template outside it).
Table Contents
?:kv_whatsapp_ordering_accounts one row per number (company 0, storefront or vendor): ids, sealed token / app secret / verify token / Flow private key, Flow id, last check
?:kv_whatsapp_ordering_sessions one conversation per user and number: BSUID or phone, name, state, JSON data (cart, checkout, navigation), Flow token, handover, opt-out, counters, last in / out
?:kv_whatsapp_ordering_messages transcript with wamid, direction, kind, delivery status, billable flag and pricing category
?:kv_whatsapp_ordering_orders checkout references (idempotent placement): ref, order id, conversation, payment mode, total
?:kv_whatsapp_ordering_referrals Click to WhatsApp ad referrals and their link to an order (see above)
?:kv_whatsapp_ordering_log, ?:kv_whatsapp_ordering_jobs log and job queue
// init.php: fn_register_hooks('kv_whatsapp_ordering_handover');
function fn_my_addon_kv_whatsapp_ordering_handover($session)
{
// A customer asked for a person: $session = conversation row (session_id, account_id, name, phone, ...).
}

Hooks used: place_order (records the order id of a placement), change_order_status_post (status updates). Both exist with the same arguments in 4.17.2 and 4.21.2.

Working with the other Kavio WhatsApp add-ons

Section titled “Working with the other Kavio WhatsApp add-ons”
  • Order Notifications for Telegram & WhatsApp: its number can be imported on the Connection page. Meta sends the webhooks of one app to one callback URL, so when it uses the same number, every verified delivery is also handed to its public handlers (Messaging\Webhook::parseWhatsapp / parseWhatsappInbound, Service::queue()->applyDeliveryReports, Inbound::handle); its kv_order_notifications_messaging_inbound hook keeps Commerce Suite’s COD buttons working. Template quick replies that are not ours are not answered by the bot. Setting: “Share the webhook with Order Notifications”.
  • Chat Button for WhatsApp: the Connection page warns when its click-to-chat number differs from the ordering number.
  • Webhook and Flow requests: signature check before anything is parsed or stored; unknown numbers refused; bodies over 3 MB refused.
  • Credentials sealed with AES-256-GCM (key derived from the store’s crypt key); forms show hints only.
  • Payment links: HMAC-signed, expiring, bound to one order; the page shows only that order and starts the payment through core functions; card data never passes through WhatsApp.
  • Status questions answer only orders of the same conversation or with the same phone number on the order.
  • Multi-Vendor vendors see and manage only their own number and conversations; queue, log and settings are admin only.
  • Full page cache: the endpoints are not cacheable dispatches, send Cache-Control: no-store and the webhook / Flow requests do not keep a session.
  • php81 tests/unit.php / php83 tests/unit.php: payload limits, webhook parsing, signatures, Flow crypto, Flow JSON, catalog id mapping, guards, payment link tokens, the whole conversation against a fake store, the Graph client against recorded responses.
  • node tests/e2e/ads.mjs --store ... --root ... --db ... --wa-port ... --meta-port ... (needs both add-ons): referral stored once, linked to the order, one Purchase to the mock dataset, retry on a 500, no second event, Status ad, cleared click id, report and CSV, Data Retention hook, Multi-Vendor parent order. The payloads follow the documentation; no real WhatsApp or Meta account was used. The dataset answer of Meta has no example in the documentation: the mock’s shape is an assumption.
  • node tests/e2e/e2e.mjs --store ... --root ... --db ... --port ...: a dev store against the mock (refuses to run unless the store points the add-on at 127.0.0.1): connection, keys, Flow creation, webhook security, chat checkout, payment link page, Flow checkout with real encryption, catalog cart, status questions and updates, handover and staff reply, billing status webhooks, Multi-Vendor split orders, admin pages.