$participant = CRM_Utils_Array::value('participant', $objects);
$memberships = CRM_Utils_Array::value('membership', $objects);
$recurContrib = CRM_Utils_Array::value('contributionRecur', $objects);
+ $recurringContributionID = (empty($recurContrib->id)) ? NULL : $recurContrib->id;
$event = CRM_Utils_Array::value('event', $objects);
$completedContributionStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
), array_intersect_key($input, array_fill_keys($inputContributionWhiteList, 1)
));
- if (!empty($recurContrib->id)) {
- $contributionParams['contribution_recur_id'] = $recurContrib->id;
+ if ($recurringContributionID) {
+ $contributionParams['contribution_recur_id'] = $recurringContributionID;
}
$changeDate = CRM_Utils_Array::value('trxn_date', $input, date('YmdHis'));
// Figure out what we gain from this.
CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values);
}
- elseif ($recurContrib && $recurContrib->id) {
+ elseif ($recurContrib && $recurringContributionID) {
$values['amount'] = $recurContrib->amount;
$values['financial_type_id'] = $objects['contributionType']->id;
$values['title'] = $source = ts('Offline Recurring Contribution');
$values['receipt_from_email'] = $domainValues[1];
}
- if ($recurContrib && $recurContrib->id && !isset($input['is_email_receipt'])) {
+ if ($recurContrib && $recurringContributionID && !isset($input['is_email_receipt'])) {
//CRM-13273 - is_email_receipt setting on recurring contribution should take precedence over contribution page setting
// but CRM-16124 if $input['is_email_receipt'] is set then that should not be overridden.
$values['is_email_receipt'] = $recurContrib->is_email_receipt;
CRM_Core_Error::debug_log_message("Contribution record updated successfully");
$transaction->commit();
- CRM_Contribute_BAO_ContributionRecur::updateRecurLinkedPledge($contribution);
+ CRM_Contribute_BAO_ContributionRecur::updateRecurLinkedPledge($contribution->id, $recurringContributionID,
+ $input['contribution_status_id'], $input['total_amount']);
// create an activity record
if ($input['component'] == 'contribute') {
* The pledge payment record should already exist & will need to be updated with the new contribution ID.
* If not the contribution will also need to be linked to the pledge
*
- * @param CRM_Contribute_BAO_Contribution $contribution
+ * @param int $contributionID
+ * @param int $contributionRecurID
+ * @param int $contributionStatusID
+ * @param float $contributionAmount
+ *
+ * @throws \CiviCRM_API3_Exception
*/
- public static function updateRecurLinkedPledge($contribution) {
+ public static function updateRecurLinkedPledge($contributionID, $contributionRecurID, $contributionStatusID, $contributionAmount) {
$returnProperties = array('id', 'pledge_id');
$paymentDetails = $paymentIDs = array();
- if (CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'contribution_id', $contribution->id,
+ if (CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'contribution_id', $contributionID,
$paymentDetails, $returnProperties
)
) {
else {
//payment is not already linked - if it is linked with a pledge we need to create a link.
// return if it is not recurring contribution
- if (!$contribution->contribution_recur_id) {
+ if (!$contributionRecurID) {
return;
}
$relatedContributions = new CRM_Contribute_DAO_Contribution();
- $relatedContributions->contribution_recur_id = $contribution->contribution_recur_id;
+ $relatedContributions->contribution_recur_id = $contributionRecurID;
$relatedContributions->find();
while ($relatedContributions->fetch()) {
// return now so we don't create a core error & roll back
return;
}
- $paymentDetails['contribution_id'] = $contribution->id;
- $paymentDetails['status_id'] = $contribution->contribution_status_id;
- $paymentDetails['actual_amount'] = $contribution->total_amount;
+ $paymentDetails['contribution_id'] = $contributionID;
+ $paymentDetails['status_id'] = $contributionStatusID;
+ $paymentDetails['actual_amount'] = $contributionAmount;
// put contribution against it
- $payment = CRM_Pledge_BAO_PledgePayment::add($paymentDetails);
- $paymentIDs[] = $payment->id;
+ $payment = civicrm_api3('PledgePayment', 'create', $paymentDetails);
+ $paymentIDs[] = $payment['id'];
}
// update pledge and corresponding payment statuses
- CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, $paymentIDs, $contribution->contribution_status_id,
- NULL, $contribution->total_amount
+ CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeId, $paymentIDs, $contributionStatusID,
+ NULL, $contributionAmount
);
}
'civicrm_participant',
'civicrm_participant_payment',
'civicrm_pledge',
+ 'civicrm_pledge_payment',
'civicrm_price_set_entity',
'civicrm_price_field_value',
'civicrm_price_field',
$this->assertEquals(date('Y-m-d 00:00:00', strtotime('+1 month')), $contributionRecur['next_sched_contribution_date']);
}
+ /**
+ * Test completing a pledge with the completeTransaction api..
+ *
+ * Note that we are creating a logged in user because email goes out from
+ * that person.
+ */
+ public function testCompleteTransactionUpdatePledgePayment() {
+ $mut = new CiviMailUtils($this, TRUE);
+ $mut->clearMessages();
+ $this->createLoggedInUser();
+ $contributionID = $this->createPendingPledgeContribution();
+ $this->callAPISuccess('contribution', 'completetransaction', array(
+ 'id' => $contributionID,
+ 'trxn_date' => '1 Feb 2013',
+ ));
+ $pledge = $this->callAPISuccessGetSingle('Pledge', array(
+ 'id' => $this->_ids['pledge'],
+ ));
+ $this->assertEquals('Completed', $pledge['pledge_status']);
+
+ $status = $this->callAPISuccessGetValue('PledgePayment', array(
+ 'pledge_id' => $this->_ids['pledge'],
+ 'return' => 'status_id',
+ ));
+ $this->assertEquals(1, $status);
+ $mut->checkMailLog(array(
+ '$ 500.00',
+ 'May 11th, 2012 12:00 AM',
+ ));
+ $mut->stop();
+ }
+
/**
* Test completing a transaction with an event via the API.
*
}
}
+ /**
+ * Create a pending contribution & linked pending pledge record.
+ */
+ public function createPendingPledgeContribution() {
+
+ $pledgeID = $this->pledgeCreate(array('contact_id' => $this->_individualId, 'installments' => 1, 'amount' => 500));
+ $this->_ids['pledge'] = $pledgeID;
+ $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array(
+ 'contribution_status_id' => 'Pending',
+ 'total_amount' => 500,
+ ))
+ );
+ $paymentID = $this->callAPISuccessGetValue('PledgePayment', array(
+ 'options' => array('limit' => 1),
+ 'return' => 'id',
+ ));
+ $this->callAPISuccess('PledgePayment', 'create', array(
+ 'id' => $paymentID,
+ 'contribution_id' =>
+ $contribution['id'],
+ 'status_id' => 'Pending',
+ 'scheduled_amount' => 500,
+ ));
+
+ return $contribution['id'];
+ }
+
/**
* Create a pending contribution & linked pending participant record (along with an event).
*/
<import>true</import>
<export>false</export>
<type>int unsigned</type>
+ <pseudoconstant>
+ <optionGroupName>contribution_status</optionGroupName>
+ </pseudoconstant>
<comment>Implicit foreign key to civicrm_option_values in the contribution_status option group.</comment>
<add>2.1</add>
</field>
<export>false</export>
<type>int unsigned</type>
<add>2.1</add>
+ <pseudoconstant>
+ <optionGroupName>contribution_status</optionGroupName>
+ </pseudoconstant>
</field>
<index>
<name>index_status</name>