Skip to content

v2.1.11 — Fix post-checkout redirect race on production

Choose a tag to compare

@dukenukemall dukenukemall released this 29 Apr 11:47
· 17 commits to main since this release

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_return resolved the WC order via either:
    1. _fungies_order_id post meta (which is only set by the webhook), or
    2. A wc_get_orders query restricted to status: 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 from pendingprocessing. The pending-only fallback then misses, the meta lookup races the webhook commit, and the handler falls through to wp_safe_redirect( wc_get_checkout_url() ).
  • On staging the webhook is slower, so the order is still pending when 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:

  1. WC sessionFungies_Return_Resolver::remember( $order_id ) is called from Fungies_Payment_Gateway::process_payment right before redirecting to Fungies. On return we recover the order id from WC()->session regardless of webhook state. This is the primary path and works in ~100 % of normal flows.
  2. Broadened email fallback — now accepts pending, on-hold, processing, and completed instead of pending only.
  3. 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.ps1 build 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.