From 58a49cd80409d927e7ac624f917bd8a26ac747aa Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" <mjw@mjwconsult.co.uk> Date: Mon, 21 Oct 2019 11:58:15 +0100 Subject: [PATCH] Don't try to record refund for an uncaptured payment(Intent) --- CRM/Core/Payment/StripeIPN.php | 5 +++++ CRM/Stripe/Api.php | 3 +++ 2 files changed, 8 insertions(+) diff --git a/CRM/Core/Payment/StripeIPN.php b/CRM/Core/Payment/StripeIPN.php index 92959adc..3f1a0115 100644 --- a/CRM/Core/Payment/StripeIPN.php +++ b/CRM/Core/Payment/StripeIPN.php @@ -248,6 +248,11 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN { return TRUE; case 'charge.refunded': + // Cancelling an uncaptured paymentIntent triggers charge.refunded but we don't want to process that + if (empty(CRM_Stripe_Api::getObjectParam('captured', $this->_inputParameters->data->object))) { + return TRUE; + }; + // This charge was actually captured, so record the refund in CiviCRM $this->setInfo(); $refunds = \Stripe\Refund::all(['charge' => $this->charge_id, 'limit' => 1]); $params = [ diff --git a/CRM/Stripe/Api.php b/CRM/Stripe/Api.php index 554563b3..55137eba 100644 --- a/CRM/Stripe/Api.php +++ b/CRM/Stripe/Api.php @@ -37,6 +37,9 @@ class CRM_Stripe_Api { case 'invoice_id': return (string) $stripeObject->invoice; + case 'captured': + return (bool) $stripeObject->captured; + } break; -- GitLab