Cancelling an Invoice creates weird Order Updates in webhooks

I’m noticing when I cancel an invoice, I get several webhook callbacks with order IDs that don’t match the order ID contained in the invoice. Also the orders are listed as COMPLETED not CANCELLED. Any idea what’s going on?

// user pays via direct arbitrary CC payment..... (not via an invoice interface)
Apr 19 16:21:35 grandslamgrading php: %TELEGRAM-QUEUE: User [xxxxxxxxxxxx] paid outstanding balance [$192] via Square. Cancelling related orders...

// ... code retrieves outstanding invoices for user

//cancel related invoice (works fine) .. notice the orderID dCyzup
Apr 19 16:21:35 grandslamgrading php: %SQUARETOOL-EXEC:https://connect.squareup.com/v2/invoices/inv:0-ChDiiX5JCJZA9D0Dayz7SHZCEMoO/cancel
Apr 19 16:21:35 grandslamgrading php: %SQUARETOOL-EXEC-PARAMS:{"version":"1"}
Apr 19 16:21:35 grandslamgrading php: %SQUARETOOL-EXEC-RESPONSE:{"invoice":{"id":"inv:0-ChDiiX5JCJZA9D0Dayz7SHZCEMoO","version":2,"location_id":"LGJDBA0PGACSP","order_id":"dCyzupOG2byBcZDBvDwMSwVcLlJZY","payment_requests":[{"uid":"ca01c4dd-6592-418e-be7c-512b7b55972f","request_type":"BALANCE","due_date":"2023-05-03","tipping_enabled":false,"computed_amount_money":{"amount":19200,"currency":"USD"},"total_completed_amount_money":{"amount":0,"currency":"USD"},"automatic_payment_source":"NONE"}],"primary_recipient":{"customer_id":"Y4VQB67N9BW63WVT7Y02HR5JTG","given_name":"xxxx","family_name":"xxxxx","email_address":"[email protected]","phone_number":"xxxxxxx"},"invoice_number":"000112","public_url":"https://squareup.com/pay-invoice/inv:0-ChDiiX5JCJZA9D0Dayz7SHZCEMoO","status":"CANCELED","timezone":"America/New_York","created_at":"2023-04-19T19:20:47Z","updated_at":"2023-04-19T20:20:29Z","accepted_payment_methods":{"card":true,"square_gift_card":true,"bank_account":true,"buy_now_pay_later":false},"delivery_method":"EMAIL","store_payment_method_enabled":false}}

// just some local database stuff
Apr 19 16:21:35 grandslamgrading php: %TRACKJOBTOOL: setting paymentComplete where squareOrderID = dCyzupOG2byBcZDBvDwMSwVcLlJZY

// process callback is the signal when we receive a webhook event...
// the orderIDs don't match the one above, and I don't know why there are two webhooks fired.
// also, why is it "COMPLETED" and not cancelled? this also causes problems.

Apr 19 16:21:37 grandslamgrading php: %DBG: process callback - {"merchant_id":"MLMXXEXQM2YSP","type":"order.updated","event_id":"cd222231-879c-3ab3-b18e-df36a6ddf7c2","created_at":"2023-04-19T20:20:30Z","data":{"type":"order","id":"1KAryniKX9L6t1ps707StSBzHSaZY","object":{"order_updated":{"created_at":"2023-04-19T20:20:27.951Z","location_id":"LGJDBA0PGACSP","order_id":"1KAryniKX9L6t1ps707StSBzHSaZY","state":"OPEN","updated_at":"2023-04-19T20:20:29.248Z","version":2}}}}
Apr 19 16:21:37 grandslamgrading php: %DBG: process callback - {"merchant_id":"MLMXXEXQM2YSP","type":"order.updated","event_id":"cd222231-879c-3ab3-b18e-df36a6ddf7c2","created_at":"2023-04-19T20:20:30Z","data":{"type":"order","id":"1KAryniKX9L6t1ps707StSBzHSaZY","object":{"order_updated":{"created_at":"2023-04-19T20:20:27.951Z","location_id":"LGJDBA0PGACSP","order_id":"1KAryniKX9L6t1ps707StSBzHSaZY","state":"COMPLETED","updated_at":"2023-04-19T20:20:29.393Z","version":3}}}}

If I open those orderIDs up using the API Explorer, the money-amount within is the same, implying they are related to the invoice I just cancelled, and the timing of the webhook events also imply relation to the recently cancelled invoice.

What are the steps to reproduce this? I just tested and the same order_id was in all webhook events. :slightly_smiling_face:

  1. Create an order. (/v2/orders, contains line_items of one or more of our catalog items (catalog_object_id)).

  2. Create an invoice (/v2/invoices, and supply the order ID from first call).

  3. Publish invoice (/v2/invoices/{$invoiceID}/publish).

  4. Cancel invoice. (/v2/invoices/{$invoiceID}/cancel).