From ab5d0906d7a0d192039df9e5b33fb5d75df6c572 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 6 Jun 2024 15:38:28 +0200 Subject: [PATCH 1/4] fix accidentally flipped condition --- CRM/Twingle/Submission.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Twingle/Submission.php b/CRM/Twingle/Submission.php index 70540ca..258f153 100644 --- a/CRM/Twingle/Submission.php +++ b/CRM/Twingle/Submission.php @@ -73,7 +73,7 @@ class CRM_Twingle_Submission { // Get the payment instrument defined within the profile, or return an error // if none matches (i.e. an unknown payment method was submitted). $payment_instrument_id = $profile->getAttribute('pi_' . $params['payment_method'], ''); - if ('' !== $payment_instrument_id) { + if ('' === $payment_instrument_id) { throw new CRM_Core_Exception( E::ts('Payment method could not be matched to existing payment instrument.'), 'invalid_format' From 4432060d0586e2f9259a2867eccca1f7a1de802e Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Tue, 11 Jun 2024 13:00:12 +0200 Subject: [PATCH 2/4] add a condition to check if the value is 1 --- api/v3/TwingleDonation/Submit.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index d307424..9ebbfb6 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -533,6 +533,7 @@ function civicrm_api3_twingle_donation_Submit($params) { if ( (bool) $profile->getAttribute('newsletter_double_opt_in') && isset($params['newsletter']) + && 1 == $params['newsletter'] && is_array($groups = $profile->getAttribute('newsletter_groups')) ) { $group_memberships = array_column( @@ -573,6 +574,7 @@ function civicrm_api3_twingle_donation_Submit($params) { } elseif ( isset($params['newsletter']) + && 1 == $params['newsletter'] && is_array($groups = $profile->getAttribute('newsletter_groups')) ) { foreach ($groups as $group_id) { @@ -592,6 +594,7 @@ function civicrm_api3_twingle_donation_Submit($params) { // If requested, add contact to postinfo groups defined in the profile. if ( isset($params['postinfo']) + && 1 == $params['postinfo'] && is_array($groups = $profile->getAttribute('postinfo_groups')) ) { foreach ($groups as $group_id) { @@ -609,6 +612,7 @@ function civicrm_api3_twingle_donation_Submit($params) { // (see issue #83) if ( isset($params['donation_receipt']) + && 1 == $params['donation_receipt'] && is_array($groups = $profile->getAttribute('donation_receipt_groups')) ) { foreach ($groups as $group_id) { From cd008d95458f84ee077aab514161e43d687a84e3 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 12 Jun 2024 10:51:01 +0200 Subject: [PATCH 3/4] fix: Check for $creditor_id always fails --- api/v3/TwingleDonation/Submit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 9ebbfb6..687f245 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -670,7 +670,7 @@ function civicrm_api3_twingle_donation_Submit($params) { } $creditor_id = $profile->getAttribute('sepa_creditor_id'); - if (!is_int($creditor_id)) { + if (!isset($creditor_id) || '' === $creditor_id) { throw new BaseException( E::ts('SEPA creditor is not configured for profile "%1".', [1 => $profile->getName()]) ); From 0cf7ccb1cba251667616a3c52e09c07f7688fbd6 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 12 Jun 2024 15:18:35 +0200 Subject: [PATCH 4/4] Code style --- CRM/Twingle/Form/Profile.php | 3 ++- CRM/Twingle/Tools.php | 5 ++++- api/v3/TwingleDonation/Submit.php | 12 ++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 2159d3b..086dc2b 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -607,7 +607,8 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { if (!isset($profile_data[$key]) && $required) { CRM_Core_Session::setStatus( E::ts( - 'The required configuration option "%1" has no value. Saving the profile might set this option to a possibly unwanted default value.', + 'The required configuration option "%1" has no value.' + . ' Saving the profile might set this option to a possibly unwanted default value.', [1 => $metadata['label'] ?? $key] ), E::ts('Error'), diff --git a/CRM/Twingle/Tools.php b/CRM/Twingle/Tools.php index 9725a96..e2abc92 100644 --- a/CRM/Twingle/Tools.php +++ b/CRM/Twingle/Tools.php @@ -116,7 +116,10 @@ class CRM_Twingle_Tools { * Recurring contribution fields. * @throws Exception could be one of the measures */ - public static function processRecurringContributionTermination(int $recurring_contribution_id, array $recurring_contribution) { + public static function processRecurringContributionTermination( + int $recurring_contribution_id, + array $recurring_contribution + ) { // check if we're suspended if (self::$protection_suspended) { return; diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 687f245..daceb36 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -532,8 +532,7 @@ function civicrm_api3_twingle_donation_Submit($params) { : 'false'; if ( (bool) $profile->getAttribute('newsletter_double_opt_in') - && isset($params['newsletter']) - && 1 == $params['newsletter'] + && (bool) ($params['newsletter'] ?? FALSE) && is_array($groups = $profile->getAttribute('newsletter_groups')) ) { $group_memberships = array_column( @@ -573,8 +572,7 @@ function civicrm_api3_twingle_donation_Submit($params) { // If requested, add contact to newsletter groups defined in the profile. } elseif ( - isset($params['newsletter']) - && 1 == $params['newsletter'] + (bool) ($params['newsletter'] ?? FALSE) && is_array($groups = $profile->getAttribute('newsletter_groups')) ) { foreach ($groups as $group_id) { @@ -593,8 +591,7 @@ function civicrm_api3_twingle_donation_Submit($params) { // If requested, add contact to postinfo groups defined in the profile. if ( - isset($params['postinfo']) - && 1 == $params['postinfo'] + (bool) ($params['postinfo'] ?? FALSE) && is_array($groups = $profile->getAttribute('postinfo_groups')) ) { foreach ($groups as $group_id) { @@ -611,8 +608,7 @@ function civicrm_api3_twingle_donation_Submit($params) { // profile. If an organisation is provided, add it to the groups instead. // (see issue #83) if ( - isset($params['donation_receipt']) - && 1 == $params['donation_receipt'] + (bool) ($params['donation_receipt'] ?? FALSE) && is_array($groups = $profile->getAttribute('donation_receipt_groups')) ) { foreach ($groups as $group_id) {