From 4a1ba425220cdd8ab51a7ba77bf956c573133927 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 12 Apr 2017 14:05:05 +1200 Subject: [PATCH] CRM-19597 allow receive_date to be passed in for A.net --- CRM/Core/Payment/AuthorizeNetIPN.php | 4 ++- CRM/Core/Payment/BaseIPN.php | 2 ++ .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CRM/Core/Payment/AuthorizeNetIPN.php b/CRM/Core/Payment/AuthorizeNetIPN.php index 5933ff9a6d..5e0a373bdc 100644 --- a/CRM/Core/Payment/AuthorizeNetIPN.php +++ b/CRM/Core/Payment/AuthorizeNetIPN.php @@ -148,7 +148,7 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { $contribution->financial_type_id = $objects['contributionType']->id; $contribution->contribution_page_id = $ids['contributionPage']; $contribution->contribution_recur_id = $ids['contributionRecur']; - $contribution->receive_date = $now; + $contribution->receive_date = $input['receive_date']; $contribution->currency = $objects['contribution']->currency; $contribution->payment_instrument_id = $objects['contribution']->payment_instrument_id; $contribution->amount_level = $objects['contribution']->amount_level; @@ -228,6 +228,8 @@ class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN { $input['response_reason_text'] = $this->retrieve('x_response_reason_text', 'String', FALSE); $input['subscription_paynum'] = $this->retrieve('x_subscription_paynum', 'Integer', FALSE, 0); $input['trxn_id'] = $this->retrieve('x_trans_id', 'String', FALSE); + $input['trxn_id'] = $this->retrieve('x_trans_id', 'String', FALSE); + $input['receive_date'] = $this->retrieve('receive_date', 'String', FALSE, 'now'); if ($input['trxn_id']) { $input['is_test'] = 0; diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index d1bbb00cba..875f2b0a3f 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -392,6 +392,8 @@ class CRM_Core_Payment_BaseIPN { } /** + * @deprecated + * * Jumbled up function. * * The purpose of this function is to transition a pending transaction to Completed including updating any diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index cbb5ce2920..169d751f26 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -56,8 +56,35 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { )); $this->assertEquals(2, $contribution['count']); $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); + $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($contribution['values'][1]['receive_date']))); } + /** + * Test IPN response updates contribution_recur & contribution for first & second contribution + */ + public function testIPNPaymentRecurSuccessSuppliedReceiveDate() { + $this->setupRecurringPaymentProcessorTransaction(); + $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); + $IPN->main(); + $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); + $this->assertEquals(1, $contribution['contribution_status_id']); + $this->assertEquals('6511143069', $contribution['trxn_id']); + // source gets set by processor + $this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:"); + $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID)); + $this->assertEquals(5, $contributionRecur['contribution_status_id']); + $IPN = new CRM_Core_Payment_AuthorizeNetIPN(array_merge(array('receive_date' => '1 July 2010'), $this->getRecurSubsequentTransaction())); + $IPN->main(); + $contribution = $this->callAPISuccess('contribution', 'get', array( + 'contribution_recur_id' => $this->_contributionRecurID, + 'sequential' => 1, + )); + $this->assertEquals(2, $contribution['count']); + $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); + $this->assertEquals('2010-07-01', date('Y-m-d', strtotime($contribution['values'][1]['receive_date']))); + } + + /** * Test IPN response updates contribution_recur & contribution for first & second contribution */ -- 2.25.1