One invoice, two charges.
Every payment attempt created a fresh gateway order, so a contractor who retried after a slow page could pay the same invoice twice. Now the service checks the invoice before creating an order. Already charged: it refuses. Pending: it asks the gateway, syncs the result and expires stale orders. Only then does it issue a new order.