Merge branch 'issue/86'

This commit is contained in:
Jens Schuppe 2024-06-06 11:07:15 +02:00
commit 5169e5a0ce
3 changed files with 11 additions and 8 deletions

View file

@ -111,7 +111,8 @@ class CRM_Twingle_Profile {
*/ */
public function getCustomFieldMapping() { public function getCustomFieldMapping() {
$custom_field_mapping = []; $custom_field_mapping = [];
if (is_string($custom_field_definition = $this->getAttribute('custom_field_mapping'))) { if ('' !== ($custom_field_definition = $this->getAttribute('custom_field_mapping', ''))) {
/** @var string $custom_field_definition */
$custom_field_maps = preg_split( $custom_field_maps = preg_split(
'/\r\n|\r|\n/', '/\r\n|\r|\n/',
$custom_field_definition, $custom_field_definition,
@ -205,7 +206,9 @@ class CRM_Twingle_Profile {
* @return mixed | NULL * @return mixed | NULL
*/ */
public function getAttribute($attribute_name, $default = NULL) { public function getAttribute($attribute_name, $default = NULL) {
return $this->data[$attribute_name] ?? $default; return (isset($this->data[$attribute_name]) && $this->data[$attribute_name] !== '')
? $this->data[$attribute_name]
: $default;
} }
/** /**

View file

@ -72,8 +72,8 @@ class CRM_Twingle_Submission {
// Get the payment instrument defined within the profile, or return an error // Get the payment instrument defined within the profile, or return an error
// if none matches (i.e. an unknown payment method was submitted). // if none matches (i.e. an unknown payment method was submitted).
$payment_instrument_id = $profile->getAttribute('pi_' . $params['payment_method']); $payment_instrument_id = $profile->getAttribute('pi_' . $params['payment_method'], '');
if (!isset($payment_instrument_id)) { if ('' !== $payment_instrument_id) {
throw new CRM_Core_Exception( throw new CRM_Core_Exception(
E::ts('Payment method could not be matched to existing payment instrument.'), E::ts('Payment method could not be matched to existing payment instrument.'),
'invalid_format' 'invalid_format'
@ -101,7 +101,7 @@ class CRM_Twingle_Submission {
// matches (i.e. an unknown gender was submitted). // matches (i.e. an unknown gender was submitted).
if (is_string($params['user_gender'])) { if (is_string($params['user_gender'])) {
$gender_id = $profile->getAttribute('gender_' . $params['user_gender']); $gender_id = $profile->getAttribute('gender_' . $params['user_gender']);
if (!isset($gender_id)) { if (!is_numeric($gender_id)) {
throw new CRM_Core_Exception( throw new CRM_Core_Exception(
E::ts('Gender could not be matched to existing gender.'), E::ts('Gender could not be matched to existing gender.'),
'invalid_format' 'invalid_format'

View file

@ -420,7 +420,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
// Get the prefix ID defined within the profile // Get the prefix ID defined within the profile
if ( if (
isset($params['user_gender']) isset($params['user_gender'])
&& NULL !== ($prefix_id = $profile->getAttribute('prefix_' . $params['user_gender'])) && is_numeric($prefix_id = $profile->getAttribute('prefix_' . $params['user_gender']))
) { ) {
$contact_data['prefix_id'] = $prefix_id; $contact_data['prefix_id'] = $prefix_id;
} }
@ -830,8 +830,8 @@ function civicrm_api3_twingle_donation_Submit($params) {
$result_values['membership'] = $membership; $result_values['membership'] = $membership;
// call the postprocess API // call the postprocess API
$postprocess_call = $profile->getAttribute('membership_postprocess_call'); if ('' !== ($postprocess_call = $profile->getAttribute('membership_postprocess_call', ''))) {
if (is_string($postprocess_call)) { /** @var string $postprocess_call */
[$pp_entity, $pp_action] = explode('.', $postprocess_call, 2); [$pp_entity, $pp_action] = explode('.', $postprocess_call, 2);
try { try {
// gather the contribution IDs // gather the contribution IDs