// 2);
}
+ /**
+ * Test retrieval by total_amount works.
+ *
+ * @throws Exception
+ */
+ public function testGetContributionByTotalAmount() {
+ $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '5')));
+ $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '10')));
+ $this->callAPISuccessGetCount('Contribution', array('total_amount' => 10), 1);
+ $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 6)), 1);
+ $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 0)), 2);
+ $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => -5)), 2);
+ $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('<' => 0)), 0);
+ $this->callAPISuccessGetCount('Contribution', array(), 2);
+ }
+
/**
* Create test with unique field name on source.
*/
'contribution_status_id' => 1,
);
- $this->callAPIFailure('contribution', 'create', $params, 'contact_id is not valid : 999');
+ $this->callAPIFailure('contribution', 'create', $params);
}
/**
$this->_checkFinancialTrxn($contribution, 'paymentInstrument', $instrumentId);
}
+ /**
+ * Function tests that financial records are updated when Payment Instrument is changed when amount is negative.
+ */
+ public function testCreateUpdateNegativeContributionPaymentInstrument() {
+ $instrumentId = $this->_addPaymentInstrument();
+ $contribParams = array(
+ 'contact_id' => $this->_individualId,
+ 'total_amount' => -100.00,
+ 'financial_type_id' => $this->_financialTypeId,
+ 'payment_instrument_id' => 4,
+ 'contribution_status_id' => 1,
+
+ );
+ $contribution = $this->callAPISuccess('contribution', 'create', $contribParams);
+
+ $newParams = array_merge($contribParams, array(
+ 'id' => $contribution['id'],
+ 'payment_instrument_id' => $instrumentId,
+ )
+ );
+ $contribution = $this->callAPISuccess('contribution', 'create', $newParams);
+ $this->assertAPISuccess($contribution);
+ $this->_checkFinancialTrxn($contribution, 'paymentInstrument', $instrumentId, array('total_amount' => '-100.00'));
+ }
+
/**
* Function tests that financial records are added when Contribution is Refunded.
*/
}
/**
- * Test repeat contribution successfully creates line items.
+ * CRM-19126 Add test to verify when complete transaction is called tax amount is not changed
*/
- public function testRepeatTransaction() {
- $originalContribution = $this->setUpRepeatTransaction();
+ public function testCheckTaxAmount() {
+ $contact = $this->createLoggedInUser();
+ $financialType = $this->callAPISuccess('financial_type', 'create', array(
+ 'name' => 'Test taxable financial Type',
+ 'is_reserved' => 0,
+ 'is_active' => 1,
+ ));
+ $financialAccount = $this->callAPISuccess('financial_account', 'create', array(
+ 'name' => 'Test Tax financial account ',
+ 'contact_id' => $contact,
+ 'financial_account_type_id' => 2,
+ 'is_tax' => 1,
+ 'tax_rate' => 5.00,
+ 'is_reserved' => 0,
+ 'is_active' => 1,
+ 'is_default' => 0,
+ ));
+ $financialTypeId = $financialType['id'];
+ $financialAccountId = $financialAccount['id'];
+ $financialAccountParams = array(
+ 'entity_table' => 'civicrm_financial_type',
+ 'entity_id' => $financialTypeId,
+ 'account_relationship' => 10,
+ 'financial_account_id' => $financialAccountId,
+ );
+ CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams);
+ $taxRates = CRM_Core_PseudoConstant::getTaxRates();
+ $params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => $financialTypeId));
+ $contribution = $this->callAPISuccess('contribution', 'create', $params);
+ $contribution1 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => 'tax_amount', 'sequential' => 1));
+ $this->callAPISuccess('contribution', 'completetransaction', array(
+ 'id' => $contribution['id'],
+ 'trxn_id' => '777788888',
+ 'fee_amount' => '6.00',
+ ));
+ $contribution2 = $this->callAPISuccess('contribution', 'get', array('id' => $contribution['id'], 'return' => array('tax_amount', 'fee_amount', 'net_amount'), 'sequential' => 1));
+ $this->assertEquals($contribution1['values'][0]['tax_amount'], $contribution2['values'][0]['tax_amount']);
+ $this->assertEquals('6.00', $contribution2['values'][0]['fee_amount']);
+ $this->assertEquals('99.00', $contribution2['values'][0]['net_amount']);
+ }
+ /**
+ * Test repeat contribution successfully creates line item.
+ */
+ public function testRepeatTransaction() {
+ $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'single');
$this->callAPISuccess('contribution', 'repeattransaction', array(
'original_contribution_id' => $originalContribution['id'],
'contribution_status_id' => 'Completed',
}
/**
- * Test repeat contribution successfully creates line items.
+ * Test repeat contribution successfully creates line items (plural).
+ */
+ public function testRepeatTransactionLineItems() {
+ // CRM-19309
+ $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'multiple');
+ $this->callAPISuccess('contribution', 'repeattransaction', array(
+ 'original_contribution_id' => $originalContribution['id'],
+ 'contribution_status_id' => 'Completed',
+ 'trxn_id' => uniqid(),
+ ));
+
+ $lineItemParams = array(
+ 'entity_id' => $originalContribution['id'],
+ 'sequential' => 1,
+ 'return' => array(
+ 'entity_table',
+ 'qty',
+ 'unit_price',
+ 'line_total',
+ 'label',
+ 'financial_type_id',
+ 'deductible_amount',
+ 'price_field_value_id',
+ 'price_field_id',
+ ),
+ );
+ $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ 'entity_id' => $originalContribution['id'],
+ )));
+ $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ 'entity_id' => $originalContribution['id'] + 1,
+ )));
+
+ // unset id and entity_id for all of them to be able to compare the lineItems:
+ unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']);
+ unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
+ $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]);
+
+ unset($lineItem1['values'][1]['id'], $lineItem1['values'][1]['entity_id']);
+ unset($lineItem2['values'][1]['id'], $lineItem2['values'][1]['entity_id']);
+ $this->assertEquals($lineItem1['values'][1], $lineItem2['values'][1]);
+
+ // CRM-19309 so in future we also want to:
+ // check that financial_line_items have been created for entity_id 3 and 4;
+
+ $this->callAPISuccessGetCount('FinancialItem', array('description' => 'Sales Tax', 'amount' => 0), 0);
+ $this->quickCleanUpFinancialEntities();
+ }
+
+ /**
+ * Test repeat contribution successfully creates is_test transaction.
*/
public function testRepeatTransactionIsTest() {
$this->_params['is_test'] = 1;
- $originalContribution = $this->setUpRepeatTransaction(array('is_test' => 1));
+ $originalContribution = $this->setUpRepeatTransaction(array('is_test' => 1), 'single');
$this->callAPISuccess('contribution', 'repeattransaction', array(
'original_contribution_id' => $originalContribution['id'],
* Test repeat contribution passed in status.
*/
public function testRepeatTransactionPassedInStatus() {
- $originalContribution = $this->setUpRepeatTransaction();
+ $originalContribution = $this->setUpRepeatTransaction($recurParams = array(), 'single');
$this->callAPISuccess('contribution', 'repeattransaction', array(
'original_contribution_id' => $originalContribution['id'],
'total_amount' => '400',
'fee_amount' => 50,
));
+
$lineItemParams = array(
'entity_id' => $originalContribution['id'],
'sequential' => 1,
$lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
'entity_id' => $originalContribution['id'] + 1,
)));
+
unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
$this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
)));
unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
+ $expectedLineItem['contribution_type_id'] = $lineItem2['values'][0]['contribution_type_id'];
$this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
}
)));
unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
+ $expectedLineItem['contribution_type_id'] = $lineItem2['values'][0]['contribution_type_id'];
$this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
}
'Event',
)
);
+
+ $this->checkCreditCardDetails($mut, $contribution['id']);
$mut->stop();
}
+ /**
+ * Check credit card details in sent mail via API
+ *
+ * @param $mut obj CiviMailUtils instance
+ * @param int $contributionID Contribution ID
+ *
+ */
+ public function checkCreditCardDetails($mut, $contributionID) {
+ $contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
+ $this->callAPISuccess('contribution', 'sendconfirmation', array(
+ 'id' => $contributionID,
+ 'receipt_from_email' => 'api@civicrm.org',
+ 'payment_processor_id' => $this->paymentProcessorID,
+ )
+ );
+ $mut->checkMailLog(array(
+ 'Credit Card Information', // credit card header
+ 'Billing Name and Address', // billing header
+ 'anthony_anderson@civicrm.org', // billing name
+ ), array(
+ 'Event',
+ )
+ );
+ }
+
/**
* Test sending a mail via the API.
*/
$trxnParams1 = array(
'id' => $trxn['financial_trxn_id'],
);
- $compareParams = array(
- 'total_amount' => -100,
- 'status_id' => 1,
- );
+ if (empty($extraParams)) {
+ $compareParams = array(
+ 'total_amount' => -100,
+ 'status_id' => 1,
+ );
+ }
+ else {
+ $compareParams = array(
+ 'total_amount' => 100,
+ 'status_id' => 1,
+ );
+ }
if ($context == 'paymentInstrument') {
$compareParams += array(
'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount(4),
*
* @return array
*/
- protected function setUpRepeatTransaction($recurParams = array()) {
+ protected function setUpRepeatTransaction($recurParams = array(), $flag) {
$paymentProcessorID = $this->paymentProcessorCreate();
$contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array(
'contact_id' => $this->_individualId,
'frequency_unit' => 'month',
'payment_processor_id' => $paymentProcessorID,
), $recurParams));
- $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
- $this->_params,
- array('contribution_recur_id' => $contributionRecur['id']))
- );
+
+ $originalContribution = '';
+ if ($flag == 'multiple') {
+ // CRM-19309 create a contribution + also add in line_items (plural):
+ $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
+ $this->_params,
+ array(
+ 'contribution_recur_id' => $contributionRecur['id'],
+ 'skipLineItem' => 1,
+ 'api.line_item.create' => array(
+ array(
+ 'price_field_id' => 1,
+ 'qty' => 2,
+ 'line_total' => '20',
+ 'unit_price' => '10',
+ 'financial_type_id' => 1,
+ ),
+ array(
+ 'price_field_id' => 1,
+ 'qty' => 1,
+ 'line_total' => '80',
+ 'unit_price' => '80',
+ 'financial_type_id' => 2,
+ ),
+ ),
+ )
+ )
+ );
+ }
+ elseif ($flag == 'single') {
+ $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
+ $this->_params,
+ array('contribution_recur_id' => $contributionRecur['id']))
+ );
+ }
+
return $originalContribution;
}