From fcbc3d55fe687d606a26961e5ef03fd45e903caf Mon Sep 17 00:00:00 2001
From: Matthew Wire <mjw@mjwconsult.co.uk>
Date: Mon, 1 May 2023 12:11:23 +0100
Subject: [PATCH] Fix charge.failed - handle both collapsed and expanded
 invoice in charge

---
 CRM/Stripe/Api.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/CRM/Stripe/Api.php b/CRM/Stripe/Api.php
index f5dccd1d..1f30185b 100644
--- a/CRM/Stripe/Api.php
+++ b/CRM/Stripe/Api.php
@@ -53,7 +53,13 @@ class CRM_Stripe_Api {
             return self::formatDate($stripeObject->created);
 
           case 'invoice_id':
-            return (string) $stripeObject->invoice;
+            // Handle both "expanded" and "collapsed" response
+            if (is_object($stripeObject->invoice)) {
+              return (string) $stripeObject->invoice->id;
+            }
+            else {
+              return (string) $stripeObject->invoice;
+            }
 
           case 'captured':
             return (bool) $stripeObject->captured;
-- 
GitLab