* Input as delivered from Payment Processor.
* @param array $ids
* Ids as Loaded by Payment Processor.
- * @param bool $required
- * Is Payment processor / contribution page required.
* @param bool $loadAll
* Load all related objects - even where id not passed in? (allows API to call this).
*
* @return bool
* @throws Exception
*/
- public function loadRelatedObjects(&$input, &$ids, $required = FALSE, $loadAll = FALSE) {
+ public function loadRelatedObjects(&$input, &$ids, $loadAll = FALSE) {
if ($loadAll) {
$ids = array_merge($this->getComponentDetails($this->id), $ids);
if (empty($ids['contact']) && isset($this->contact_id)) {
}
}
}
-
- if (!$paymentProcessorID) {
- //fail to load payment processor id.
- // this seems a bit dubious....
- if (empty($ids['pledge_payment'])) {
- $loadObjectSuccess = TRUE;
- if ($required) {
- throw new Exception("Could not find contribution page for contribution record: " . $this->id);
- }
- return $loadObjectSuccess;
- }
- }
}
else {
// we are in event mode
$ids['paymentProcessor'] = $paymentProcessorID;
$this->_relatedObjects['paymentProcessor'] = $paymentProcessor;
}
- elseif ($required) {
- throw new Exception("Could not find payment processor for contribution record: " . $this->id);
- }
-
return TRUE;
}
throw new Exception('Contribution does not exist');
}
$input = $ids = $cvalues = array('receipt_from_email' => $params['receipt_from_email']);
- $contribution->loadRelatedObjects($input, $ids, FALSE, TRUE);
+ $contribution->loadRelatedObjects($input, $ids, TRUE);
$contribution->composeMessageArray($input, $ids, $cvalues, FALSE, FALSE);
}
throw new API_Exception('A valid contribution ID is required', 'invalid_data');
}
- if (!$contribution->loadRelatedObjects($input, $ids, FALSE, TRUE)) {
+ if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
throw new API_Exception('failed to load related objects');
}
elseif ($contribution->contribution_status_id == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
}
$original_contribution = clone $contribution;
try {
- if (!$contribution->loadRelatedObjects($input, $ids, FALSE, TRUE)) {
+ if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
throw new API_Exception('failed to load related objects');
}
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->find(TRUE);
- $contribution->loadRelatedObjects($this->input, $this->ids, FALSE, TRUE);
+ $contribution->loadRelatedObjects($this->input, $this->ids, TRUE);
$this->assertFalse(empty($contribution->_relatedObjects['membership']));
$this->assertArrayHasKey($this->_membershipTypeID, $contribution->_relatedObjects['membership']);
$this->assertTrue(is_a($contribution->_relatedObjects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
*/
public function testRequiredWithoutProcessorID() {
$this->_setUpPledgeObjects();
- $values = array();
$result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
$this->assertArrayHasKey('error_message', $result);
$this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
}
/**
- *
* Test that an error is not if required set & no processor ID
*/
public function testRequiredWithContributionPage() {
$this->_setUpContributionObjects(TRUE);
$result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
- $this->assertFalse(is_array($result), $result['error_message']);
+ $this->assertEquals(1, $result['is_error']);
+ ;
+ }
+
+ /**
+ * Test that if part of $input the payment processor loads OK.
+ *
+ * It's preferable to pass it in as it cannot be correctly calculated.
+ */
+ public function testPaymentProcessorLoadsAsParam() {
+ $this->_setUpContributionObjects();
+ $this->input = array_merge($this->input, array('payment_processor_id' => $this->_processorId));
+ $this->assertTrue($this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1)));
}
/**
$this->_setUpContributionObjects();
$result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL, array('return_error' => 1));
$this->assertArrayHasKey('error_message', $result);
- $this->assertEquals('Could not find contribution page for contribution record: 1', $result['error_message']);
+ $this->assertEquals('Could not find payment processor for contribution record: 1', $result['error_message']);
// error is only returned if $required set to True
$result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL, array('return_error' => 1));
$this->assertFalse(is_array($result));