*/
public $_ppID;
- /**
- * The id of the pledge that we are processing.
- *
- * @var int
- */
- public $_pledgeID;
-
/**
* Is this contribution associated with an online.
* financial transaction
// Get the submitted form values.
$submittedValues = $this->controller->exportValues($this->_name);
- $contribution = $this->submit($submittedValues, $this->_action);
+ $contribution = $this->submit($submittedValues, $this->_action, $this->_ppID);
$session = CRM_Core_Session::singleton();
$buttonName = $this->controller->getButtonName();
if ($this->_context == 'standalone') {
*
* @throws CRM_Core_Exception
*/
- protected function processCreditCard($submittedValues, $lineItem) {
+ protected function processCreditCard($submittedValues, $lineItem, $pledgePaymentID) {
$sendReceipt = $contribution = FALSE;
$unsetParams = array(
// Store contribution id in payment record.
CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_ppID, 'contribution_id', $contribution->id);
- CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($this->_pledgeID,
+ CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID,
array($this->_ppID),
$contribution->contribution_status_id,
NULL,
'cancel_date_time' => '',
);
- $this->submit(array_merge($defaults, $params), $action);
+ $this->submit(array_merge($defaults, $params), $action, CRM_Utils_Array::value('pledge_payment_id', $params));
}
/**
* @return array
* @throws \Exception
*/
- protected function submit($submittedValues, $action) {
+ protected function submit($submittedValues, $action, $pledgePaymentID) {
$softParams = $softIDs = array();
$pId = $contribution = $isRelatedId = FALSE;
if (!empty($submittedValues['price_set_id']) && $action & CRM_Core_Action::UPDATE) {
// Credit Card Contribution.
if ($this->_mode) {
- $this->processCreditCard($submittedValues, $lineItem);
+ $this->processCreditCard($submittedValues, $lineItem, $pledgePaymentID);
return FALSE;
}
else {
);
//update pledge payment status.
- if ((($this->_ppID && $contribution->id) && $action & CRM_Core_Action::ADD) ||
+ if ((($pledgePaymentID && $contribution->id) && $action & CRM_Core_Action::ADD) ||
(($pledgePaymentId) && $action & CRM_Core_Action::UPDATE)
) {
- if ($this->_ppID) {
+ if ($pledgePaymentID) {
//store contribution id in payment record.
- CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_ppID, 'contribution_id', $contribution->id);
+ CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentID, 'contribution_id', $contribution->id);
}
else {
- $this->_ppID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
+ $pledgePaymentID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
$contribution->id,
'id',
'contribution_id'
);
- $this->_pledgeID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
- $contribution->id,
- 'pledge_id',
- 'contribution_id'
- );
}
+ $pledgeID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
+ $contribution->id,
+ 'pledge_id',
+ 'contribution_id'
+ );
$adjustTotalAmount = FALSE;
if (CRM_Utils_Array::value('option_type', $formValues) == 2) {
}
if ($updatePledgePaymentStatus) {
- CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($this->_pledgeID,
- array($this->_ppID),
+ CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID,
+ array($pledgePaymentID),
$contribution->contribution_status_id,
NULL,
$contribution->total_amount,
'receive_date_time' => '11:27PM',
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
- ));
+ ),
+ CRM_Core_Action::ADD);
$this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
}
'receive_date_time' => '11:27PM',
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
- ));
+ ), CRM_Core_Action::ADD);
$this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
}
'contact_id' => $this->_individualId,
'is_email_receipt' => TRUE,
'from_email_address' => 'test@test.com',
- ));
+ ), CRM_Core_Action::ADD);
$this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
$mut->checkMailLog(array(
'<p>Please print this receipt for your records.</p>',
$mut->stop();
}
+ /**
+ * Test that a contribution is assigned against a pledge.
+ */
+ public function testUpdatePledge() {
+ $pledge = $this->callAPISuccess('pledge', 'create', array(
+ 'contact_id' => $this->_individualId,
+ 'pledge_create_date' => date('Ymd'),
+ 'start_date' => date('Ymd'),
+ 'amount' => 100.00,
+ 'pledge_status_id' => '2',
+ 'pledge_financial_type_id' => '1',
+ 'pledge_original_installment_amount' => 20,
+ 'frequency_interval' => 5,
+ 'frequency_unit' => 'year',
+ 'frequency_day' => 15,
+ 'installments' => 2,
+ 'sequential' => 1,
+ ));
+ $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', array(
+ 'pledge_id' => $pledge['id'],
+ 'options' => array('limit' => 1),
+ 'return' => 'id',
+ ));
+ $form = new CRM_Contribute_Form_Contribution();
+ $form->testSubmit(array(
+ 'total_amount' => 50,
+ 'financial_type_id' => 1,
+ 'receive_date' => '04/21/2015',
+ 'receive_date_time' => '11:27PM',
+ 'contact_id' => $this->_individualId,
+ 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
+ 'pledge_payment_id' => $pledgePaymentID,
+ ), CRM_Core_Action::ADD);
+ $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', array('id' => $pledgePaymentID));
+ $this->assertNotEmpty($pledgePayment['contribution_id']);
+ $this->assertEquals($pledgePayment['actual_amount'], 50);
+ $this->assertEquals(1, $pledgePayment['status_id']);
+ }
}