Assuming that you have a payment page with the "Payment form" webpart, where the "Thank you page URL" setting is set to "/Special-Pages/Order-Completed.aspx", you could customise the webpart to append a query string with the order ID.
~/CMS/CMSWebParts/Ecommerce/Checkout/Forms/PaymentForm.ascx.cs file, append the order ID in the
get of the
public string RedirectAfterPurchase
return ValidationHelper.GetString(GetValue("RedirectAfterPurchase"), "") + "?orderid=" + orderId;
. . .
Please note that in the webpart that will consume this order ID, remember to do a security check to ensure that the order belongs to the customer (if possible).
Furthermore, it is good practice to duplicate webparts before customising them.