if (!empty($input['amount'])) {
$contribution->total_amount = $contributionParams['total_amount'] = $input['amount'];
}
- $contributionParams['payment_processor'] = $input['payment_processor'] = $paymentProcessorID;
if (!empty($contributionParams['contribution_recur_id'])) {
$recurringContribution = civicrm_api3('ContributionRecur', 'getsingle', array(
}
elseif (!empty($params['payment_processor'])) {
$params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($params['payment_processor'], 'civicrm_payment_processor', 'financial_account_id');
+ $params['payment_instrument_id'] = civicrm_api3('PaymentProcessor', 'getvalue', array(
+ 'id' => $params['payment_processor'],
+ 'return' => 'payment_instrument_id',
+ ));
}
elseif (!empty($params['payment_instrument_id'])) {
$params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($params['payment_instrument_id']);
'currency' => $params['contribution']->currency,
'trxn_id' => $params['contribution']->trxn_id,
'status_id' => $statusId,
- 'payment_instrument_id' => $params['contribution']->payment_instrument_id,
+ 'payment_instrument_id' => CRM_Utils_Array::value('payment_instrument_id', $params, $params['contribution']->payment_instrument_id),
'check_number' => CRM_Utils_Array::value('check_number', $params),
);
if ($contributionStatus == 'Refunded' || $contributionStatus == 'Chargeback') {
'source' => self::getRecurringContributionDescription($contribution, $event),
), array_intersect_key($input, array_fill_keys($inputContributionWhiteList, 1)
));
+ $contributionParams['payment_processor'] = $input['payment_processor'] = $paymentProcessorId;
if ($recurringContributionID) {
$contributionParams['contribution_recur_id'] = $recurringContributionID;
CRM_Contact_BAO_Group::getPermissionClause(TRUE);
}
+ /**
+ * @param array $params
+ * @param $context
+ */
+ public function _checkFinancialRecords($params, $context) {
+ $entityParams = array(
+ 'entity_id' => $params['id'],
+ 'entity_table' => 'civicrm_contribution',
+ );
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
+ $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
+ if ($context == 'pending') {
+ $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
+ $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
+ return;
+ }
+ $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
+ $trxnParams = array(
+ 'id' => $trxn['financial_trxn_id'],
+ );
+ if ($context != 'online' && $context != 'payLater') {
+ $compareParams = array(
+ 'to_financial_account_id' => 6,
+ 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100),
+ 'status_id' => 1,
+ );
+ }
+ if ($context == 'feeAmount') {
+ $compareParams['fee_amount'] = 50;
+ }
+ elseif ($context == 'online') {
+ $compareParams = array(
+ 'to_financial_account_id' => 12,
+ 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100),
+ 'status_id' => 1,
+ 'payment_instrument_id' => 1,
+ );
+ }
+ elseif ($context == 'payLater') {
+ $compareParams = array(
+ 'to_financial_account_id' => 7,
+ 'total_amount' => CRM_Utils_Array::value('total_amount', $params, 100),
+ 'status_id' => 2,
+ );
+ }
+ $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
+ $entityParams = array(
+ 'financial_trxn_id' => $trxn['financial_trxn_id'],
+ 'entity_table' => 'civicrm_financial_item',
+ );
+ $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
+ $fitemParams = array(
+ 'id' => $entityTrxn['entity_id'],
+ );
+ $compareParams = array(
+ 'amount' => CRM_Utils_Array::value('total_amount', $params, 100),
+ 'status_id' => 1,
+ 'financial_account_id' => 1,
+ );
+ if ($context == 'payLater') {
+ $compareParams = array(
+ 'amount' => CRM_Utils_Array::value('total_amount', $params, 100),
+ 'status_id' => 3,
+ 'financial_account_id' => 1,
+ );
+ }
+ $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
+ if ($context == 'feeAmount') {
+ $maxParams = array(
+ 'entity_id' => $params['id'],
+ 'entity_table' => 'civicrm_contribution',
+ );
+ $maxTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($maxParams, TRUE));
+ $trxnParams = array(
+ 'id' => $maxTrxn['financial_trxn_id'],
+ );
+ $compareParams = array(
+ 'to_financial_account_id' => 5,
+ 'from_financial_account_id' => 6,
+ 'total_amount' => 50,
+ 'status_id' => 1,
+ );
+ $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['id'], 'DESC');
+ $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
+ $fitemParams = array(
+ 'entity_id' => $trxnId['financialTrxnId'],
+ 'entity_table' => 'civicrm_financial_trxn',
+ );
+ $compareParams = array(
+ 'amount' => 50,
+ 'status_id' => 1,
+ 'financial_account_id' => 5,
+ );
+ $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
+ }
+ // This checks that empty Sales tax rows are not being created. If for any reason it needs to be removed the
+ // line should be copied into all the functions that call this function & evaluated there
+ // Be really careful not to remove or bypass this without ensuring stray rows do not re-appear
+ // when calling completeTransaction or repeatTransaction.
+ $this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0);
+ }
+
}
$this->assertEquals(10, $contribution['total_amount']);
$this->assertEquals(.85, $contribution['fee_amount']);
$this->assertEquals(9.15, $contribution['net_amount']);
+ $this->_checkFinancialRecords(array(
+ 'id' => $contribution['id'],
+ 'total_amount' => $contribution['total_amount'],
+ ), 'online');
}
/**
return $optionValue['values'][$optionValue['id']]['value'];
}
- /**
- * @param array $params
- * @param $context
- */
- public function _checkFinancialRecords($params, $context) {
- $entityParams = array(
- 'entity_id' => $params['id'],
- 'entity_table' => 'civicrm_contribution',
- );
- $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $params['id']));
- $this->assertEquals($contribution['total_amount'] - $contribution['fee_amount'], $contribution['net_amount']);
- if ($context == 'pending') {
- $trxn = CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams);
- $this->assertNull($trxn, 'No Trxn to be created until IPN callback');
- return;
- }
- $trxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
- $trxnParams = array(
- 'id' => $trxn['financial_trxn_id'],
- );
- if ($context != 'online' && $context != 'payLater') {
- $compareParams = array(
- 'to_financial_account_id' => 6,
- 'total_amount' => 100,
- 'status_id' => 1,
- );
- }
- if ($context == 'feeAmount') {
- $compareParams['fee_amount'] = 50;
- }
- elseif ($context == 'online') {
- $compareParams = array(
- 'to_financial_account_id' => 12,
- 'total_amount' => 100,
- 'status_id' => 1,
- );
- }
- elseif ($context == 'payLater') {
- $compareParams = array(
- 'to_financial_account_id' => 7,
- 'total_amount' => 100,
- 'status_id' => 2,
- );
- }
- $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
- $entityParams = array(
- 'financial_trxn_id' => $trxn['financial_trxn_id'],
- 'entity_table' => 'civicrm_financial_item',
- );
- $entityTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($entityParams));
- $fitemParams = array(
- 'id' => $entityTrxn['entity_id'],
- );
- $compareParams = array(
- 'amount' => 100,
- 'status_id' => 1,
- 'financial_account_id' => 1,
- );
- if ($context == 'payLater') {
- $compareParams = array(
- 'amount' => 100,
- 'status_id' => 3,
- 'financial_account_id' => 1,
- );
- }
- $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
- if ($context == 'feeAmount') {
- $maxParams = array(
- 'entity_id' => $params['id'],
- 'entity_table' => 'civicrm_contribution',
- );
- $maxTrxn = current(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($maxParams, TRUE));
- $trxnParams = array(
- 'id' => $maxTrxn['financial_trxn_id'],
- );
- $compareParams = array(
- 'to_financial_account_id' => 5,
- 'from_financial_account_id' => 6,
- 'total_amount' => 50,
- 'status_id' => 1,
- );
- $trxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['id'], 'DESC');
- $this->assertDBCompareValues('CRM_Financial_DAO_FinancialTrxn', $trxnParams, $compareParams);
- $fitemParams = array(
- 'entity_id' => $trxnId['financialTrxnId'],
- 'entity_table' => 'civicrm_financial_trxn',
- );
- $compareParams = array(
- 'amount' => 50,
- 'status_id' => 1,
- 'financial_account_id' => 5,
- );
- $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);
- }
- // This checks that empty Sales tax rows are not being created. If for any reason it needs to be removed the
- // line should be copied into all the functions that call this function & evaluated there
- // Be really careful not to remove or bypass this without ensuring stray rows do not re-appear
- // when calling completeTransaction or repeatTransaction.
- $this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0);
- }
-
/**
* Set up the basic recurring contribution for tests.
*