diff --git a/CRM/Twingle/Form/Settings.php b/CRM/Twingle/Form/Settings.php index b85fe5e..dba6a28 100644 --- a/CRM/Twingle/Form/Settings.php +++ b/CRM/Twingle/Form/Settings.php @@ -28,6 +28,7 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form { public static $SETTINGS_LIST = [ 'twingle_prefix', 'twingle_use_sepa', + 'twingle_dont_use_reference', 'twingle_protect_recurring', 'twingle_protect_recurring_activity_type', 'twingle_protect_recurring_activity_subject', @@ -54,6 +55,12 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form { E::ts("Use CiviSEPA") ); + $this->add( + 'checkbox', + 'twingle_dont_use_reference', + E::ts("Use CiviSEPA generated reference") + ); + $this->add( 'select', 'twingle_protect_recurring', diff --git a/api/v3/TwingleDonation/Cancel.php b/api/v3/TwingleDonation/Cancel.php index d2bba26..e3dee49 100644 --- a/api/v3/TwingleDonation/Cancel.php +++ b/api/v3/TwingleDonation/Cancel.php @@ -150,7 +150,7 @@ function civicrm_api3_twingle_donation_Cancel($params) { $result = civicrm_api3_create_success($contribution); } - catch (CiviCRM_API3_Exception $exception) { + catch (Exception $exception) { $result = civicrm_api3_create_error($exception->getMessage()); } diff --git a/api/v3/TwingleDonation/Endrecurring.php b/api/v3/TwingleDonation/Endrecurring.php index 318b115..12c93c4 100644 --- a/api/v3/TwingleDonation/Endrecurring.php +++ b/api/v3/TwingleDonation/Endrecurring.php @@ -139,7 +139,7 @@ function civicrm_api3_twingle_donation_endrecurring($params) { $result = civicrm_api3_create_success($contribution); } - catch (CiviCRM_API3_Exception $exception) { + catch (Exception $exception) { $result = civicrm_api3_create_error($exception->getMessage()); } diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 5856996..8828c82 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -604,6 +604,12 @@ function civicrm_api3_twingle_donation_Submit($params) { // mandate type. unset($mandate_data['payment_instrument_id']); + // If requested, let CiviSEPA generate the mandate reference + $use_own_mandate_reference = Civi::settings()->get('twingle_dont_use_reference'); + if (!empty($use_own_mandate_reference)) { + unset($mandate_data['reference']); + } + // Create the mandate. $mandate = civicrm_api3('SepaMandate', 'createfull', $mandate_data); @@ -707,13 +713,15 @@ function civicrm_api3_twingle_donation_Submit($params) { $recurring_contribution_id = $contribution_id = ''; if (isset($contribution_recur['id'])) { $recurring_contribution_id = $contribution_recur['id']; + } elseif (!empty($mandate['entity_id']) && $mandate['type'] == 'RCUR') { + $recurring_contribution_id = $mandate['entity_id']; } if (isset($contribution['id'])) { $contribution_id = $contribution['id']; } // run the call - civicrm_api3($pp_entity, $pp_action, [ + civicrm_api3(trim($pp_entity), trim($pp_action), [ 'membership_id' => $membership['id'], 'contact_id' => $contact_id, 'organization_id' => isset($organisation_id) ? $organisation_id : '', @@ -727,14 +735,16 @@ function civicrm_api3_twingle_donation_Submit($params) { } catch (Exception $ex) { // TODO: more error handling? Civi::log()->debug("Twingle membership postprocessing call {$pp_entity}.{$pp_action} has failed: " . $ex->getMessage()); + throw new Exception( + E::ts("Twingle membership postprocessing call has failed, see log for more information") + ); } } - } $result = civicrm_api3_create_success($result_values); } - catch (CiviCRM_API3_Exception $exception) { + catch (Exception $exception) { $result = civicrm_api3_create_error($exception->getMessage()); } diff --git a/templates/CRM/Twingle/Form/Settings.hlp b/templates/CRM/Twingle/Form/Settings.hlp index 8b5ef1b..7b82e7b 100644 --- a/templates/CRM/Twingle/Form/Settings.hlp +++ b/templates/CRM/Twingle/Form/Settings.hlp @@ -16,6 +16,10 @@ {ts domain="de.systopia.twingle" 1="CiviSEPA (org.project60.sepa) extension"}When the %1 is enabled and one of its payment instruments is assigned to a Twingle payment method (practically the debit_manual payment method), submitting a Twingle donation through the API will create a SEPA mandate with the given data.{/ts} {/htxt} +{htxt id='id-twingle_dont_use_reference'} + {ts domain="de.systopia.twingle" 1="CiviSEPA (org.project60.sepa) extension"}When the %1 is enabled, you can activate this to use your own references instead of the ones submitted by Twingle.{/ts} +{/htxt} + {htxt id='id-twingle_protect_recurring'} {ts domain="de.systopia.twingle"}Will protect all recurring contributions created by Twingle from termination, since this does NOT terminate the Twingle collection process{/ts} {/htxt} diff --git a/templates/CRM/Twingle/Form/Settings.tpl b/templates/CRM/Twingle/Form/Settings.tpl index 49d068e..e5fa54f 100644 --- a/templates/CRM/Twingle/Form/Settings.tpl +++ b/templates/CRM/Twingle/Form/Settings.tpl @@ -28,6 +28,18 @@ + + {$form.twingle_dont_use_reference.label}   + + {$form.twingle_dont_use_reference.html} +
+ + {$formElements.twingle_dont_use_reference.description} + + + + + {$form.twingle_prefix.label}