diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php
index 37e9365..0be09b9 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 83f20e0..baecb32 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 9a52c42..2bc3d3a 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}