Skip to content

Webhook job: one failed GET /v1/payments/{id} drops the payment — a Swish order whose buyer did not return is cancelled while charged #367

Open

Description

@terminalstate

Version: 2.14.8 (WordPress.org; master as of 2026-10-06), WooCommerce 11.2.1.

What happens. Nexi's payment.checkout.completed is answered 200 at once and handled by one Action Scheduler job two minutes later (class-nets-easy-api-callbacks.php#L50-L75). The job calls wc_dibs_confirm_dibs_order() (#L84-L103), which makes one GET /v1/payments/{id}. If that request fails — a timeout, a 5xx — it adds the note "Error when confirming order" and returns (nets-easy-functions.php#L205-L216). The action completes, nothing re-schedules it, and Nexi will not resend an event it got 200 for.

For a buyer who comes back through the return URL the order is confirmed there. For one who does not — Swish, MobilePay or Vipps paid in the app, a return in another browser (the case class-nets-easy-confirmation.php#L98-L108 describes) — this job is the only path. The order stays pending, wc_cancel_unpaid_orders() cancels it after the hold-stock time, and the cancel hook skips Nexi because _dibs_date_paid is empty (class-nets-easy-order-management.php#L115-L124). With Swish, A2A or auto-capture the customer is charged for a cancelled order; with a card reservation the amount stays reserved and the sale is lost.

Reproduced on a WordPress 7.1.3 / WooCommerce 11.2.1 site with 2.14.8 from WordPress.org, a pending nets_easy_swish order and only the Nexi API faked (the GET times out once, answers "charged" afterwards): webhook 200, the job adds the note and completes, nothing else is scheduled, wc_cancel_unpaid_orders() → cancelled, one GET in total and no cancel call to Nexi. With the GET succeeding the same webhook completes the order. Stand: https://github.com/terminalstate/callback-audit/tree/main/repro/nexi-checkout-woocommerce

Possible fix. Let the job retry when the read fails, with a growing delay and a cap — this is what I checked on the stand (the second run confirms the payment, the order is processing):

--- a/includes/nets-easy-functions.php
+++ b/includes/nets-easy-functions.php
@@ -212,7 +212,7 @@
 				$request->get_error_message()
 			)
 		);
-		return;
+		return $request;
 	}
--- a/classes/class-nets-easy-api-callbacks.php
+++ b/classes/class-nets-easy-api-callbacks.php
@@ -97,7 +97,16 @@
 		} else {
 			Nets_Easy_Logger::log( 'Order status not set correctly for order ' . $order->get_order_number() . ' during checkout process. Setting order status to Processing/Completed in API callback.' );
-			wc_dibs_confirm_dibs_order( $order->get_id() );
+			$result = wc_dibs_confirm_dibs_order( $order->get_id() );
+			if ( is_wp_error( $result ) ) {
+				$attempts = (int) $order->get_meta( '_dibs_callback_attempts' ) + 1;
+				$order->update_meta_data( '_dibs_callback_attempts', $attempts );
+				$order->save();
+				if ( $attempts < 10 ) {
+					as_schedule_single_action( time() + 300 * $attempts, 'dibs_payment_created_callback', array( $payment_id, $order_number, $amount ) );
+				}
+				return;
+			}
 			$this->check_order_totals( $order, $amount );
 		}

Another option is to do the GET inside the webhook request and answer non-200 when it fails, so Nexi's own retries (up to 10, over several hours) cover it. Separately, the cancel hook could ask Nexi before skipping an order without _dibs_date_paid. Happy to open a PR for whichever you prefer.

Activity

  1. krokedilmartin commented on Oct 22, 2026

    @krokedilmartin
    Contributor

    Thank you @terminalstate
    We will look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions