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

Fix fatal error by checking for valid order before processing webhook #4287

Merged
merged 4 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fix-4286-fix-webhook-service-fatal-error
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fixes fatal error on payment intent succeeded webhook.
3 changes: 3 additions & 0 deletions includes/class-wc-payments-webhook-processing-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ private function process_webhook_payment_intent_succeeded( $event_body ) {
$charges_data = $this->read_webhook_property( $event_charges, 'data' );
$charge_id = $this->read_webhook_property( $charges_data[0], 'id' );

if ( ! $order ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move order fetching at the begging of the function, and use this if statement right after it to prevent getting all this data for nothing if the order is false

return;
}
// update _charge_id meta if it doesn't exist - happens when maybe_process_upe_redirect fails sometimes.
if ( $charge_id && ! $order->get_meta( '_charge_id' ) ) {
$order->update_meta_data( '_charge_id', $charge_id );
Expand Down