diff --git a/CRM/Stripe/Check.php b/CRM/Stripe/Check.php index 6be58cfa46b8e5b2b3c0c4a8a65e8b1943596689..1337636fa1a747c87abde0bb89d344a98fafb065 100644 --- a/CRM/Stripe/Check.php +++ b/CRM/Stripe/Check.php @@ -32,6 +32,7 @@ class CRM_Stripe_Check { self::checkExtensionMjwshared($messages); self::checkExtensionFirewall($messages); self::checkExtensionSweetalert($messages); + self::checkIfSeparateMembershipPaymentEnabled($messages); } /** @@ -49,7 +50,7 @@ class CRM_Stripe_Check { if (empty($extensions['id']) || ($extensions['values'][$extensions['id']]['status'] !== 'installed')) { $message = new CRM_Utils_Check_Message( - 'stripe_requirements', + __FUNCTION__ . 'stripe_requirements', E::ts('The Stripe extension requires the mjwshared extension which is not installed (https://lab.civicrm.org/extensions/mjwshared).'), E::ts('Stripe: Missing Requirements'), \Psr\Log\LogLevel::ERROR, @@ -83,7 +84,7 @@ class CRM_Stripe_Check { if (empty($extensions['id']) || ($extensions['values'][$extensions['id']]['status'] !== 'installed')) { $message = new CRM_Utils_Check_Message( - 'stripe_recommended', + __FUNCTION__ . 'stripe_recommended', E::ts('If you are using Stripe to accept payments on public forms (eg. contribution/event registration forms) it is recommended that you install the <strong><a href="https://lab.civicrm.org/extensions/firewall">firewall</a></strong> extension. Some sites have become targets for spammers who use the payment endpoint to try and test credit cards by submitting invalid payments to your Stripe account.'), E::ts('Recommended Extension: firewall'), @@ -114,7 +115,7 @@ class CRM_Stripe_Check { if (empty($extensions['id']) || ($extensions['values'][$extensions['id']]['status'] !== 'installed')) { $message = new CRM_Utils_Check_Message( - 'stripe_recommended', + __FUNCTION__ . 'stripe_recommended', E::ts('It is recommended that you install the <strong><a href="https://civicrm.org/extensions/sweetalert">sweetalert</a></strong> extension. This allows the stripe extension to show useful messages to the user when processing payment. If this is not installed it will fallback to the browser "alert" message but you will @@ -146,7 +147,7 @@ class CRM_Stripe_Check { private static function requireExtensionMinVersion(&$messages, $extensionName, $minVersion, $actualVersion) { if (version_compare($actualVersion, $minVersion) === -1) { $message = new CRM_Utils_Check_Message( - 'stripe_requirements', + __FUNCTION__ . $extensionName . 'stripe_requirements', E::ts('The Stripe extension requires the %1 extension version %2 or greater but your system has version %3.', [ 1 => $extensionName, @@ -167,4 +168,56 @@ class CRM_Stripe_Check { } } + /** + * @throws \CiviCRM_API3_Exception + */ + private static function checkIfSeparateMembershipPaymentEnabled(&$messages) { + $membershipBlocks = civicrm_api3('MembershipBlock', 'get', [ + 'is_separate_payment' => 1, + ]); + if ($membershipBlocks['count'] === 0) { + return; + } + else { + $contributionPagesToCheck = []; + foreach ($membershipBlocks['values'] as $blockID => $blockDetails) { + if ($blockDetails['entity_table'] !== 'civicrm_contribution_page') { + continue; + } + $contributionPagesToCheck[] = $blockDetails['entity_id']; + } + $stripePaymentProcessorIDs = civicrm_api3('PaymentProcessor', 'get', [ + 'return' => ['id'], + 'payment_processor_type_id' => 'Stripe', + ]); + $stripePaymentProcessorIDs = CRM_Utils_Array::collect('id', $stripePaymentProcessorIDs['values']); + if (!empty($contributionPagesToCheck)) { + $contributionPages = civicrm_api3('ContributionPage', 'get', [ + 'return' => ['payment_processor'], + 'id' => ['IN' => $contributionPagesToCheck], + ]); + foreach ($contributionPages['values'] as $contributionPage) { + $enabledPaymentProcessors = explode(CRM_Core_DAO::VALUE_SEPARATOR, $contributionPage['payment_processor']); + foreach ($enabledPaymentProcessors as $enabledID) { + if (in_array($enabledID, $stripePaymentProcessorIDs)) { + $message = new CRM_Utils_Check_Message( + __FUNCTION__ . 'stripe_requirements', + E::ts('Stripe does not support "Separate Membership Payment" on contribution pages but you have one or more contribution pages with + that setting enabled and Stripe as the payment processor (found on contribution page ID: %1).', + [ + 1 => $contributionPage['id'], + ]), + E::ts('Stripe: Invalid configuration'), + \Psr\Log\LogLevel::ERROR, + 'fa-money' + ); + $messages[] = $message; + return; + } + } + } + } + } + } + } diff --git a/CRM/Stripe/Webhook.php b/CRM/Stripe/Webhook.php index 4c13719ae77128c4cd53b731c0ffdbc40b54debe..2b48b5b1fa4847909d67f00904d9879881a69d91 100644 --- a/CRM/Stripe/Webhook.php +++ b/CRM/Stripe/Webhook.php @@ -46,7 +46,7 @@ class CRM_Stripe_Webhook { catch (Exception $e) { $error = $e->getMessage(); $messages[] = new CRM_Utils_Check_Message( - 'stripe_webhook', + __FUNCTION__ . $paymentProcessor['id'] . 'stripe_webhook', $error, self::getTitle($paymentProcessor), \Psr\Log\LogLevel::ERROR, @@ -67,7 +67,7 @@ class CRM_Stripe_Webhook { if (!empty($wh->api_version) && (strtotime($wh->api_version) < strtotime(CRM_Stripe_Check::API_MIN_VERSION))) { // Add message about API version. $messages[] = new CRM_Utils_Check_Message( - 'stripe_webhook', + __FUNCTION__ . $paymentProcessor['id'] . 'stripe_webhook', E::ts('Webhook API version is set to %2 but CiviCRM requires %3. To correct this please delete the webhook at Stripe and then revisit this page which will recreate it correctly. <em>Webhook path is: <a href="%1" target="_blank">%1</a>.</em>', [ 1 => urldecode($webhook_path), @@ -85,7 +85,7 @@ class CRM_Stripe_Webhook { if ($attemptFix) { // We should try to update the webhook. $messages[] = new CRM_Utils_Check_Message( - 'stripe_webhook', + __FUNCTION__ . $paymentProcessor['id'] . 'stripe_webhook', E::ts('Unable to update the webhook %1. To correct this please delete the webhook at Stripe and then revisit this page which will recreate it correctly.', [1 => urldecode($webhook_path)] ), @@ -97,7 +97,7 @@ class CRM_Stripe_Webhook { } else { $message = new CRM_Utils_Check_Message( - 'stripe_webhook', + __FUNCTION__ . $paymentProcessor['id'] . 'stripe_webhook', E::ts('Problems detected with Stripe webhook! <em>Webhook path is: <a href="%1" target="_blank">%1</a>.</em>', [1 => urldecode($webhook_path)] ), @@ -117,7 +117,7 @@ class CRM_Stripe_Webhook { } catch (Exception $e) { $messages[] = new CRM_Utils_Check_Message( - 'stripe_webhook', + __FUNCTION__ . $paymentProcessor['id'] . 'stripe_webhook', E::ts('Could not check/update existing webhooks, got error from stripe <em>%1</em>', [ 1 => htmlspecialchars($e->getMessage()) ] @@ -138,7 +138,7 @@ class CRM_Stripe_Webhook { } catch (Exception $e) { $messages[] = new CRM_Utils_Check_Message( - 'stripe_webhook', + __FUNCTION__ . $paymentProcessor['id'] . 'stripe_webhook', E::ts('Could not create webhook, got error from stripe <em>%1</em>', [ 1 => htmlspecialchars($e->getMessage()) ]), @@ -150,7 +150,7 @@ class CRM_Stripe_Webhook { } else { $message = new CRM_Utils_Check_Message( - 'stripe_webhook', + __FUNCTION__ . $paymentProcessor['id'] . 'stripe_webhook', E::ts( 'Stripe Webhook missing or needs update! <em>Expected webhook path is: <a href="%1" target="_blank">%1</a></em>', [1 => $webhook_path]