Commit 5659c61e authored by mattwire's avatar mattwire
Browse files

Extract description generation into it's own function

parent 459131e8
......@@ -509,10 +509,10 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$contactContribution = $this->getContactId($params) . '-' . ($this->getContributionId($params) ?: 'XX');
$intentParams = [
'customer' => $stripeCustomer->id,
'description' => "{$params['description']} {$contactContribution} #" . CRM_Utils_Array::value('invoiceID', $params),
'description' => $this->getDescription($params, 'description'),
];
$intentParams['statement_descriptor_suffix'] = "{$contactContribution} " . substr($params['description'],0,7);
$intentParams['statement_descriptor'] = substr("{$contactContribution} " . $params['description'], 0, 22);
$intentParams['statement_descriptor_suffix'] = $this->getDescription($params, 'statement_descriptor_suffix');
$intentParams['statement_descriptor'] = $this->getDescription($params, 'statement_descriptor');
// This is where we actually charge the customer
try {
......@@ -717,6 +717,30 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
return $refundParams;
}
/**
* Get a description field
* @param array $params
* @param string $type
* One of description, statement_descriptor, statement_descriptor_suffix
*
* @return string
*/
private function getDescription($params, $type = 'description') {
if (!isset(\Civi::$statics[__CLASS__]['description']['contact_contribution'])) {
\Civi::$statics[__CLASS__]['description']['contact_contribution'] = $this->getContactId($params) . '-' . ($this->getContributionId($params) ?: 'XX');
}
switch ($type) {
case 'statement_descriptor':
return substr(\Civi::$statics[__CLASS__]['description']['contact_contribution'] . " " . $params['description'], 0, 22);
case 'statement_descriptor_suffix':
return \Civi::$statics[__CLASS__]['description']['contact_contribution'] . " " . substr($params['description'],0,7);
default:
return "{$params['description']} " . \Civi::$statics[__CLASS__]['description']['contact_contribution'] . " #" . CRM_Utils_Array::value('invoiceID', $params);
}
}
/**
* Calculate the end_date for a recurring contribution based on the number of installments
* @param $params
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment