*/
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)) {
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',
protected $_params;
protected $_ids = array();
protected $_pageParams = array();
+ /**
+ * Payment processor ID (dummy processor).
+ *
+ * @var int
+ */
+ protected $paymentProcessorID;
/**
* Parameters to create payment processor.
'url_recur' => 'http://dummy.com',
'billing_mode' => 1,
);
+ $this->paymentProcessorID = $this->processorCreate();
$this->_pageParams = array(
'title' => 'Test Contribution Page',
'financial_type_id' => 1,
'currency' => 'USD',
'financial_account_id' => 1,
- 'payment_processor' => $this->processorCreate(),
+ 'payment_processor' => $this->paymentProcessorID,
'is_active' => 1,
'is_allow_other_amount' => 1,
'min_amount' => 10,
$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.
*/
}
/**
- * 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();