$this->_component = strtolower(CRM_Utils_Array::value('component', $input, 'contribute'));
}
}
- $paymentProcessorID = CRM_Utils_Array::value('paymentProcessor', $ids);
- $contributionType = new CRM_Financial_BAO_FinancialType();
- $contributionType->id = $this->financial_type_id;
- $contributionType->find(TRUE);
- if (!empty($ids['contact'])) {
- $this->_relatedObjects['contact'] = new CRM_Contact_BAO_Contact();
- $this->_relatedObjects['contact']->id = $ids['contact'];
- $this->_relatedObjects['contact']->find(TRUE);
+ // If the object is not fully populated then make sure it is - this is a more about legacy paths & cautious
+ // refactoring than anything else, and has unit test coverage.
+ if (empty($this->financial_type_id)) {
+ $this->find(TRUE);
+ }
+
+ $paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $input, CRM_Utils_Array::value(
+ 'paymentProcessor',
+ $ids
+ ));
+
+ if (!$paymentProcessorID && $this->contribution_page_id) {
+ $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
+ $this->contribution_page_id,
+ 'payment_processor'
+ );
+ if ($paymentProcessorID) {
+ $intentionalEnotice = $CRM16923AnUnreliableMethodHasBeenUserToDeterminePaymentProcessorFromContributionPage;
+ }
+ }
+
+
+ $ids['contributionType'] = $this->financial_type_id;
+ $ids['financialType'] = $this->financial_type_id;
+
+ $entities = array(
+ 'contact' => 'CRM_Contact_BAO_Contact',
+ 'contributionRecur' => 'CRM_Contribute_BAO_ContributionRecur',
+ 'contributionType' => 'CRM_Financial_BAO_FinancialType',
+ 'financialType' => 'CRM_Financial_BAO_FinancialType',
+ );
+ foreach ($entities as $entity => $bao) {
+ if (!empty($ids[$entity])) {
+ $this->_relatedObjects[$entity] = new $bao();
+ $this->_relatedObjects[$entity]->id = $ids[$entity];
+ if (!$this->_relatedObjects[$entity]->find(TRUE)) {
+ throw new CRM_Core_Exception($entity . ' could not be loaded');
+ }
+ }
+ }
+
+ if (!empty($ids['contributionRecur']) && !$paymentProcessorID) {
+ $paymentProcessorID = $this->_relatedObjects['contributionRecur']->payment_processor_id;
+ }
+
+ if (!empty($ids['pledge_payment'])) {
+ foreach ($ids['pledge_payment'] as $key => $paymentID) {
+ if (empty($paymentID)) {
+ continue;
+ }
+ $payment = new CRM_Pledge_BAO_PledgePayment();
+ $payment->id = $paymentID;
+ if (!$payment->find(TRUE)) {
+ throw new Exception("Could not find pledge payment record: " . $paymentID);
+ }
+ $this->_relatedObjects['pledge_payment'][] = $payment;
+ }
}
- $this->_relatedObjects['contributionType'] = $contributionType;
if ($this->_component == 'contribute') {
// retrieve the other optional objects first so
}
}
- if (!empty($ids['pledge_payment'])) {
-
- foreach ($ids['pledge_payment'] as $key => $paymentID) {
- if (empty($paymentID)) {
- continue;
- }
- $payment = new CRM_Pledge_BAO_PledgePayment();
- $payment->id = $paymentID;
- if (!$payment->find(TRUE)) {
- throw new Exception("Could not find pledge payment record: " . $paymentID);
- }
- $this->_relatedObjects['pledge_payment'][] = $payment;
- }
- }
-
- if (!empty($ids['contributionRecur'])) {
- $recur = new CRM_Contribute_BAO_ContributionRecur();
- $recur->id = $ids['contributionRecur'];
- if (!$recur->find(TRUE)) {
- throw new Exception("Could not find recur record: " . $ids['contributionRecur']);
- }
- $this->_relatedObjects['contributionRecur'] = &$recur;
- //get payment processor id from recur object.
- $paymentProcessorID = $recur->payment_processor_id;
- }
- //for normal contribution get the payment processor id.
if (!$paymentProcessorID) {
- if ($this->contribution_page_id) {
- // get the payment processor id from contribution page
- $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage',
- $this->contribution_page_id,
- 'payment_processor'
- );
- }
//fail to load payment processor id.
- elseif (empty($ids['pledge_payment'])) {
+ // 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);
$this->_relatedObjects['participant'] = &$participant;
+ // get the payment processor id from event - this is inaccurate see CRM-16923
+ // in future we should look at throwing an exception here rather than an dubious guess.
if (!$paymentProcessorID) {
$paymentProcessorID = $this->_relatedObjects['event']->payment_processor;
+ if ($paymentProcessorID) {
+ $intentionalEnotice = $CRM16923AnUnreliableMethodHasBeenUserToDeterminePaymentProcessorFromEvent;
+ }
}
}
if (!empty($lineItem)) {
$itemId = key($lineItem);
foreach ($lineItem as &$eachItem) {
- if (array_key_exists($eachItem['membership_type_id'], $this->_relatedObjects['membership'])) {
+ if (is_array($this->_relatedObjects['membership']) && array_key_exists($eachItem['membership_type_id'], $this->_relatedObjects['membership'])) {
$eachItem['join_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->join_date);
$eachItem['start_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->start_date);
$eachItem['end_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->end_date);
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
*/
/**
class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_ContributionPage {
/**
- * Takes an associative array and creates a contribution page object.
+ * Creates a contribution page.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
*
* @return CRM_Contribute_DAO_ContributionPage
*/
- public static function &create(&$params) {
+ public static function create($params) {
$financialTypeId = NULL;
if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
$financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
}
+
+ if (isset($params['payment_processor']) && is_array($params['payment_processor'])) {
+ $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']);
+ }
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params);
$dao = new CRM_Contribute_DAO_ContributionPage();
/**
* Update the is_active flag in the db.
*
+ * @deprecated - this bypasses hooks.
+ *
* @param int $id
* Id of the database record.
* @param bool $is_active
}
/**
+ * Load values for a contribution page.
+ *
* @param int $id
- * @param $values
+ * @param array $values
*/
public static function setValues($id, &$values) {
$params = array(
else {
$values['custom_post_id'] = '';
}
- // // add an accounting code also
- // if ($values ['financial_type_id']) {
- // $values ['accountingCode'] = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_FinancialType', $values ['financial_type_id'], 'accounting_code' );
- // }
}
/**
* @param bool $returnMessageText
* Return the message text instead of sending the mail.
*
- * @param null $fieldTypes
- *
- * @return void
+ * @param array $fieldTypes
*/
public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) {
$gIds = $params = array();
*/
public static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) {
$value = array();
+ $isEmailReceipt = FALSE;
if ($pageID) {
CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array(
'title',
* @param array $params
* Params to build component whereclause.
*
- * @param null $fieldTypes
- *
- * @return void
+ * @param array $fieldTypes
*/
- public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = NULL) {
+ public static function buildCustomDisplay($gid, $name, $cid, &$template, &$params, $fieldTypes = array()) {
if ($gid) {
if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) {
$values = array();
}
/**
- * make a copy of a contribution page, including
- * all the blocks in the page
+ * Make a copy of a contribution page, including all the blocks in the page.
*
* @param int $id
* The contribution page id to copy.
$premiumDao = CRM_Core_DAO::executeQuery($premiumQuery, CRM_Core_DAO::$_nullArray);
while ($premiumDao->fetch()) {
if ($premiumDao->id) {
- $copyPremiumProduct = &CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
+ CRM_Core_DAO::copyGeneric('CRM_Contribute_DAO_PremiumsProduct', array(
'premiums_id' => $premiumDao->id,
), array(
'premiums_id' => $copyPremium->id,
return $copy;
}
- /**
- * Check if contribution page contains payment
- * processor that supports recurring payment
- *
- * @param int $contributionPageId
- * Contribution Page Id.
- *
- * @return bool
- * true if payment processor supports recurring
- * else false
- *
- */
- public static function checkRecurPaymentProcessor($contributionPageId) {
- //FIXME
- $sql = "
- SELECT pp.is_recur
- FROM civicrm_contribution_page cp,
- civicrm_payment_processor pp
- WHERE cp.payment_processor = pp.id
- AND cp.id = {$contributionPageId}
-";
-
- if ($recurring = &CRM_Core_DAO::singleValueQuery($sql, CRM_Core_DAO::$_nullArray)) {
- return TRUE;
- }
- return FALSE;
- }
-
/**
* Get info for all sections enable/disable.
*
}
/**
- * Generate html for pdf in confirmation receipt email attachment.
+ * Generate html for pdf in confirmation receipt email attachment.
+ *
* @param int $contributionId
* Contribution Page Id.
* @param int $userID
* = error or success, unless it is a recurring contribution in which case it is pending.
*/
if ($result['payment_status_id'] == array_search('Completed', $statuses)) {
- civicrm_api3('contribution', 'completetransaction', array('id' => $contribution->id, 'trxn_id' => $result['trxn_id']));
+ try {
+ civicrm_api3('contribution', 'completetransaction', array(
+ 'id' => $contribution->id,
+ 'trxn_id' => $result['trxn_id'],
+ 'payment_processor_id' => $this->_paymentProcessor['id'],
+ 'is_transactional' => FALSE,
+ ));
+ // This has now been set to 1 in the DB - declare it here also
+ $contribution->contribution_status_id = 1;
+ }
+ catch (CiviCRM_API3_Exception $e) {
+ if ($e->getErrorCode() != 'contribution_completed') {
+ throw new CRM_Core_Exception('Failed to update contribution in database');
+ }
+ }
}
else {
// Save the trxn_id.
'id' => $paymentResult['contribution']->id,
'trxn_id' => $paymentResult['contribution']->trxn_id,
'is_transactional' => FALSE,
+ 'payment_processor_id' => $form->_paymentProcessor['id'],
));
}
catch (CiviCRM_API3_Exception $e) {
civicrm_api3('contribution', 'completetransaction', array(
'id' => $result['contribution']->id,
'trxn_id' => CRM_Utils_Array::value('trxn_id', $result),
+ 'payment_processor_id' => $this->_paymentProcessor['id'],
)
);
}
}
elseif ($memType['is_active']) {
$javascriptMethod = NULL;
- $allowAutoRenewOpt = 1;
+ $allowAutoRenewOpt = (int) $memType['auto_renew'];
if (is_array($this->_paymentProcessors)) {
foreach ($this->_paymentProcessors as $id => $val) {
if (!$val['is_recur']) {
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
*/
class CRM_Core_Payment_AuthorizeNetIPN extends CRM_Core_Payment_BaseIPN {
// load post ids in $ids
$this->getIDs($ids, $input);
- $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
+ // This is an unreliable method as there could be more than one instance.
+ // Recommended approach is to use the civicrm/payment/ipn/xx url where xx is the payment
+ // processor id & the handleNotification function (which should call the completetransaction api & by-pass this
+ // entirely). The only thing the IPN class should really do is extract data from the request, validate it
+ // & call completetransaction or call fail? (which may not exist yet).
+ $paymentProcessorTypeID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
'AuthNet', 'id', 'name'
);
+ $paymentProcessorID = (int) civicrm_api3('PaymentProcessor', 'getvalue', array(
+ 'is_test' => 0,
+ 'options' => array('limit' => 1),
+ 'payment_processor_type_id' => $paymentProcessorTypeID,
+ 'return' => 'id',
+ ));
if (!$this->validateData($input, $ids, $objects, TRUE, $paymentProcessorID)) {
return FALSE;
}
}
- $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
+ // This is an unreliable method as there could be more than one instance.
+ // Recommended approach is to use the civicrm/payment/ipn/xx url where xx is the payment
+ // processor id & the handleNotification function (which should call the completetransaction api & by-pass this
+ // entirely). The only thing the IPN class should really do is extract data from the request, validate it
+ // & call completetransaction or call fail? (which may not exist yet).
+ $paymentProcessorTypeID = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessorType',
'PayPal', 'id', 'name'
);
+ $paymentProcessorID = (int) civicrm_api3('PaymentProcessor', 'getvalue', array(
+ 'is_test' => 0,
+ 'options' => array('limit' => 1),
+ 'payment_processor_type_id' => $paymentProcessorTypeID,
+ 'return' => 'id',
+ ));
if (!$this->validateData($input, $ids, $objects, TRUE, $paymentProcessorID)) {
return FALSE;
function civicrm_api3_contribution_completetransaction(&$params) {
$input = $ids = array();
+ if (isset($params['payment_processor_id'])) {
+ $input['payment_processor_id'] = $params['payment_processor_id'];
+ }
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $params['id'];
$contribution->find(TRUE);
if (!$contribution->id == $params['id']) {
throw new API_Exception('A valid contribution ID is required', 'invalid_data');
}
- try {
- if (!$contribution->loadRelatedObjects($input, $ids, FALSE, TRUE)) {
- throw new API_Exception('failed to load related objects');
- }
- elseif ($contribution->contribution_status_id == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
- throw new API_Exception(ts('Contribution already completed'));
- }
- $input['trxn_id'] = !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id;
- $params = _ipn_process_transaction($params, $contribution, $input, $ids);
+
+ if (!$contribution->loadRelatedObjects($input, $ids, FALSE, TRUE)) {
+ throw new API_Exception('failed to load related objects');
}
- catch(Exception $e) {
- throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
+ elseif ($contribution->contribution_status_id == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
+ throw new API_Exception(ts('Contribution already completed'), 'contribution_completed');
}
+ $input['trxn_id'] = !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id;
+ $params = _ipn_process_transaction($params, $contribution, $input, $ids);
+
}
/**
'description' => '. If not provided this will default to domain mail or contribution page',
'type' => CRM_Utils_Type::T_STRING,
);
+
+ $params['payment_processor_id'] = array(
+ 'title' => 'Payment processor ID',
+ 'description' => '. Providing this is strongly recommended, as not possible to calculate it accurately always',
+ 'type' => CRM_Utils_Type::T_INT,
+ );
}
/**
'selectMembership' => array(
'0' => 1,
),
- 'payment_processor' => 1,
+ 'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
'credit_card_exp_date' => array(
/*
* This example has been generated from the API test suite.
-* The test that created it is called "testLegacySubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed"
+* The test that created it is called "testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed"
* and can be found at:
* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionPageTest.php
*
ContributionPage::delete($copycontributionpage->id);
}
- /**
- * Test checkRecurPaymentProcessor() method
- */
- public function testcheckRecurPaymentProcessor() {
- //@todo paypalpro create seems to fail silently without causing this class to fail
- // $this->paymentProcessorCreate may be a better option
- $paymentProcessor = PaypalPro::create();
- $params = array(
- 'title' => 'Test Contribution Page',
- 'financial_type_id' => $this->_financialTypeID,
- 'is_active' => 1,
- 'payment_processor_id' => $paymentProcessor,
- );
-
- $contributionpage = CRM_Contribute_BAO_ContributionPage::create($params);
- $id = $contributionpage->id;
- $checkRecurring = CRM_Contribute_BAO_ContributionPage::checkRecurPaymentProcessor($id);
- $this->assertEquals($checkRecurring, FALSE, 'Check for false return.');
- ContributionPage::delete($contributionpage->id);
- }
-
}
*/
public function testIPNPaymentRecurSuccess() {
$this->setupRecurringPaymentProcessorTransaction();
- $paypalIPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
- $paypalIPN->main();
+ $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
+ $IPN->main();
$contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('6511143069', $contribution['trxn_id']);
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
$contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
- $paypalIPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction());
- $paypalIPN->main();
+ $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction());
+ $IPN->main();
$contribution = $this->callAPISuccess('contribution', 'get', array(
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
*/
public function testIPNPaymentMembershipRecurSuccess() {
$this->setupMembershipRecurringPaymentProcessorTransaction();
- $paypalIPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
- $paypalIPN->main();
+ $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction());
+ $IPN->main();
$contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
$this->assertEquals(1, $contribution['contribution_status_id']);
$this->assertEquals('6511143069', $contribution['trxn_id']);
$this->assertTrue(substr($contribution['contribution_source'], 0, 20) == "Online Contribution:");
$contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
- $paypalIPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction());
- $paypalIPN->main();
+ $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurSubsequentTransaction());
+ $IPN->main();
$contribution = $this->callAPISuccess('contribution', 'get', array(
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
*/
class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
- protected $_contributionTypeId;
+ protected $_financialTypeId;
protected $_contributionParams;
protected $_contactId;
protected $_contributionId;
public function setUp() {
parent::setUp();
- $this->_processorId = $this->paymentProcessorAuthorizeNetCreate();
+ $this->_processorId = $this->paymentProcessorAuthorizeNetCreate(array('is_test' => 0));
$this->input = $this->ids = $this->objects = array();
$this->IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->input);
$this->_contactId = $this->individualCreate();
$this->ids['contact'] = $this->_contactId;
- $this->_contributionTypeId = 1;
+ $this->_financialTypeId = 1;
$this->_contributionParams = array(
'contact_id' => $this->_contactId,
'version' => 3,
- 'financial_type_id' => $this->_contributionTypeId,
+ 'financial_type_id' => $this->_financialTypeId,
'receive_date' => date('Ymd'),
'total_amount' => 150.00,
'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885',
'currency' => 'USD',
'contribution_recur_id' => $this->_recurId,
- 'is_test' => 1,
'contribution_status_id' => 2,
);
- $contribution = civicrm_api('contribution', 'create', $this->_contributionParams);
- $this->assertAPISuccess($contribution, ' set-up of contribution ');
+ $contribution = $this->callAPISuccess('contribution', 'create', $this->_contributionParams);
$this->_contributionId = $contribution['id'];
$contribution = new CRM_Contribute_BAO_Contribution();
$this->assertFalse(empty($this->objects['membership']));
$this->assertArrayHasKey($this->_membershipTypeID, $this->objects['membership']);
$this->assertTrue(is_a($this->objects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
- $this->assertTrue(is_a($this->objects['contributionType'], 'CRM_Financial_BAO_FinancialType'));
+ $this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
$this->assertFalse(empty($this->objects['contributionRecur']));
$this->assertFalse(empty($this->objects['paymentProcessor']));
}
$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'));
- $this->assertTrue(is_a($contribution->_relatedObjects['contributionType'], 'CRM_Financial_BAO_FinancialType'));
+ $this->assertTrue(is_a($contribution->_relatedObjects['financialType'], 'CRM_Financial_BAO_FinancialType'));
$this->assertFalse(empty($contribution->_relatedObjects['contributionRecur']));
$this->assertFalse(empty($contribution->_relatedObjects['paymentProcessor']));
}
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertFalse(empty($this->objects['participant']));
$this->assertTrue(is_a($this->objects['participant'], 'CRM_Event_BAO_Participant'));
- $this->assertTrue(is_a($this->objects['contributionType'], 'CRM_Financial_BAO_FinancialType'));
+ $this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
$this->assertFalse(empty($this->objects['event']));
$this->assertTrue(is_a($this->objects['event'], 'CRM_Event_BAO_Event'));
$this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution'));
$this->_setUpPledgeObjects();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertFalse(empty($this->objects['pledge_payment'][0]));
- $this->assertTrue(is_a($this->objects['contributionType'], 'CRM_Financial_BAO_FinancialType'));
+ $this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
$this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution'));
$this->assertTrue(is_a($this->objects['pledge_payment'][0], 'CRM_Pledge_BAO_PledgePayment'));
$this->assertFalse(empty($this->objects['pledge_payment'][0]->id));
- $this->assertEquals($this->_contributionTypeId, $this->objects['contributionType']->id);
+ $this->assertEquals($this->_financialTypeId, $this->objects['financialType']->id);
$this->assertEquals($this->_processorId, $this->objects['paymentProcessor']['id']);
$this->assertEquals($this->_contributionId, $this->objects['contribution']->id);
$this->assertEquals($this->_contactId, $this->objects['contact']->id);
$this->_membershipId = $membership['id'];
//we'll create membership payment here because to make setup more re-usable
- civicrm_api('membership_payment', 'create', array(
- 'version' => 3,
+ $this->callAPISuccess('membership_payment', 'create', array(
'contribution_id' => $this->_contributionId,
'membership_id' => $this->_membershipId,
));
'create_date' => date('Ymd'),
'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885',
'contribution_status_id' => 2,
- 'is_test' => 1,
- 'financial_type_id' => $this->_contributionTypeId,
+ 'financial_type_id' => $this->_financialTypeId,
'version' => 3,
'payment_processor_id' => $this->_processorId,
);
- $this->_recurId = civicrm_api('contribution_recur', 'create', $this->_contributionRecurParams);
- $this->assertAPISuccess($this->_recurId, 'line ' . __LINE__ . ' set-up of recurring contrib');
+ $this->_recurId = $this->callAPISuccess('contribution_recur', 'create', $this->_contributionRecurParams);
$this->_recurId = $this->_recurId['id'];
$this->input['contributionRecurId'] = $this->_recurId;
$this->ids['contributionRecur'] = $this->_recurId;
*/
public function _setUpParticipantObjects() {
$event = $this->eventCreate(array('is_email_confirm' => 1));
- $this->assertAPISuccess($event, 'line ' . __LINE__ . ' set-up of event');
+
$this->_eventId = $event['id'];
$this->_participantId = $this->participantCreate(array(
'event_id' => $this->_eventId,
'contact_id' => $this->_contactId,
));
//we'll create membership payment here because to make setup more re-usable
- $participantPayment = civicrm_api('participant_payment', 'create', array(
- 'version' => 3,
+ $participantPayment = $this->callAPISuccess('participant_payment', 'create', array(
'contribution_id' => $this->_contributionId,
'participant_id' => $this->_participantId,
));
- $this->assertAPISuccess($participantPayment, 'line ' . __LINE__ . ' set-up of event');
+
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->find();
public function _setUpPledgeObjects() {
$this->_pledgeId = $this->pledgeCreate($this->_contactId);
//we'll create membership payment here because to make setup more re-usable
- $pledgePayment = civicrm_api('pledge_payment', 'create', array(
+ $pledgePayment = $this->callAPISuccess('pledge_payment', 'create', array(
'version' => 3,
'pledge_id' => $this->_pledgeId,
'contribution_id' => $this->_contributionId,
'status_id' => 1,
'actual_amount' => 50,
));
- $this->assertAPISuccess($pledgePayment, 'line ' . __LINE__ . ' set-up of pledge payment');
+
$this->input = array(
'component' => 'contribute',
'total_amount' => 150.00,
$this->callAPISuccess('contribution', 'getsingle', array('contribution_page_id' => $this->_ids['contribution_page']));
}
+ /**
+ * Test process with instant payment when more than one configured for the page.
+ *
+ * CRM-16923
+ */
+ public function testSubmitRecurMultiProcessorInstantPayment() {
+ $this->setUpContributionPage();
+ $this->setupPaymentProcessor();
+ $paymentProcessor2ID = $this->paymentProcessorCreate(array(
+ 'payment_processor_type_id' => 'Dummy',
+ 'name' => 'processor 2',
+ 'class_name' => 'Payment_Dummy',
+ 'billing_mode' => 1,
+ ));
+ $dummyPP = Civi\Payment\System::singleton()->getById($paymentProcessor2ID);
+ $dummyPP->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'create_first_success'));
+ $this->callAPISuccess('ContributionPage', 'create', array(
+ 'id' => $this->_ids['contribution_page'],
+ 'payment_processor' => array($paymentProcessor2ID, $this->_ids['payment_processor']),
+ ));
+
+ $priceFieldID = reset($this->_ids['price_field']);
+ $priceFieldValueID = reset($this->_ids['price_field_value']);
+ $submitParams = array(
+ 'price_' . $priceFieldID => $priceFieldValueID,
+ 'id' => (int) $this->_ids['contribution_page'],
+ 'amount' => 10,
+ 'is_recur' => 1,
+ 'frequency_interval' => 1,
+ 'frequency_unit' => 'month',
+ 'payment_processor_id' => $paymentProcessor2ID,
+ );
+
+ $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+ $this->callAPISuccess('contribution', 'getsingle', array(
+ 'contribution_page_id' => $this->_ids['contribution_page'],
+ 'contribution_status_id' => 1,
+ ));
+ }
/**
* Test submit with a membership block in place.
*/
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'selectMembership' => $this->_ids['membership_type'],
- 'payment_processor_id' => 1,
+ 'payment_processor_id' => $this->_paymentProcessor['id'],
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
'credit_card_exp_date' => array('M' => 9, 'Y' => 2040),
$this->callAPISuccess('contribution', 'completetransaction', array(
'id' => $contribution['id'],
'trxn_id' => 'ipn_called',
+ 'payment_processor_id' => $this->_paymentProcessor['id'],
));
$membership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
//renew it with processor setting completed - should extend membership