CRM-18166 Update receipt_date in IPN calls
authoreileenmcnaughton <eileen@fuzion.co.nz>
Sat, 5 Mar 2016 02:58:33 +0000 (02:58 +0000)
committereileen <emcnaughton@wikimedia.org>
Mon, 7 Mar 2016 22:20:16 +0000 (11:20 +1300)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Form/Task/PDF.php
tests/phpunit/api/v3/ContributionTest.php

index 149a5b26cf2a7f0b18989fd469498a1c1cd07258..365ca8f1e2b507ec3770259317518e6ead492f2a 100644 (file)
@@ -4401,10 +4401,6 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
         $values['is_email_receipt'] = $recurContrib->is_email_receipt;
       }
 
-      if (!empty($values['is_email_receipt'])) {
-        $contributionParams['receipt_date'] = $changeDate;
-      }
-
       if (!empty($memberships)) {
         foreach ($memberships as $membershipTypeIdKey => $membership) {
           if ($membership) {
@@ -4621,6 +4617,10 @@ LIMIT 1;";
         $values['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $input, $userName);
       }
     }
+    // Contribution ID should really always be set. But ?
+    if (!$returnMessageText && (!isset($input['receipt_update']) || $input['receipt_update'])) {
+      civicrm_api3('Contribution', 'create', array('receipt_date' => 'now', 'id' => $contribution->id));
+    }
     return $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText);
   }
 
index e06a79e877061d36358c0ddfaae8744bc95e8213..a3b941811f2d5eba7eb3d820c0a2a07b64dbe1a6 100644 (file)
@@ -180,7 +180,7 @@ AND    {$this->_componentClause}";
       $input['net_amount'] = $contribution->net_amount;
       $input['trxn_id'] = $contribution->trxn_id;
       $input['trxn_date'] = isset($contribution->trxn_date) ? $contribution->trxn_date : NULL;
-      $input['receipt_date'] = $contribution->receipt_date;
+      $input['receipt_update'] = $params['receipt_update'];
 
       // CRM_Contribute_BAO_Contribution::composeMessageArray expects mysql formatted date
       $objects['contribution']->receive_date = CRM_Utils_Date::isoToMysql($objects['contribution']->receive_date);
@@ -198,10 +198,6 @@ AND    {$this->_componentClause}";
 
       // reset template values before processing next transactions
       $template->clearTemplateVars();
-      if (!empty($params['receipt_update'])) {
-        $objects['contribution']->receipt_date = date('Y-m-d H-i-s');
-        $objects['contribution']->save();
-      }
     }
 
     if ($elements['createPdf']) {
index a374f8f8eeed790b13e5c33677e73b8db7f8df45..d5d97da0c9a6c286e55f14d0dd4c7aed16ab61c2 100644 (file)
@@ -1578,8 +1578,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     $this->callAPISuccess('contribution', 'completetransaction', array(
       'id' => $contribution['id'],
     ));
-    $contribution = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'sequential' => 1));
-    $this->assertEquals('Completed', $contribution['values'][0]['contribution_status']);
+    $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
+    $this->assertEquals('Completed', $contribution['contribution_status']);
+    $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['receipt_date'])));
     $mut->checkMailLog(array(
       'Receipt - Contribution',
       'Please print this confirmation for your records.',