Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9.1.1: WC_Stripe_Webhook_Handler: Cannot use object of type stdClass as array #3721

Open
rdj opened this issue Jan 14, 2025 · 1 comment
Open

Comments

@rdj
Copy link

rdj commented Jan 14, 2025

Describe the bug
Since 9.1.0 I see a fatal error "Cannot use object of type stdClass as array".

The 9.1.1 release notes contain a bullet indicating this should be fixed: "• Fix - Fixes the webhook order retrieval by intent charges. The processed event is an object, not an array."

However, I still see the fatal errors in the webhook handler:

2025-01-13T06:55:49+00:00 CRITICAL Uncaught Error: Cannot use object of type stdClass as array in /data/wordpress/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php:1319 CONTEXT: {"error":{"type":1,"file":"/data/wordpress/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php","line":1319},"remote-logging":true,"backtrace":["","#0 /data/wordpress/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(967): WC_Stripe_Webhook_Handler->get_order_from_intent()","#1 /data/wordpress/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(1266): WC_Stripe_Webhook_Handler->process_payment_intent()","#2 /data/wordpress/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(107): WC_Stripe_Webhook_Handler->process_webhook()","#3 /data/wordpress/wp-includes/class-wp-hook.php(324): WC_Stripe_Webhook_Handler->check_for_webhook()","#4 /data/wordpress/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()","#5 /data/wordpress/wp-includes/plugin.php(517): WP_Hook->do_action()","#6 /data/wordpress/wp-content/plugins/woocommerce/src/Internal/Utilities/LegacyRestApiSt"]}

To Reproduce
Steps to reproduce the behavior:

  1. Install Woocommerce Gateway Stripe 9.1.1
  2. Receive a webhook
  3. Error appears in the WooCommerce fatal-errors log.

Expected behavior
No fatal error.

Screenshots
N/A

Environment (please complete the following information):

  • WordPress Version 6.7.1
  • WooCommerce Version 9.5.2 by Automattic | Auto-updates enabled
  • WooCommerce Stripe Gateway Version 9.1.1 by Stripe | Auto-updates enabled
  • Browser [e.g. chrome, safari] and Version: n/a
  • Any other plugins installed: Lots and I don't see anybody else in the callstack so let me know if you have specific questions.

Additional context
First instance of this error was 2025-01-10T12:09:43+00:00, after the 9.1.0 update. The log above definitely happened after the 9.1.1 update that purports to fix the issue. The specific code referenced in the stack trace is:

// class-wc-stripe-webhook-handler.php excerpt ...

        // Try to retrieve from the charges array.
        if ( ! empty( $intent->charges ) ) {
            $charge   = $intent->charges[0] ?? [];    // Line 1319
            $order_id = $charge->metadata->order_id ?? null;
            return $order_id ? wc_get_order( $order_id ) : false;
        }

This looks like the commit that attempted to fix this issue: b1b5c8f

@Sandra-headscape
Copy link

Sandra-headscape commented Jan 14, 2025

WP 6.7.1, WC 9.5.2, Stripe Gateway 9.1.1, PHP 8.2

For context, we had this issue occurring when using a donation form at checkout, and the webhook responding to the donation payment didn't return an Order object (same error message). Disabling the donation plugin used (can't remember the exact name) and not having donations on checkout solved the issue.

The code above seems to assign an empty array as default and then tries to get metadata from that, which would explain the fatal error...

Thanks

in case it helps, a log of the error from a staging site

ERROR: PHP Fatal error: Uncaught Exception: Cannot use object of type stdClass as array

FILE: /nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php LINE: 1319 

TRACE: #0 /nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(967): WC_Stripe_Webhook_Handler->get_order_from_intent(Object(stdClass))
#1 /nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(1266): WC_Stripe_Webhook_Handler->process_payment_intent(Object(stdClass))
#2 /nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(107): WC_Stripe_Webhook_Handler->process_webhook('{\n  "id": "evt_...')
#3 /nas/content/live/resoc/wp-includes/class-wp-hook.php(324): WC_Stripe_Webhook_Handler->check_for_webhook('')
#4 /nas/content/live/resoc/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#5 /nas/content/live/resoc/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#6 /nas/content/live/resoc/wp-content/plugins/woocommerce/src/Internal/Utilities/LegacyRestApiStub.php(162): do_action('woocommerce_api...')
#7 /nas/content/live/resoc/wp-content/plugins/woocommerce/src/Internal/Utilities/LegacyRestApiStub.php(91): Automattic\WooCommerce\Internal\Utilities\LegacyRestApiStub::maybe_process_wc_api_query_var()
#8 [internal function]: Automattic\WooCommerce\Internal\Utilities\LegacyRestApiStub::parse_legacy_rest_api_request(Object(WP))
#9 /nas/content/live/resoc/wp-content/plugins/woocommerce/src/Internal/Traits/AccessiblePrivateMethods.php(178): call_user_func_array(Array, Array)
#10 /nas/content/live/resoc/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Internal\Utilities\LegacyRestApiStub::__callStatic('parse_legacy_re...', Array)
#11 /nas/content/live/resoc/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#12 /nas/content/live/resoc/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#13 /nas/content/live/resoc/wp-includes/class-wp.php(418): do_action_ref_array('parse_request', Array)
#14 /nas/content/live/resoc/wp-includes/class-wp.php(813): WP->parse_request('')
#15 /nas/content/live/resoc/wp-includes/functions.php(1336): WP->main('')
#16 /nas/content/live/resoc/wp-blog-header.php(16): wp()
#17 /nas/content/live/resoc/index.php(17): require('/nas/content/li...')
#18 {main}
stripe webhook event data for payment_intent.succeeded

json, redacted

{
  "object": {
    "id": "pi_REDACTED",
    "object": "payment_intent",
    "amount": 10000,
    "amount_capturable": 0,
    "amount_details": {
      "tip": {
      }
    },
    "amount_received": 10000,
    "application": "ca_REDACTED",
    "application_fee_amount": null,
    "automatic_payment_methods": null,
    "canceled_at": null,
    "cancellation_reason": null,
    "capture_method": "automatic",
    "charges": {
      "object": "list",
      "data": [
        {
          "id": "ch_REDACTED",
          "object": "charge",
          "amount": 10000,
          "amount_captured": 10000,
          "amount_refunded": 0,
          "application": "ca_REDACTED",
          "application_fee": null,
          "application_fee_amount": null,
          "balance_transaction": "txn_REDACTED",
          "billing_details": {
            "address": "REDACTED",
            "email": "REDACTED",
            "name": "REDACTED",
            "phone": null
          },
          "calculated_statement_descriptor": "REDACTED",
          "captured": true,
          "created": 1736775696,
          "currency": "REDACTED",
          "customer": "cus_REDACTED",
          "description": "REDACTED",
          "destination": null,
          "dispute": null,
          "disputed": false,
          "failure_balance_transaction": null,
          "failure_code": null,
          "failure_message": null,
          "fraud_details": {
          },
          "invoice": null,
          "livemode": false,
          "metadata": {
            "Donation Post ID": "REDACTED",
            "Email": "REDACTED"
          },
          "on_behalf_of": null,
          "order": null,
          "outcome": {
            "advice_code": null,
            "network_advice_code": null,
            "network_decline_code": null,
            "network_status": "approved_by_network",
            "reason": null,
            "risk_level": "normal",
            "risk_score": 11,
            "seller_message": "Payment complete.",
            "type": "authorized"
          },
          "paid": true,
          "payment_intent": "pi_REDACTED",
          "payment_method": "pm_REDACTED",
          "payment_method_details": {
            "card": {
              "amount_authorized": 10000,
              "authorization_code": null,
              "brand": "visa",
              "checks": {
                "address_line1_check": "pass",
                "address_postal_code_check": "pass",
                "cvc_check": "pass"
              },
              "country": "US",
              "exp_month": 12,
              "exp_year": 2025,
              "extended_authorization": {
                "status": "disabled"
              },
              "fingerprint": "REDACTED",
              "funding": "credit",
              "incremental_authorization": {
                "status": "unavailable"
              },
              "installments": null,
              "last4": "4242",
              "mandate": null,
              "moto": null,
              "multicapture": {
                "status": "unavailable"
              },
              "network": "visa",
              "network_token": {
                "used": false
              },
              "network_transaction_id": "REDACTED",
              "overcapture": {
                "maximum_amount_capturable": 10000,
                "status": "unavailable"
              },
              "regulated_status": "unregulated",
              "three_d_secure": null,
              "wallet": null
            },
            "type": "card"
          },
          "radar_options": {
          },
          "receipt_email": null,
          "receipt_number": null,
          "receipt_url": "https://pay.stripe.com/receipts/payment/REDACTED",
          "refunded": false,
          "refunds": {
            "object": "list",
            "data": [
            ],
            "has_more": false,
            "total_count": 0,
            "url": "/v1/charges/ch_REDACTED/refunds"
          },
          "review": null,
          "shipping": null,
          "source": null,
          "source_transfer": null,
          "statement_descriptor": null,
          "statement_descriptor_suffix": null,
          "status": "succeeded",
          "transfer_data": null,
          "transfer_group": null
        }
      ],
      "has_more": false,
      "total_count": 1,
      "url": "/v1/charges?payment_intent=pi_REDACTED"
    },
    "client_secret": "pi_REDACTED",
    "confirmation_method": "automatic",
    "created": 1736775696,
    "currency": "REDACTED",
    "customer": "cus_REDACTED",
    "description": "REDACTED",
    "invoice": null,
    "last_payment_error": null,
    "latest_charge": "ch_REDACTED",
    "livemode": false,
    "metadata": {
      "Donation Post ID": "REDACTED",
      "Email": "REDACTED"
    },
    "next_action": null,
    "on_behalf_of": null,
    "payment_method": "pm_REDACTED",
    "payment_method_configuration_details": null,
    "payment_method_options": {
      "card": {
        "installments": null,
        "mandate_options": null,
        "network": null,
        "request_three_d_secure": "automatic"
      }
    },
    "payment_method_types": [
      "card"
    ],
    "processing": null,
    "receipt_email": null,
    "review": null,
    "setup_future_usage": null,
    "shipping": null,
    "source": null,
    "statement_descriptor": null,
    "statement_descriptor_suffix": null,
    "status": "succeeded",
    "transfer_data": null,
    "transfer_group": null
  }
}
stripe webhook logged response to event data

HTTP status code: 500 (Internal Server Error)

response (json) with the same error log (18 lines traced) as above

{
  "code": "internal_server_error",
  "message": "<p>There has been a critical error on this website.</p><p><a href=\"https://wordpress.org/documentation/article/faq-troubleshooting/\">Learn more about troubleshooting WordPress.</a></p>",
  "data": {
    "status": 500,
    "error": {
      "type": 1,
      "message": "Uncaught Error: Cannot use object of type stdClass as array in /nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php:1319\nStack trace:\n#0 /nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(967): WC_Stripe_Webhook_Handler->get_order_from_intent(Object(stdClass))\n#1 /nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(1266): WC_Stripe_Webhook_Handler->process_payment_intent(Object(stdClass))\n#2 /nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php(107): WC_Stripe_Webhook_Handler->process_webhook('{\\n  \"id\": \"evt_...')\n#3 /nas/content/live/resoc/wp-includes/class-wp-hook.php(324): WC_Stripe_Webhook_Handler->check_for_webhook('')\n#4 /nas/content/live/resoc/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)\n#5 /nas/content/live/resoc/wp-includes/plugin.php(517): WP_Hook->do_action(Array)\n#6 /nas/content/live/resoc/wp-content/plugins/woocommerce/src/Internal/Utilities/LegacyRestApiStub.php(162): do_action('woocommerce_api...')\n#7 /nas/content/live/resoc/wp-content/plugins/woocommerce/src/Internal/Utilities/LegacyRestApiStub.php(91): Automattic\\WooCommerce\\Internal\\Utilities\\LegacyRestApiStub::maybe_process_wc_api_query_var()\n#8 [internal function]: Automattic\\WooCommerce\\Internal\\Utilities\\LegacyRestApiStub::parse_legacy_rest_api_request(Object(WP))\n#9 /nas/content/live/resoc/wp-content/plugins/woocommerce/src/Internal/Traits/AccessiblePrivateMethods.php(178): call_user_func_array(Array, Array)\n#10 /nas/content/live/resoc/wp-includes/class-wp-hook.php(324): Automattic\\WooCommerce\\Internal\\Utilities\\LegacyRestApiStub::__callStatic('parse_legacy_re...', Array)\n#11 /nas/content/live/resoc/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)\n#12 /nas/content/live/resoc/wp-includes/plugin.php(565): WP_Hook->do_action(Array)\n#13 /nas/content/live/resoc/wp-includes/class-wp.php(418): do_action_ref_array('parse_request', Array)\n#14 /nas/content/live/resoc/wp-includes/class-wp.php(813): WP->parse_request('')\n#15 /nas/content/live/resoc/wp-includes/functions.php(1336): WP->main('')\n#16 /nas/content/live/resoc/wp-blog-header.php(16): wp()\n#17 /nas/content/live/resoc/index.php(17): require('/nas/content/li...')\n#18 {main}\n  thrown",
      "file": "/nas/content/live/resoc/wp-content/plugins/woocommerce-gateway-stripe/includes/class-wc-stripe-webhook-handler.php",
      "line": 1319
    }
  },
  "additional_errors": [
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants