CRM-17718 update repeattransaction to accept contribution_recur_id instead of origina...
authoreileenmcnaughton <eileen@fuzion.co.nz>
Wed, 16 Dec 2015 16:25:37 +0000 (16:25 +0000)
committereileenmcnaugton <eileen@fuzion.co.nz>
Sun, 14 Feb 2016 22:52:38 +0000 (11:52 +1300)
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
tests/phpunit/api/v3/ContributionTest.php

index 19a915db42c3a3221d19e588e8c19636ae3b233a..d90b4623fb1d7de5f61a40d44ca3401fa7db1330 100644 (file)
@@ -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',
index 9df3baf52b129f72b8448cfb8427895e77bb1a08..4829ea110a4e382fe057447f07b429cc45a207d3 100644 (file)
@@ -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();