diff --git a/CRM/Core/Payment/Stripe.php b/CRM/Core/Payment/Stripe.php index 06002c9920d3b08bd35550e06b88634dacb532fc..1a8a38c90829c54c62bef43030584d9bfb2294e9 100644 --- a/CRM/Core/Payment/Stripe.php +++ b/CRM/Core/Payment/Stripe.php @@ -318,12 +318,12 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { 'publishableKey' => CRM_Core_Payment_Stripe::getPublicKeyById($form->_paymentProcessor['id']), 'jsDebug' => TRUE, ]; - CRM_Core_Resources::singleton()->addVars(E::SHORT_NAME, $jsVars); + \Civi::resources()->addVars(E::SHORT_NAME, $jsVars); // Add help and javascript CRM_Core_Region::instance('billing-block')->add( ['template' => 'CRM/Core/Payment/Stripe/Card.tpl', 'weight' => -1]); - CRM_Core_Resources::singleton() + \Civi::resources() ->addStyleFile(E::LONG_NAME, 'css/elements.css', 0, 'page-header') ->addScriptFile('com.drastikbydesign.stripe', 'js/civicrm_stripe.js'); } diff --git a/CRM/Stripe/Check.php b/CRM/Stripe/Check.php new file mode 100644 index 0000000000000000000000000000000000000000..22a8f421fd76cda7ee59bb3c9824d51b4d65510b --- /dev/null +++ b/CRM/Stripe/Check.php @@ -0,0 +1,46 @@ +<?php + +/** + * https://civicrm.org/licensing + */ + +use CRM_Stripe_ExtensionUtil as E; + +/** + * Class CRM_Stripe_Check + */ +class CRM_Stripe_Check { + + const MIN_VERSION_MJWSHARED = 0.2; + + public static function checkRequirements(&$messages) { + $extensions = civicrm_api3('Extension', 'get', [ + 'full_name' => "mjwshared", + ]); + + if (empty($extensions['id']) || ($extensions['values'][$extensions['id']]['status'] !== 'installed')) { + $messages[] = new CRM_Utils_Check_Message( + '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, + 'fa-money' + ); + } + + if (version_compare($extensions['values'][$extensions['id']]['version'], self::MIN_VERSION_MJWSHARED) === -1) { + $messages[] = new CRM_Utils_Check_Message( + 'stripe_requirements', + E::ts('The Stripe extension requires the mjwshared extension version %1 or greater but your system has version %2.', + [ + 1 => self::MIN_VERSION_MJWSHARED, + 2 => $extensions['values'][$extensions['id']]['version'] + ]), + E::ts('Stripe: Missing Requirements'), + \Psr\Log\LogLevel::ERROR, + 'fa-money' + ); + } + } + +} diff --git a/docs/release/release_notes.md b/docs/release/release_notes.md index 18aac1e2c665bba79a7e07999f5de5c015ed54d2..716a8202864ff56c22084592bb4ac9c815ab34e0 100644 --- a/docs/release/release_notes.md +++ b/docs/release/release_notes.md @@ -1,8 +1,11 @@ ## Release 6.0 (not yet released) -* Stripe API Version: 2019-08-14 -* Switch publishable key/secret key in settings (upgrader does this automatically) so they are now "correct" per CiviCRM settings pages. +**This is a major new release. You cannot rollback once you've upgraded.** +* Use Stripe Elements: https://stripe.com/payments/elements. +* Use PaymentIntents and comply with the European SCA directive (https://stripe.com/docs/strong-customer-authentication). +* Require Stripe API Version: 2019-08-14 and ensure that all codepaths specify the API version. +* Switch publishable key/secret key in settings (upgrader does this automatically) so they are now "correct" per CiviCRM settings pages. ## Release 5.4.1 * Don't overwrite system messages when performing webhook checks. diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js index 15f3010ba0af869c96fbda6abf3306d57d34df0c..3a761160bf63a6970da9678a47e631e3b3dfce96 100644 --- a/js/civicrm_stripe.js +++ b/js/civicrm_stripe.js @@ -92,6 +92,7 @@ CRM.$(function($) { $(document).ready(function() { // Disable the browser "Leave Page Alert" which is triggered because we mess with the form submit function. window.onbeforeunload = null; + // Load Stripe onto the form. loadStripeBillingBlock(); diff --git a/stripe.php b/stripe.php index 366d4091fdbafe5542cbddfc196d66a062b32eac..2fa79b182581eab9765f2196ecc97a8ac6881b69 100644 --- a/stripe.php +++ b/stripe.php @@ -160,7 +160,7 @@ function stripe_civicrm_buildForm($formName, &$form) { // Load stripe.js on all civi forms per stripe requirements if (!isset(\Civi::$statics[E::LONG_NAME]['stripeJSLoaded'])) { - CRM_Core_Resources::singleton()->addScriptUrl('https://js.stripe.com/v3'); + \Civi::resources()->addScriptUrl('https://js.stripe.com/v3'); \Civi::$statics[E::LONG_NAME]['stripeJSLoaded'] = TRUE; } } @@ -194,6 +194,7 @@ function stripe_civicrm_postProcess($formName, &$form) { */ function stripe_civicrm_check(&$messages) { CRM_Stripe_Webhook::check($messages); + CRM_Stripe_Check::checkRequirements($messages); } /**