[#8] added transaction prefix

This commit is contained in:
B. Endres 2019-11-15 11:13:33 +01:00
commit c9695c1773
6 changed files with 41 additions and 6 deletions

View file

@ -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).

View file

@ -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';
}

View file

@ -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.

View file

@ -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,

View file

@ -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.',
),
);

View file

@ -15,3 +15,7 @@
{htxt id='id-twingle_use_sepa'}
{ts domain="de.systopia.twingle" 1="<a href=\"https://github.com/project60/org.project60.sepa\" target=\"_blank\">CiviSEPA (<kbd>org.project60.sepa</kbd>) extension</a>"}When the %1 is enabled and one of its payment instruments is assigned to a Twingle payment method (practically the <em>debit_manual</em> 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}