From c2ca07094cb558b099905767291689c77c90cd74 Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot <forums@artfulrobot.uk> Date: Fri, 19 Mar 2021 13:37:28 +0000 Subject: [PATCH] Remove static method call --- CRM/Core/Payment/StripeIPN.php | 11 ++++++++++- CRM/Stripe/Api.php | 6 ++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CRM/Core/Payment/StripeIPN.php b/CRM/Core/Payment/StripeIPN.php index 754adda3..fc20aa31 100644 --- a/CRM/Core/Payment/StripeIPN.php +++ b/CRM/Core/Payment/StripeIPN.php @@ -412,11 +412,20 @@ class CRM_Core_Payment_StripeIPN { if ($this->contribution['contribution_status_id'] == $pendingContributionStatusID) { // If this contribution is Pending, set it to Failed. + + // To obtain the failure_message we need to look up the charge object + $failureMessage = ''; + if ($this->charge_id) { + $stripeCharge = $this->_paymentProcessor->stripeClient->charges->retrieve($this->charge_id); + $failureMessage = CRM_Stripe_Api::getObjectParam('failure_message', $stripeCharge); + $failureMessage = is_string($failureMessage) ? $failureMessage : ''; + } + $params = [ 'contribution_id' => $this->contribution['id'], 'order_reference' => $this->invoice_id, 'cancel_date' => $this->receive_date, - 'cancel_reason' => $this->retrieve('failure_message', 'String'), + 'cancel_reason' => $failureMessage, ]; $this->updateContributionFailed($params); } diff --git a/CRM/Stripe/Api.php b/CRM/Stripe/Api.php index 18a65944..f44c6263 100644 --- a/CRM/Stripe/Api.php +++ b/CRM/Stripe/Api.php @@ -103,10 +103,8 @@ class CRM_Stripe_Api { return (string) $stripeObject->customer; case 'failure_message': - if (!empty($stripeObject->charge)) { - $stripeCharge = \Stripe\Charge::retrieve($stripeObject->charge); - return (string) $stripeCharge->failure_message; - } + // This is a coding error, but it looks like the general policy here is to return something. Could otherwise consider throwing an exception. + Civi::log()->error("Coding error: CRM_Stripe_Api::getObjectParam failure_message is not a property on a Stripe Invoice object. Please alter your code to fetch the Charge and obtain the failure_message from that."); return ''; } -- GitLab