CRM-21200: Pay Now payment overwrites the contribution
authordeb.monish <monish.deb@jmaconsulting.biz>
Tue, 3 Oct 2017 12:03:53 +0000 (17:33 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Mon, 23 Oct 2017 08:07:06 +0000 (13:37 +0530)
CRM/Contribute/BAO/Contribution/Utils.php

index 3930addfda79f1f62fe04e001cffed6f5735a30c..c245f95a17fee8949107256dd17d2d94ba752715 100644 (file)
@@ -102,10 +102,26 @@ class CRM_Contribute_BAO_Contribution_Utils {
         'id' => CRM_Utils_Array::value('contribution_id', $paymentParams),
         'contact_id' => $contactID,
         'is_test' => $isTest,
-        'campaign_id' => CRM_Utils_Array::value('campaign_id', $paymentParams, CRM_Utils_Array::value('campaign_id', $form->_values)),
-        'contribution_page_id' => $form->_id,
         'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)),
       );
+
+      // CRM-21200: Don't overwrite contribution details during 'Pay now' payment
+      if (empty($form->_params['contribution_id'])) {
+        $contributionParams['contribution_page_id'] = $form->_id;
+        $contributionParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $paymentParams, CRM_Utils_Array::value('campaign_id', $form->_values));
+      }
+      // In case of 'Pay now' payment, append the contribution source with new text 'Paid later via page ID: N.'
+      else {
+        // contribution.source only allows 255 characters so we are using ellipsify(...) to ensure it.
+        $contributionParams['source'] = CRM_Utils_String::ellipsify(
+          ts('Paid later via page ID: %1. %2', array(
+            1 => $form->_id,
+            2 => $contributionParams['source'],
+          )),
+          220 // eventually activity.description append price information to source text so keep it 220 to ensure string length doesn't exceed 255 characters.
+        );
+      }
+
       if (isset($paymentParams['line_item'])) {
         // @todo make sure this is consisently set at this point.
         $contributionParams['line_item'] = $paymentParams['line_item'];