From 5d484a2548f54a4d61ec2a02ec70e77070c69d7c Mon Sep 17 00:00:00 2001 From: eileenmcnaughton Date: Wed, 16 Dec 2015 16:25:37 +0000 Subject: [PATCH] CRM-17718 update repeattransaction to accept contribution_recur_id instead of original_contribution_id wq I feel like passing in the contribution_recur_id actually makes more sense - the internals of which contribution is repeated should be 'core business' & consistent across processors. Importantly it has been set here to repeat the latest rather than the earliest which is not as good as saving such things as line items against the recurring transaction but better than using the earliest - ie. pick up changes over time Conflicts: tests/phpunit/api/v3/ContributionTest.php --- api/v3/Contribution.php | 14 +++++++- tests/phpunit/api/v3/ContributionTest.php | 42 +++++++++++++++++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 19a915db42..d90b4623fb 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -483,6 +483,14 @@ function _civicrm_api3_contribution_completetransaction_spec(&$params) { */ function civicrm_api3_contribution_repeattransaction(&$params) { $input = $ids = array(); + civicrm_api3_verify_one_mandatory($params, NULL, array('contribution_recur_id', 'original_contribution_id')); + if (empty($params['original_contribution_id'])) { + $params['original_contribution_id'] = civicrm_api3('contribution', 'getvalue', array( + 'return' => 'id', + 'contribution_recur_id' => $params['contribution_recur_id'], + 'options' => array('limit' => 1, 'sort' => 'id DESC'), + )); + } $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $params['original_contribution_id']; if (!$contribution->find(TRUE)) { @@ -565,8 +573,12 @@ function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstC function _civicrm_api3_contribution_repeattransaction_spec(&$params) { $params['original_contribution_id'] = array( 'title' => 'Original Contribution ID', + 'description' => 'Contribution ID to copy (will be calculated from recurring contribution if not provided)', + 'type' => CRM_Utils_Type::T_INT, + ); + $params['contribution_recur_id'] = array( + 'title' => 'Recurring contribution ID', 'type' => CRM_Utils_Type::T_INT, - 'api.required' => TRUE, ); $params['trxn_id'] = array( 'title' => 'Transaction ID', diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 9df3baf52b..4829ea110a 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -49,6 +49,12 @@ class api_v3_ContributionTest extends CiviUnitTestCase { protected $_params; protected $_ids = array(); protected $_pageParams = array(); + /** + * Payment processor ID (dummy processor). + * + * @var int + */ + protected $paymentProcessorID; /** * Parameters to create payment processor. @@ -72,7 +78,6 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->_apiversion = 3; $this->_individualId = $this->individualCreate(); - $paymentProcessor = $this->processorCreate(); $this->_params = array( 'contact_id' => $this->_individualId, 'receive_date' => '20120511', @@ -95,12 +100,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'url_recur' => 'http://dummy.com', 'billing_mode' => 1, ); + $this->processor = $this->processorCreate(); + $this->paymentProcessorID = $this->processor->id; $this->_pageParams = array( 'title' => 'Test Contribution Page', 'financial_type_id' => 1, 'currency' => 'USD', 'financial_account_id' => 1, - 'payment_processor' => $paymentProcessor->id, + 'payment_processor' => $this->paymentProcessorID, 'is_active' => 1, 'is_allow_other_amount' => 1, 'min_amount' => 10, @@ -1413,6 +1420,35 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->quickCleanUpFinancialEntities(); } + /** + * Test repeat contribution accepts recur_id instead of original_contribution_id. + */ + public function testRepeatTransactionAcceptRecurID() { + $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array( + 'contact_id' => $this->_individualId, + 'installments' => '12', + 'frequency_interval' => '1', + 'amount' => '100', + 'contribution_status_id' => 1, + 'start_date' => '2012-01-01 00:00:00', + 'currency' => 'USD', + 'frequency_unit' => 'month', + 'payment_processor_id' => $this->paymentProcessorID, + )); + $this->callAPISuccess('contribution', 'create', array_merge( + $this->_params, + array('contribution_recur_id' => $contributionRecur['id'])) + ); + + $this->callAPISuccess('contribution', 'repeattransaction', array( + 'contribution_recur_id' => $contributionRecur['id'], + 'contribution_status_id' => 'Completed', + 'trxn_id' => uniqid(), + )); + + $this->quickCleanUpFinancialEntities(); + } + /** * CRM-16397 test appropriate action if total amount has changed for single line items. */ @@ -1482,7 +1518,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } /** - * CRM-16397 test appropriate action if total amount has changed for single line items. + * CRM-16397 test appropriate action if campaign has been passed in. */ public function testRepeatTransactionPassedInCampaign() { $paymentProcessorID = $this->paymentProcessorCreate(); -- 2.25.1