From efa36d6e602b72dcd43078c4e9fbf6d015cf07ce Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Thu, 1 Oct 2015 21:43:54 +1300 Subject: [PATCH] CRM-17318 add getPaymentDescript to Core_Payment class This is primarily in the interests of stopping processor extension writers from recreating the wheel --- CRM/Core/Payment.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 7e00e8f755..3c8a67637c 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1178,4 +1178,33 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) return isset($this->_paymentProcessor['url_recur']) ? $this->_paymentProcessor['url_recur'] : ''; } + /** + * Get description of payment to pass to processor. + * + * This is often what people see in the interface so we want to get + * as much unique information in as possible within the field length (& presumably the early part of the field) + * + * People seeing these can be assumed to be advanced users so quantity of information probably trumps + * having field names to clarify + * + * @param array $params + * @param int $length + * + * @return string + */ + protected function getPaymentDescription($params, $length = 24) { + $parts = array('contactID', 'contributionID', 'description', 'billing_first_name', 'billing_last_name'); + $validParts = array(); + if (isset($params['description'])) { + $uninformativeStrings = array(ts('Online Event Registration: '), ts('Online Contribution: ')); + $params['description'] = str_replace($uninformativeStrings, '', $params['description']); + } + foreach ($parts as $part) { + if ((!empty($params[$part]))) { + $validParts[] = $params[$part]; + } + } + return substr(implode('-', $validParts), 0, $length); + } + } -- 2.25.1