protected $_financialTypeId = 1;
+ /**
+ * Should financials be checked after the test but before tear down.
+ *
+ * Ideally all tests (or at least all that call any financial api calls ) should do this but there
+ * are some test data issues and some real bugs currently blocking.
+ *
+ * @var bool
+ */
+ protected $isValidateFinancialsOnPostAssert = TRUE;
+
/**
* Setup function.
*
'Balance Owed: $ 0.00',
'Thank you for completing this payment.',
]);
- $this->validateAllPayments();
}
/**
'is_payment' => 1,
];
foreach ($expected as $key => $value) {
- $this->assertEquals($expected[$key], $payment[$key], 'mismatch on key ' . $key);
+ $this->assertEquals($value, $payment[$key], 'mismatch on key ' . $key);
}
$this->callAPISuccess('Payment', 'sendconfirmation', ['id' => $payment['id']]);
'Transaction Date: November 13th, 2018 12:01 PM',
'Total Paid: $ 170' . $decimalSeparator . '00',
]);
- $this->validateAllPayments();
}
/**
'order_id' => $order['id'],
'total_amount' => 50,
]);
- $this->validateAllPayments();
}
/**
]);
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_financial_item');
$this->callAPISuccess('Payment', 'create', ['contribution_id' => $contribution['id'], 'payment_instrument_id' => 'Check', 'total_amount' => 5]);
- $this->validateAllPayments();
}
/**
$participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $paymentParticipant);
$participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
$this->assertEquals('Registered', $participant['values'][$participant['id']]['participant_status']);
- $this->callAPISuccess('Contribution', 'Delete', [
- 'id' => $contribution['id'],
- ]);
- $this->validateAllPayments();
}
/**
$participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $paymentParticipant);
$participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
$this->assertEquals('Registered', $participant['values'][$participant['id']]['participant_status']);
- $this->validateAllPayments();
}
/**
*/
public function testRefundPayment(): void {
$result = $this->callAPISuccess('Contribution', 'create', [
- 'financial_type_id' => "Donation",
+ 'financial_type_id' => 'Donation',
'total_amount' => 100,
'contact_id' => $this->_individualId,
]);
]);
$contribution = $this->callAPISuccessGetSingle('Contribution', [
- 'return' => ["contribution_status_id"],
+ 'return' => ['contribution_status_id'],
'id' => $contributionID,
]);
//Still we've a status of Completed after refunding a partial amount.
*/
public function testRefundPaymentWithCancelledPaymentId(): void {
$result = $this->callAPISuccess('Contribution', 'create', [
- 'financial_type_id' => "Donation",
+ 'financial_type_id' => 'Donation',
'total_amount' => 100,
'contact_id' => $this->_individualId,
]);
$this->callAPISuccess('Payment', 'create', [
'contribution_id' => $contributionID,
'total_amount' => -100,
- 'cancelled_payment_id' => 12345,
+ 'cancelled_payment_id' => (int) $this->callAPISuccess('Payment', 'get', [])['id'],
]);
$contribution = $this->callAPISuccessGetSingle('Contribution', [
'return' => ['contribution_status_id'],
foreach ($payment['values'] as $value) {
$this->assertEquals($value['total_amount'], array_pop($amounts), 'Mismatch total amount');
}
-
- $this->callAPISuccess('Contribution', 'Delete', [
- 'id' => $contribution['id'],
- ]);
- $this->validateAllPayments();
}
/**
$payment = $this->callAPIAndDocument('payment', 'create', $params, __FUNCTION__, __FILE__, 'Update Payment', 'UpdatePayment');
$this->validateAllPayments();
- // Check for proportional cancelled payment against lineitems.
+ // Check for proportional cancelled payment against line items.
$minParams = [
'entity_table' => 'civicrm_financial_item',
'financial_trxn_id' => $payment['id'] - 1,
$this->assertEquals($value['amount'], array_pop($amounts));
}
- // Check for proportional updated payment against lineitems.
+ // Check for proportional updated payment against line items.
$params = [
'entity_table' => 'civicrm_financial_item',
'financial_trxn_id' => $payment['id'],
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
$this->assertEquals($eft['values'][$eft['id']]['amount'], $amount);
}
-
- $this->callAPISuccess('Contribution', 'Delete', [
- 'id' => $contribution['id'],
- ]);
- $this->validateAllPayments();
}
/**
* Test that a contribution can be overpaid with the payment api.
*
+ * @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
public function testCreatePaymentOverPay(): void {
$contributionID = $this->contributionCreate(['contact_id' => $this->individualCreate()]);
}
/**
- * Test create payment api for paylater contribution
+ * Test create payment api for pay later contribution
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public function testCreatePaymentPayLater(): void {
$this->createLoggedInUser();
'payment_instrument_id' => 'Check',
'check_number' => $checkNumber2,
]);
- $expectedConcatanatedCheckNumbers = implode(',', [$checkNumber1, $checkNumber2]);
+ $expectedConcatenatedCheckNumbers = implode(',', [$checkNumber1, $checkNumber2]);
//Assert check number is concatenated on the main contribution.
$contributionValues = $this->callAPISuccess('Contribution', 'getsingle', ['id' => $contribution['id']]);
- $this->assertEquals($expectedConcatanatedCheckNumbers, $contributionValues['check_number']);
+ $this->assertEquals($expectedConcatenatedCheckNumbers, $contributionValues['check_number']);
}
/**
* Test create payment api for failed contribution.
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public function testCreatePaymentOnFailedContribution(): void {
$this->createLoggedInUser();
* Test create payment api for pay later contribution with partial payment.
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public function testCreatePaymentPayLaterPartialPayment(): void {
$this->createLoggedInUser();
]);
$this->callAPISuccess('OptionValue', 'get', ['name' => 'Completed', 'option_group_id' => 'contribution_status', 'api.OptionValue.create' => ['label' => 'Completed']]);
$this->callAPISuccessGetCount('Activity', ['target_contact_id' => $this->_individualId, 'activity_type_id' => 'Payment'], 2);
- $this->validateAllPayments();
}
/**
'loc_block_id' => $location['id'],
'is_show_location' => TRUE,
]);
- $this->validateAllPayments();
}
/**
*
* @throws \CRM_Core_Exception
*/
- protected function checkPaymentIsValid(int $paymentID, int $contributionID, $amount = 50): void {
+ protected function checkPaymentIsValid(int $paymentID, int $contributionID, int $amount = 50): void {
$payment = $this->callAPISuccess('Payment', 'getsingle', ['financial_trxn_id' => $paymentID]);
$this->assertEquals(7, $payment['from_financial_account_id']);
$this->assertEquals(6, $payment['to_financial_account_id']);
]);
$this->assertEquals($eft['values'][$eft['id']]['amount'], $amount);
- $this->validateAllPayments();
}
/**
$this->assertEquals(99.8, $contribution['net_amount']);
$this->assertEquals($trxnID, $contribution['trxn_id'],
- "Contribution trxn_id should have been set to that of the payment.");
+ 'Contribution trxn_id should have been set to that of the payment.');
$this->assertEquals($originalReceiveDate, $contribution['receive_date'],
- "Contribution receive date was changed, but should not have been.");
-
- $this->validateAllPayments();
- $this->validateAllContributions();
+ 'Contribution receive date was changed, but should not have been.');
}