From 51f09348d8323f25b61ade33a0b1a5b82e43e765 Mon Sep 17 00:00:00 2001 From: olorunnfemi Date: Tue, 15 Sep 2026 12:22:53 +0100 Subject: [PATCH] issue/147 - process_webhooks() blocks on sleep(10) before responding, causing intermittent lost order confirmations (especially Bank Transfer) --- includes/class-wc-gateway-paystack.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-gateway-paystack.php b/includes/class-wc-gateway-paystack.php index 6404c31..a78a9fd 100644 --- a/includes/class-wc-gateway-paystack.php +++ b/includes/class-wc-gateway-paystack.php @@ -1398,6 +1398,29 @@ public function process_webhooks() { return; } + + // Tell PHP to keep running even if Paystack closes the connection early + ignore_user_abort( true ); + + // Send 200 OK immediately to satisfy Paystack's webhook timeout + http_response_code( 200 ); + + // Close the connection to the client so they don't hang, but keep the script running + if ( function_exists( 'fastcgi_finish_request' ) ) { + fastcgi_finish_request(); + } elseif ( function_exists( 'litespeed_finish_request' ) ) { + litespeed_finish_request(); + } else { + // Fallback for standard server environments + header( 'Connection: close' ); + header( 'Content-Length: ' . ob_get_length() ); + ob_end_flush(); + @ob_flush(); + flush(); + } + + + sleep( 10 ); $paystack_response = $this->get_paystack_transaction( $event->data->reference ); @@ -1422,8 +1445,6 @@ public function process_webhooks() { exit; } - http_response_code( 200 ); - if ( in_array( $order->get_status(), array( 'processing', 'completed', 'on-hold' ), true ) ) { exit; }