Hello Zen Cart Community,

I'm working with a custom payment module on my Zen Cart site that relies on an iframe for processing payments. The flow is as follows:

The customer completes their order and confirms it.
An iframe is generated for payment processing.
Upon payment completion, a success page is displayed.
Simultaneously, a webhook is triggered to handle post-payment actions.
The challenge I'm encountering is related to the externalUserId parameter in the webhook. The externalUserId should contain the most recent order ID generated by Zen Cart upon order confirmation. However, attempts to retrieve this ID have been unsuccessful – I either get an outdated order number (the previous order) or no result at all.

The expected behavior is to capture the latest order ID in time to include it in the webhook payload. However, there seems to be a timing issue or a session management problem that prevents the accurate retrieval of the order ID after the order confirmation and before the webhook is sent.

Here's what I have tried so far:

Using session variables to pass the order ID, which has resulted in incorrect or empty values.
Directly querying the database for the latest order ID, which also doesn't seem to capture the correct ID in time.
This has been a persistent issue affecting the payment confirmation process, and I'm looking for insights or suggestions on how to reliably capture the latest order ID in the webhook after the customer has confirmed their order.

I have spent over a month on this pulling my hair out. I now am hoping that someone else that has been through this, could possibly direct me in the right direction.

Thank you in advance.