Skip to content
Snippets Groups Projects
Commit e7ef5976 authored by mattwire's avatar mattwire
Browse files

Enhance tests to validate financialtrxn params including new 'available_on' field

parent 0b14c6e4
No related branches found
No related tags found
1 merge request!217Implement Stripe Checkout (with support for SEPA and ACH)
......@@ -343,6 +343,32 @@ abstract class CRM_Stripe_BaseTest extends \PHPUnit\Framework\TestCase implement
}
}
/**
* Sugar for checking things on the FinancialTrxn.
*
* @param array $expectations key => value pairs.
* @param int $contributionID
* - if null, use this->contributionID
* - if array, assume it's the result of a contribution.getsingle
* - if int, load that contrib.
*/
protected function checkFinancialTrxn(array $expectations, int $contributionID) {
$this->assertGreaterThan(0, $contributionID);
$latestFinancialTrxn = \Civi\Api4\FinancialTrxn::get(FALSE)
->addSelect('*', 'custom.*')
->addJoin('Contribution AS contribution', 'LEFT', 'EntityFinancialTrxn')
->addWhere('contribution.id', '=', $contributionID)
->addWhere('is_payment', '=', TRUE)
->addOrderBy('id', 'DESC')
->execute()
->first();
foreach ($expectations as $field => $expect) {
$this->assertArrayHasKey($field, $latestFinancialTrxn);
$this->assertEquals($expect, $latestFinancialTrxn[$field], "Expected FinancialTrxn.$field = " . json_encode($expect));
}
}
/**
* Sugar for checking things on the contribution recur.
*/
......
......@@ -73,7 +73,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
]);
$this->assertEquals(TRUE, $success, 'IPN did not return OK');
// Ensure Contribution status is updated to complete and that we now have both invoice ID and charge ID as the transaction ID.
// charge is not yet captured so contribution should remain pending
$this->checkContrib([
'contribution_status_id' => 'Pending',
'trxn_id' => 'ch_mock',
......@@ -336,6 +336,17 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'trxn_id' => 'ch_mock',
'fee_amount' => 11.90
]);
// Check we set some values on the FinancialTrxn (payment)
$this->checkFinancialTrxn([
'Payment_details.available_on' => '2023-06-10 21:05:05',
'fee_amount' => 11.90,
'total_amount' => $this->total,
'order_reference' => 'ch_mock',
'trxn_id' => 'ch_mock'
],
$this->contributionID
);
}
/**
......@@ -734,11 +745,23 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
], TRUE);
// Check the contribution was updated.
$this->checkContrib([
'contribution_status_id' => 'Completed',
'trxn_id' => 'in_mock_2,ch_mock_2',
'fee_amount' => 11.90
], (int) $contrib2['id']);
'contribution_status_id' => 'Completed',
'trxn_id' => 'in_mock_2,ch_mock_2',
'fee_amount' => 11.90
],
(int) $contrib2['id']
);
// Check we set some values on the FinancialTrxn (payment)
$this->checkFinancialTrxn([
'Payment_details.available_on' => '2023-06-10 21:05:05',
'fee_amount' => 11.90,
'total_amount' => $this->total,
'order_reference' => 'in_mock_2',
'trxn_id' => 'ch_mock_2'
],
(int) $contrib2['id']
);
}
/**
* It's possible that the payment_succeeded event comes in before finalized.
......@@ -1222,6 +1245,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'fee' => 1190, /* means $11.90 */
'status' => 'available',
'type' => 'charge',
'available_on' => '1686427505' // 2023-06-10 21:05:05
]);
$this->paymentObject->stripeClient->balanceTransactions = $this->createMock('Stripe\\Service\\BalanceTransactionService');
......@@ -1343,6 +1367,7 @@ class CRM_Stripe_IpnTest extends CRM_Stripe_BaseTest {
'currency' => 'usd',
'exchange_rate' => NULL,
'object' => 'balance_transaction',
'available_on' => '1686427505' // 2023-06-10 21:05:05
]));
$mockRefund = new PropertySpy('Refund', [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment