Automattic / newspack-plugin

An advanced open-source publishing and revenue-generating platform for news organizations.
https://newspack.com
GNU General Public License v2.0
333 stars 49 forks source link

Fatal error on Stripe webhook request #2094

Closed miguelpeixe closed 2 years ago

miguelpeixe commented 2 years ago

Submitting a donation using the streamlined SDB (Stripe) is causing a fatal error on the Stripe webhook request:

PHP Fatal error:  Uncaught Error: Cannot use object of type WP_Error as array in newspack-plugin/includes/reader-revenue/class-stripe-connection.php:1369

Looks like the Newspack\Stripe_Connection::get_invoice() method is returning WP_Error, which is not being handled by Newspack\Stripe_Connection::create_wc_transaction_payload()

adekbadek commented 2 years ago

This is in a case of an error – do you have steps to reproduce to trigger an error there?

miguelpeixe commented 2 years ago

This is in a case of an error

Indeed, an unhandled one.

do you have steps to reproduce to trigger an error there?

  1. Fresh instance with a fresh Stripe connection
  2. Send a donation using the SDB and wait for the Stripe webhook to trigger.
  3. Confirm the fatal error in the logs

The unhandled error is this: Could not fetch invoice.

If the invoice is "optional" it should identify that is_wp_error() and bail. If not, we should figure out why the invoice is missing.

dkoo commented 2 years ago

2103 fixed the fatal error that occurred when Newspack\Stripe_Connection::get_invoice() returns an error. However, it doesn't address the cause of the original error, and it's not clear to me whether we need to fix that. We have a live site which is experiencing a lot of such errors in their webhooks, so I'll plan to install #2103 on their site early next week to see if we can better diagnose the actual error.

miguelpeixe commented 2 years ago

2117 tweaks the error handling to identify if the invoice ID missing before trying to fetch the invoice data.

adekbadek commented 2 years ago

It looks like the invoice is created when a subscription is. So one-time transactions will not get the invoice ID in the webhook payload.

adekbadek commented 2 years ago

Resolved in #2103. The invoice is optional, as described in my previous comment.