From 65bf8b86d7e029d91e3cf71095c06964f367f3c3 Mon Sep 17 00:00:00 2001 From: Matthew Wire <mjw@mjwconsult.co.uk> Date: Fri, 23 Jun 2023 15:46:33 +0100 Subject: [PATCH] Wrap StripeCheckout errors in try/catch and log (but don't report to end-user) the actual error --- CRM/Core/Payment/StripeCheckout.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Payment/StripeCheckout.php b/CRM/Core/Payment/StripeCheckout.php index 200b9cf1..27cf748f 100644 --- a/CRM/Core/Payment/StripeCheckout.php +++ b/CRM/Core/Payment/StripeCheckout.php @@ -155,7 +155,6 @@ class CRM_Core_Payment_StripeCheckout extends CRM_Core_Payment_Stripe { $failUrl = $this->getCancelUrl($paymentParams['qfKey'], NULL); // Get existing/saved Stripe customer or create a new one - $stripeCustomerID = NULL; $existingStripeCustomer = \Civi\Api4\StripeCustomer::get(FALSE) ->addWhere('contact_id', '=', $propertyBag->getContactID()) ->addWhere('processor_id', '=', $this->getPaymentProcessor()['id']) @@ -211,7 +210,13 @@ class CRM_Core_Payment_StripeCheckout extends CRM_Core_Payment_Stripe { // Allows you to alter the params passed to StripeCheckout (eg. payment_method_types) CRM_Utils_Hook::alterPaymentProcessorParams($this, $propertyBag, $checkoutSessionParams); - $checkoutSession = $this->stripeClient->checkout->sessions->create($checkoutSessionParams); + try { + $checkoutSession = $this->stripeClient->checkout->sessions->create($checkoutSessionParams); + } + catch (Exception $e) { + $parsedError = $this->parseStripeException('doPayment', $e); + throw new PaymentProcessorException($parsedError['message']); + } CRM_Stripe_BAO_StripeCustomer::updateMetadata(['contact_id' => $propertyBag->getContactID()], $this, $checkoutSession['customer']); -- GitLab