From d9a44f07e70691848886f3cbae89ed74b8658c4e Mon Sep 17 00:00:00 2001 From: "B. Endres" Date: Fri, 15 Nov 2019 09:09:14 +0100 Subject: [PATCH 1/2] [#8] added twingle ID prefix --- CRM/Twingle/Profile.php | 15 +++++++++++++++ api/v3/TwingleDonation/Cancel.php | 5 +++-- api/v3/TwingleDonation/Endrecurring.php | 3 ++- api/v3/TwingleDonation/Submit.php | 6 +++--- settings/twingle.setting.php | 14 ++++++++++++++ templates/CRM/Twingle/Form/Settings.hlp | 4 ++++ templates/CRM/Twingle/Form/Settings.tpl | 2 +- 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index bd1e7c3..760e11b 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -145,6 +145,21 @@ class CRM_Twingle_Profile { $this->data[$attribute_name] = $value; } + /** + * Get the CiviCRM transaction ID (to be used in contributions and recurring contributions) + * + * @param $twingle_id string Twingle ID + * @return string CiviCRM transaction ID + */ + public function getTransactionID($twingle_id) { + $prefix = CRM_Core_BAO_Setting::getItem('de.systopia.twingle', 'twingle_prefix'); + if (empty($prefix)) { + return $twingle_id; + } else { + return $prefix . $twingle_id; + } + } + /** * Verifies whether the profile is valid (i.e. consistent and not colliding * with other profiles). diff --git a/api/v3/TwingleDonation/Cancel.php b/api/v3/TwingleDonation/Cancel.php index 7a8c5fc..00fc6a8 100644 --- a/api/v3/TwingleDonation/Cancel.php +++ b/api/v3/TwingleDonation/Cancel.php @@ -80,15 +80,16 @@ function civicrm_api3_twingle_donation_Cancel($params) { } // Retrieve (recurring) contribution. + $default_profile = CRM_Twingle_Profile::getProfile('default'); try { $contribution = civicrm_api3('Contribution', 'getsingle', array( - 'trxn_id' => $params['trx_id'], + 'trxn_id' => $default_profile->getTransactionID($params['trx_id']), )); $contribution_type = 'Contribution'; } catch (CiviCRM_API3_Exception $exception) { $contribution = civicrm_api3('ContributionRecur', 'getsingle', array( - 'trxn_id' => $params['trx_id'], + 'trxn_id' => $default_profile->getTransactionID($params['trx_id']), )); $contribution_type = 'ContributionRecur'; } diff --git a/api/v3/TwingleDonation/Endrecurring.php b/api/v3/TwingleDonation/Endrecurring.php index 005b6c9..cf9401f 100644 --- a/api/v3/TwingleDonation/Endrecurring.php +++ b/api/v3/TwingleDonation/Endrecurring.php @@ -72,8 +72,9 @@ function civicrm_api3_twingle_donation_endrecurring($params) { ); } + $default_profile = CRM_Twingle_Profile::getProfile('default'); $contribution = civicrm_api3('ContributionRecur', 'getsingle', array( - 'trxn_id' => $params['trx_id'], + 'trxn_id' => $default_profile->getTransactionID($params['trx_id']), )); // End SEPA mandate (which ends the associated recurring contribution) or // recurring contributions. diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 5ea08e3..5fb3239 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -278,10 +278,10 @@ function civicrm_api3_twingle_donation_Submit($params) { // Do not process an already existing contribution with the given // transaction ID. $existing_contribution = civicrm_api3('Contribution', 'get', array( - 'trxn_id' => $params['trx_id'] + 'trxn_id' => $profile->getTransactionID($params['trx_id']) )); $existing_contribution_recur = civicrm_api3('ContributionRecur', 'get', array( - 'trxn_id' => $params['trx_id'] + 'trxn_id' => $profile->getTransactionID($params['trx_id']) )); if ($existing_contribution['count'] > 0 || $existing_contribution_recur['count'] > 0) { throw new CiviCRM_API3_Exception( @@ -511,7 +511,7 @@ function civicrm_api3_twingle_donation_Submit($params) { $contribution_data = array( 'contact_id' => (isset($organisation_id) ? $organisation_id : $contact_id), 'currency' => $params['currency'], - 'trxn_id' => $params['trx_id'], + 'trxn_id' => $profile->getTransactionID($params['trx_id']), 'payment_instrument_id' => $params['payment_instrument_id'], 'amount' => $params['amount'] / 100, 'total_amount' => $params['amount'] / 100, diff --git a/settings/twingle.setting.php b/settings/twingle.setting.php index 164c97e..1df4d27 100644 --- a/settings/twingle.setting.php +++ b/settings/twingle.setting.php @@ -31,4 +31,18 @@ return array( 'is_contact' => 0, 'description' => 'Whether to provide CiviSEPA functionality for manual debit payment method. This requires the CiviSEPA (org.project60.sepa) extension be installed.', ), + 'twingle_prefix' => array( + 'group_name' => 'de.systopia.twingle', + 'group' => 'de.systopia.twingle', + 'name' => 'twingle_prefix', + 'type' => CRM_Utils_Type::T_STRING, + 'quick_form_type' => 'Element', + 'html_type' => 'text', + 'title' => 'Twingle ID Prefix', + 'default' => '', + 'add' => '4.6', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'You can use this setting to add a prefix to the Twingle transaction ID, in order to avoid collisions with other transaction ids.', + ), ); diff --git a/templates/CRM/Twingle/Form/Settings.hlp b/templates/CRM/Twingle/Form/Settings.hlp index 2f0a45a..b9ff9d1 100644 --- a/templates/CRM/Twingle/Form/Settings.hlp +++ b/templates/CRM/Twingle/Form/Settings.hlp @@ -15,3 +15,7 @@ {htxt id='id-twingle_use_sepa'} {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_prefix'} + {ts domain="de.systopia.twingle"}You can use this setting to add a prefix to the Twingle transaction ID, in order to avoid collisions with other transaction ids.{/ts} +{/htxt} diff --git a/templates/CRM/Twingle/Form/Settings.tpl b/templates/CRM/Twingle/Form/Settings.tpl index 6f57d37..d1fb8c6 100644 --- a/templates/CRM/Twingle/Form/Settings.tpl +++ b/templates/CRM/Twingle/Form/Settings.tpl @@ -22,7 +22,7 @@ {foreach from=$elementNames item=elementName} - +
{$form.$elementName.label}  {$form.$elementName.label}   {$form.$elementName.html}
From 30ab55f3baa274e6677ec859a390d9fa1907a288 Mon Sep 17 00:00:00 2001 From: "B. Endres" Date: Fri, 15 Nov 2019 09:35:18 +0100 Subject: [PATCH 2/2] [#8] fixed broken help link --- templates/CRM/Twingle/Form/Settings.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/CRM/Twingle/Form/Settings.tpl b/templates/CRM/Twingle/Form/Settings.tpl index d1fb8c6..6f57d37 100644 --- a/templates/CRM/Twingle/Form/Settings.tpl +++ b/templates/CRM/Twingle/Form/Settings.tpl @@ -22,7 +22,7 @@ {foreach from=$elementNames item=elementName} - +
{$form.$elementName.label}  {$form.$elementName.label}   {$form.$elementName.html}