/**
* Setup function.
*
- * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public function setUp(): void {
parent::setUp();
*
* @throws \CRM_Core_Exception
*/
- public function testGetPayment() {
+ public function testGetPayment(): void {
$p = [
'contact_id' => $this->_individualId,
'receive_date' => '2010-01-20',
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'administer CiviCRM'];
$this->callAPIFailure('payment', 'get', $params, 'API permission check failed for Payment/get call; insufficient permission: require access CiviCRM and access CiviContribute');
- array_push(CRM_Core_Config::singleton()->userPermissionClass->permissions, 'access CiviContribute');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions[] = 'access CiviContribute';
$this->callAPISuccess('payment', 'get', $params);
$payment = $this->callAPIAndDocument('payment', 'get', $params, __FUNCTION__, __FILE__);
*
* @throws \CRM_Core_Exception
*/
- public function testMultiplePaymentsForContribution() {
+ public function testMultiplePaymentsForContribution(): void {
$params = [
'contact_id' => $this->_individualId,
'total_amount' => 100,
* Retrieve Payment using trxn_id.
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testGetPaymentWithTrxnID() {
- $this->_individualId2 = $this->individualCreate();
+ public function testGetPaymentWithTrxnID(): void {
+ $individual2 = $this->individualCreate();
$params1 = [
'contact_id' => $this->_individualId,
'trxn_id' => 111111,
$contributionID1 = $this->contributionCreate($params1);
$params2 = [
- 'contact_id' => $this->_individualId2,
+ 'contact_id' => $individual2,
'trxn_id' => 222222,
'total_amount' => 20,
];
*
* @throws \CRM_Core_Exception
*/
- public function testPaymentSendContributionReceipt() {
+ public function testPaymentSendContributionReceipt(): void {
$mut = new CiviMailUtils($this);
$contribution = $this->createPartiallyPaidParticipantOrder();
$event = $this->callAPISuccess('Event', 'get', []);
/**
* Test full refund when no payment has actually been record.
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testFullRefundWithPaymentAlreadyRefunded() {
+ public function testFullRefundWithPaymentAlreadyRefunded(): void {
$params1 = [
'contact_id' => $this->_individualId,
'trxn_id' => 111111,
$contributionID1 = $this->contributionCreate($params1);
$paymentParams = ['contribution_id' => $contributionID1];
$this->callAPISuccess('Payment', 'create', ['total_amount' => '-10', 'contribution_id' => $contributionID1]);
- $payment = $this->callAPISuccess('payment', 'get', $paymentParams);
+ $this->callAPISuccess('payment', 'get', $paymentParams);
$this->callAPISuccess('Payment', 'create', ['total_amount' => '-10', 'contribution_id' => $contributionID1]);
- $payment = $this->callAPISuccess('payment', 'get', $paymentParams);
+ $this->callAPISuccess('payment', 'get', $paymentParams);
$this->validateAllPayments();
}
- public function testNegativePaymentWithNegativeContribution() {
+ /**
+ * @throws \CRM_Core_Exception
+ */
+ public function testNegativePaymentWithNegativeContribution(): void {
$params1 = [
'contact_id' => $this->_individualId,
'trxn_id' => 111111,
$contributionID1 = $this->contributionCreate($params1);
$this->callAPISuccess('Payment', 'create', ['total_amount' => '-20', 'contribution_id' => $contributionID1]);
$paymentParams = ['contribution_id' => $contributionID1];
- $payment = $this->callAPISuccess('payment', 'get', $paymentParams);
+ $this->callAPISuccess('payment', 'get', $paymentParams);
$this->validateAllPayments();
}
*
* @throws \CRM_Core_Exception
*/
- public function testPaymentEmailReceipt() {
+ public function testPaymentEmailReceipt(): void {
$mut = new CiviMailUtils($this);
$contribution = $this->createPartiallyPaidParticipantOrder();
$event = $this->callAPISuccess('Event', 'get', []);
*
* @throws \CRM_Core_Exception
*/
- public function testPaymentEmailReceiptFullyPaid() {
+ public function testPaymentEmailReceiptFullyPaid(): void {
$mut = new CiviMailUtils($this);
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviContribute', 'edit contributions', 'access CiviCRM'];
$contribution = $this->createPartiallyPaidParticipantOrder();
*
* @throws \CRM_Core_Exception
*/
- public function testRefundEmailReceipt($thousandSeparator) {
+ public function testRefundEmailReceipt(string $thousandSeparator): void {
$this->setCurrencySeparators($thousandSeparator);
$decimalSeparator = ($thousandSeparator === ',' ? '.' : ',');
$mut = new CiviMailUtils($this);
*
* @throws \CRM_Core_Exception
*/
- public function testCreatePaymentPendingOrderNoLineItems() {
+ public function testCreatePaymentPendingOrderNoLineItems(): void {
$order = $this->createPendingParticipantOrder();
$this->callAPISuccess('Payment', 'create', [
'order_id' => $order['id'],
* that in an artificial way.
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testAddPaymentMissingFinancialItems() {
+ public function testAddPaymentMissingFinancialItems(): void {
$contribution = $this->callAPISuccess('Contribution', 'create', [
'total_amount' => 50,
'financial_type_id' => 'Donation',
*
* @throws \CRM_Core_Exception
*/
- protected function createPendingParticipantOrder() {
+ protected function createPendingParticipantOrder(): array {
return $this->callAPISuccess('Order', 'create', $this->getParticipantOrderParams());
}
*
* @throws \CRM_Core_Exception
*/
- public function testCreatePaymentNoLineItems() {
+ public function testCreatePaymentNoLineItems(): void {
$contribution = $this->createPartiallyPaidParticipantOrder();
//Create partial payment
// Check contribution for completed status
$contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id']]);
- $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
- $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 300.00);
+ $this->assertEquals('Completed', $contribution['values'][$contribution['id']]['contribution_status']);
+ $this->assertEquals(300.00, $contribution['values'][$contribution['id']]['total_amount']);
$paymentParticipant = [
'contribution_id' => $contribution['id'],
];
$participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $paymentParticipant);
$participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
- $this->assertEquals($participant['values'][$participant['id']]['participant_status'], 'Registered');
+ $this->assertEquals('Registered', $participant['values'][$participant['id']]['participant_status']);
$this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
]);
/**
* Function to assert db values
*
+ * @param array $payment
+ * @param array $expectedResult
+ *
* @throws \CRM_Core_Exception
*/
- public function checkPaymentResult($payment, $expectedResult) {
+ public function checkPaymentResult(array $payment, array $expectedResult): void {
$refreshedPayment = $this->callAPISuccessGetSingle('Payment', ['financial_trxn_id' => $payment['id']]);
foreach ($expectedResult[$payment['id']] as $key => $value) {
$this->assertEquals($refreshedPayment[$key], $value, 'mismatch on ' . $key); $this->assertEquals($refreshedPayment[$key], $value, 'mismatch on ' . $key);
*
* @throws \CRM_Core_Exception
*/
- public function testCreatePaymentLineItems() {
+ public function testCreatePaymentLineItems(): void {
$contribution = $this->createPartiallyPaidParticipantOrder();
$lineItems = $this->callAPISuccess('LineItem', 'get', ['contribution_id' => $contribution['id']])['values'];
// Check contribution for completed status
$contribution = $this->callAPISuccess('Contribution', 'get', ['id' => $contribution['id']]);
- $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
- $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 300.00);
+ $this->assertEquals('Completed', $contribution['values'][$contribution['id']]['contribution_status']);
+ $this->assertEquals(300.00, $contribution['values'][$contribution['id']]['total_amount']);
$paymentParticipant = [
'contribution_id' => $contribution['id'],
];
$participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $paymentParticipant);
$participant = $this->callAPISuccess('participant', 'get', ['id' => $participantPayment['participant_id']]);
- $this->assertEquals($participant['values'][$participant['id']]['participant_status'], 'Registered');
+ $this->assertEquals('Registered', $participant['values'][$participant['id']]['participant_status']);
$this->validateAllPayments();
}
*
* @throws \CRM_Core_Exception
*/
- public function testRefundPayment() {
+ public function testRefundPayment(): void {
$result = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => "Donation",
'total_amount' => 100,
'id' => $contributionID,
]);
//Still we've a status of Completed after refunding a partial amount.
- $this->assertEquals($contribution['contribution_status'], 'Completed');
+ $this->assertEquals('Completed', $contribution['contribution_status']);
//Refund the complete amount.
$this->callAPISuccess('Payment', 'create', [
'id' => $contributionID,
]);
//Assert if main contribution status is updated to "Refunded".
- $this->assertEquals($contribution['contribution_status'], 'Refunded Label**');
+ $this->assertEquals('Refunded Label**', $contribution['contribution_status']);
}
/**
*
* @throws \CRM_Core_Exception
*/
- public function testRefundPaymentWithCancelledPaymentId() {
+ public function testRefundPaymentWithCancelledPaymentId(): void {
$result = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => "Donation",
'total_amount' => 100,
'id' => $contributionID,
]);
//Assert if main contribution status is updated to "Refunded".
- $this->assertEquals($contribution['contribution_status'], 'Refunded Label**');
+ $this->assertEquals('Refunded Label**', $contribution['contribution_status']);
}
/**
*
* @throws \CRM_Core_Exception
*/
- public function testCancelPayment() {
+ public function testCancelPayment(): void {
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer CiviCRM', 'access CiviContribute'];
$contribution = $this->createPartiallyPaidParticipantOrder();
*
* @throws \CRM_Core_Exception
*/
- public function testDeletePayment() {
+ public function testDeletePayment(): void {
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer CiviCRM', 'access CiviContribute'];
$contribution = $this->createPartiallyPaidParticipantOrder();
*
* @throws \CRM_Core_Exception
*/
- public function testUpdatePayment() {
+ public function testUpdatePayment(): void {
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer CiviCRM', 'access CiviContribute', 'edit contributions'];
$contribution = $this->createPartiallyPaidParticipantOrder();
* Test that a contribution can be overpaid with the payment api.
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testCreatePaymentOverPay() {
+ public function testCreatePaymentOverPay(): void {
$contributionID = $this->contributionCreate(['contact_id' => $this->individualCreate()]);
$payment = $this->callAPISuccess('Payment', 'create', ['total_amount' => 5, 'order_id' => $contributionID]);
$contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contributionID]);
*
* @throws \CRM_Core_Exception
*/
- public function testCreatePaymentPayLater() {
+ public function testCreatePaymentPayLater(): void {
$this->createLoggedInUser();
$processorID = $this->paymentProcessorCreate();
$contributionParams = [
'financial_trxn_id' => $payment['id'],
];
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
- $this->assertEquals($eft['values'][$eft['id']]['amount'], 100);
+ $this->assertEquals(100, $eft['values'][$eft['id']]['amount']);
$params = [
'entity_table' => 'civicrm_financial_item',
'financial_trxn_id' => $payment['id'],
];
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
- $this->assertEquals($eft['values'][$eft['id']]['amount'], 100);
+ $this->assertEquals(100, $eft['values'][$eft['id']]['amount']);
// Check contribution for completed status
$contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id']]);
- $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Completed');
- $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
+ $this->assertEquals('Completed', $contribution['values'][$contribution['id']]['contribution_status']);
+ $this->assertEquals(100.00, $contribution['values'][$contribution['id']]['total_amount']);
$this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
]);
*
* @throws \CRM_Core_Exception
*/
- public function testNetAmount() {
+ public function testNetAmount(): void {
$order = $this->createPendingParticipantOrder();
$payment = $this->callAPISuccess('Payment', 'create', ['order_id' => $order['id'], 'total_amount' => 10, 'fee_amount' => .25]);
$this->assertEquals('9.75', $this->callAPISuccessGetValue('Payment', ['id' => $payment['id'], 'return' => 'net_amount']));
* https://lab.civicrm.org/dev/financial/issues/69
* @throws \CRM_Core_Exception
*/
- public function testCreatePaymentIncompletePaymentPartialPayment() {
+ public function testCreatePaymentIncompletePaymentPartialPayment(): void {
$contributionParams = [
'total_amount' => 100,
'currency' => 'USD',
*
* @throws \CRM_Core_Exception
*/
- public function testCreatePaymentOnFailedContribution() {
+ public function testCreatePaymentOnFailedContribution(): void {
$this->createLoggedInUser();
//Create a direct Failed Contribution (no ft record inserted).
$contributionParams = [
'contribution_id' => $contribution['id'],
'total_amount' => 50,
];
- $payment = $this->callAPISuccess('Payment', 'create', $params);
+ $this->callAPISuccess('Payment', 'create', $params);
//Verify 2 rows are added to the financial trxn as payment is moved from
//Failed -> Pending -> Completed, i.e, 0 -> 7(Account receivable) -> 6 (Deposit Bank).
'entity_table' => 'civicrm_contribution',
];
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
- $this->assertEquals($eft['count'], 2);
+ $this->assertEquals(2, $eft['count']);
//Test 2
//Create a Pending Contribution so an FT record is inserted.
'entity_table' => 'civicrm_contribution',
];
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
- $this->assertEquals($eft['count'], 4);
+ $this->assertEquals(4, $eft['count']);
$this->validateAllPayments();
}
* @param $contributionID
* @param $partialAmount
* @param $totalAmount
+ *
+ * @throws \CRM_Core_Exception
*/
- public function createPartialPaymentOnContribution($contributionID, $partialAmount, $totalAmount) {
+ public function createPartialPaymentOnContribution($contributionID, $partialAmount, $totalAmount): void {
//Create partial payment
$params = [
'contribution_id' => $contributionID,
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
$this->assertEquals($eft['values'][$eft['id']]['amount'], $partialAmount);
$contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contributionID]);
- $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Partially paid');
+ $this->assertEquals('Partially paid', $contribution['values'][$contribution['id']]['contribution_status']);
$this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], $totalAmount);
}
*
* @throws \CRM_Core_Exception
*/
- public function testCreatePaymentPayLaterPartialPayment() {
+ public function testCreatePaymentPayLaterPartialPayment(): void {
$this->createLoggedInUser();
$contributionParams = [
'total_amount' => 100,
'financial_trxn_id' => $payment['id'],
];
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
- $this->assertEquals($eft['values'][$eft['id']]['amount'], 40);
+ $this->assertEquals(40, $eft['values'][$eft['id']]['amount']);
$params = [
'entity_table' => 'civicrm_financial_item',
'financial_trxn_id' => $payment['id'],
];
$eft = $this->callAPISuccess('EntityFinancialTrxn', 'get', $params);
- $this->assertEquals($eft['values'][$eft['id']]['amount'], 40);
+ $this->assertEquals(40, $eft['values'][$eft['id']]['amount']);
// Check contribution for completed status
$contribution = $this->callAPISuccess('contribution', 'get', ['id' => $contribution['id']]);
- $this->assertEquals($contribution['values'][$contribution['id']]['contribution_status'], 'Unicorn');
- $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 100.00);
+ $this->assertEquals('Unicorn', $contribution['values'][$contribution['id']]['contribution_status']);
+ $this->assertEquals(100.00, $contribution['values'][$contribution['id']]['total_amount']);
$this->callAPISuccess('Contribution', 'Delete', [
'id' => $contribution['id'],
]);
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
*/
- public function testPaymentWithProcessorWithOddFinancialAccount() {
+ public function testPaymentWithProcessorWithOddFinancialAccount(): void {
$processor = $this->dummyProcessorCreate(['financial_account_id' => 'Deposit Bank Account', 'payment_instrument_id' => 'Cash']);
$processor2 = $this->dummyProcessorCreate(['financial_account_id' => 'Payment Processor Account', 'name' => 'p2', 'payment_instrument_id' => 'EFT']);
$contributionParams = [
*
* @throws \CRM_Core_Exception
*/
- protected function addLocationToEvent($eventID) {
+ protected function addLocationToEvent(int $eventID): void {
$addressParams = [
'name' => 'event place',
'street_address' => 'streety street',
*
* @throws \CRM_Core_Exception
*/
- protected function checkPaymentIsValid($paymentID, $contributionID, $amount = 50) {
+ protected function checkPaymentIsValid(int $paymentID, int $contributionID, $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']);
* @see https://github.com/civicrm/civicrm-core/pull/17688
* @see https://lab.civicrm.org/dev/financial/-/issues/139
*
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
- public function testPaymentCreateTrxnIdAndDates() {
+ public function testPaymentCreateTrxnIdAndDates(): void {
$trxnDate = '2010-01-01 09:00:00';
$trxnID = 'aabbccddeeffggh';
'receive_date' => $originalReceiveDate,
]);
- $payment = $this->callAPISuccess('Payment', 'create', [
+ $this->callAPISuccess('Payment', 'create', [
'total_amount' => 100,
'order_id' => $contributionID,
'trxn_date' => $trxnDate,