From 62b0d11e9e9792bd5844fa799ddde70d1ba1c138 Mon Sep 17 00:00:00 2001 From: Matthew Wire <mjw@mjwconsult.co.uk> Date: Tue, 9 Feb 2021 21:32:39 +0000 Subject: [PATCH] Fix Stripe.Ipn API --- api/v3/Stripe/Ipn.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/api/v3/Stripe/Ipn.php b/api/v3/Stripe/Ipn.php index abfcbc39..4bffc64e 100644 --- a/api/v3/Stripe/Ipn.php +++ b/api/v3/Stripe/Ipn.php @@ -48,6 +48,7 @@ function civicrm_api3_stripe_Ipn($params) { $stripeObject = NULL; $paymentProcessorID = NULL; + /** @var \CRM_Core_Payment_Stripe $paymentProcessor */ if (array_key_exists('id', $params)) { // Read from civicrm SystemLog $data = civicrm_api3('SystemLog', 'getsingle', ['id' => $params['id'], 'return' => ['message', 'context']]); @@ -55,8 +56,10 @@ function civicrm_api3_stripe_Ipn($params) { throw new API_Exception('Failed to find that entry in the system log', 3234); } $stripeObject = json_decode($data['context']); - if (preg_match('/processor_id=([0-9]+)$/', $stripeObject['message'], $matches)) { + if (preg_match('/processor_id=([0-9]+)$/', $data['message'], $matches)) { $paymentProcessorID = $matches[1]; + $paymentProcessor = \Civi\Payment\System::singleton()->getById($paymentProcessorID); + $paymentProcessor->setAPIParams(); } else { throw new API_Exception('Failed to find payment processor id in system log', 3235); @@ -70,7 +73,10 @@ function civicrm_api3_stripe_Ipn($params) { $paymentProcessorID = $params['ppid']; $paymentProcessor = \Civi\Payment\System::singleton()->getById($paymentProcessorID); $paymentProcessor->setAPIParams(); - $stripeObject = \Stripe\Event::retrieve($params['evtid']); + $stripeObject = $paymentProcessor->stripeClient->events->retrieve($params['evtid']); + } + else { + throw new API_Exception('Missing parameters. You must specify id or evtid', 3237); } // By default, set emailReceipt to NULL so the default receipt setting -- GitLab