v2.1.11 — Fix post-checkout redirect race on production
v2.1.11 — Fix post-checkout redirect race on production
What was broken
Customers returning from the Fungies hosted checkout on production were being bounced back to the WooCommerce checkout/cart page instead of the order-received ("thank you") page. Staging worked correctly.
Root cause
A timing race between the Fungies payment_success webhook and the customer's browser redirect.
- The old return handler in
Fungies_Checkout::handle_returnresolved the WC order via either:_fungies_order_idpost meta (which is only set by the webhook), or- A
wc_get_ordersquery restricted tostatus: pending.
- On production the webhook fires fast enough that by the time the user's browser lands on
?wc-api=fungies_return, the order has already moved frompending→processing. The pending-only fallback then misses, the meta lookup races the webhook commit, and the handler falls through towp_safe_redirect( wc_get_checkout_url() ). - On staging the webhook is slower, so the order is still
pendingwhen the user returns, and the old fallback happens to work — masking the bug.
Fix
Introduced Fungies_Return_Resolver with three layered recovery strategies, deterministic to flaky:
- WC session —
Fungies_Return_Resolver::remember( $order_id )is called fromFungies_Payment_Gateway::process_paymentright before redirecting to Fungies. On return we recover the order id fromWC()->sessionregardless of webhook state. This is the primary path and works in ~100 % of normal flows. - Broadened email fallback — now accepts
pending,on-hold,processing, andcompletedinstead ofpendingonly. - Brief poll (~3 s total, 6 × 500 ms) for the meta or a matching order, in case the webhook is landing right at that moment.
_fungies_order_id post meta is now also linked at return time using the fngs-order-id URL param, so any subsequent webhook call matches the existing order via meta and never creates a duplicate orphan order.
What's still in here from earlier
- v2.1.10 —
build.ps1build script that enforces forward-slash zip packaging. - v2.1.9 / v2.1.8 — workspace-scoped
_fungies_pushed_*post meta keyed by a hash of the active Fungies secret key, so toggling Sandbox Mode (production ↔ staging) no longer creates duplicates.
Install
Download fungies-checkout-2.1.11.zip and upload via Plugins → Add New → Upload Plugin in WordPress.