Skip to content

Commit

Permalink
Merge pull request #17688 from artfulrobot/artfulrobot-trxn-id-and-date
Browse files Browse the repository at this point in the history
Payment.create should not set contribution date to today
  • Loading branch information
eileenmcnaughton authored Jun 25, 2020
2 parents 833e552 + 4fa3b81 commit a5e01e6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public static function create($params) {
'id' => $contribution['id'],
'is_post_payment_create' => TRUE,
'is_email_receipt' => $params['is_send_contribution_notification'],
'trxn_date' => $params['trxn_date'],
]);
// Get the trxn
$trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
Expand Down
60 changes: 60 additions & 0 deletions tests/phpunit/api/v3/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,4 +1074,64 @@ protected function checkPaymentIsValid($paymentID, $contributionID, $amount = 50
$this->validateAllPayments();
}

/**
* This test was introduced in
* https://github.com/civicrm/civicrm-core/pull/17688 to ensure that a
* contribution's date is not set to today's date when a payment is received,
* and that the contribution's trxn_id is set to that of the payment.
*
* This tests the current behaviour, but there are questions about whether
* that's right.
*
* The current behaviour is that when a payment is received that completes a
* contribution: the contribution's receive_date is set to that of the
* payment (passed to Payment.create as trxn_date).
*
* But why *should* we update the receive_date at all?
*
* If we decide that receive_date should not be touched, just change
* $trxnDate for $trxnID as detailed in the code comment below, which will
* still make sure we're not setting today's date, as well as confirming
* that the original date is not changed.
*
* @see https://github.com/civicrm/civicrm-core/pull/17688
* @see https://lab.civicrm.org/dev/financial/-/issues/139
*
*/
public function testPaymentCreateTrxnIdAndDates() {

$trxnDate = '2010-01-01 09:00:00';
$trxnID = 'aabbccddeeffggh';
$originalReceiveDate = '2010-02-02 22:22:22';

$contributionID = $this->contributionCreate([
'contact_id' => $this->individualCreate(),
'total_amount' => 100,
'contribution_status_id' => 'Pending',
'receive_date' => $originalReceiveDate,
]);

$payment = $this->callAPISuccess('Payment', 'create', [
'total_amount' => 100,
'order_id' => $contributionID,
'trxn_date' => $trxnDate,
'trxn_id' => $trxnID,
]);

$contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contributionID]);
$this->assertEquals('Completed', $contribution['contribution_status']);

$this->assertEquals($trxnID, $contribution['trxn_id'],
"Contribution trxn_id should have been set to that of the payment.");

// change $trxnDate for $receiveDate if we agree that transactions should NOT
// update contributions.
$this->assertEquals($trxnDate, $contribution['receive_date'],
"Contribution receive date was changed, but should not have been.");

$this->validateAllPayments();
$this->validateAllContributions();

}

}

0 comments on commit a5e01e6

Please sign in to comment.